Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<title>Bug 1434357: Allow Web Request API to redirect to data: URI</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript">
"use strict";
/* Description of the test:
* We load a *.js file which gets redirected to a data: URI.
* Since there is no good way to communicate loaded data: URI scripts
* we use updating a divContainer as a detour to verify the data: URI
* script has loaded.
const WIN_URL =
add_task(async function test_webRequest_redirect_data_uri() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: [
content_scripts: [{
matches: ["*://mochi.test/tests/*/file_redirect_data_uri.html"],
run_at: "document_end",
js: ["content_script.js"],
"all_frames": true,
background() {
browser.webRequest.onBeforeRequest.addListener((details) => {
if (details.url.includes("dummy_non_existend_file.js")) {
let redirectUrl =
return {redirectUrl};
}, {urls: ["*://mochi.test/tests/*"]}, ["blocking"]);
files: {
"content_script.js": function() {
let scriptEl = document.createElement("script");
// please note that dummy_non_existend_file.js file does not really need
// to exist because we redirect the load within onBeforeRequest().
scriptEl.src = "dummy_non_existend_file.js";
scriptEl.onload = function() {
let divContent = document.getElementById("testdiv").textContent;
browser.test.assertEq(divContent, "loaded",
"redirect to data: URI allowed");
scriptEl.onerror = function() {"script load failure");
await extension.startup();
let win =;
await extension.awaitMessage("finished");
await extension.unload();