Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gecko Bug 1919248] transform WPT <to-javascript-url-script-src.html>'s async sub-tests to promise-tests and remove checking the securitypolicyevent's target element. #48884

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
<body>

<script nonce="abc">
function assert_csp_event_for_element(test, element) {
function assert_csp_event_for_element(test, element, resolve) {
assert_equals(typeof SecurityPolicyViolationEvent, "function", "These tests require 'SecurityPolicyViolationEvent'.");
document.addEventListener("securitypolicyviolation", test.step_func(e => {
if (e.target != element)
return;
assert_equals(e.blockedURI, "inline");
assert_equals(e.effectiveDirective, "script-src-elem");
assert_equals(element.contentDocument.body.innerText, "", "Ensure that 'Fail' doesn't appear in the child document.");
element.remove();
test.done();
}));
resolve();
}, { once: true }));
}

function navigate_to_javascript_onload(test, iframe) {
Expand All @@ -32,41 +30,49 @@
}));
}

async_test(t => {
var i = document.createElement("iframe");
i.src = "javascript:'Fail.'";
promise_test(t => {
return new Promise(resolve => {
var i = document.createElement("iframe");
i.src = "javascript:'Fail.'";

assert_csp_event_for_element(t, i);
assert_csp_event_for_element(t, i, resolve);

document.body.appendChild(i);
document.body.appendChild(i);
})
}, "<iframe src='javascript:'> blocked without 'unsafe-inline'.");

async_test(t => {
var i = document.createElement("iframe");
promise_test(t => {
return new Promise(resolve => {
var i = document.createElement("iframe");

assert_csp_event_for_element(t, i);
navigate_to_javascript_onload(t, i);
assert_csp_event_for_element(t, i, resolve);
navigate_to_javascript_onload(t, i);

document.body.appendChild(i);
document.body.appendChild(i);
})
}, "<iframe> navigated to 'javascript:' blocked without 'unsafe-inline'.");

async_test(t => {
var i = document.createElement("iframe");
i.src = "../support/echo-policy.py?policy=" + encodeURIComponent("script-src 'unsafe-inline'");
promise_test(t => {
return new Promise(resolve => {
var i = document.createElement("iframe");
i.src = "../support/echo-policy.py?policy=" + encodeURIComponent("script-src 'unsafe-inline'");

assert_csp_event_for_element(t, i);
navigate_to_javascript_onload(t, i);
assert_csp_event_for_element(t, i, resolve);
navigate_to_javascript_onload(t, i);

document.body.appendChild(i);
document.body.appendChild(i);
})
}, "<iframe src='...'> with 'unsafe-inline' navigated to 'javascript:' blocked in this document");

async_test(t => {
var i = document.createElement("iframe");
i.src = "../support/echo-policy.py?policy=" + encodeURIComponent("script-src 'none'");
promise_test(t => {
return new Promise(resolve => {
var i = document.createElement("iframe");
i.src = "../support/echo-policy.py?policy=" + encodeURIComponent("script-src 'none'");

assert_csp_event_for_element(t, i);
navigate_to_javascript_onload(t, i);
assert_csp_event_for_element(t, i, resolve);
navigate_to_javascript_onload(t, i);

document.body.appendChild(i);
document.body.appendChild(i);
})
}, "<iframe src='...'> without 'unsafe-inline' navigated to 'javascript:' blocked in this document.");
</script>