Bug 1233497 - Make browser_bug710878.js avoid CPOW usage in utilityOverlay.js. r?felipe draft
authorMike Conley <mconley@mozilla.com>
Tue, 05 Jan 2016 13:53:27 -0500
changeset 322527 4a91b63ac0cd94b617e80d974e8411a82e9d63c7
parent 322526 5d08d5ac1b78fdb933e3a2a1c60cccb2d562ff3b
child 322528 0b73a0a0f7f9d54e77df9a37b9207fbc685cb108
push id9629
push usermconley@mozilla.com
push dateMon, 18 Jan 2016 22:25:49 +0000
reviewersfelipe
bugs1233497, 710878
milestone46.0a1
Bug 1233497 - Make browser_bug710878.js avoid CPOW usage in utilityOverlay.js. r?felipe
browser/base/content/test/general/browser_bug710878.js
--- a/browser/base/content/test/general/browser_bug710878.js
+++ b/browser/base/content/test/general/browser_bug710878.js
@@ -1,26 +1,34 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-function test()
-{
-  waitForExplicitFinish();
-
-  gBrowser.selectedTab = gBrowser.addTab();
-  gBrowser.selectedBrowser.addEventListener("load", function onload() {
-    gBrowser.selectedBrowser.removeEventListener("load", onload, true);
-    waitForFocus(performTest, content);
-  }, true);
-
-  content.location = "data:text/html;charset=utf-8,<a href='%23xxx'><span>word1 <span> word2 </span></span><span> word3</span></a>";
+const PAGE = "data:text/html;charset=utf-8,<a href='%23xxx'><span>word1 <span> word2 </span></span><span> word3</span></a>";
 
-  function performTest()
-  {
-    let doc = content.document;
-    let link = doc.querySelector("a");;
-    let text = gatherTextUnder(link);
-    is(text, "word1 word2 word3", "Text under link is correctly computed.");
-    gBrowser.removeCurrentTab();
-    finish();
-  }
-}
+/**
+ * Tests that we correctly compute the text for context menu
+ * selection of some content.
+ */
+add_task(function*() {
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: PAGE,
+  }, function*(browser) {
+      let contextMenu = document.getElementById("contentAreaContextMenu");
+      let awaitPopupShown = BrowserTestUtils.waitForEvent(contextMenu,
+                                                          "popupshown");
+      let awaitPopupHidden = BrowserTestUtils.waitForEvent(contextMenu,
+                                                           "popuphidden");
 
+      yield BrowserTestUtils.synthesizeMouseAtCenter("a", {
+        type: "contextmenu",
+        button: 2,
+      }, browser);
+
+      yield awaitPopupShown;
+
+      is(gContextMenu.linkTextStr, "word1 word2 word3",
+         "Text under link is correctly computed.");
+
+      contextMenu.hidePopup();
+      yield awaitPopupHidden;
+  });
+});