Files
tubestation/browser/components/attribution/test/xpcshell/head.js
Nick Alexander 39987ecf12 Bug 1525076 - Part 0: Test more scenarios on macOS; handle URI component encoding. r=mixedpuppy
The existing code handles Windows and macOS quite differently.  On
macOS, the tests were not as comprehensive; this patch brings them
level and makes the form of the attribution data uniform on Windows
and macOS.  In particular, attribution data fields will now be URI
coded, just as they are on Windows.

This will allow us to re-use the parsing machinery we have on Windows
when we cache attribution codes on macOS.

Differential Revision: https://phabricator.services.mozilla.com/D92692
2020-10-11 18:18:11 +00:00

64 lines
1.8 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
const { AttributionCode } = ChromeUtils.import(
"resource:///modules/AttributionCode.jsm"
);
let validAttrCodes = [
{
code:
"source%3Dgoogle.com%26medium%3Dorganic%26campaign%3D(not%20set)%26content%3D(not%20set)",
parsed: {
source: "google.com",
medium: "organic",
campaign: "(not%20set)",
content: "(not%20set)",
},
},
{
code: "source%3Dgoogle.com%26medium%3Dorganic%26campaign%3D%26content%3D",
parsed: { source: "google.com", medium: "organic" },
},
{
code: "source%3Dgoogle.com%26medium%3Dorganic%26campaign%3D(not%20set)",
parsed: {
source: "google.com",
medium: "organic",
campaign: "(not%20set)",
},
},
{
code: "source%3Dgoogle.com%26medium%3Dorganic",
parsed: { source: "google.com", medium: "organic" },
},
{ code: "source%3Dgoogle.com", parsed: { source: "google.com" } },
{ code: "medium%3Dgoogle.com", parsed: { medium: "google.com" } },
{ code: "campaign%3Dgoogle.com", parsed: { campaign: "google.com" } },
{ code: "content%3Dgoogle.com", parsed: { content: "google.com" } },
{
code: "experiment%3Dexperimental",
parsed: { experiment: "experimental" },
},
{ code: "variation%3Dvaried", parsed: { variation: "varied" } },
{
code: "ua%3DGoogle%20Chrome%20123",
parsed: { ua: "Google%20Chrome%20123" },
},
];
let invalidAttrCodes = [
// Empty string
"",
// Not escaped
"source=google.com&medium=organic&campaign=(not set)&content=(not set)",
// Too long
"campaign%3D" + "a".repeat(1000),
// Unknown key name
"source%3Dgoogle.com%26medium%3Dorganic%26large%3Dgeneticallymodified",
// Empty key name
"source%3Dgoogle.com%26medium%3Dorganic%26%3Dgeneticallymodified",
];