1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
<!DOCTYPE html>
<meta charset=urf-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<title>Test dialog form submission</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<body>
<dialog id="favDialog">
<form id="dialogForm" method="dialog">
<button id="confirmBtn" value="default">Confirm</button>
<input id="confirmImgBtn" src="./resources/submit.jpg" width="41"
height="41" type="image" alt="Hello">
</form>
<form method="post">
<input id="confirmImgBtn2" src="./resources/submit.jpg" width="41"
formmethod="dialog" height="41" type="image" alt="Hello">
</form>
</dialog>
<script>
promise_test(async (t) => {
const dialog = document.querySelector('dialog');
const button = document.querySelector('button');
t.add_cleanup(() => {
dialog.close();
dialog.returnValue = "";
button.removeAttribute("value");
});
dialog.showModal();
button.click();
assert_false(dialog.open, "dialog should be closed now");
assert_equals(dialog.returnValue, "default", "Return the default value");
}, 'click the form submission button should close the dialog');
promise_test(async (t) => {
const dialog = document.querySelector('dialog');
const button = document.querySelector('button');
t.add_cleanup(() => {
dialog.close();
dialog.returnValue = "";
button.removeAttribute("value");
});
dialog.returnValue = "initial";
dialog.showModal();
button.value = "sushi";
button.click();
assert_false(dialog.open, "dialog should be closed now");
assert_equals(dialog.returnValue, "sushi", "Return the updated value");
}, 'form submission should return correct value');
promise_test(async (t) => {
const dialog = document.querySelector('dialog');
const button = document.querySelector('button');
t.add_cleanup(() => {
dialog.close();
dialog.returnValue = "";
button.removeAttribute("value");
});
dialog.returnValue = "initial";
dialog.showModal();
button.removeAttribute("value");
button.click();
assert_false(dialog.open, "dialog should be closed now");
assert_equals(dialog.returnValue, "initial", "returnValue should not be updated");
}, "returnValue doesn't update when there's no value attribute.");
promise_test(async (t) => {
const dialog = document.querySelector('dialog');
const button = document.querySelector('button');
t.add_cleanup(() => {
dialog.close();
dialog.returnValue = "";
button.removeAttribute("value");
});
dialog.returnValue = "initial";
dialog.showModal();
button.setAttribute("value", "");
button.click();
assert_false(dialog.open, "dialog should be closed now");
assert_equals(dialog.returnValue, "", "returnValue should be updated");
}, "returnValue does update when there's an empty value attribute.");
promise_test(async (t) => {
const dialog = document.querySelector('dialog');
const button = document.querySelector('input');
t.add_cleanup(() => {
dialog.close();
dialog.returnValue = "";
button.removeAttribute("value");
});
dialog.showModal();
let expectedReturnValue = "";
button.addEventListener('click', function(event) {
expectedReturnValue = event.offsetX + "," + event.offsetY;
});
await test_driver.click(button);
assert_false(dialog.open, "dialog should be closed now");
assert_not_equals(dialog.returnValue, "", "returnValue shouldn't be empty string");
assert_equals(dialog.returnValue, expectedReturnValue, "returnValue should be the offsets of the click");
}, "input image button should return the coordinates");
promise_test(async (t) => {
const dialog = document.querySelector('dialog');
t.add_cleanup(() => {
dialog.close();
dialog.returnValue = "";
button.removeAttribute("value");
});
dialog.showModal();
const button = document.getElementById('confirmImgBtn2');
await test_driver.click(button);
assert_false(dialog.open, "dialog should be closed now");
}, "formmethod attribute should use dialog form submission");
promise_test(async (t) => {
const dialog = document.querySelector('dialog');
t.add_cleanup(() => {
dialog.close();
dialog.returnValue = "";
button.removeAttribute("value");
});
dialog.returnValue = "";
dialog.showModal();
const button = document.querySelector('button');
button.value = "sushi";
const dialogForm = document.getElementById('dialogForm');
dialogForm.onsubmit = function() {
dialog.close();
}
button.click();
assert_false(dialog.open, "dialog should be closed now");
// If the submission request got processed, the returnValue should change
// to "sushi" because that's the value of the submitter
assert_equals(dialog.returnValue, "", "dialog's returnValue remains the same");
}, "closing the dialog while submitting should stop the submission");
promise_test(async (t) => {
const dialog = document.querySelector('dialog');
t.add_cleanup(() => {
dialog.close();
dialog.returnValue = "";
button.removeAttribute("value");
});
dialog.returnValue = undefined;
dialog.showModal();
let submitEvent = false;
const dialogForm = document.getElementById('dialogForm');
dialogForm.onsubmit = function() {
submitEvent = true;
assert_false(dialog.open, "dialog should be closed");
assert_equals(dialog.returnValue, "", "dialog's returnValue remains the same");
};
const button = document.querySelector('button');
button.value = "sushi";
button.onclick = function() {
dialogForm.submit();
assert_false(dialog.open, "dialog should be closed now");
// The returnValue should be "" because there is no submitter
assert_equals(dialog.returnValue, "", "returnValue shouldn be empty string");
};
button.click();
assert_true(submitEvent, "Should have submit event");
assert_false(dialog.open, "dialog should be closed");
assert_equals(dialog.returnValue, "", "dialog's returnValue remains the same");
}, "calling form.submit() in click handler of submit button should start the submission synchronously");
</script>
</body>
|