4 <script src=
"../../../resources/js-test.js"></script>
6 /* Position on an integer offset to avoid rounding errors during the test to click on a coordinate. */
16 <form method=
"dialog">
17 <input id=
"outer-submit-empty-string" type=
"submit" value=
"">
20 <form method=
"dialog">
21 <input id=
"inner-submit-yes" type=
"submit" value=
"Yes">
22 <input id=
"inner-submit-no" type=
"submit" value=
"No">
23 <input id=
"image" type=
"image"
24 src=
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANcAAACuCAIAAAAqMg/rAAAAAXNSR0IArs4c6QAAAU9JREFUeNrt0jERAAAIxDDAv+dHAxNLIqHXTlLwaiTAheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSF4EJcCC7EheBCXAguxIXgQlwILsSFEuBCcCEuBBfiQnAhLgQX4kJwIS4EF+JCcCEuBBfiQnAhLgQX4kJwIS4EF+JCcCEuBBfiQnAhLgQX4kJwIS4EF+JCcCEuBBfiQnAhLoSDBZXqBFnkRyeqAAAAAElFTkSuQmCC">
28 <input id=
"outer-submit-no-value" formmethod=
"dialog" type=
"submit">
31 <dialog id=
"host"></dialog>
32 <form method=
"dialog">
33 <input id=
"no-dialog-ancestor-1" type=
"submit" value=
"Clicking me shouldn't submit">
34 <input id=
"no-dialog-ancestor-2" formmethod=
"dialog" type=
"submit" value=
"I also don't submit">
36 <form id=
"form_without_submit_button" method=
"dialog">
39 window
.jsTestIsAsync
= true;
41 function openDialogs()
43 var dialogs
= document
.querySelectorAll('dialog');
44 for (var i
= 0; i
< dialogs
.length
; ++i
) {
45 dialogs
[i
].returnValue
= 'init';
50 function closeDialogs()
52 var dialogs
= document
.querySelectorAll('dialog');
53 for (var i
= 0; i
< dialogs
.length
; ++i
) {
59 function checkDialogs(button
, targetDialog
, expectedResult
)
61 dialogs
= document
.querySelectorAll('dialog');
62 for (var i
= 0; i
< dialogs
.length
; ++i
) {
64 if (dialog
== targetDialog
)
65 shouldBeFalse(dialog
.id
+ '; dialog.open');
67 shouldBeTrue(dialog
.id
+ '; dialog.open');
69 if (dialog
== targetDialog
&& expectedResult
!== null)
70 shouldBeEqualToString(dialog
.id
+ '; dialog.returnValue', expectedResult
);
72 shouldBeEqualToString(dialog
.id
+ '; dialog.returnValue', 'init');
78 return document
.getElementById(id
);
81 function testDialogWithoutSubmitButton()
83 debug('Submitting a form without submit button (this should not crash)');
84 form
= $('form_without_submit_button');
89 function testClosedDialog()
91 debug('Clicking a button in a closed dialog');
93 button
= $('outer-submit-empty-string');
95 dialog
.returnValue
= 'init';
97 shouldBeFalse('dialog.open');
98 shouldBeEqualToString('dialog.returnValue', 'init');
102 function testClickMethodOnImageButton()
104 debug('Activating an image button by click()');
106 $('inner').addEventListener('close', testClickMethodOnImageButtonClose
);
110 function testClickMethodOnImageButtonClose()
112 var image
= $('image');
113 var inner
= $('inner');
114 inner
.removeEventListener('close', testClickMethodOnImageButtonClose
);
115 checkDialogs(image
, inner
, '0,0');
117 setTimeout(testKeyboardActivatingImageButton
, 0);
120 function testKeyboardActivatingImageButton()
122 debug('Activating an image button by keyboard');
124 $('inner').addEventListener('close', testKeyboardActivatingImageButtonClose
);
125 if (!window
.eventSender
) {
126 debug('This test requires eventSender.');
130 eventSender
.keyDown(' ');
133 function testKeyboardActivatingImageButtonClose()
135 var image
= $('image');
136 var inner
= $('inner');
138 inner
.removeEventListener('close', testKeyboardActivatingImageButtonClose
);
139 checkDialogs(image
, inner
, '0,0');
141 setTimeout(testClickingImageButton
, 0);
144 function testClickingImageButton()
146 debug('Clicking an image button');
148 var image
= $('image');
149 var inner
= $('inner');
150 var x
= image
.getBoundingClientRect().left
+ 10;
151 var y
= image
.getBoundingClientRect().top
+ 5;
153 inner
.addEventListener('close', testClickingImageButtonClose
);
154 if (!window
.eventSender
) {
155 debug('This test requires eventSender');
158 eventSender
.mouseMoveTo(x
, y
);
159 eventSender
.mouseDown();
160 eventSender
.mouseUp();
163 function testClickingImageButtonClose()
165 var image
= $('image');
166 var inner
= $('inner');
168 inner
.removeEventListener('close', testClickingImageButtonClose
);
169 checkDialogs(image
, inner
, '10,5');
175 description('Tests form submission with method=dialog');
176 var host
= document
.querySelector('#host');
177 var shadowRoot
= host
.createShadowRoot();
178 shadowRoot
.innerHTML
=
179 '<form method="dialog">' +
180 ' <input id="host-submit-yes" type=submit value=Yes>' +
184 { button
: $('outer-submit-empty-string'), targetDialog
: $('outer'), result
: '' },
185 { button
: $('outer-submit-no-value'), targetDialog
: $('outer'), result
: null },
186 { button
: $('inner-submit-yes'), targetDialog
: $('inner'), result
: 'Yes' },
187 { button
: $('inner-submit-no'), targetDialog
: $('inner'), result
: 'No' },
188 { button
: $('no-dialog-ancestor-1'), targetDialog
: null },
189 { button
: $('no-dialog-ancestor-2'), targetDialog
: null },
190 { button
: host
.shadowRoot
.querySelector('#host-submit-yes'), targetDialog
: $('host'), result
: 'Yes' }
193 for (var i
= 0; i
< tests
.length
; ++i
) {
194 var button
= tests
[i
].button
;
196 debug('Clicking ' + button
.id
);
198 checkDialogs(button
, tests
[i
].targetDialog
, tests
[i
].result
);
202 testDialogWithoutSubmitButton();
206 // The tests involving image button seem to need to be async.
207 testClickMethodOnImageButton();