fune/browser/components/attribution/test/xpcshell/test_attribution_parsing.js
Nick Alexander 05efc87784 Bug 1525076 - Part 3: Add method to serialize attribution data. r=mixedpuppy
On Windows, we parse the attribution data as if it was the
`URL.search` parameter.  On macOS, we parse a URL slightly
differently: we parse it like `URL.searchParams` and we deduplicate
parameters.

For caching on macOS we need to serialize the parsed data.  We could
use either approach but we elect to write the code serialized as it
would be on Windows, since that is the one that is getting actively
tested in the wild.

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

44 lines
1.3 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
/**
* This test file exists to be run on any platform during development,
* whereas the test_AttributionCode.js will test the attribution file
* in the app local data dir on Windows. It will only run under
* Windows on try.
*/
/**
* Test validation of attribution codes.
*/
add_task(async function testValidAttrCodes() {
for (let entry of validAttrCodes) {
let result = AttributionCode.parseAttributionCode(entry.code);
Assert.deepEqual(
result,
entry.parsed,
"Parsed code should match expected value, code was: " + entry.code
);
result = AttributionCode.serializeAttributionData(entry.parsed);
if (!entry.doesNotRoundtrip) {
Assert.deepEqual(
result,
entry.code,
"Serialized data should match expected value, code was: " + entry.code
);
}
}
});
/**
* Make sure codes with various formatting errors are not seen as valid.
*/
add_task(async function testInvalidAttrCodes() {
for (let code of invalidAttrCodes) {
let result = AttributionCode.parseAttributionCode(code);
Assert.deepEqual(result, {}, "Code should have failed to parse: " + code);
}
});