Bug 1290680 - Add test coverage for TooltipToggle on HTMLTooltip r=jdescottes
authorJarda Snajdr <jsnajdr@gmail.com>
Mon, 15 Aug 2016 16:03:16 +0200
changeset 400737 3e4803eb9a5ca755a8881bf599f05f8430ffb343
parent 400736 9ccc7eb9a74c20aae65d79a1dddb180c2d3609f5
child 400738 9564d4db6d685e237f6a19883bb0165daf5e9b70
child 400780 62dd82f4b4c09709fbe7a6ce3345fe35c1755ba2
child 400825 054d4856cea6150a6638e5daf7913713281af97d
child 400829 e13da7163887f8f3d043978dc939ec74dae2a82a
child 401132 d0a74aff2b1f170e1ee2d8b5bc034d64ff07e492
child 401171 3fee301bf006af47e68b83403cc08f50adbb0696
child 401204 147f26d0a9b752e6348577f0026a0369af7f33a7
push id26263
push userbmo:standard8@mozilla.com
push dateMon, 15 Aug 2016 16:06:35 +0000
reviewersjdescottes
bugs1290680
milestone51.0a1
Bug 1290680 - Add test coverage for TooltipToggle on HTMLTooltip r=jdescottes MozReview-Commit-ID: 8j3fbJ2xhml
devtools/client/shared/test/browser.ini
devtools/client/shared/test/browser_html_tooltip_hover.js
--- a/devtools/client/shared/test/browser.ini
+++ b/devtools/client/shared/test/browser.ini
@@ -116,16 +116,17 @@ skip-if = e10s # Bug 1221911, bug 122228
 [browser_html_tooltip-01.js]
 [browser_html_tooltip-02.js]
 [browser_html_tooltip-03.js]
 [browser_html_tooltip-04.js]
 [browser_html_tooltip-05.js]
 [browser_html_tooltip_arrow-01.js]
 [browser_html_tooltip_arrow-02.js]
 [browser_html_tooltip_consecutive-show.js]
+[browser_html_tooltip_hover.js]
 [browser_html_tooltip_offset.js]
 [browser_html_tooltip_rtl.js]
 [browser_html_tooltip_variable-height.js]
 [browser_html_tooltip_width-auto.js]
 [browser_html_tooltip_xul-wrapper.js]
 [browser_inplace-editor-01.js]
 [browser_inplace-editor-02.js]
 [browser_inplace-editor_autocomplete_01.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/shared/test/browser_html_tooltip_hover.js
@@ -0,0 +1,63 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+/* import-globals-from helper_html_tooltip.js */
+
+"use strict";
+
+/**
+ * Test the TooltipToggle helper class for HTMLTooltip
+ */
+
+const HTML_NS = "http://www.w3.org/1999/xhtml";
+const TEST_URI = `data:text/xml;charset=UTF-8,<?xml version="1.0"?>
+  <?xml-stylesheet href="chrome://global/skin/global.css"?>
+  <?xml-stylesheet href="chrome://devtools/skin/variables.css"?>
+  <?xml-stylesheet href="chrome://devtools/skin/tooltips.css"?>
+  <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+   class="theme-light" title="Tooltip hover test">
+    <vbox id="container" flex="1">
+      <hbox id="box1" flex="1"><label>test1</label></hbox>
+      <hbox id="box2" flex="1"><label>test2</label></hbox>
+      <hbox id="box3" flex="1"><label>test3</label></hbox>
+      <hbox id="box4" flex="1"><label>test4</label></hbox>
+    </vbox>
+  </window>`;
+
+const {HTMLTooltip} = require("devtools/client/shared/widgets/HTMLTooltip");
+loadHelperScript("helper_html_tooltip.js");
+
+add_task(function* () {
+  let [,, doc] = yield createHost("bottom", TEST_URI);
+
+  let width = 100, height = 50;
+  let tooltipContent = doc.createElementNS(HTML_NS, "div");
+  tooltipContent.textContent = "tooltip";
+  let tooltip = new HTMLTooltip({doc}, {useXulWrapper: false});
+  tooltip.setContent(tooltipContent, {width, height});
+
+  let container = doc.getElementById("container");
+  tooltip.startTogglingOnHover(container, () => true);
+
+  info("Hover on each of the 4 boxes, expect the tooltip to appear");
+  function* showAndCheck(boxId, position) {
+    info(`Show tooltip on ${boxId}`);
+    let box = doc.getElementById(boxId);
+    let shown = tooltip.once("shown");
+    EventUtils.synthesizeMouseAtCenter(box, { type: "mousemove" }, doc.defaultView);
+    yield shown;
+    checkTooltipGeometry(tooltip, box, {position, width, height});
+  }
+
+  yield showAndCheck("box1", "bottom");
+  yield showAndCheck("box2", "bottom");
+  yield showAndCheck("box3", "top");
+  yield showAndCheck("box4", "top");
+
+  info("Move out of the container");
+  let hidden = tooltip.once("hidden");
+  EventUtils.synthesizeMouseAtCenter(container, { type: "mouseout" }, doc.defaultView);
+  yield hidden;
+
+  info("Destroy the tooltip and finish");
+  tooltip.destroy();
+});