Bug 1308440 - fix related contextMenu tests; r=Tomcat
authorFred Lin <gasolin@mozilla.com>
Mon, 24 Oct 2016 03:21:00 +0200
changeset 319143 08efaee1d568cea9e70c86a7eca49c3c53553ed8
parent 319142 c0a8fecacb46f22d16205470dfdeb5e6aea815f8
child 319165 c845bfd0accb7e0c29b41713255963b08006e701
child 319166 426d6b4448a7da82db5b00cd48ea0571ec0e60fe
push id30861
push usercbook@mozilla.com
push dateMon, 24 Oct 2016 14:54:01 +0000
treeherdermozilla-central@08efaee1d568 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersTomcat
bugs1308440
milestone52.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 1308440 - fix related contextMenu tests; r=Tomcat MozReview-Commit-ID: BXBm42C1Xu
devtools/client/netmonitor/test/browser_net_copy_params.js
devtools/client/netmonitor/test/head.js
--- a/devtools/client/netmonitor/test/browser_net_copy_params.js
+++ b/devtools/client/netmonitor/test/browser_net_copy_params.js
@@ -6,17 +6,17 @@
 /**
  * Tests whether copying a request item's parameters works.
  */
 
 add_task(function* () {
   let { tab, monitor } = yield initNetMonitor(PARAMS_URL);
   info("Starting test... ");
 
-  let { document, NetMonitorView } = monitor.panelWin;
+  let { NetMonitorView } = monitor.panelWin;
   let { RequestsMenu } = NetMonitorView;
 
   RequestsMenu.lazyUpdate = false;
 
   let wait = waitForNetworkEvents(monitor, 1, 6);
   yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
     content.wrappedJSObject.performRequests();
   });
@@ -60,32 +60,36 @@ add_task(function* () {
 
   RequestsMenu.selectedItem = RequestsMenu.getItemAtIndex(6);
   yield testCopyUrlParamsHidden(true);
   yield testCopyPostDataHidden(true);
 
   return teardown(monitor);
 
   function testCopyUrlParamsHidden(hidden) {
-    RequestsMenu._onContextShowing();
-    is(document.querySelector("#request-menu-context-copy-url-params").hidden, hidden,
+    let allMenuItems = openContextMenuAndGetAllItems(NetMonitorView);
+    let copyUrlParamsNode = allMenuItems.find(item =>
+      item.id === "request-menu-context-copy-url-params");
+    is(copyUrlParamsNode.visible, !hidden,
       "The \"Copy URL Parameters\" context menu item should" + (hidden ? " " : " not ") +
         "be hidden.");
   }
 
   function* testCopyUrlParams(queryString) {
     yield waitForClipboardPromise(function setup() {
       RequestsMenu.copyUrlParams();
     }, queryString);
     ok(true, "The url query string copied from the selected item is correct.");
   }
 
   function testCopyPostDataHidden(hidden) {
-    RequestsMenu._onContextShowing();
-    is(document.querySelector("#request-menu-context-copy-post-data").hidden, hidden,
+    let allMenuItems = openContextMenuAndGetAllItems(NetMonitorView);
+    let copyPostDataNode = allMenuItems.find(item =>
+      item.id === "request-menu-context-copy-post-data");
+    is(copyPostDataNode.visible, !hidden,
       "The \"Copy POST Data\" context menu item should" + (hidden ? " " : " not ") +
         "be hidden.");
   }
 
   function* testCopyPostData(postData) {
     yield waitForClipboardPromise(function setup() {
       RequestsMenu.copyPostData();
     }, postData);
--- a/devtools/client/netmonitor/test/head.js
+++ b/devtools/client/netmonitor/test/head.js
@@ -485,8 +485,28 @@ function waitForContentMessage(name) {
 
   let def = promise.defer();
   mm.addMessageListener(name, function onMessage(msg) {
     mm.removeMessageListener(name, onMessage);
     def.resolve(msg);
   });
   return def.promise;
 }
+
+/**
+ * Open the requestMenu menu and return all of it's items in a flat array
+ * @param {netmonitorPanel} netmonitor
+ * @param {Object} options to pass into openMenu
+ * @return An array of MenuItems
+ */
+function openContextMenuAndGetAllItems(netmonitor, options) {
+  let menu = netmonitor.RequestsMenu._openMenu(options);
+
+  // Flatten all menu items into a single array to make searching through it easier
+  let allItems = [].concat.apply([], menu.items.map(function addItem(item) {
+    if (item.submenu) {
+      return addItem(item.submenu.items);
+    }
+    return item;
+  }));
+
+  return allItems;
+}