mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Update web-platform-tests to revision 7c50c216081d6ea3c9afe553ee7b64534020a1b2
This commit is contained in:
parent
5063ac465b
commit
f9ee2396ab
254 changed files with 2043 additions and 1285 deletions
|
@ -0,0 +1,98 @@
|
|||
function assertOpenIsEffective(doc, initialNodeCount) {
|
||||
assert_equals(doc.childNodes.length, initialNodeCount);
|
||||
|
||||
// Test direct document.open() call.
|
||||
assert_equals(doc.open(), doc);
|
||||
assert_equals(doc.childNodes.length, 0, "after open: no nodes in document");
|
||||
doc.write("<!DOCTYPE html>");
|
||||
assert_equals(doc.childNodes.length, 1, "after write: doctype node in document");
|
||||
doc.close();
|
||||
assert_equals(doc.childNodes.length, 2, "after parser close: doctype node and an html element in document");
|
||||
|
||||
// Test implicit document.open() call through write(). Since we called
|
||||
// doc.close() above, which sets the insertion point of the parser to
|
||||
// undefined, document.write() will run the document open steps.
|
||||
doc.write();
|
||||
assert_equals(doc.childNodes.length, 0, "after implicit open: no nodes in document");
|
||||
doc.write("<!DOCTYPE html>");
|
||||
assert_equals(doc.childNodes.length, 1, "after write: doctype node in document");
|
||||
doc.close();
|
||||
assert_equals(doc.childNodes.length, 2, "after parser close: doctype node and an html element in document");
|
||||
}
|
||||
|
||||
test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe"));
|
||||
t.add_cleanup(() => frame.remove());
|
||||
assertOpenIsEffective(frame.contentDocument, 1);
|
||||
}, "document.open() removes the document's children (fully active document)");
|
||||
|
||||
async_test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe"));
|
||||
t.add_cleanup(() => frame.remove());
|
||||
frame.onload = t.step_func(() => {
|
||||
const childFrame = frame.contentDocument.querySelector("iframe");
|
||||
const childDoc = childFrame.contentDocument;
|
||||
const childWin = childFrame.contentWindow;
|
||||
|
||||
// Right now childDoc is still fully active.
|
||||
|
||||
frame.onload = t.step_func_done(() => {
|
||||
// Now childDoc is still active but no longer fully active.
|
||||
assertOpenIsEffective(childDoc, 1);
|
||||
});
|
||||
frame.src = "/common/blank.html";
|
||||
});
|
||||
frame.src = "resources/page-with-frame.html";
|
||||
}, "document.open() removes the document's children (active but not fully active document)");
|
||||
|
||||
test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe"));
|
||||
const doc = frame.contentDocument;
|
||||
|
||||
// Right now the frame is connected and it has an active document.
|
||||
frame.remove();
|
||||
|
||||
// Now the frame is no longer connected. Its document is no longer active.
|
||||
assertOpenIsEffective(doc, 1);
|
||||
}, "document.open() removes the document's children (non-active document with an associated Window object; frame is removed)");
|
||||
|
||||
async_test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe"));
|
||||
t.add_cleanup(() => frame.remove());
|
||||
frame.src = "resources/dummy.html";
|
||||
|
||||
frame.onload = t.step_func(() => {
|
||||
const firstDocument = frame.contentDocument;
|
||||
// Right now the frame is connected and it has an active document.
|
||||
|
||||
frame.onload = t.step_func_done(() => {
|
||||
// Now even though the frame is still connected, its document is no
|
||||
// longer active.
|
||||
assert_not_equals(frame.contentDocument, firstDocument);
|
||||
assertOpenIsEffective(firstDocument, 2);
|
||||
});
|
||||
|
||||
frame.src = "/common/blank.html";
|
||||
});
|
||||
}, "document.open() removes the document's children (non-active document with an associated Window object; navigated away)");
|
||||
|
||||
test(t => {
|
||||
const doc = document.implementation.createHTMLDocument();
|
||||
assertOpenIsEffective(doc, 2);
|
||||
}, "document.open() removes the document's children (non-active document without an associated Window object; createHTMLDocument)");
|
||||
|
||||
test(t => {
|
||||
const doc = new DOMParser().parseFromString("", "text/html");
|
||||
assertOpenIsEffective(doc, 1);
|
||||
}, "document.open() removes the document's children (non-active document without an associated Window object; DOMParser)");
|
||||
|
||||
async_test(t => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onload = t.step_func_done(() => {
|
||||
assert_equals(xhr.status, 200);
|
||||
assertOpenIsEffective(xhr.responseXML, 2);
|
||||
});
|
||||
xhr.responseType = "document";
|
||||
xhr.open("GET", "resources/dummy.html");
|
||||
xhr.send();
|
||||
}, "document.open() removes the document's children (non-active document without an associated Window object; XMLHttpRequest)");
|
|
@ -1,3 +1,7 @@
|
|||
// Many of the active-related test cases in this file came from
|
||||
// active.window.js. However, we cannot test the "navigated away" non-active
|
||||
// case right now due to https://github.com/whatwg/html/issues/3997.
|
||||
|
||||
test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe")),
|
||||
body = frame.contentDocument.body;
|
||||
|
@ -36,6 +40,130 @@ test(t => {
|
|||
frame.contentDocument.close();
|
||||
}, "Standard event listeners are to be removed from Window");
|
||||
|
||||
async_test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe"));
|
||||
t.add_cleanup(() => frame.remove());
|
||||
frame.onload = t.step_func(() => {
|
||||
const childFrame = frame.contentDocument.querySelector("iframe");
|
||||
const childWin = childFrame.contentWindow;
|
||||
const childDoc = childFrame.contentDocument;
|
||||
const childBody = childDoc.body;
|
||||
|
||||
// Right now childDoc is still fully active.
|
||||
|
||||
frame.onload = t.step_func_done(() => {
|
||||
// Focus on the current window so that the frame's window is blurred.
|
||||
window.focus();
|
||||
// Now childDoc is still active but no longer fully active.
|
||||
childWin.addEventListener("focus", t.unreached_func("window event listener not removed"));
|
||||
childBody.onfocus = t.unreached_func("body event listener not removed");
|
||||
|
||||
childDoc.open();
|
||||
assert_equals(childBody.onfocus, null);
|
||||
|
||||
// Now try to fire the focus event two different ways.
|
||||
childWin.focus();
|
||||
const focusEvent = new FocusEvent("focus");
|
||||
childWin.dispatchEvent(focusEvent);
|
||||
childDoc.close();
|
||||
});
|
||||
frame.src = "/common/blank.html";
|
||||
});
|
||||
frame.src = "resources/page-with-frame.html";
|
||||
}, "Standard event listeners are to be removed from Window for an active but not fully active document");
|
||||
|
||||
test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe"));
|
||||
const win = frame.contentWindow;
|
||||
const doc = frame.contentDocument;
|
||||
const body = doc.body;
|
||||
|
||||
// Right now the frame is connected and it has an active document.
|
||||
frame.remove();
|
||||
|
||||
win.addEventListener("focus", t.unreached_func("window event listener not removed"));
|
||||
body.onfocus = t.unreached_func("body event listener not removed");
|
||||
doc.open();
|
||||
assert_equals(body.onfocus, null);
|
||||
|
||||
// Now try to fire the focus event two different ways.
|
||||
win.focus();
|
||||
const focusEvent = new FocusEvent("focus");
|
||||
win.dispatchEvent(focusEvent);
|
||||
doc.close();
|
||||
}, "Standard event listeners are to be removed from Window for a non-active document that is the associated Document of a Window (frame is removed)");
|
||||
|
||||
test(t => {
|
||||
let winHappened = 0;
|
||||
const winListener = t.step_func(() => { winHappened++; });
|
||||
window.addEventListener("focus", winListener);
|
||||
t.add_cleanup(() => { window.removeEventListener("focus", winListener); });
|
||||
|
||||
let bodyHappened = 0;
|
||||
const bodyListener = t.step_func(() => { bodyHappened++; });
|
||||
document.body.onfocus = bodyListener;
|
||||
t.add_cleanup(() => { document.body.onfocus = null; });
|
||||
|
||||
const doc = document.implementation.createHTMLDocument();
|
||||
doc.open();
|
||||
|
||||
const focusEvent = new FocusEvent("focus");
|
||||
window.dispatchEvent(focusEvent);
|
||||
|
||||
assert_equals(winHappened, 1);
|
||||
assert_equals(bodyHappened, 1);
|
||||
}, "Standard event listeners are NOT to be removed from Window for a Window-less document (createHTMLDocument)");
|
||||
|
||||
test(t => {
|
||||
let winHappened = 0;
|
||||
const winListener = t.step_func(() => { winHappened++; });
|
||||
window.addEventListener("focus", winListener);
|
||||
t.add_cleanup(() => { window.removeEventListener("focus", winListener); });
|
||||
|
||||
let bodyHappened = 0;
|
||||
const bodyListener = t.step_func(() => { bodyHappened++; });
|
||||
document.body.onfocus = bodyListener;
|
||||
t.add_cleanup(() => { document.body.onfocus = null; });
|
||||
|
||||
const doc = new DOMParser().parseFromString("", "text/html");
|
||||
doc.open();
|
||||
|
||||
const focusEvent = new FocusEvent("focus");
|
||||
window.dispatchEvent(focusEvent);
|
||||
|
||||
assert_equals(winHappened, 1);
|
||||
assert_equals(bodyHappened, 1);
|
||||
}, "Standard event listeners are NOT to be removed from Window for a Window-less document (DOMParser)");
|
||||
|
||||
async_test(t => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onload = t.step_func_done(() => {
|
||||
assert_equals(xhr.status, 200);
|
||||
const doc = xhr.responseXML;
|
||||
|
||||
let winHappened = 0;
|
||||
const winListener = t.step_func(() => { winHappened++; });
|
||||
window.addEventListener("focus", winListener);
|
||||
t.add_cleanup(() => { window.removeEventListener("focus", winListener); });
|
||||
|
||||
let bodyHappened = 0;
|
||||
const bodyListener = t.step_func(() => { bodyHappened++; });
|
||||
document.body.onfocus = bodyListener;
|
||||
t.add_cleanup(() => { document.body.onfocus = null; });
|
||||
|
||||
doc.open();
|
||||
|
||||
const focusEvent = new FocusEvent("focus");
|
||||
window.dispatchEvent(focusEvent);
|
||||
|
||||
assert_equals(winHappened, 1);
|
||||
assert_equals(bodyHappened, 1);
|
||||
});
|
||||
xhr.responseType = "document";
|
||||
xhr.open("GET", "resources/dummy.html");
|
||||
xhr.send();
|
||||
}, "Standard event listeners are NOT to be removed from Window for a Window-less document (XMLHttpRequest)");
|
||||
|
||||
test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe"));
|
||||
t.add_cleanup(() => frame.remove());
|
||||
|
@ -45,6 +173,76 @@ test(t => {
|
|||
frame.contentDocument.close();
|
||||
}, "Custom event listeners are to be removed from Window");
|
||||
|
||||
async_test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe"));
|
||||
t.add_cleanup(() => frame.remove());
|
||||
frame.onload = t.step_func(() => {
|
||||
const childFrame = frame.contentDocument.querySelector("iframe");
|
||||
const childDoc = childFrame.contentDocument;
|
||||
const childWin = childFrame.contentWindow;
|
||||
|
||||
// Right now childDoc is still fully active.
|
||||
|
||||
frame.onload = t.step_func_done(() => {
|
||||
// Now childDoc is still active but no longer fully active.
|
||||
childWin.addEventListener("x", t.unreached_func("window event listener not removed"));
|
||||
childDoc.open();
|
||||
childWin.dispatchEvent(new Event("x"));
|
||||
childDoc.close();
|
||||
});
|
||||
frame.src = "/common/blank.html";
|
||||
});
|
||||
frame.src = "resources/page-with-frame.html";
|
||||
}, "Custom event listeners are to be removed from Window for an active but not fully active document");
|
||||
|
||||
test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe"));
|
||||
const win = frame.contentWindow;
|
||||
const doc = frame.contentDocument;
|
||||
|
||||
// Right now the frame is connected and it has an active document.
|
||||
frame.remove();
|
||||
|
||||
win.addEventListener("x", t.unreached_func("window event listener not removed"));
|
||||
doc.open();
|
||||
win.dispatchEvent(new Event("x"));
|
||||
doc.close();
|
||||
}, "Custom event listeners are to be removed from Window for a non-active document that is the associated Document of a Window (frame is removed)");
|
||||
|
||||
test(t => {
|
||||
const doc = document.implementation.createHTMLDocument();
|
||||
let happened = false;
|
||||
window.addEventListener("createHTMLDocumentTest", t.step_func(() => { happened = true; }));
|
||||
doc.open();
|
||||
window.dispatchEvent(new Event("createHTMLDocumentTest"));
|
||||
assert_true(happened);
|
||||
}, "Custom event listeners are NOT to be removed from Window for a Window-less document (createHTMLDocument)");
|
||||
|
||||
test(t => {
|
||||
const doc = new DOMParser().parseFromString("", "text/html");
|
||||
let happened = false;
|
||||
window.addEventListener("DOMParserTest", t.step_func(() => { happened = true; }));
|
||||
doc.open();
|
||||
window.dispatchEvent(new Event("DOMParserTest"));
|
||||
assert_true(happened);
|
||||
}, "Custom event listeners are NOT to be removed from Window for a Window-less document (DOMParser)");
|
||||
|
||||
async_test(t => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onload = t.step_func_done(() => {
|
||||
assert_equals(xhr.status, 200);
|
||||
const doc = xhr.responseXML;
|
||||
let happened = false;
|
||||
window.addEventListener("XHRTest", t.step_func(() => { happened = true; }));
|
||||
doc.open();
|
||||
window.dispatchEvent(new Event("XHRTest"));
|
||||
assert_true(happened);
|
||||
});
|
||||
xhr.responseType = "document";
|
||||
xhr.open("GET", "resources/dummy.html");
|
||||
xhr.send();
|
||||
}, "Custom event listeners are NOT to be removed from Window for a Window-less document (XMLHttpRequest)");
|
||||
|
||||
test(t => {
|
||||
const frame = document.body.appendChild(document.createElement("iframe")),
|
||||
body = frame.contentDocument.body;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<iframe src="/common/blank.html"></iframe>
|
Loading…
Add table
Add a link
Reference in a new issue