imported patch add-toolbox-zoom-test
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Fri, 27 Apr 2018 15:12:42 +0900
changeset 1496877 e5f8476ba86a66916e3471081e782c4df8d23951
parent 1496876 7dd8d0dc985473ca6a948ec067ab19cf10ede767
child 1496878 89e1ac3a002391339028e7dcb251ec5766af4ccc
push id267791
push usermantaroh@gmail.com
push dateFri, 27 Apr 2018 06:44:39 +0000
treeherdertry@0d5b8f93ab57 [default view] [failures only]
milestone61.0a1
imported patch add-toolbox-zoom-test
devtools/client/framework/test/browser_toolbox_zoom.js
--- a/devtools/client/framework/test/browser_toolbox_zoom.js
+++ b/devtools/client/framework/test/browser_toolbox_zoom.js
@@ -3,32 +3,81 @@
 
 "use strict";
 
 let {Toolbox} = require("devtools/client/framework/toolbox");
 
 const {LocalizationHelper} = require("devtools/shared/l10n");
 const L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties");
 
+// Use simple URL in order to prevent displacing the left positon of frames menu.
+const TEST_URL = "data:text/html,<iframe/>";
+
 add_task(async function() {
+  Services.prefs.setCharPref("devtools.toolbox.zoomValue", "1.0");
   await addTab("about:blank");
   let target = TargetFactory.forTab(gBrowser.selectedTab);
   let toolbox = await gDevTools.showToolbox(target,
                                             "styleeditor",
                                             Toolbox.HostType.BOTTOM);
 
   info("testing zoom keys");
 
   testZoomLevel("In", 2, 1.2, toolbox);
   testZoomLevel("Out", 3, 0.9, toolbox);
   testZoomLevel("Reset", 1, 1, toolbox);
 
   await toolbox.destroy();
   gBrowser.removeCurrentTab();
-  finish();
+});
+
+add_task(async function() {
+  const zoom = 1.5;
+
+  info("Load iframe page for checking the frame menu with x1.5 zoom.");
+  Services.prefs.setCharPref("devtools.toolbox.zoomValue", zoom.toString(10));
+  let tab = await addTab(TEST_URL);
+  let target = TargetFactory.forTab(gBrowser.selectedTab);
+  let toolbox = await gDevTools.showToolbox(target,
+                                            "webconsole",
+                                            Toolbox.HostType.BOTTOM);
+  await waitUntil(() => toolbox.win.devicePixelRatio === zoom);
+
+  info("Resizing the toolbox window in order to display the chevron menu.");
+  let hostWindow = toolbox.win.parent;
+  // If window is displayed bottom of screen, menu might be displayed above of button.
+  hostWindow.moveTo(0, 0);
+
+  let originWidth = hostWindow.outerWidth;
+  let originHeight = hostWindow.outerHeight;
+  let onResize = once(hostWindow, "resize");
+  hostWindow.resizeTo(1175, originHeight);
+  await onResize;
+
+  let menuList = ["toolbox-meatball-menu-button",
+                  "command-button-frames",
+                  "tools-chevron-menu-button"];
+
+  info("Check the each menus");
+  for (const menu of menuList) {
+    let [btnRect, menuRect] = await getButtonAndMenuRects(toolbox, menu);
+
+    // This rectangle's unit is viewport size, so this test allow the 2px error.
+    ok(Math.abs(menuRect.left - btnRect.left) / zoom < 2 &&
+       Math.abs(menuRect.top - btnRect.bottom) / zoom < 2,
+       "Menu has been displayed under the button. #" + menu);
+  }
+
+  onResize = once(hostWindow, "resize");
+  hostWindow.resizeTo(originWidth, originHeight);
+  await onResize;
+  Services.prefs.setCharPref("devtools.toolbox.zoomValue", "1.0");
+
+  await toolbox.destroy();
+  gBrowser.removeCurrentTab();
 });
 
 function testZoomLevel(type, times, expected, toolbox) {
   sendZoomKey("toolbox.zoom" + type + ".key", times);
 
   let zoom = getCurrentZoom(toolbox);
   is(zoom.toFixed(2), expected, "zoom level correct after zoom " + type);
 
@@ -44,8 +93,33 @@ function sendZoomKey(shortcut, times) {
   }
 }
 
 function getCurrentZoom(toolbox) {
   let windowUtils = toolbox.win.QueryInterface(Ci.nsIInterfaceRequestor)
     .getInterface(Ci.nsIDOMWindowUtils);
   return windowUtils.fullZoom;
 }
+
+async function getButtonAndMenuRects(toolbox, btnId) {
+  let doc = toolbox.win.document;
+  let menuButton = doc.getElementById(btnId);
+  menuButton.click();
+
+  let popupset = doc.querySelector("popupset");
+  let menuPopup;
+  await waitUntil(() => {
+    menuPopup = popupset.querySelector("menupopup[menu-api=\"true\"]");
+    return !!menuPopup && menuPopup.state === "open";
+  });
+  ok(menuPopup, "Menu popup is displayed.");
+
+  let windowUtils = toolbox.win.QueryInterface(Ci.nsIInterfaceRequestor)
+      .getInterface(Ci.nsIDOMWindowUtils);
+  let btnRect = windowUtils.getBoundsWithoutFlushing(menuButton);
+  let menuRect = windowUtils.getBoundsWithoutFlushing(menuPopup);
+
+  let onPopupHidden = once(menuPopup, "popuphidden");
+  menuPopup.hidePopup();
+  await onPopupHidden;
+
+  return [btnRect, menuRect];
+}