Bug 1253163 - [e10s] Fix browser_tabDrop.js to run in e10s. r=mattn, a=ritu
authorJared Wein <jwein@mozilla.com>
Sun, 06 Mar 2016 22:14:00 -0500
changeset 325259 9f020db3c130db6e2733b11ab35de4c3769ecfa9
parent 325258 2926f802082183857b1c4e6f3774c742be98470d
child 325260 8893af0b7e816b74ba4be00f4b4a23f178d3b90f
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattn, ritu
bugs1253163
milestone47.0a2
Bug 1253163 - [e10s] Fix browser_tabDrop.js to run in e10s. r=mattn, a=ritu
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_tabDrop.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -410,17 +410,17 @@ support-files =
 [browser_selectpopup.js]
 run-if = e10s
 [browser_selectTabAtIndex.js]
 [browser_ssl_error_reports.js]
 [browser_star_hsts.js]
 [browser_subframe_favicons_not_used.js]
 [browser_syncui.js]
 [browser_tabDrop.js]
-skip-if = buildapp == 'mulet' || e10s
+skip-if = buildapp == 'mulet'
 [browser_tabReorder.js]
 skip-if = buildapp == 'mulet'
 [browser_tabMatchesInAwesomebar.js]
 [browser_tabMatchesInAwesomebar_perwindowpb.js]
 skip-if = e10s || os == 'linux' # Bug 1093373, bug 1104755
 [browser_tab_detach_restore.js]
 [browser_tab_drag_drop_perwindow.js]
 skip-if = buildapp == 'mulet'
--- a/browser/base/content/test/general/browser_tabDrop.js
+++ b/browser/base/content/test/general/browser_tabDrop.js
@@ -1,77 +1,61 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-function test() {
-  waitForExplicitFinish();
+registerCleanupFunction(function* cleanup() {
+  while (gBrowser.tabs.length > 1) {
+    yield BrowserTestUtils.removeTab(gBrowser.tabs[gBrowser.tabs.length - 1]);
+  }
+  Services.search.currentEngine = originalEngine;
+  let engine = Services.search.getEngineByName("MozSearch");
+  Services.search.removeEngine(engine);
+});
 
-  let newTab = gBrowser.selectedTab = gBrowser.addTab("about:blank", {skipAnimation: true});
-  registerCleanupFunction(function () {
-    gBrowser.removeTab(newTab);
-  });
+let originalEngine;
+add_task(function* test_setup() {
+  // Stop search-engine loads from hitting the network
+  Services.search.addEngineWithDetails("MozSearch", "", "", "", "GET",
+                                       "http://example.com/?q={searchTerms}");
+  let engine = Services.search.getEngineByName("MozSearch");
+  originalEngine = Services.search.currentEngine;
+  Services.search.currentEngine = engine;
+});
 
+add_task(function*() { yield drop("mochi.test/first", true); });
+add_task(function*() { yield drop("javascript:'bad'"); });
+add_task(function*() { yield drop("jAvascript:'bad'"); });
+add_task(function*() { yield drop("search this", true); });
+add_task(function*() { yield drop("mochi.test/second", true); });
+add_task(function*() { yield drop("data:text/html,bad"); });
+add_task(function*() { yield drop("mochi.test/third", true); });
+
+function* drop(text, valid = false) {
+  info(`Starting test for text:${text}; valid:${valid}`);
   let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                      getService(Ci.mozIJSSubScriptLoader);
   let ChromeUtils = {};
   scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils);
 
-  let tabContainer = gBrowser.tabContainer;
-  var receivedDropCount = 0;
-  function dropListener() {
-    receivedDropCount++;
-    if (receivedDropCount == triggeredDropCount) {
-      is(openedTabs, validDropCount, "correct number of tabs were opened");
-      executeSoon(finish);
-    }
+  let awaitDrop = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "drop");
+  let awaitTabOpen = valid && BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen");
+  // A drop type of "link" onto an existing tab would normally trigger a
+  // load in that same tab, but tabbrowser code in _getDragTargetTab treats
+  // drops on the outer edges of a tab differently (loading a new tab
+  // instead). Make events created by synthesizeDrop have all of their
+  // coordinates set to 0 (screenX/screenY), so they're treated as drops
+  // on the outer edge of the tab, thus they open new tabs.
+  var event = {
+    clientX: 0,
+    clientY: 0,
+    screenX: 0,
+    screenY: 0,
+  };
+  ChromeUtils.synthesizeDrop(gBrowser.selectedTab, gBrowser.selectedTab, [[{type: "text/plain", data: text}]], "link", window, undefined, event);
+  let tabOpened = false;
+  if (awaitTabOpen) {
+    let tabOpenEvent = yield awaitTabOpen;
+    info("Got TabOpen event");
+    tabOpened = true;
+    yield BrowserTestUtils.removeTab(tabOpenEvent.target);
   }
-  tabContainer.addEventListener("drop", dropListener, false);
-  registerCleanupFunction(function () {
-    tabContainer.removeEventListener("drop", dropListener, false);
-  });
-
-  var openedTabs = 0;
-  function tabOpenListener(e) {
-    openedTabs++;
-    let tab = e.target;
-    executeSoon(function () {
-      gBrowser.removeTab(tab);
-    });
-  }
-
-  tabContainer.addEventListener("TabOpen", tabOpenListener, false);
-  registerCleanupFunction(function () {
-    tabContainer.removeEventListener("TabOpen", tabOpenListener, false);
-  });
+  is(tabOpened, valid, `Tab for ${text} should only open if valid`);
 
-  var triggeredDropCount = 0;
-  var validDropCount = 0;
-  function drop(text, valid) {
-    triggeredDropCount++;
-    if (valid)
-      validDropCount++;
-    executeSoon(function () {
-      // A drop type of "link" onto an existing tab would normally trigger a
-      // load in that same tab, but tabbrowser code in _getDragTargetTab treats
-      // drops on the outer edges of a tab differently (loading a new tab
-      // instead). Make events created by synthesizeDrop have all of their
-      // coordinates set to 0 (screenX/screenY), so they're treated as drops
-      // on the outer edge of the tab, thus they open new tabs.
-      var event = {
-        clientX: 0,
-        clientY: 0,
-        screenX: 0,
-        screenY: 0,
-      };
-      ChromeUtils.synthesizeDrop(newTab, newTab, [[{type: "text/plain", data: text}]], "link", window, undefined, event);
-    });
-  }
-
-  // Begin and end with valid drops to make sure we wait for all drops before
-  // ending the test
-  drop("mochi.test/first", true);
-  drop("javascript:'bad'");
-  drop("jAvascript:'bad'");
-  drop("search this", true);
-  drop("mochi.test/second", true);
-  drop("data:text/html,bad");
-  drop("mochi.test/third", true);
+  yield awaitDrop;
+  ok(true, "Got drop event");
 }