tor-browser

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

browser_103_no_cancel_on_error.js (2275B)


      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 /* This Source Code Form is subject to the terms of the Mozilla Public
      6 * License, v. 2.0. If a copy of the MPL was not distributed with this
      7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      8 
      9 Services.prefs.setBoolPref("network.early-hints.enabled", true);
     10 
     11 const { request_count_checking } = ChromeUtils.importESModule(
     12  "resource://testing-common/early_hint_preload_test_helper.sys.mjs"
     13 );
     14 
     15 // - httpCode is the response code we're testing for. This file mostly covers 400 and 500 responses
     16 async function test_hint_completion_on_error(httpCode) {
     17  // reset the count
     18  let headers = new Headers();
     19  headers.append("X-Early-Hint-Count-Start", "");
     20  await fetch(
     21    "https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs",
     22    { headers }
     23  );
     24 
     25  let requestUrl = `https://example.com/browser/netwerk/test/browser/early_hint_asset_html.sjs?hinted=1&as=image&code=${httpCode}`;
     26 
     27  await BrowserTestUtils.withNewTab(
     28    {
     29      gBrowser,
     30      url: requestUrl,
     31      waitForLoad: true,
     32    },
     33    async function () {}
     34  );
     35 
     36  let gotRequestCount = await fetch(
     37    "https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs"
     38  ).then(response => response.json());
     39 
     40  await request_count_checking(`test_103_error_${httpCode}`, gotRequestCount, {
     41    hinted: 1,
     42    normal: 0,
     43  });
     44 }
     45 
     46 // 400 Bad Request
     47 add_task(async function test_complete_103_on_400() {
     48  await test_hint_completion_on_error(400);
     49 });
     50 add_task(async function test_complete_103_on_401() {
     51  await test_hint_completion_on_error(401);
     52 });
     53 add_task(async function test_complete_103_on_402() {
     54  await test_hint_completion_on_error(402);
     55 });
     56 add_task(async function test_complete_103_on_403() {
     57  await test_hint_completion_on_error(403);
     58 });
     59 add_task(async function test_complete_103_on_500() {
     60  await test_hint_completion_on_error(500);
     61 });
     62 add_task(async function test_complete_103_on_501() {
     63  await test_hint_completion_on_error(501);
     64 });
     65 add_task(async function test_complete_103_on_502() {
     66  await test_hint_completion_on_error(502);
     67 });