From 55ec2da2291b670e4343bdb7a960fce0a073dc9c Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 7 Nov 2016 15:59:48 -0500 Subject: [PATCH] Update tests for subtle ordering issues --- ...document-open-inside-domcontentloaded.html | 80 +++++++++++++++++++ .../document-promises.html | 18 ++++- 2 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 html/dom/documents/resource-metadata-management/document-promises-with-document-open-inside-domcontentloaded.html diff --git a/html/dom/documents/resource-metadata-management/document-promises-with-document-open-inside-domcontentloaded.html b/html/dom/documents/resource-metadata-management/document-promises-with-document-open-inside-domcontentloaded.html new file mode 100644 index 00000000000000..edc69ead8287ba --- /dev/null +++ b/html/dom/documents/resource-metadata-management/document-promises-with-document-open-inside-domcontentloaded.html @@ -0,0 +1,80 @@ + + +document.interactive, document.contentLoaded, and document.loaded when document.open() happens inside DOMContentLoaded + + + + + + + + + + + + diff --git a/html/dom/documents/resource-metadata-management/document-promises.html b/html/dom/documents/resource-metadata-management/document-promises.html index 6ebb58795bf90b..4e33007f33c1c4 100644 --- a/html/dom/documents/resource-metadata-management/document-promises.html +++ b/html/dom/documents/resource-metadata-management/document-promises.html @@ -13,6 +13,7 @@ let onDomContentLoadedFired = false; let onLoadFired = false; +const readyStateChanges = []; let interactiveFulfilled = false; let contentLoadedFulfilled = false; @@ -21,6 +22,10 @@ let interactiveAssertions, contentLoadedAssertions, loadedAssertions; test(() => { + document.addEventListener("readystatechange", () => { + readyStateChanges.push(document.readyState); + }); + document.addEventListener("DOMContentLoaded", () => { onDomContentLoadedFired = true; }); @@ -30,7 +35,8 @@ }); // A note on timing: - // The event handler function must execute before the promise fulfillment callback does, because the sequence goes: + // The readystatechange event handler function must execute before the promise fulfillment callback does, because the + // sequence goes: // - UA code resolves the promise, thus enqueuing a microtask to call the onFulfilled // - UA code fires an event // - Eventually this uses Web IDL to invoke the callback @@ -42,6 +48,8 @@ interactiveFulfilled = true; assert_equals(value, undefined, "The document.interactive promise must fulfill with undefined"); + assert_array_equals(readyStateChanges, ["interactive"], + "Inside the document.interactive fulfillment handler, the readystatechange event must have fired once already"); assert_equals(document.readyState, "interactive", "Inside the document.interactive fulfillment handler, readyState must be interactive"); }); @@ -56,6 +64,8 @@ "Inside the document.contentLoaded fulfillment handler, document.interactive must have already fulfilled"); assert_equals(onDomContentLoadedFired, true, "Inside the document.contentLoaded fulfillment handler, DOMContentLoaded must have already fired"); + assert_array_equals(readyStateChanges, ["interactive"], + "Inside the document.interactive fulfillment handler, the readystatechange event must have fired exactly once"); }); loadedAssertions = document.loaded.then(value => { @@ -70,8 +80,10 @@ "Inside the document.loaded fulfillment handler, document.contentLoaded must have already fulfilled"); assert_equals(onDomContentLoadedFired, true, "Inside the document.loaded fulfillment handler, DOMContentLoaded must have already fired"); - assert_equals(onLoadFired, true, - "Inside the document.loaded fulfillment handler, load must have already fired"); + assert_equals(onLoadFired, false, + "Inside the document.loaded fulfillment handler, load must not have already fired"); + assert_array_equals(readyStateChanges, ["interactive", "complete"], + "Inside the document.interactive fulfillment handler, the readystatechange event must have fired exactly twice"); }); }, "Setup code");