Skip to content

Commit

Permalink
Rewrite fetch/corb/response_block.tentative test.
Browse files Browse the repository at this point in the history
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
otherdaniel authored and pull[bot] committed Dec 22, 2023
1 parent 39fc9e0 commit 1453112
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 45 deletions.
2 changes: 1 addition & 1 deletion fetch/corb/resources/response_block_probe.js
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.
50 changes: 50 additions & 0 deletions fetch/corb/response_block.tentative.https.html
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>
44 changes: 0 additions & 44 deletions fetch/corb/response_block.tentative.sub.https.html

This file was deleted.

0 comments on commit 1453112

Please sign in to comment.