Bug 1307687 - Intermittent load failure in browser_urlbarTrimURLs.js. r=Gijs, a=test-only
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 15 Nov 2016 17:15:14 +0100
changeset 352496 6ef846dd261712913e1c138ce7d80eab02210a25
parent 352495 a6fc43194f279a3051a2e6af60824d8445df81d6
child 352497 035f8923037c68fcdaa6615ccd6b6444237483ad
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, test-only
bugs1307687
milestone52.0a2
Bug 1307687 - Intermittent load failure in browser_urlbarTrimURLs.js. r=Gijs, a=test-only MozReview-Commit-ID: LMMTOkXqWI5
browser/base/content/test/urlbar/browser_urlbarTrimURLs.js
--- a/browser/base/content/test/urlbar/browser_urlbarTrimURLs.js
+++ b/browser/base/content/test/urlbar/browser_urlbarTrimURLs.js
@@ -1,30 +1,20 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
+add_task(function* () {
+  const PREF_TRIMURLS = "browser.urlbar.trimURLs";
 
-function testVal(originalValue, targetValue) {
-  gURLBar.value = originalValue;
-  gURLBar.valueIsTyped = false;
-  is(gURLBar.textValue, targetValue || originalValue, "url bar value set");
-}
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser);
 
-function test() {
-  const prefname = "browser.urlbar.trimURLs";
-
-  gBrowser.selectedTab = gBrowser.addTab();
-
-  registerCleanupFunction(function () {
-    gBrowser.removeCurrentTab();
-    Services.prefs.clearUserPref(prefname);
+  registerCleanupFunction(function* () {
+    yield BrowserTestUtils.removeTab(tab);
+    Services.prefs.clearUserPref(PREF_TRIMURLS);
     URLBarSetURI();
   });
 
-  Services.prefs.setBoolPref(prefname, true);
+  Services.prefs.setBoolPref(PREF_TRIMURLS, true);
 
   testVal("http://mozilla.org/", "mozilla.org");
   testVal("https://mozilla.org/", "https://mozilla.org");
   testVal("http://mözilla.org/", "mözilla.org");
   testVal("http://mozilla.imaginatory/", "mozilla.imaginatory");
   testVal("http://www.mozilla.org/", "www.mozilla.org");
   testVal("http://sub.mozilla.org/", "sub.mozilla.org");
   testVal("http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org");
@@ -66,40 +56,43 @@ function test() {
   Services.prefs.clearUserPref(fixupWhitelistPref);
 
   testVal("http:// invalid url");
 
   testVal("http://someotherhostwithnodots");
   testVal("http://localhost/ foo bar baz");
   testVal("http://localhost.localdomain/ foo bar baz", "localhost.localdomain/ foo bar baz");
 
-  Services.prefs.setBoolPref(prefname, false);
+  Services.prefs.setBoolPref(PREF_TRIMURLS, false);
 
   testVal("http://mozilla.org/");
 
-  Services.prefs.setBoolPref(prefname, true);
-
-  waitForExplicitFinish();
+  Services.prefs.setBoolPref(PREF_TRIMURLS, true);
 
-  gBrowser.selectedBrowser.addEventListener("load", function () {
-    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+  let promiseLoaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser,
+                                                     false, "http://example.com/");
+  gBrowser.loadURI("http://example.com/");
+  yield promiseLoaded;
 
-    is(gBrowser.currentURI.spec, "http://example.com/", "expected page should have loaded");
+  yield testCopy("example.com", "http://example.com/")
 
-    testCopy("example.com", "http://example.com/", function () {
-      SetPageProxyState("invalid");
-      gURLBar.valueIsTyped = true;
-      testCopy("example.com", "example.com", finish);
-    });
-  }, true);
+  SetPageProxyState("invalid");
+  gURLBar.valueIsTyped = true;
+  yield testCopy("example.com", "example.com");
+});
 
-  gBrowser.loadURI("http://example.com/");
+function testVal(originalValue, targetValue) {
+  gURLBar.value = originalValue;
+  gURLBar.valueIsTyped = false;
+  is(gURLBar.textValue, targetValue || originalValue, "url bar value set");
 }
 
-function testCopy(originalValue, targetValue, cb) {
-  waitForClipboard(targetValue, function () {
-    is(gURLBar.textValue, originalValue, "url bar copy value set");
+function testCopy(originalValue, targetValue) {
+  return new Promise((resolve, reject) => {
+    waitForClipboard(targetValue, function () {
+      is(gURLBar.textValue, originalValue, "url bar copy value set");
 
-    gURLBar.focus();
-    gURLBar.select();
-    goDoCommand("cmd_copy");
-  }, cb, cb);
+      gURLBar.focus();
+      gURLBar.select();
+      goDoCommand("cmd_copy");
+    }, resolve, reject);
+  });
 }