Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

/* Any copyright is dedicated to the Public Domain.
/*
* This test ensures we compare URLs correctly. For more info on the scores,
* please read the function definition.
*/
ChromeUtils.defineESModuleGetters(this, {
SearchSERPTelemetry: "resource:///modules/SearchSERPTelemetry.sys.mjs",
});
const TESTS = [
{
title: "No difference",
expected: Infinity,
},
{
// Since the ordering is different, a strict equality match is not going
// match. The score will be high, but not Infinity.
title: "Different ordering of query parameters",
expected: 7,
},
{
title: "Different protocol",
expected: 0,
},
{
title: "Different origin",
expected: 0,
},
{
title: "Different path",
expected: 1,
},
{
title: "Different path, path on",
options: {
path: true,
},
expected: 0,
},
{
title: "Different query parameter keys",
expected: 3,
},
{
title: "Different query parameter keys, paramValues on",
options: {
paramValues: true,
},
// Shouldn't change the score because the option should only nullify
// the result if one of the keys match but has different values.
expected: 3,
},
{
title: "Some different query parameter keys",
expected: 5,
},
{
title: "Some different query parameter keys, paramValues on",
options: {
paramValues: true,
},
// Shouldn't change the score because the option should only trigger
// if the keys match but values differ.
expected: 5,
},
{
title: "Different query parameter values",
expected: 4,
},
{
title: "Different query parameter values, paramValues on",
options: {
paramValues: true,
},
expected: 0,
},
{
title: "Some different query parameter values",
expected: 6,
},
{
title: "Different query parameter values, paramValues on",
options: {
paramValues: true,
},
expected: 0,
},
{
title: "Empty query parameter",
expected: 7,
},
{
title: "Empty query parameter, paramValues on",
options: {
paramValues: true,
},
expected: 7,
},
{
title: "Missing empty query parameter",
expected: 5,
},
{
title: "Missing empty query parameter, paramValues on",
options: {
paramValues: true,
},
expected: 5,
},
{
title: "Different empty query parameter",
expected: 6,
},
{
title: "Different empty query parameter, paramValues on",
options: {
paramValues: true,
},
expected: 0,
},
];
add_setup(async function () {
await SearchSERPTelemetry.init();
});
add_task(async function test_parsing_extracted_urls() {
for (let test of TESTS) {
info(test.title);
let result = SearchSERPTelemetry.compareUrls(
new URL(test.url1),
new URL(test.url2),
test.options
);
Assert.equal(result, test.expected, "Equality: url1, url2");
// Flip the URLs to ensure order doesn't matter.
result = SearchSERPTelemetry.compareUrls(
new URL(test.url2),
new URL(test.url1),
test.options
);
Assert.equal(result, test.expected, "Equality: url2, url1");
}
});