mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1905892 - Add urlbar-persisted-search-terms dump and create tests. r=jteow
Differential Revision: https://phabricator.services.mozilla.com/D215508
This commit is contained in:
parent
32296baa4c
commit
9e1eb79878
@ -0,0 +1,85 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
ChromeUtils.defineESModuleGetters(this, {
|
||||
RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
|
||||
JsonSchema: "resource://gre/modules/JsonSchema.sys.mjs",
|
||||
});
|
||||
|
||||
const URLBAR_PERSISTENCE_SETTINGS_KEY = "urlbar-persisted-search-terms";
|
||||
|
||||
/**
|
||||
* Checks to see if a value is an object or not.
|
||||
*
|
||||
* @param {*} value
|
||||
* The value to check.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isObject(value) {
|
||||
return value != null && typeof value == "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function modifies the schema to prevent allowing additional properties
|
||||
* on objects. This is used to enforce that the schema contains everything that
|
||||
* we deliver via the search configuration.
|
||||
*
|
||||
* These checks are not enabled in-product, as we want to allow older versions
|
||||
* to keep working if we add new properties for whatever reason.
|
||||
*
|
||||
* @param {object} section
|
||||
* The section to check to see if an additionalProperties flag should be added.
|
||||
*/
|
||||
function disallowAdditionalProperties(section) {
|
||||
// It is generally acceptable for new properties to be added to the
|
||||
// configuration as older builds will ignore them.
|
||||
//
|
||||
// As a result, we only check for new properties on nightly builds, and this
|
||||
// avoids us having to uplift schema changes. This also helps preserve the
|
||||
// schemas as documentation of "what was supported in this version".
|
||||
if (!AppConstants.NIGHTLY_BUILD) {
|
||||
info("Skipping additional properties validation.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (section.type == "object") {
|
||||
section.additionalProperties = false;
|
||||
}
|
||||
for (let value of Object.values(section)) {
|
||||
if (isObject(value)) {
|
||||
disallowAdditionalProperties(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_task(async function test_search_telemetry_validates_to_schema() {
|
||||
let schema = await IOUtils.readJSON(
|
||||
PathUtils.join(
|
||||
do_get_cwd().path,
|
||||
"urlbar-persisted-search-terms-schema.json"
|
||||
)
|
||||
);
|
||||
|
||||
disallowAdditionalProperties(schema);
|
||||
|
||||
let data = await RemoteSettings(URLBAR_PERSISTENCE_SETTINGS_KEY).get();
|
||||
|
||||
let validator = new JsonSchema.Validator(schema);
|
||||
|
||||
for (let entry of data) {
|
||||
// Records in Remote Settings contain additional properties independent of
|
||||
// the schema. Hence, we don't want to validate their presence.
|
||||
delete entry.schema;
|
||||
delete entry.id;
|
||||
delete entry.last_modified;
|
||||
|
||||
let result = validator.validate(entry);
|
||||
let message = `Should validate ${entry.providerId}`;
|
||||
if (!result.valid) {
|
||||
message += `:\n${JSON.stringify(result.errors, null, 2)}`;
|
||||
}
|
||||
Assert.ok(result.valid, message);
|
||||
}
|
||||
});
|
@ -202,6 +202,9 @@ support-files = [
|
||||
|
||||
["test_unitConversion.js"]
|
||||
|
||||
["test_urlbar_persisted_search_terms_validation.js"]
|
||||
support-files = ["../../schema/urlbar-persisted-search-terms-schema.json"]
|
||||
|
||||
["test_urlbar_search_terms_persistence.js"]
|
||||
|
||||
["test_word_boundary_search.js"]
|
||||
|
@ -9,6 +9,7 @@ if CONFIG["MOZ_BUILD_APP"] == "browser":
|
||||
"search-telemetry-v2.json",
|
||||
"sites-classification.json",
|
||||
"top-sites.json",
|
||||
"urlbar-persisted-search-terms.json",
|
||||
]
|
||||
|
||||
# These collections are referenced in toolkit/ or other core code, however
|
||||
|
@ -0,0 +1,48 @@
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"schema": 1719398671127,
|
||||
"providerId": "qwant",
|
||||
"includeParams": [
|
||||
{
|
||||
"key": "t",
|
||||
"values": [
|
||||
"web"
|
||||
],
|
||||
"canBeMissing": true
|
||||
}
|
||||
],
|
||||
"searchPageRegexp": "^https://www\\.qwant\\.com/",
|
||||
"id": "aa456ed6-cf07-4c2a-af58-bcfe7f03cfee",
|
||||
"last_modified": 1719927826949
|
||||
},
|
||||
{
|
||||
"schema": 1719587527089,
|
||||
"providerId": "duckduckgo",
|
||||
"excludeParams": [
|
||||
{
|
||||
"key": "iax"
|
||||
},
|
||||
{
|
||||
"key": "iar"
|
||||
},
|
||||
{
|
||||
"key": "iaxm"
|
||||
}
|
||||
],
|
||||
"includeParams": [
|
||||
{
|
||||
"key": "ia",
|
||||
"values": [
|
||||
"web"
|
||||
],
|
||||
"canBeMissing": true
|
||||
}
|
||||
],
|
||||
"searchPageRegexp": "^https://duckduckgo\\.com/",
|
||||
"id": "ca94a030-39a0-48ed-a1d1-b003f2be1adb",
|
||||
"last_modified": 1719927826946
|
||||
}
|
||||
],
|
||||
"timestamp": 1719927826946
|
||||
}
|
Loading…
Reference in New Issue
Block a user