Bug 1496075 - Part 2: Telemetry changes to support search extensions. r=chutten,raphael

Differential Revision: https://phabricator.services.mozilla.com/D25245

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dale Harvey 2019-04-11 20:48:57 +00:00
Родитель 7ebe97c465
Коммит 81edbab4a6
7 изменённых файлов: 76 добавлений и 27 удалений

Просмотреть файл

@ -596,23 +596,26 @@ EnvironmentAddonBuilder.prototype = {
},
// AddonListener
onEnabled() {
this._onAddonChange();
onEnabled(addon) {
this._onAddonChange(addon);
},
onDisabled() {
this._onAddonChange();
onDisabled(addon) {
this._onAddonChange(addon);
},
onInstalled() {
this._onAddonChange();
onInstalled(addon) {
this._onAddonChange(addon);
},
onUninstalling() {
this._onAddonChange();
onUninstalling(addon) {
this._onAddonChange(addon);
},
onUninstalled() {
this._onAddonChange();
onUninstalled(addon) {
this._onAddonChange(addon);
},
_onAddonChange() {
_onAddonChange(addon) {
if (addon && addon.isBuiltin && !addon.isSystem) {
return;
}
this._environment._log.trace("_onAddonChange");
this._checkForChanges("addons-changed");
},
@ -719,6 +722,10 @@ EnvironmentAddonBuilder.prototype = {
this._environment._addonsAreFull = fullData;
let activeAddons = {};
for (let addon of allAddons) {
// Don't collect any information about the new built-in search webextensions
if (addon.isBuiltin && !addon.isSystem) {
continue;
}
// Weird addon data in the wild can lead to exceptions while collecting
// the data.
try {

Просмотреть файл

@ -18,14 +18,17 @@ class TestSearchCounts(TelemetryTestCase):
"""Retrieve the identifier of the default search engine."""
script = """\
let [resolve] = arguments;
let searchService = Components.classes[
"@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsISearchService);
return searchService.defaultEngine.identifier;
return searchService.init().then(function () {
resolve(searchService.defaultEngine.identifier);
});
"""
with self.marionette.using_context(self.marionette.CONTEXT_CHROME):
return self.marionette.execute_script(textwrap.dedent(script))
return self.marionette.execute_async_script(textwrap.dedent(script))
def setUp(self):
"""Set up the test case and store the identifier of the default

Просмотреть файл

@ -0,0 +1,7 @@
{
"default": {
"visibleDefaultEngines": [
"telemetrySearchIdentifier"
]
}
}

Просмотреть файл

@ -0,0 +1,29 @@
{
"name": "telemetrySearchIdentifier",
"manifest_version": 2,
"version": "1.0",
"description": "telemetrySearchIdentifier",
"applications": {
"gecko": {
"id": "telemetrySearchIdentifier@search.mozilla.org"
}
},
"hidden": true,
"chrome_settings_overrides": {
"search_provider": {
"name": "telemetrySearchIdentifier",
"search_url": "https://ar.wikipedia.org/wiki/%D8%AE%D8%A7%D8%B5:%D8%A8%D8%AD%D8%AB",
"params": [
{
"name": "search",
"value": "{searchTerms}"
},
{
"name": "sourceId",
"value": "Mozilla-search"
}
],
"suggest_url": "https://ar.wikipedia.org/w/api.php?action=opensearch&search={searchTerms}"
}
}
}

Просмотреть файл

@ -862,8 +862,6 @@ function checkEnvironmentData(data, options = {}) {
}
add_task(async function setup() {
// Load a custom manifest to provide search engine loading from JAR files.
do_load_manifest("chrome.manifest");
registerFakeSysInfo();
spoofGfxAdapter();
do_get_profile();
@ -1527,19 +1525,21 @@ add_task(async function test_collectionWithbrokenAddonData() {
add_task(async function test_defaultSearchEngine() {
// Check that no default engine is in the environment before the search service is
// initialized.
let searchExtensions = do_get_cwd();
searchExtensions.append("data");
searchExtensions.append("search-extensions");
let resProt = Services.io.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler);
resProt.setSubstitution("search-extensions",
Services.io.newURI("file://" + searchExtensions.path));
let data = await TelemetryEnvironment.testCleanRestart().onInitialized();
checkEnvironmentData(data);
Assert.ok(!("defaultSearchEngine" in data.settings));
Assert.ok(!("defaultSearchEngineData" in data.settings));
// Load the engines definitions from a custom JAR file: that's needed so that
// Load the engines definitions from a xpcshell data: that's needed so that
// the search provider reports an engine identifier.
let url = "chrome://testsearchplugin/locale/searchplugins/";
let resProt = Services.io.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler);
resProt.setSubstitution("search-plugins",
Services.io.newURI(url));
// Initialize the search service.
await Services.search.init();
@ -1551,10 +1551,10 @@ add_task(async function test_defaultSearchEngine() {
checkEnvironmentData(data);
Assert.equal(data.settings.defaultSearchEngine, "telemetrySearchIdentifier");
let expectedSearchEngineData = {
name: "telemetrySearchIdentifier",
loadPath: "jar:[other]/searchTest.jar!testsearchplugin/telemetrySearchIdentifier.xml",
origin: "default",
submissionURL: "http://ar.wikipedia.org/wiki/%D8%AE%D8%A7%D8%B5:%D8%A8%D8%AD%D8%AB?search=&sourceid=Mozilla-search",
"name": "telemetrySearchIdentifier",
"loadPath": "[other]addEngineWithDetails:telemetrySearchIdentifier@search.mozilla.org",
"origin": "default",
"submissionURL": "https://ar.wikipedia.org/wiki/%D8%AE%D8%A7%D8%B5:%D8%A8%D8%AD%D8%AB?search=&sourceId=Mozilla-search",
};
Assert.deepEqual(data.settings.defaultSearchEngineData, expectedSearchEngineData);

Просмотреть файл

@ -55,6 +55,9 @@ add_task(async function test_setup() {
finishAddonManagerStartup();
fakeIntlReady();
// Make sure SearchService is ready for it to be called.
await Services.search.init();
// Make sure we don't generate unexpected pings due to pref changes.
await setEmptyPrefWatchlist();

Просмотреть файл

@ -4,8 +4,8 @@ firefox-appdir = browser
# The *.xpi files are only needed for test_TelemetryEnvironment.js, but
# xpcshell fails to install tests if we move them under the test entry.
support-files =
../search/chrome.manifest
../search/searchTest.jar
data/search-extensions/list.json
data/search-extensions/telemetrySearchIdentifier/manifest.json
dictionary.xpi
engine.xml
system.xpi