Bug 1359137 - fix BrowserUITelemetry's reliance on the default state of things in CustomizableUI, r?mikedeboer draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 31 May 2017 14:15:18 +0100
changeset 588983 fed312704085858ce6dfa5a22a764d57168db77a
parent 588982 843b4eb59b9c44e027f88bc1bd2285d55337d67b
child 588984 b125d74b48669372c32c7046c6ac9f8ac889e8c0
push id62208
push usergijskruitbosch@gmail.com
push dateMon, 05 Jun 2017 10:41:48 +0000
reviewersmikedeboer
bugs1359137
milestone55.0a1
Bug 1359137 - fix BrowserUITelemetry's reliance on the default state of things in CustomizableUI, r?mikedeboer MozReview-Commit-ID: I4mpVR6G8pi
browser/modules/BrowserUITelemetry.jsm
browser/modules/test/browser/browser_BrowserUITelemetry_syncedtabs.js
--- a/browser/modules/BrowserUITelemetry.jsm
+++ b/browser/modules/BrowserUITelemetry.jsm
@@ -22,37 +22,40 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "UITour",
   "resource:///modules/UITour.jsm");
 XPCOMUtils.defineLazyGetter(this, "Timer", function() {
   let timer = {};
   Cu.import("resource://gre/modules/Timer.jsm", timer);
   return timer;
 });
 
+XPCOMUtils.defineLazyPreferenceGetter(this, "gPhotonStructure", "browser.photon.structure.enabled");
+
 const MS_SECOND = 1000;
 const MS_MINUTE = MS_SECOND * 60;
 const MS_HOUR = MS_MINUTE * 60;
 
+const LEGACY_PANEL_PLACEMENTS = [
+  "edit-controls",
+  "zoom-controls",
+  "new-window-button",
+  "privatebrowsing-button",
+  "save-page-button",
+  "print-button",
+  "history-panelmenu",
+  "fullscreen-button",
+  "find-button",
+  "preferences-button",
+  "add-ons-button",
+  "sync-button",
+  "developer-button"
+];
+
 XPCOMUtils.defineLazyGetter(this, "DEFAULT_AREA_PLACEMENTS", function() {
   let result = {
-    "PanelUI-contents": [
-      "edit-controls",
-      "zoom-controls",
-      "new-window-button",
-      "privatebrowsing-button",
-      "save-page-button",
-      "print-button",
-      "history-panelmenu",
-      "fullscreen-button",
-      "find-button",
-      "preferences-button",
-      "add-ons-button",
-      "sync-button",
-      "developer-button",
-    ],
     "nav-bar": [
       "urlbar-container",
       "search-container",
       "bookmarks-menu-button",
       "pocket-button",
       "downloads-button",
       "home-button",
       "social-share-button",
@@ -68,27 +71,32 @@ XPCOMUtils.defineLazyGetter(this, "DEFAU
       "new-tab-button",
       "alltabs-button",
     ],
     "PersonalToolbar": [
       "personal-bookmarks",
     ],
   };
 
-  let showCharacterEncoding = Services.prefs.getComplexValue(
-    "browser.menu.showCharacterEncoding",
-    Ci.nsIPrefLocalizedString
-  ).data;
-  if (showCharacterEncoding == "true") {
-    result["PanelUI-contents"].push("characterencoding-button");
-  }
+  if (gPhotonStructure) {
+    result["widget-overflow-fixed-list"] = [];
+  } else {
+    result["PanelUI-contents"] = LEGACY_PANEL_PLACEMENTS;
+    let showCharacterEncoding = Services.prefs.getComplexValue(
+      "browser.menu.showCharacterEncoding",
+      Ci.nsIPrefLocalizedString
+    ).data;
+    if (showCharacterEncoding == "true") {
+      result["PanelUI-contents"].push("characterencoding-button");
+    }
 
-  if (!AppConstants.RELEASE_OR_BETA) {
-    if (Services.prefs.getBoolPref("extensions.webcompat-reporter.enabled")) {
-      result["PanelUI-contents"].push("webcompat-reporter-button");
+    if (!AppConstants.RELEASE_OR_BETA) {
+      if (Services.prefs.getBoolPref("extensions.webcompat-reporter.enabled")) {
+        result["PanelUI-contents"].push("webcompat-reporter-button");
+      }
     }
   }
 
   return result;
 });
 
 XPCOMUtils.defineLazyGetter(this, "DEFAULT_AREAS", function() {
   return Object.keys(DEFAULT_AREA_PLACEMENTS);
@@ -99,17 +107,20 @@ XPCOMUtils.defineLazyGetter(this, "PALET
     "open-file-button",
     "developer-button",
     "feed-button",
     "email-link-button",
     "containers-panelmenu",
   ];
 
   let panelPlacements = DEFAULT_AREA_PLACEMENTS["PanelUI-contents"];
-  if (panelPlacements.indexOf("characterencoding-button") == -1) {
+  if (!panelPlacements) {
+    result.push(... LEGACY_PANEL_PLACEMENTS);
+  }
+  if (!panelPlacements || !panelPlacements.includes("characterencoding-button")) {
     result.push("characterencoding-button");
   }
 
   if (Services.prefs.getBoolPref("privacy.panicButton.enabled")) {
     result.push("panic-button");
   }
 
   return result;
@@ -463,34 +474,34 @@ this.BrowserUITelemetry = {
     if (item.id == "bookmarks-menu-button" ||
         getIDBasedOnFirstIDedAncestor(item) == "bookmarks-menu-button") {
       this._bookmarksMenuButtonMouseUp(aEvent);
       return;
     }
 
     // Perhaps we're seeing one of the default toolbar items
     // being clicked.
-    if (ALL_BUILTIN_ITEMS.indexOf(item.id) != -1) {
+    if (ALL_BUILTIN_ITEMS.includes(item.id)) {
       // Base case - we clicked directly on one of our built-in items,
       // and we can go ahead and register that click.
       this._countMouseUpEvent("click-builtin-item", item.id, aEvent.button);
       return;
     }
 
     // If not, we need to check if the item's anonid is in our list
     // of built-in items to check.
-    if (ALL_BUILTIN_ITEMS.indexOf(item.getAttribute("anonid")) != -1) {
+    if (ALL_BUILTIN_ITEMS.includes(item.getAttribute("anonid"))) {
       this._countMouseUpEvent("click-builtin-item", item.getAttribute("anonid"), aEvent.button);
       return;
     }
 
     // If not, we need to check if one of the ancestors of the clicked
     // item is in our list of built-in items to check.
     let candidate = getIDBasedOnFirstIDedAncestor(item);
-    if (ALL_BUILTIN_ITEMS.indexOf(candidate) != -1) {
+    if (ALL_BUILTIN_ITEMS.includes(candidate)) {
       this._countMouseUpEvent("click-builtin-item", candidate, aEvent.button);
     }
   },
 
   _getWindowMeasurements(aWindow, searchResult) {
     let document = aWindow.document;
     let result = {};
 
--- a/browser/modules/test/browser/browser_BrowserUITelemetry_syncedtabs.js
+++ b/browser/modules/test/browser/browser_BrowserUITelemetry_syncedtabs.js
@@ -60,32 +60,33 @@ function promiseTabsUpdated() {
 
 add_task(async function test_menu() {
   // Reset BrowserUITelemetry's world.
   BUIT._countableEvents = {};
 
   let tabsUpdated = promiseTabsUpdated();
 
   // check the button's functionality
-  await PanelUI.show();
+  CustomizableUI.addWidgetToArea("sync-button", "nav-bar");
 
   let syncButton = document.getElementById("sync-button");
   syncButton.click();
 
   await tabsUpdated;
   // Get our 1 tab and click on it.
   let tabList = document.getElementById("PanelUI-remotetabs-tabslist");
   let tabEntry = tabList.firstChild.nextSibling;
   tabEntry.click();
 
   let counts = BUIT._countableEvents[BUIT.currentBucket];
   Assert.deepEqual(counts, {
     "click-builtin-item": { "sync-button": { left: 1 } },
     "synced-tabs": { open: { "toolbarbutton-subview": 1 } },
   });
+  CustomizableUI.reset();
 });
 
 add_task(async function test_sidebar() {
   // Reset BrowserUITelemetry's world.
   BUIT._countableEvents = {};
 
   await SidebarUI.show("viewTabsSidebar");