Bug 1359137 - fix BrowserUITelemetry's reliance on the default state of things in CustomizableUI, r=mikedeboer
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 31 May 2017 14:15:18 +0100
changeset 410456 4f3980aa447fda41b2b082195b5addd1417733cf
parent 410455 5ec621ced42e4e1758e0c5ebe4974d041aa45ef7
child 410457 a0899380ac24b0dfea3ea5d6e2ed5f981491bf0e
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1359137
milestone55.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 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");