tor-browser

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

test_attribution_parsing.js (1280B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/
      3 */
      4 "use strict";
      5 
      6 /**
      7 * This test file exists to be run on any platform during development,
      8 * whereas the test_AttributionCode.js will test the attribution file
      9 * in the app local data dir on Windows.  It will only run under
     10 * Windows on try.
     11 */
     12 
     13 /**
     14 * Test validation of attribution codes.
     15 */
     16 add_task(async function testValidAttrCodes() {
     17  for (let entry of validAttrCodes) {
     18    let result = AttributionCode.parseAttributionCode(entry.code);
     19    Assert.deepEqual(
     20      result,
     21      entry.parsed,
     22      "Parsed code should match expected value, code was: " + entry.code
     23    );
     24 
     25    result = AttributionCode.serializeAttributionData(entry.parsed);
     26    if (!entry.doesNotRoundtrip) {
     27      Assert.deepEqual(
     28        result,
     29        entry.code,
     30        "Serialized data should match expected value, code was: " + entry.code
     31      );
     32    }
     33  }
     34 });
     35 
     36 /**
     37 * Make sure codes with various formatting errors are not seen as valid.
     38 */
     39 add_task(async function testInvalidAttrCodes() {
     40  for (let code of invalidAttrCodes) {
     41    let result = AttributionCode.parseAttributionCode(code);
     42    Assert.deepEqual(result, {}, "Code should have failed to parse: " + code);
     43  }
     44 });