Commit 3787f538 authored by Aaron Tagliaboschi's avatar Aaron Tagliaboschi Committed by Commit Bot

[Critical-CH] Refactor WPTs

Remove duplicate code and move to slightly less flaky messages

Bug: 1127313
Change-Id: I926c6f66d23ac6ed101ff85777d187a45ad9a50f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2519393
Commit-Queue: Aaron Tagliaboschi <aarontag@chromium.org>
Reviewed-by: default avatarYoav Weiss <yoavweiss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824415}
parent 447477a2
// META: script=resources/util.js
async_test((t) => { async_test((t) => {
var iframe = document.createElement("iframe"); var iframe = document.createElement("iframe");
iframe.addEventListener('load', (e) => { iframe.src = ECHO_URL;
t.step(()=>{assert_equals(iframe.contentDocument.body.textContent, "FAIL");});
t.done();
});
iframe.src = "resources/echo-critical-hint.py";
document.body.appendChild(iframe); document.body.appendChild(iframe);
iframe.contentWindow.addEventListener('message', message_listener(t, "FAIL"));
}, "Critical-CH iframe"); }, "Critical-CH iframe");
// META: script=resources/util.js
// META: script=/common/utils.js // META: script=/common/utils.js
async_test((t) => { async_test(make_message_test(ECHO_URL+"?mismatch=true&token="+token(), "1"), "Critical-CH no restart on mismatched hints")
var popup_window = window.open("resources/echo-critical-hint.py?mismatch=true&token="+token());
assert_not_equals(popup_window, null, "Popup windows not allowed?");
popup_window.addEventListener('load', (e) => {
t.step(()=>{assert_equals(popup_window.document.body.textContent, "1")});
t.done();
});
}, "Critical-CH navigation")
async_test((t) => { // META: script=resources/util.js
var popup_window = window.open("resources/echo-critical-hint.py?mismatch=true");
assert_not_equals(popup_window, null, "Popup windows not allowed?"); async_test(make_message_test(ECHO_URL+"?mismatch=true", "FAIL"), "Critical-CH Mis-matched hints")
popup_window.addEventListener('load', (e) => {
t.step(()=>{assert_equals(popup_window.document.body.textContent, "FAIL")});
t.done();
});
}, "Critical-CH navigation")
async_test((t) => { // META: script=resources/util.js
var popup_window = window.open("resources/echo-critical-hint.py");
assert_not_equals(popup_window, null, "Popup windows not allowed?"); async_test(make_message_test(ECHO_URL, "PASS"), "Critical-CH navigation")
popup_window.addEventListener('load', (e) => {
t.step(()=>{assert_equals(popup_window.document.body.textContent, "PASS")});
t.done();
});
}, "Critical-CH navigation")
async_test((t) => { // META: script=resources/util.js
var popup_window = window.open("resources/echo-critical-hint.py");
assert_not_equals(popup_window, null, "Popup windows not allowed?"); async_test(make_message_test(ECHO_URL, "FAIL"), "Critical-CH navigation non-secure")
popup_window.addEventListener('load', (e) => {
t.step(()=>{assert_equals(popup_window.document.body.textContent, "FAIL")});
t.done();
});
}, "Critical-CH non-secure navigation")
// META: script=resources/util.js
// META: script=/common/utils.js // META: script=/common/utils.js
async_test((t) => { async_test(make_message_test(ECHO_URL+"?token="+token(), "2"), "Critical-CH navigation restart")
var popup_window = window.open("resources/echo-critical-hint.py?token="+token());
assert_not_equals(popup_window, null, "Popup windows not allowed?");
popup_window.addEventListener('load', (e) => {
t.step(()=>{assert_equals(popup_window.document.body.textContent, "2")});
t.done();
});
}, "Critical-CH navigation")
...@@ -40,4 +40,4 @@ def main(request, response): ...@@ -40,4 +40,4 @@ def main(request, response):
if b"viewport-width" in request.headers: if b"viewport-width" in request.headers:
result = "MISMATCH" result = "MISMATCH"
response.content = result response.content = "<script>window.postMessage('{0}', '*')</script>".format(result)
ECHO_URL = "resources/echo-critical-hint.py"
message_listener = (t, message) =>
(e) => {
t.step(()=>{assert_equals(e.data, message)});
t.done();
}
make_message_test = (url, message) =>
(t) => {
popup_window = window.open("/common/blank.html");
assert_not_equals(popup_window, null, "Popup windows not allowed?");
popup_window.addEventListener('message', message_listener(t, message));
popup_window.location = url;
}
// META: script=resources/util.js
// META: script=/common/utils.js
promise_test(() => promise_test(() =>
fetch("resources/echo-critical-hint.py") fetch("resources/echo-critical-hint.py")
.then((r) => r.text()) .then((r) => r.text())
.then((r) => { .then((r) => {
assert_equals(r, "FAIL"); assert_true(r.includes("FAIL"));
}) })
, "Critical-CH"); , "Critical-CH subresource fetch");
This is a testharness.js-based test. This is a testharness.js-based test.
FAIL Critical-CH navigation assert_equals: expected "2" but got "1" FAIL Critical-CH navigation restart assert_equals: expected "2" but got "1"
Harness: the test ran to completion. Harness: the test ran to completion.
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