Bug 1510182 - Load edit menu strings for each new toolbox window;r=Honza
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 28 Nov 2018 11:43:34 +0000
changeset 504923 de432b1f84fcb772f1432fba941246782f1ab1d0
parent 504922 66612048bbdcd6a587c480ede79a5cc53138db7e
child 504924 6adfb885abd523d418b0919cabd04b4a22472a25
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1510182
milestone65.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 1510182 - Load edit menu strings for each new toolbox window;r=Honza Differential Revision: https://phabricator.services.mozilla.com/D13222
devtools/client/framework/toolbox-context-menu.js
devtools/client/inspector/test/browser.ini
devtools/client/inspector/test/browser_inspector_textbox-menu_reopen_toolbox.js
--- a/devtools/client/framework/toolbox-context-menu.js
+++ b/devtools/client/framework/toolbox-context-menu.js
@@ -4,28 +4,30 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const Menu = require("devtools/client/framework/menu");
 const MenuItem = require("devtools/client/framework/menu-item");
 
-var stringsLoaded = false;
+// This WeakMap will be used to know if strings have already been loaded in a given
+// window, which will be used as key.
+const stringsLoaded = new WeakMap();
 
 /**
  * Lazily load strings for the edit menu.
  */
 function loadEditMenuStrings(win) {
-  if (stringsLoaded) {
+  if (stringsLoaded.has(win)) {
     return;
   }
 
   if (win.MozXULElement) {
-    stringsLoaded = true;
+    stringsLoaded.set(win, true);
     win.MozXULElement.insertFTLIfNeeded("toolkit/main-window/editmenu.ftl");
   }
 }
 
 /**
  * Return an 'edit' menu for a input field. This integrates directly
  * with docshell commands to provide the right enabled state and editor
  * functionality.
--- a/devtools/client/inspector/test/browser.ini
+++ b/devtools/client/inspector/test/browser.ini
@@ -192,8 +192,9 @@ skip-if = (os == 'linux' && bits == 32 &
 [browser_inspector_search-suggests-ids-and-classes.js]
 [browser_inspector_select-docshell.js]
 [browser_inspector_select-last-selected.js]
 [browser_inspector_search-navigation.js]
 [browser_inspector_sidebarstate.js]
 [browser_inspector_startup.js]
 [browser_inspector_switch-to-inspector-on-pick.js]
 [browser_inspector_textbox-menu.js]
+[browser_inspector_textbox-menu_reopen_toolbox.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/test/browser_inspector_textbox-menu_reopen_toolbox.js
@@ -0,0 +1,45 @@
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Test that textbox context menu elements are still displayed correctly after reopening
+// the toolbox. Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1510182.
+
+add_task(async function() {
+  await addTab(`data:text/html;charset=utf-8,<div>test</div>`);
+
+  info("Testing the textbox context menu a first time");
+  const {toolbox, inspector} = await openInspector();
+  await checkContextMenuOnSearchbox(inspector, toolbox);
+
+  // Destroy the toolbox and try the context menu again with a new toolbox.
+  await toolbox.destroy();
+
+  info("Testing the textbox context menu after reopening the toolbox");
+  const {toolbox: newToolbox, inspector: newInspector} = await openInspector();
+  await checkContextMenuOnSearchbox(newInspector, newToolbox);
+});
+
+async function checkContextMenuOnSearchbox(inspector, toolbox) {
+  // The same context menu is used for any text input.
+  // Here we use the inspector searchbox for this test because it is always available.
+  const searchbox = inspector.panelDoc.getElementById("inspector-searchbox");
+
+  info("Simulating context click on the textbox and expecting the menu to open");
+  const onContextMenu = toolbox.once("menu-open");
+  synthesizeContextMenuEvent(searchbox);
+  await onContextMenu;
+
+  const textboxContextMenu = toolbox.doc.getElementById("toolbox-menu");
+  info("Wait until menu items are rendered");
+  const pasteElement = textboxContextMenu.querySelector("#editmenu-paste");
+  await waitUntil(() => !!pasteElement.getAttribute("label"));
+
+  is(pasteElement.getAttribute("label"), "Paste", "Paste is visible and localized");
+
+  info("Closing the menu");
+  const onContextMenuHidden = toolbox.once("menu-close");
+  EventUtils.sendKey("ESCAPE", toolbox.win);
+  await onContextMenuHidden;
+}