tor-browser

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

test_http3_prio_enabled.js (3448B)


      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 test file can be run directly as a part of parent/main process
      6 // or indirectly from the wrapper test file as a part of child/content process
      7 
      8 // need to get access to helper functions/structures
      9 // load ensures
     10 // * testing environment is available (ie Assert.ok())
     11 /*global inChildProcess, test_flag_priority */
     12 load("../unit/test_http3_prio_helpers.js");
     13 
     14 // direct call to this test file should cleanup after itself
     15 // otherwise the wrapper will handle
     16 if (!inChildProcess()) {
     17  registerCleanupFunction(async () => {
     18    Services.prefs.clearUserPref("network.http.http3.priority");
     19    Services.prefs.clearUserPref("network.http.priority_header.enabled");
     20    http3_clear_prefs();
     21  });
     22 }
     23 
     24 // setup once, before tests
     25 add_task(async function setup() {
     26  // wrapper handles when testing as content process for pref change
     27  if (!inChildProcess()) {
     28    await http3_setup_tests("h3");
     29  }
     30 });
     31 
     32 // tests various flags when priority has been enabled on variable incremental
     33 // this function should only be called the preferences priority disabled
     34 async function test_http3_prio_enabled(incremental) {
     35  await test_flag_priority("enabled (none)", null, "u=4", null, false); // default-test
     36  await test_flag_priority(
     37    "enabled (urgent_start)",
     38    Ci.nsIClassOfService.UrgentStart,
     39    "u=1",
     40    incremental,
     41    incremental
     42  );
     43  await test_flag_priority(
     44    "enabled (leader)",
     45    Ci.nsIClassOfService.Leader,
     46    "u=2",
     47    incremental,
     48    incremental
     49  );
     50 
     51  // if priority-urgency and incremental are both default values
     52  // then we shouldn't expect to see the priority header at all
     53  // hence when:
     54  //  incremental=true  -> we expect incremental
     55  //  incremental=false -> we expect null
     56  await test_flag_priority(
     57    "enabled (unblocked)",
     58    Ci.nsIClassOfService.Unblocked,
     59    null,
     60    incremental,
     61    incremental ? incremental : null
     62  );
     63 
     64  await test_flag_priority(
     65    "enabled (follower)",
     66    Ci.nsIClassOfService.Follower,
     67    "u=4",
     68    incremental,
     69    incremental
     70  );
     71  await test_flag_priority(
     72    "enabled (speculative)",
     73    Ci.nsIClassOfService.Speculative,
     74    "u=6",
     75    incremental,
     76    incremental
     77  );
     78  await test_flag_priority(
     79    "enabled (background)",
     80    Ci.nsIClassOfService.Background,
     81    "u=6",
     82    incremental,
     83    incremental
     84  );
     85  await test_flag_priority(
     86    "enabled (tail)",
     87    Ci.nsIClassOfService.Tail,
     88    "u=6",
     89    incremental,
     90    incremental
     91  );
     92 }
     93 
     94 // with priority enabled: test urgency flags with both incremental enabled and disabled
     95 add_task(async function test_http3_prio_enabled_incremental_true() {
     96  // wrapper handles when testing as content process for pref change
     97  if (!inChildProcess()) {
     98    Services.prefs.setBoolPref("network.http.http3.priority", true);
     99    Services.prefs.setBoolPref("network.http.priority_header.enabled", true);
    100  }
    101  await test_http3_prio_enabled(true);
    102 });
    103 
    104 add_task(async function test_http3_prio_enabled_incremental_false() {
    105  // wrapper handles when testing as content process for pref change
    106  if (!inChildProcess()) {
    107    Services.prefs.setBoolPref("network.http.http3.priority", true);
    108    Services.prefs.setBoolPref("network.http.priority_header.enabled", true);
    109  }
    110  await test_http3_prio_enabled(false);
    111 });