Skip to content

Commit

Permalink
Factor out common test helper for tied-to-window
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed May 1, 2017
1 parent 80eda53 commit 8e8d41b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 41 deletions.
61 changes: 61 additions & 0 deletions common/object-association.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"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`);

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}`);

async_test(t => {
const iframe = document.createElement("iframe");

iframe.onload = t.step_func(() => {
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);
t.done();
});

iframe.src = "/common/blank.html";
document.body.appendChild(iframe);
}, `document.open() must replace window.${propertyName}`);
};
43 changes: 2 additions & 41 deletions custom-elements/custom-element-registry/per-global.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,11 @@
<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:d@domenic.me">
<script src="/common/object-association.js"></script>

<iframe id="blank-iframe"></iframe>

<script>
"use strict";

async_test(t => {
const iframe = document.querySelector("#blank-iframe");
const frame = iframe.contentWindow;

const ceBefore = frame.customElements;
assert_true(typeof ceBefore === "object" && ceBefore !== null, "window.customElements must be implemented");

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 ceAfter = frame.customElements;
assert_equals(ceAfter, ceBefore);
t.done();
});

iframe.src = "/common/blank.html";
}, "Navigating from the initial about:blank must not replace the CustomElementRegistry");

async_test(t => {
const iframe = document.createElement("iframe");

iframe.onload = t.step_func(() => {
const frame = iframe.contentWindow;
const ceBefore = frame.customElements;
assert_true(typeof ceBefore === "object" && ceBefore !== null, "window.customElements must be implemented");

frame.document.open();

const ceAfter = frame.customElements;
assert_not_equals(ceAfter, ceBefore);
t.done();
});

iframe.src = "/common/blank.html";
document.body.appendChild(iframe);
}, "document.open() must replace the CustomElementRegistry");
testIsPerWindow("customElements");
</script>

0 comments on commit 8e8d41b

Please sign in to comment.