Bug 1496075 - Part 2: Telemetry changes to support search extensions. r=chutten,raphael
authorDale Harvey <dale@arandomurl.com>
Thu, 11 Apr 2019 20:48:57 +0000
changeset 469100 e07b4ceea0777d40402f2af1b601b2705deb2a78
parent 469099 7efb082cc25d1a58fe343055982b1459b2f9e1ee
child 469101 9e0b9cbb8982e59fab316a224d17b53f38a4ea65
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten, raphael
bugs1496075
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1496075 - Part 2: Telemetry changes to support search extensions. r=chutten,raphael Differential Revision: https://phabricator.services.mozilla.com/D25245
toolkit/components/telemetry/app/TelemetryEnvironment.jsm
toolkit/components/telemetry/tests/marionette/tests/client/test_search_counts_across_sessions.py
toolkit/components/telemetry/tests/unit/data/search-extensions/list.json
toolkit/components/telemetry/tests/unit/data/search-extensions/telemetrySearchIdentifier/manifest.json
toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
toolkit/components/telemetry/tests/unit/xpcshell.ini
--- a/toolkit/components/telemetry/app/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/app/TelemetryEnvironment.jsm
@@ -591,33 +591,36 @@ EnvironmentAddonBuilder.prototype = {
    * Register an addon listener and watch for changes.
    */
   watchForChanges() {
     this._loaded = true;
     AddonManager.addAddonListener(this);
   },
 
   // 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");
   },
 
   // nsIObserver
   observe(aSubject, aTopic, aData) {
     this._environment._log.trace("observe - Topic " + aTopic);
     if (aTopic == BLOCKLIST_LOADED_TOPIC) {
@@ -714,16 +717,20 @@ EnvironmentAddonBuilder.prototype = {
    */
   async _getActiveAddons() {
     // Request addons, asynchronously.
     let {addons: allAddons, fullData} = await AddonManager.getActiveAddons(["extension", "service"]);
 
     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 {
         // Make sure to have valid dates.
         let updateDate = new Date(Math.max(0, addon.updateDate));
 
         activeAddons[addon.id] = {
           version: limitStringToLength(addon.version, MAX_ADDON_STRING_LENGTH),
--- a/toolkit/components/telemetry/tests/marionette/tests/client/test_search_counts_across_sessions.py
+++ b/toolkit/components/telemetry/tests/marionette/tests/client/test_search_counts_across_sessions.py
@@ -13,24 +13,27 @@ from telemetry_harness.ping_filters impo
 
 class TestSearchCounts(TelemetryTestCase):
     """Test for SEARCH_COUNTS across sessions."""
 
     def get_default_search_engine(self):
         """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
         search engine, which is required for reading SEARCH_COUNTS from
         keyed histograms in pings.
         """
         super(TestSearchCounts, self).setUp()
         self.search_engine = self.get_default_search_engine()
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/data/search-extensions/list.json
@@ -0,0 +1,7 @@
+{
+  "default": {
+    "visibleDefaultEngines": [
+      "telemetrySearchIdentifier"
+    ]
+  }
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/data/search-extensions/telemetrySearchIdentifier/manifest.json
@@ -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}"
+    }
+  }
+}
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
@@ -857,18 +857,16 @@ function checkEnvironmentData(data, opti
   checkSettingsSection(data);
   checkProfileSection(data);
   checkPartnerSection(data, isInitial);
   checkSystemSection(data);
   checkAddonsSection(data, expectBrokenAddons);
 }
 
 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();
 
   // The system add-on must be installed before AddonManager is started.
   const distroDir = FileUtils.getDir("ProfD", ["sysfeatures", "app0"], true);
   do_get_file("system.xpi").copyTo(distroDir, "tel-system-xpi@tests.mozilla.org.xpi");
   let system_addon = FileUtils.File(distroDir.path);
@@ -1522,44 +1520,46 @@ add_task(async function test_collectionW
   // Uninstall the valid addon.
   await addon.startupPromise;
   await addon.uninstall();
 });
 
 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();
   await promiseNextTick();
 
   // Our default engine from the JAR file has an identifier. Check if it is correctly
   // reported.
   data = TelemetryEnvironment.currentEnvironment;
   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);
 
   // Remove all the search engines.
   for (let engine of await Services.search.getEngines()) {
     await Services.search.removeEngine(engine);
   }
   // The search service does not notify "engine-current" when removing a default engine.
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
@@ -50,16 +50,19 @@ function setMinimumPolicyVersion(aNewPol
 
 add_task(async function test_setup() {
   // Addon manager needs a profile directory
   do_get_profile(true);
   loadAddonManager("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   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();
 
   // Don't bypass the notifications in this test, we'll fake it.
   Services.prefs.setBoolPref(TelemetryUtils.Preferences.BypassNotification, false);
 
   TelemetryReportingPolicy.setup();
 });
--- a/toolkit/components/telemetry/tests/unit/xpcshell.ini
+++ b/toolkit/components/telemetry/tests/unit/xpcshell.ini
@@ -1,16 +1,16 @@
 [DEFAULT]
 head = head.js
 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
   restartless.xpi
   testUnicodePDB32.dll
   testNoPDB32.dll
   testUnicodePDB64.dll
   testNoPDB64.dll