-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that window.customElements is per global, not per-document
Closes whatwg/html#2578.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"use strict"; | ||
|
||
// For now this only has per-Window tests, but we could expand it to also test per-Document | ||
|
||
window.testIsPerWindow = propertyName => { | ||
test(t => { | ||
const iframe = document.createElement("iframe"); | ||
document.body.appendChild(iframe); | ||
const frame = iframe.contentWindow; | ||
|
||
const before = frame[propertyName]; | ||
assert_true(before !== undefined && before !== null, `window.${propertyName} must be implemented`); | ||
|
||
iframe.remove(); | ||
|
||
const after = frame[propertyName]; | ||
assert_equals(after, before); | ||
}, `Discarding the browsing context must not change window.${propertyName}`); | ||
|
||
async_test(t => { | ||
const iframe = document.createElement("iframe"); | ||
document.body.appendChild(iframe); | ||
const frame = iframe.contentWindow; | ||
|
||
const before = frame[propertyName]; | ||
assert_true(before !== undefined && before !== null, `window.${propertyName} must be implemented`); | ||
|
||
// Note: cannot use step_func_done for this because it might be called twice, per the below comment. | ||
iframe.onload = t.step_func(() => { | ||
if (frame.location.href === "about:blank") { | ||
// Browsers are not reliable on whether about:blank fires the load event; see | ||
// https://github.com/whatwg/html/issues/490 | ||
return; | ||
} | ||
|
||
const after = frame[propertyName]; | ||
assert_equals(after, before); | ||
t.done(); | ||
}); | ||
|
||
iframe.src = "/common/blank.html"; | ||
}, `Navigating from the initial about:blank must not replace window.${propertyName}`); | ||
|
||
// Note: document.open()'s spec doesn't match most browsers; see https://github.com/whatwg/html/issues/1698. | ||
// However, as explained in https://github.com/whatwg/html/issues/1698#issuecomment-298748641, even an updated spec | ||
// will probably still reset Window-associated properties. | ||
async_test(t => { | ||
const iframe = document.createElement("iframe"); | ||
|
||
iframe.onload = t.step_func_done(() => { | ||
const frame = iframe.contentWindow; | ||
const before = frame[propertyName]; | ||
assert_true(before !== undefined && before !== null, `window.${propertyName} must be implemented`); | ||
|
||
frame.document.open(); | ||
|
||
const after = frame[propertyName]; | ||
assert_not_equals(after, before); | ||
}); | ||
|
||
iframe.src = "/common/blank.html"; | ||
document.body.appendChild(iframe); | ||
}, `document.open() must replace window.${propertyName}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Custom Elements: CustomElementRegistry is per global</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/#custom-elements-api"> | ||
<link rel="author" title="Domenic Denicola" href="mailto:[email protected]"> | ||
<script src="/common/object-association.js"></script> | ||
|
||
<body> | ||
<script> | ||
"use strict"; | ||
testIsPerWindow("customElements"); | ||
</script> |