tor-browser

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

head.js (5919B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/
      3 */
      4 "use strict";
      5 
      6 const { AttributionCode } = ChromeUtils.importESModule(
      7  "moz-src:///browser/components/attribution/AttributionCode.sys.mjs"
      8 );
      9 
     10 let validAttrCodes = [
     11  {
     12    code: "source%3Dgoogle.com%26medium%3Dorganic%26campaign%3D(not%20set)%26content%3D(not%20set)",
     13    parsed: {
     14      source: "google.com",
     15      medium: "organic",
     16      campaign: "(not%20set)",
     17      content: "(not%20set)",
     18    },
     19  },
     20  {
     21    code: "source%3Dgoogle.com%26medium%3Dorganic%26campaign%3D(not%20set)%26content%3D(not%20set)%26msstoresignedin%3Dtrue",
     22    parsed: {
     23      source: "google.com",
     24      medium: "organic",
     25      campaign: "(not%20set)",
     26      content: "(not%20set)",
     27      msstoresignedin: true,
     28    },
     29    platforms: ["win"],
     30  },
     31  {
     32    code: "source%3Dgoogle.com%26medium%3Dorganic%26campaign%3D%26content%3D",
     33    parsed: { source: "google.com", medium: "organic" },
     34    doesNotRoundtrip: true, // `campaign=` and `=content` are dropped.
     35  },
     36  {
     37    code: "source%3Dgoogle.com%26medium%3Dorganic%26campaign%3D(not%20set)",
     38    parsed: {
     39      source: "google.com",
     40      medium: "organic",
     41      campaign: "(not%20set)",
     42    },
     43  },
     44  {
     45    code: "source%3Dgoogle.com%26medium%3Dorganic",
     46    parsed: { source: "google.com", medium: "organic" },
     47  },
     48  { code: "source%3Dgoogle.com", parsed: { source: "google.com" } },
     49  { code: "medium%3Dgoogle.com", parsed: { medium: "google.com" } },
     50  { code: "campaign%3Dgoogle.com", parsed: { campaign: "google.com" } },
     51  { code: "content%3Dgoogle.com", parsed: { content: "google.com" } },
     52  {
     53    code: "experiment%3Dexperimental",
     54    parsed: { experiment: "experimental" },
     55  },
     56  { code: "variation%3Dvaried", parsed: { variation: "varied" } },
     57  {
     58    code: "ua%3DGoogle%20Chrome%20123",
     59    parsed: { ua: "Google%20Chrome%20123" },
     60  },
     61  {
     62    code: "dltoken%3Dc18f86a3-f228-4d98-91bb-f90135c0aa9c",
     63    parsed: { dltoken: "c18f86a3-f228-4d98-91bb-f90135c0aa9c" },
     64  },
     65  {
     66    code: "dlsource%3Dsome-dl-source",
     67    parsed: {
     68      dlsource: "some-dl-source",
     69    },
     70  },
     71  // Microsoft Store Ads attribution is not URL encoded, and instead provides a
     72  // Microsoft Click ID in the format `storeBingAd_uuid` when requesting the
     73  // Campaign ID. When retrieving this we append an additional key
     74  // `&msstoresignedin=bool` as we would for a URL encoded campaign.
     75  //
     76  // At present we have not found a documented schema for Campaign IDs
     77  // associated to Microsoft Store Ads, therefore don't test additional
     78  // key/value combinations as `%26` is not guaranteed to be the key seperator
     79  // if additional keys were added.
     80  {
     81    code: "storeBingAd_45cbbf091fb541f0ae959d50ffb8c5b8%26msstoresignedin%3Dtrue",
     82    parsed: {
     83      msclkid: "45cbbf091fb541f0ae959d50ffb8c5b8",
     84      msstoresignedin: true,
     85    },
     86    doesNotRoundtrip: true, // `storeBingAd_uuid` becomes `msclkid=uuid`.
     87  },
     88  {
     89    code: "storeBingAd_45cbbf091fb541f0ae959d50ffb8c5b8%26msstoresignedin%3Dfalse",
     90    parsed: {
     91      msclkid: "45cbbf091fb541f0ae959d50ffb8c5b8",
     92      msstoresignedin: false,
     93    },
     94    doesNotRoundtrip: true, // `storeBingAd_uuid` becomes `msclkid=uuid`.
     95  },
     96  {
     97    code: "storeBingAd_%26msstoresignedin%3Dfalse",
     98    parsed: {
     99      msclkid: "",
    100      msstoresignedin: false,
    101    },
    102    doesNotRoundtrip: true, // `storeBingAd_uuid` becomes `msclkid=uuid`.
    103  },
    104 ];
    105 
    106 let invalidAttrCodes = [
    107  // Empty string
    108  "",
    109  // Not escaped
    110  "source=google.com&medium=organic&campaign=(not set)&content=(not set)",
    111  // Too long
    112  "campaign%3D" + "a".repeat(1000),
    113  // Unknown key name
    114  "source%3Dgoogle.com%26medium%3Dorganic%26large%3Dgeneticallymodified",
    115  // Empty key name
    116  "source%3Dgoogle.com%26medium%3Dorganic%26%3Dgeneticallymodified",
    117 ];
    118 
    119 /**
    120 * Arrange for each test to have a unique application path for storing
    121 * quarantine data.
    122 *
    123 * The quarantine data is necessarily a shared system resource, managed by the
    124 * OS, so we need to avoid polluting it during tests.
    125 *
    126 * There are at least two ways to achieve this.  Here we use Sinon to stub the
    127 * relevant accessors: this has the advantage of being local and relatively easy
    128 * to follow.  In the App Update Service tests, an `nsIDirectoryServiceProvider`
    129 * is installed, which is global and much harder to extract for re-use.
    130 */
    131 async function setupStubs() {
    132  // Local imports to avoid polluting the global namespace.
    133  const { AppConstants } = ChromeUtils.importESModule(
    134    "resource://gre/modules/AppConstants.sys.mjs"
    135  );
    136  const { sinon } = ChromeUtils.importESModule(
    137    "resource://testing-common/Sinon.sys.mjs"
    138  );
    139 
    140  // This depends on the caller to invoke it by name.  We do try to
    141  // prevent the most obvious incorrect invocation, namely
    142  // `add_task(setupStubs)`.
    143  let caller = Components.stack.caller;
    144  const testID = caller.filename.toString().split("/").pop().split(".")[0];
    145  notEqual(testID, "head");
    146 
    147  let applicationFile = do_get_tempdir();
    148  applicationFile.append(testID);
    149  applicationFile.append("App.app");
    150 
    151  if (AppConstants.platform == "macosx") {
    152    // We're implicitly using the fact that modules are shared between importers here.
    153    const { MacAttribution } = ChromeUtils.importESModule(
    154      "moz-src:///browser/components/attribution/MacAttribution.sys.mjs"
    155    );
    156    sinon
    157      .stub(MacAttribution, "applicationPath")
    158      .get(() => applicationFile.path);
    159  }
    160 
    161  // The macOS quarantine database applies to existing paths only, so make
    162  // sure our mock application path exists.  This also creates the parent
    163  // directory for the attribution file, needed on both macOS and Windows.  We
    164  // don't ignore existing paths because we're inside a temporary directory:
    165  // this should never be invoked twice for the same test.
    166  await IOUtils.makeDirectory(applicationFile.path, {
    167    from: do_get_tempdir().path,
    168  });
    169 }