|
11 | 11 |
|
12 | 12 | <script>
|
13 | 13 | const dialog = document.querySelector('dialog');
|
14 |
| -function openDialog(modal) { |
| 14 | +function openDialog(openMethod) { |
15 | 15 | assert_false(dialog.open);
|
16 |
| - if (modal) { |
17 |
| - dialog.showModal(); |
18 |
| - } else { |
19 |
| - dialog.show(); |
| 16 | + assert_false(dialog.matches(':open')); |
| 17 | + switch (openMethod) { |
| 18 | + case 'modeless': |
| 19 | + dialog.show(); |
| 20 | + break; |
| 21 | + case 'modal': |
| 22 | + dialog.showModal(); |
| 23 | + break; |
| 24 | + case 'open': |
| 25 | + dialog.open = true; |
| 26 | + break; |
| 27 | + default: |
| 28 | + assert_unreached('Unknown open method'); |
20 | 29 | }
|
21 | 30 | assert_true(dialog.open);
|
22 |
| - assert_equals(dialog.matches(':modal'),modal); |
| 31 | + assert_true(dialog.matches(':open')); |
| 32 | + assert_equals(dialog.matches(':modal'),openMethod === 'modal'); |
23 | 33 | }
|
24 | 34 | function getSignal(t) {
|
25 | 35 | const controller = new AbortController();
|
|
43 | 53 | return getSignal(t);
|
44 | 54 | }
|
45 | 55 |
|
46 |
| -[false,true].forEach(modal => { |
| 56 | +['modeless','modal','open'].forEach(openMethod => { |
47 | 57 | [null,'any','closedrequest','none'].forEach(closedby => {
|
48 |
| - const testDescription = `for ${modal ? "modal" : "modeless"} dialog with closedby=${closedby}`; |
| 58 | + const testDescription = `for ${openMethod} dialog with closedby=${closedby}`; |
49 | 59 | promise_test(async (t) => {
|
50 | 60 | await setup(t,closedby);
|
51 |
| - openDialog(modal); |
| 61 | + openDialog(openMethod); |
52 | 62 | dialog.requestClose();
|
53 | 63 | assert_false(dialog.open);
|
| 64 | + assert_false(dialog.matches(':open')); |
54 | 65 | },`requestClose basic behavior ${testDescription}`);
|
55 | 66 |
|
56 | 67 | promise_test(async (t) => {
|
57 | 68 | const signal = await setup(t,closedby);
|
58 | 69 | let events = [];
|
59 | 70 | dialog.addEventListener('cancel',() => events.push('cancel'),{signal});
|
60 | 71 | dialog.addEventListener('close',() => events.push('close'),{signal});
|
61 |
| - openDialog(modal); |
| 72 | + openDialog(openMethod); |
62 | 73 | assert_array_equals(events,[]);
|
63 | 74 | dialog.requestClose();
|
64 | 75 | assert_false(dialog.open);
|
| 76 | + assert_false(dialog.matches(':open')); |
65 | 77 | assert_array_equals(events,['cancel'],'close is scheduled');
|
66 | 78 | await new Promise(resolve => requestAnimationFrame(resolve));
|
67 | 79 | assert_array_equals(events,['cancel','close']);
|
|
72 | 84 | let events = [];
|
73 | 85 | dialog.addEventListener('cancel',() => events.push('cancel'),{signal});
|
74 | 86 | dialog.addEventListener('close',() => events.push('close'),{signal});
|
75 |
| - openDialog(modal); |
| 87 | + openDialog(openMethod); |
76 | 88 | dialog.setAttribute('closedby',closedby);
|
77 | 89 | assert_array_equals(events,[]);
|
78 | 90 | dialog.requestClose();
|
79 | 91 | assert_false(dialog.open,'Adding closedby after dialog is open');
|
| 92 | + assert_false(dialog.matches(':open')); |
80 | 93 | assert_array_equals(events,['cancel']);
|
81 | 94 | events=[];
|
82 |
| - openDialog(modal); |
| 95 | + openDialog(openMethod); |
83 | 96 | dialog.removeAttribute('closedby');
|
84 | 97 | assert_array_equals(events,[]);
|
85 | 98 | dialog.requestClose();
|
|
96 | 109 | e.preventDefault();
|
97 | 110 | }
|
98 | 111 | },{signal});
|
99 |
| - openDialog(modal); |
| 112 | + openDialog(openMethod); |
100 | 113 | dialog.requestClose();
|
101 | 114 | assert_true(dialog.open,'cancel event was cancelled - dialog shouldn\'t close');
|
| 115 | + assert_true(dialog.matches(':open')); |
102 | 116 | shouldPreventDefault = false;
|
103 | 117 | dialog.requestClose();
|
104 | 118 | assert_false(dialog.open,'cancel event was not cancelled - dialog should now close');
|
| 119 | + assert_false(dialog.matches(':open')); |
105 | 120 | },`requestClose can be cancelled ${testDescription}`);
|
106 | 121 |
|
107 | 122 | promise_test(async (t) => {
|
108 | 123 | const signal = await setup(t,closedby);
|
109 | 124 | dialog.addEventListener('cancel',(e) => e.preventDefault(),{signal});
|
110 |
| - openDialog(modal); |
| 125 | + openDialog(openMethod); |
111 | 126 | // No user activation here.
|
112 | 127 | dialog.requestClose();
|
113 | 128 | dialog.requestClose();
|
114 | 129 | dialog.requestClose();
|
115 | 130 | assert_true(dialog.open,'cancel event was cancelled - dialog shouldn\'t close');
|
| 131 | + assert_true(dialog.matches(':open')); |
116 | 132 | },`requestClose avoids abuse prevention logic ${testDescription}`);
|
117 | 133 |
|
118 | 134 | promise_test(async (t) => {
|
119 | 135 | await setup(t,closedby);
|
120 |
| - openDialog(modal); |
| 136 | + openDialog(openMethod); |
121 | 137 | assert_equals(dialog.returnValue,'','Return value starts out empty');
|
122 | 138 | const returnValue = 'The return value';
|
123 | 139 | dialog.requestClose(returnValue);
|
124 | 140 | assert_false(dialog.open);
|
| 141 | + assert_false(dialog.matches(':open')); |
125 | 142 | assert_equals(dialog.returnValue,returnValue,'Return value should be set');
|
126 | 143 | dialog.show();
|
127 | 144 | dialog.close();
|
|
134 | 151 | promise_test(async (t) => {
|
135 | 152 | await setup(t,closedby);
|
136 | 153 | dialog.addEventListener('cancel',(e) => e.preventDefault(),{once:true});
|
137 |
| - openDialog(modal); |
| 154 | + openDialog(openMethod); |
138 | 155 | dialog.returnValue = 'foo';
|
139 | 156 | assert_equals(dialog.returnValue,'foo');
|
140 | 157 | dialog.requestClose('This should not get saved');
|
141 | 158 | assert_true(dialog.open,'cancelled');
|
| 159 | + assert_true(dialog.matches(':open')); |
142 | 160 | assert_equals(dialog.returnValue,'foo','Return value should not be changed');
|
143 | 161 | },`requestClose(returnValue) doesn't change returnvalue when cancelled ${testDescription}`);
|
144 | 162 | }
|
|
0 commit comments