Commit 8168e512 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[blink][web_tests] document-write tests cleanup

- Add better assertion failure messages
- Use better content for document.write

The tests assume that the ignore-destructive-writes counter is only
incremented during the synchronous part of module evaluation (see
https://github.com/whatwg/html/pull/4352#issuecomment-611193922).

This also fixes document-write/module-delayed.html which accidentally
had wrong test expectations checked in that made it pass.

Bug: 1127215
Bug: 1022182
Bug: v8:9344
Change-Id: I01a75534f7efd0bd8e376dfd049432e52661604d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2397696Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807384}
parent 276267a3
This is a testharness.js-based test.
FAIL async document.write in a module assert_equals: expected "Initial body contents\n" but got "document.write body contents\n"
Harness: the test ran to completion.
......@@ -10,16 +10,17 @@ async_test(t => {
const iframe = document.createElement("iframe");
iframe.onerror = t.unreached_func("Error loading iframe");
let onLoadWasCalled = false;
iframe.onload = t.step_func(() => {
onLoadWasCalled = true;
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
// Don't call the event handler another time after document.write.
iframe.onload = null;
onLoadWasCalled = true;
});
document.addEventListener("documentWriteDone", t.step_func_done(() => {
assert_equals(iframe.onload, null);
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
assert_true(onLoadWasCalled, "onload must be called");
assert_equals(iframe.contentDocument.body.textContent, "document.write body contents\n");
}));
iframe.src = "module-delayed-iframe.html";
......
......@@ -8,14 +8,16 @@ async_test(t => {
const iframe = document.createElement("iframe");
iframe.onerror = t.unreached_func("Error loading iframe");
let onLoadWasCalled = false;
iframe.onload = t.step_func(() => {
onLoadWasCalled = true;
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
// Don't call the event handler another time after document.write.
iframe.onload = null;
onLoadWasCalled = true;
});
document.addEventListener("documentWriteDone", t.step_func_done(() => {
assert_true(onLoadWasCalled);
assert_true(onLoadWasCalled, "onload must be called");
assert_equals(iframe.contentDocument.body.textContent, "document.write body contents\n");
}));
......
......@@ -8,16 +8,17 @@ async_test(t => {
// Expose {test} in the iframe for using the step_timeout helper.
document.test = t;
const iframe = document.createElement("iframe");
iframe.onerror = t.unreached_func("Error loading iframe");
let onLoadWasCalled = false;
iframe.onload = t.step_func(() => {
onLoadWasCalled = true;
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
// Don't call the event handler another time after document.write.
iframe.onload = null;
onLoadWasCalled = true;
});
document.addEventListener("documentWriteDone", t.step_func_done(() => {
assert_true(onLoadWasCalled);
assert_true(onLoadWasCalled, "onload must be called");
assert_equals(iframe.contentDocument.body.textContent, "document.write body contents\n");
}));
......
......@@ -6,15 +6,16 @@
<script>
async_test(t => {
const iframe = document.createElement("iframe");
iframe.onerror = t.unreached_func("Error loading iframe");
let testEndWasCalled = false;
document.addEventListener("documentWriteDone", t.step_func(() => {
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
testEndWasCalled = true;
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
}));
iframe.onload = t.step_func_done(() => {
assert_true(testEndWasCalled);
assert_true(testEndWasCalled, "onload must be called");
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
});
......
......@@ -4,7 +4,7 @@ let delay = new Promise(
resolve => window.parent.document.test.step_timeout(resolve, 0));
delay.then(() => {
document.write("FAIL");
document.write("document.write body contents\n");
document.close();
window.parent.document.dispatchEvent(new CustomEvent("documentWriteDone"));
});
......
......@@ -15,13 +15,13 @@ async_test(t => {
let onLoadWasCalled = false;
iframe.onload = t.step_func(() => {
onLoadWasCalled = true;
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
iframe.onload = null;
onLoadWasCalled = true;
});
document.addEventListener("documentWriteDone", t.step_func_done(() => {
assert_true(onLoadWasCalled);
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
assert_true(onLoadWasCalled, "onload must be called");
assert_equals(iframe.contentDocument.body.textContent, "document.write body contents\n");
}));
iframe.src = "module-tla-delayed-iframe.html";
......
......@@ -9,16 +9,17 @@ async_test(t => {
document.test = t;
const iframe = document.createElement("iframe");
iframe.onerror = t.unreached_func("Error loading iframe");
let onLoadWasCalled = false;
iframe.onload = t.step_func(() => {
onLoadWasCalled = true;
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
// Don't call the event handler another time after document.write.
iframe.onload = null;
onLoadWasCalled = true;
});
document.addEventListener("documentWriteDone", t.step_func_done(() => {
assert_true(onLoadWasCalled);
assert_false(onLoadWasCalled, "onload must not be called yet");
assert_equals(iframe.contentDocument.body.textContent, "Initial body contents\n");
}));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment