tor-browser

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

test_networkconnection_spoofing.html (2531B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8" />
      5 <title>
      6  Test that RFP hides preload behaviour when the NetworkConnection RFP target is enabled
      7 </title>
      8 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9 <script src="/tests/dom/serviceworkers/test/utils.js"></script>
     10 <link rel="stylesheet" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <script>
     13 "use strict";
     14 
     15 async function run_test(preload) {
     16  // Set all preload prefs to 1=None so that we can be sure RFP overrides the behavior
     17  await SpecialPowers.pushPrefEnv({
     18    set: [
     19      ["media.preload.default.cellular", 1],
     20      ["media.preload.default", 1],
     21      ["media.preload.auto.cellular", 1],
     22      ["media.preload.auto", 1],
     23    ],
     24  });
     25 
     26  const audioThatShouldntBeLoaded = new Audio();
     27  for (const event of ["loadedmetadata", "loadeddata", "error"]) {
     28    audioThatShouldntBeLoaded.addEventListener(event, () => {
     29      ok(
     30        false,
     31        `Audio event ${event} should not be called as RFP is disabled currently and the pref is respected`
     32      );
     33    });
     34  }
     35  await Promise.all([
     36    new Promise(resolve => {
     37      audioThatShouldntBeLoaded.addEventListener("suspend", () => {
     38        resolve();
     39      });
     40    }),
     41    (audioThatShouldntBeLoaded.preload = preload),
     42    (audioThatShouldntBeLoaded.src = "owl.mp3"),
     43  ]);
     44 
     45  // Enable RFP and verify that the new audio element loads
     46  await SpecialPowers.pushPrefEnv({
     47    set: [
     48      ["privacy.fingerprintingProtection", true],
     49      [
     50        "privacy.fingerprintingProtection.overrides",
     51        "-AllTargets,+NetworkConnection",
     52      ],
     53    ],
     54  });
     55 
     56  const audioThatShouldBeLoaded = new Audio();
     57  const promises = ["loadedmetadata", "loadeddata"].map(event => {
     58    return new Promise(resolve => {
     59      audioThatShouldBeLoaded.addEventListener(event, () => {
     60        ok(
     61          true,
     62          `Audio event ${event} should be called as fingerprinting protection overrides preload prefs`
     63        );
     64        resolve();
     65      });
     66    });
     67  });
     68  audioThatShouldBeLoaded.addEventListener("error", () => {
     69    ok(
     70      false,
     71      "Audio event error should not be called as as fingerprinting protection overrides preload prefs"
     72    );
     73  });
     74  audioThatShouldBeLoaded.preload = preload;
     75  audioThatShouldBeLoaded.src = "owl.mp3";
     76  await Promise.all(promises);
     77 
     78  await SpecialPowers.popPrefEnv(); // Pop the RFP prefs
     79  await SpecialPowers.popPrefEnv(); // Pop the preload prefs
     80 }
     81 
     82 add_task(async function () {
     83  await run_test("auto");
     84  await run_test(undefined);
     85 });
     86 </script>
     87 </html>