Bug 693808 - part 3: add browser test for the notification for localhosts, r=mak
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 15 Jul 2014 18:00:43 +0100
changeset 216830 16ef256da46b7826fdeec67be45c4b4ea0faa521
parent 216829 e92d6fb6dd5ffc9a60fb9cb53ac932c4879489d7
child 216831 9365ece2ed9022055017ff881efb102cbc39e025
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs693808
milestone33.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 693808 - part 3: add browser test for the notification for localhosts, r=mak
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_urlbarSearchSingleWordNotification.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -396,16 +396,17 @@ skip-if = e10s # Bug ?????? - test uses 
 [browser_urlHighlight.js]
 [browser_urlbarAutoFillTrimURLs.js]
 [browser_urlbarCopying.js]
 skip-if = e10s # Bug 932651 - getClipboardData in specialpowersAPI.js not e10s friendly
 [browser_urlbarEnter.js]
 skip-if = e10s # Bug ?????? - obscure non-windows child process crashes on try
 [browser_urlbarRevert.js]
 skip-if = e10s # Bug ?????? - ESC reverted the location bar value - Got foobar, expected example.com
+[browser_urlbarSearchSingleWordNotification.js]
 [browser_urlbarStop.js]
 skip-if = e10s # Bug ????? - test calls gBrowser.contentWindow.stop
 [browser_urlbarTrimURLs.js]
 [browser_urlbar_search_healthreport.js]
 skip-if = e10s # Bug ?????? - FHR tests failing (either with "no data for today" or "2 records for today")
 [browser_utilityOverlay.js]
 [browser_visibleFindSelection.js]
 skip-if = e10s # Bug ?????? - test directly manipulates content
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_urlbarSearchSingleWordNotification.js
@@ -0,0 +1,80 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+registerCleanupFunction(function() {
+  Services.prefs.clearUserPref("browser.fixup.domainwhitelist.localhost");
+});
+
+function promiseNotificationForTab(value, expected, tab=gBrowser.selectedTab) {
+  let deferred = Promise.defer();
+  let notificationBox = gBrowser.getNotificationBox(tab.linkedBrowser);
+  if (expected) {
+    waitForCondition(() => notificationBox.getNotificationWithValue(value) !== null,
+                     deferred.resolve, "Were expecting to get a notification");
+  } else {
+    setTimeout(() => {
+      is(notificationBox.getNotificationWithValue(value), null, "We are expecting to not get a notification");
+      deferred.resolve();
+    }, 1000);
+  }
+  return deferred.promise;
+}
+
+function* runURLBarSearchTest(valueToOpen, expectSearch, expectNotification) {
+  gURLBar.value = valueToOpen;
+  let expectedURI;
+  if (!expectSearch) {
+    expectedURI = "http://" + valueToOpen + "/";
+  } else {
+    yield new Promise(resolve => {
+      Services.search.init(resolve)
+    });
+    expectedURI = Services.search.defaultEngine.getSubmission(valueToOpen, null, "keyword").uri.spec;
+  }
+  gURLBar.focus();
+  let docLoadPromise = waitForDocLoadAndStopIt(expectedURI);
+  EventUtils.synthesizeKey("VK_RETURN", {});
+
+  yield docLoadPromise;
+
+  yield promiseNotificationForTab("keyword-uri-fixup", expectNotification);
+}
+
+add_task(function* test_navigate_full_domain() {
+  let tab = gBrowser.selectedTab = gBrowser.addTab();
+  yield* runURLBarSearchTest("www.mozilla.org", false, false);
+  gBrowser.removeTab(tab);
+});
+
+add_task(function* test_navigate_single_host() {
+  Services.prefs.setBoolPref("browser.fixup.domainwhitelist.localhost", false);
+  let tab = gBrowser.selectedTab = gBrowser.addTab();
+  yield* runURLBarSearchTest("localhost", true, true);
+
+  let notificationBox = gBrowser.getNotificationBox(tab.linkedBrowser);
+  let notification = notificationBox.getNotificationWithValue("keyword-uri-fixup");
+  let docLoadPromise = waitForDocLoadAndStopIt("http://localhost/");
+  notification.querySelector(".notification-button-default").click();
+
+  // check pref value
+  let pref = "browser.fixup.domainwhitelist.localhost";
+  let prefValue = Services.prefs.getBoolPref(pref);
+  ok(prefValue, "Pref should have been toggled");
+
+  yield docLoadPromise;
+  gBrowser.removeTab(tab);
+
+  // Now try again with the pref set.
+  let tab = gBrowser.selectedTab = gBrowser.addTab();
+  yield* runURLBarSearchTest("localhost", false, false);
+  gBrowser.removeTab(tab);
+});
+
+add_task(function* test_navigate_invalid_url() {
+  let tab = gBrowser.selectedTab = gBrowser.addTab();
+  yield* runURLBarSearchTest("mozilla is awesome", true, false);
+  gBrowser.removeTab(tab);
+});
+