-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite fetch/corb/response_block.tentative test.
The test now covers different types of fetches and gives clearer messages about the expected results. Bug: 1463725 Change-Id: I860787d9172d5e287f1cefc484cb49bda883193f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4669448 Reviewed-by: Titouan Rigoudy <titouan@chromium.org> Commit-Queue: Daniel Vogelheim <vogelheim@chromium.org> Cr-Commit-Position: refs/heads/main@{#1169268}
- Loading branch information
1 parent
39fc9e0
commit 1453112
Showing
3 changed files
with
51 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
window.script_callback(); | ||
alert(1); // Arbitrary JavaScript. Details don't matter for the test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<body> | ||
<script> | ||
// A cross-origin response containing JavaScript, labelled as text/csv. | ||
const probeUrl = get_host_info().HTTPS_REMOTE_ORIGIN + | ||
"/fetch/corb/resources/response_block_probe.js"; | ||
|
||
// Test handling of blocked responses in CORB/ORB for <script> elements. | ||
function probe_script() { | ||
// We will cross-origin load a script resource that should get blocked by all | ||
// versions of CORB/ORB. Two things may happen: | ||
// | ||
// 1, An empty response is injected. (What CORB does.) | ||
// 2, An error is injected and script loading aborts. (What ORB does.) | ||
|
||
// Load the probe as a script. | ||
const script = document.createElement("script"); | ||
script.src = probeUrl; | ||
document.body.appendChild(script); | ||
|
||
// Return a promise that will return a string description corresponding to the | ||
// conditions above. | ||
return new Promise((resolve, reject) => { | ||
script.onload = _ => resolve("Resource loaded (expected for CORB)"); | ||
script.onerror = _ => resolve("ORB-style network error"); | ||
}); | ||
} | ||
|
||
// Test handling of blocked responses in CORB/ORB for script-initiated fetches. | ||
function probe_fetch() { | ||
return fetch(probeUrl, {mode: "no-cors"}) | ||
.then(response => response.text()) | ||
.then(text => { | ||
assert_equals(text, ""); | ||
return "Resource loaded (expected for CORB)"; | ||
}) | ||
.catch(_ => "ORB-style network error"); | ||
} | ||
|
||
// These tests check for ORB behaviour. | ||
promise_test(t => probe_script().then( | ||
value => assert_equals(value, "ORB-style network error")), | ||
"ORB: Expect error response from <script> fetch."); | ||
promise_test(t => probe_fetch().then( | ||
value => assert_equals(value, "ORB-style network error")), | ||
"ORB: Expect error response from fetch()."); | ||
</script> |
This file was deleted.
Oops, something went wrong.