mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Update web-platform-tests to revision 8a2ceb5f18911302b7a5c1cd2791f4ab50ad4326
This commit is contained in:
parent
462c272380
commit
1f531f66ea
5377 changed files with 174916 additions and 84369 deletions
|
@ -0,0 +1,42 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="./resources/common.js"></script>
|
||||
<script>
|
||||
promise_test(() => {
|
||||
return waitUntilLoadedAndAutofocused().then(() => {
|
||||
assert_equals(document.activeElement, document.getElementById("outer-button"));
|
||||
|
||||
var focusCount = 0;
|
||||
var dlg = document.getElementById("dlg");
|
||||
var input1 = document.getElementById("input1");
|
||||
var input2 = document.getElementById("input2");
|
||||
input2.onfocus = function() { focusCount += 1 };
|
||||
|
||||
var expectedFocusCount = 3;
|
||||
for (i = 0; i < expectedFocusCount; i++) {
|
||||
dlg.show();
|
||||
assert_equals(document.activeElement, input2);
|
||||
input1.focus();
|
||||
assert_equals(document.activeElement,input1);
|
||||
dlg.close();
|
||||
}
|
||||
|
||||
assert_equals(focusCount.toString(), expectedFocusCount.toString());
|
||||
});
|
||||
}, "autofocus is run every time a dialog is opened");
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<button id="outer-button" autofocus></button>
|
||||
<dialog id="dlg">
|
||||
<!-- Unfocusable elements with [autofocus] should be ignored. -->
|
||||
<input autofocus disabled>
|
||||
<textarea autofocus hidden></textarea>
|
||||
<input id="input1"></input>
|
||||
<input id="input2" autofocus></input>
|
||||
</dialog>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,65 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="./resources/common.js"></script>
|
||||
<script>
|
||||
promise_test(() => {
|
||||
return waitUntilLoadedAndAutofocused().then(() => {
|
||||
assert_equals(document.activeElement, document.getElementById("outer-button"));
|
||||
|
||||
var dialog = document.getElementById('dialog');
|
||||
dialog.showModal();
|
||||
|
||||
autofocusButton = document.getElementById('autofocus-button');
|
||||
assert_equals(document.activeElement, autofocusButton);
|
||||
|
||||
anotherButton = document.getElementById('another-button');
|
||||
anotherButton.focus();
|
||||
assert_equals(document.activeElement, anotherButton);
|
||||
|
||||
// Test that recreating layout does not give focus back to a previously autofocused element.
|
||||
autofocusButton.style.display = 'none';
|
||||
document.body.offsetHeight;
|
||||
autofocusButton.style.display = 'block';
|
||||
document.body.offsetHeight;
|
||||
assert_equals(document.activeElement, anotherButton);
|
||||
|
||||
// Test that reinserting does not give focus back to a previously autofocused element.
|
||||
var parentNode = autofocusButton.parentNode;
|
||||
parentNode.removeChild(autofocusButton);
|
||||
document.body.offsetHeight;
|
||||
parentNode.appendChild(autofocusButton);
|
||||
document.body.offsetHeight;
|
||||
assert_equals(document.activeElement, anotherButton);
|
||||
|
||||
dialog.close();
|
||||
// Test that dialog focusing steps run when a dialog is reopened.
|
||||
dialog.showModal();
|
||||
assert_equals(document.activeElement, autofocusButton);
|
||||
dialog.close();
|
||||
});
|
||||
}, "autofocus when a modal dialog is opened");
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<button id="outer-button" autofocus></button>
|
||||
<dialog id="dialog">
|
||||
<button></button>
|
||||
<!-- Unfocusable elements with [autofocus] should be ignored. -->
|
||||
<input autofocus disabled>
|
||||
<textarea autofocus hidden></textarea>
|
||||
<dialog>
|
||||
<button autofocus></button>
|
||||
</dialog>
|
||||
<div>
|
||||
<span>
|
||||
<button id="autofocus-button" autofocus></button>
|
||||
</span>
|
||||
</div>
|
||||
<button id="another-button" autofocus></button>
|
||||
</dialog>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -38,6 +38,9 @@
|
|||
<input id="i82" value="foobar" autofocus>
|
||||
<button id="b8">OK</button>
|
||||
</dialog>
|
||||
<dialog id="d9"></dialog>
|
||||
<dialog id="d10"></dialog>
|
||||
<dialog id="d11"></dialog>
|
||||
<script>
|
||||
var d1 = document.getElementById('d1'),
|
||||
d2 = document.getElementById('d2'),
|
||||
|
@ -47,6 +50,9 @@
|
|||
d6 = document.getElementById('d6'),
|
||||
d7 = document.getElementById('d7'),
|
||||
d8 = document.getElementById('d8'),
|
||||
d9 = document.getElementById('d9'),
|
||||
d10 = document.getElementById('d10'),
|
||||
d11 = document.getElementById('d11'),
|
||||
b0 = document.getElementById('b0'),
|
||||
b1 = document.getElementById('b1'),
|
||||
b3 = document.getElementById('b3'),
|
||||
|
@ -55,9 +61,11 @@
|
|||
|
||||
test(function(){
|
||||
assert_false(d1.open);
|
||||
assert_false(d1.hasAttribute("open"));
|
||||
d1.showModal();
|
||||
this.add_cleanup(function() { d1.close(); });
|
||||
assert_true(d1.open);
|
||||
assert_equals(d1.getAttribute("open"), "");
|
||||
assert_equals(document.activeElement, b1);
|
||||
});
|
||||
|
||||
|
@ -68,6 +76,16 @@
|
|||
});
|
||||
}, "showModal() on a <dialog> that already has an open attribute throws an InvalidStateError exception");
|
||||
|
||||
test(function(){
|
||||
d9.showModal();
|
||||
this.add_cleanup(function() { d9.close(); });
|
||||
assert_true(d9.open);
|
||||
d9.removeAttribute("open");
|
||||
assert_false(d9.open);
|
||||
d9.showModal();
|
||||
assert_true(d9.open);
|
||||
}, "showModal() on a <dialog> after initial showModal() and removing the open attribute");
|
||||
|
||||
test(function(){
|
||||
var d = document.createElement("dialog");
|
||||
assert_throws("INVALID_STATE_ERR", function() {
|
||||
|
@ -114,4 +132,41 @@
|
|||
assert_true(d8.open);
|
||||
assert_equals(document.activeElement, document.getElementById("i82"));
|
||||
}, "opening dialog with multiple focusable children, one having the autofocus attribute");
|
||||
|
||||
test(function(){
|
||||
assert_false(d10.open);
|
||||
assert_false(d11.open);
|
||||
d10.showModal();
|
||||
this.add_cleanup(function() { d10.close(); });
|
||||
d11.showModal();
|
||||
this.add_cleanup(function() { d11.close(); });
|
||||
var rect10 = d10.getBoundingClientRect();
|
||||
var rect11 = d11.getBoundingClientRect();
|
||||
|
||||
// The two <dialog>s are both in top layer, with the same position/size.
|
||||
assert_equals(rect10.left, rect11.left);
|
||||
assert_equals(rect10.top, rect11.top);
|
||||
assert_equals(rect10.width, rect11.width);
|
||||
assert_equals(rect10.height, rect11.height);
|
||||
|
||||
var pointX = rect10.left + rect10.width / 2,
|
||||
pointY = rect10.top + rect10.height / 2;
|
||||
function topElement() {
|
||||
return document.elementFromPoint(pointX, pointY);
|
||||
}
|
||||
|
||||
// d11 was most recently openened, and thus on top.
|
||||
assert_equals(topElement(), d11);
|
||||
|
||||
// Removing the open attribute and running through the showModal() algorithm
|
||||
// again should not promote d10 to the top.
|
||||
d10.removeAttribute("open");
|
||||
assert_equals(topElement(), d11);
|
||||
d10.showModal();
|
||||
assert_equals(topElement(), d11);
|
||||
|
||||
// Closing d11 with close() should cause d10 to be the topmost element.
|
||||
d11.close();
|
||||
assert_equals(topElement(), d10);
|
||||
}, "when opening multiple dialogs, the most recently opened is rendered on top");
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
function waitUntilLoadedAndAutofocused() {
|
||||
return new Promise(function(resolve) {
|
||||
var loaded = false;
|
||||
var autofocused = false;
|
||||
window.addEventListener('load', function() {
|
||||
loaded = true;
|
||||
if (autofocused)
|
||||
resolve();
|
||||
}, false);
|
||||
document.addEventListener('focusin', function() {
|
||||
if (autofocused)
|
||||
return;
|
||||
autofocused = true;
|
||||
if (loaded)
|
||||
resolve();
|
||||
}, false);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue