--- 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);
+ });
}