tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_103_csp.js (2363B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 Services.prefs.setBoolPref("network.early-hints.enabled", true);
      8 
      9 const { test_preload_hint_and_request } = ChromeUtils.importESModule(
     10  "resource://testing-common/early_hint_preload_test_helper.sys.mjs"
     11 );
     12 
     13 add_task(async function test_preload_images_csp_in_early_hints_response() {
     14  let tests = [
     15    {
     16      input: {
     17        test_name: "image - no csp",
     18        resource_type: "image",
     19        csp: "",
     20        csp_in_early_hint: "",
     21        host: "",
     22        hinted: true,
     23      },
     24      expected: { hinted: 1, normal: 0 },
     25    },
     26    {
     27      input: {
     28        test_name: "image img-src 'self';",
     29        resource_type: "image",
     30        csp: "",
     31        csp_in_early_hint: "img-src 'self';",
     32        host: "",
     33        hinted: true,
     34      },
     35      expected: { hinted: 1, normal: 0 },
     36    },
     37    {
     38      input: {
     39        test_name: "image img-src 'self'; same host provided",
     40        resource_type: "image",
     41        csp: "",
     42        csp_in_early_hint: "img-src 'self';",
     43        host: "https://example.com/browser/netwerk/test/browser/",
     44        hinted: true,
     45      },
     46      expected: { hinted: 1, normal: 0 },
     47    },
     48    {
     49      input: {
     50        test_name: "image img-src 'self'; other host provided",
     51        resource_type: "image",
     52        csp: "",
     53        csp_in_early_hint: "img-src 'self';",
     54        host: "https://example.org/browser/netwerk/test/browser/",
     55        hinted: true,
     56      },
     57      expected: { hinted: 0, normal: 1 },
     58    },
     59    {
     60      input: {
     61        test_name: "image img-src 'none';",
     62        resource_type: "image",
     63        csp: "",
     64        csp_in_early_hint: "img-src 'none';",
     65        host: "",
     66        hinted: true,
     67      },
     68      expected: { hinted: 0, normal: 1 },
     69    },
     70    {
     71      input: {
     72        test_name: "image img-src 'none'; same host provided",
     73        resource_type: "image",
     74        csp: "",
     75        csp_in_early_hint: "img-src 'none';",
     76        host: "https://example.com/browser/netwerk/test/browser/",
     77        hinted: true,
     78      },
     79      expected: { hinted: 0, normal: 1 },
     80    },
     81  ];
     82 
     83  for (let test of tests) {
     84    await test_preload_hint_and_request(test.input, test.expected);
     85  }
     86 });