Bug 1442167 - Use text that will not be fixed to URL when testing non-URL case. r=Gijs
authorTooru Fujisawa <arai_a@mac.com>
Fri, 09 Mar 2018 10:53:36 +0900
changeset 462326 e7c9b954c90f74553b342351d11eaad7f4faf8dc
parent 462325 5a091ec4e060846c84d650395791b095ef4c73e4
child 462327 d660ed0a7b4673769ab76298f78ed6661ef6138d
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1442167
milestone60.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 1442167 - Use text that will not be fixed to URL when testing non-URL case. r=Gijs
browser/base/content/test/general/browser_newTabDrop.js
--- a/browser/base/content/test/general/browser_newTabDrop.js
+++ b/browser/base/content/test/general/browser_newTabDrop.js
@@ -93,29 +93,29 @@ add_task(async function multiple_tabs_ov
 });
 
 // Open URLs ignoring non-URL.
 add_task(async function multiple_urls() {
   await dropText(`
     mochi.test/urls0
     mochi.test/urls1
     mochi.test/urls2
-    non-url0
+    non url0
     mochi.test/urls3
-    non-url1
-    non-url2
+    non url1
+    non url2
 `, 4);
 });
 
 // Open single search if there's no URL.
 add_task(async function multiple_text() {
   await dropText(`
-    non-url0
-    non-url1
-    non-url2
+    non url0
+    non url1
+    non url2
 `, 1);
 });
 
 function dropText(text, expectedTabOpenCount = 0) {
   return drop([[{type: "text/plain", data: text}]], expectedTabOpenCount);
 }
 
 async function drop(dragData, expectedTabOpenCount = 0) {
@@ -128,31 +128,39 @@ async function drop(dragData, expectedTa
   let dragSrcElement = document.getElementById("downloads-button");
   ok(dragSrcElement, "Downloads button exists");
   let newTabButton = document.getElementById("new-tab-button");
   ok(newTabButton, "New Tab button exists");
 
   let awaitDrop = BrowserTestUtils.waitForEvent(newTabButton, "drop");
   let actualTabOpenCount = 0;
   let openedTabs = [];
-  let checkCount = function(event) {
+  let promiseTabsOpen = null;
+  let resolve = null;
+  let handler = function(event) {
     openedTabs.push(event.target);
     actualTabOpenCount++;
-    return actualTabOpenCount == expectedTabOpenCount;
+    if (actualTabOpenCount == expectedTabOpenCount && resolve) {
+      resolve();
+    }
   };
-  let awaitTabOpen = expectedTabOpenCount && BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen", false, checkCount);
+  gBrowser.tabContainer.addEventListener("TabOpen", handler);
+  if (expectedTabOpenCount) {
+    promiseTabsOpen = new Promise(r => { resolve = r; });
+  }
 
   EventUtils.synthesizeDrop(dragSrcElement, newTabButton, dragData, "link", window);
 
-  let tabsOpened = false;
-  if (awaitTabOpen) {
-    await awaitTabOpen;
+  if (promiseTabsOpen) {
+    await promiseTabsOpen;
     info("Got TabOpen event");
-    tabsOpened = true;
     for (let tab of openedTabs) {
       await BrowserTestUtils.removeTab(tab);
     }
   }
-  is(tabsOpened, !!expectedTabOpenCount, `Tabs for ${dragDataString} should only open if any of dropped items are valid`);
 
   await awaitDrop;
   ok(true, "Got drop event");
+
+  gBrowser.tabContainer.removeEventListener("TabOpen", handler);
+  is(actualTabOpenCount, expectedTabOpenCount,
+     "No other tabs are opened");
 }