diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js')
-rw-r--r-- | browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js b/browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js new file mode 100644 index 000000000..ee0342055 --- /dev/null +++ b/browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js @@ -0,0 +1,198 @@ +"use strict"; + +var notificationObserver; +registerCleanupFunction(function() { + Services.prefs.clearUserPref("browser.fixup.domainwhitelist.localhost"); + if (notificationObserver) { + notificationObserver.disconnect(); + } +}); + +function promiseNotification(aBrowser, value, expected, input) { + let deferred = Promise.defer(); + let notificationBox = aBrowser.getNotificationBox(aBrowser.selectedBrowser); + if (expected) { + info("Waiting for " + value + " notification"); + let checkForNotification = function() { + if (notificationBox.getNotificationWithValue(value)) { + info("Saw the notification"); + notificationObserver.disconnect(); + notificationObserver = null; + deferred.resolve(); + } + } + if (notificationObserver) { + notificationObserver.disconnect(); + } + notificationObserver = new MutationObserver(checkForNotification); + notificationObserver.observe(notificationBox, {childList: true}); + } else { + setTimeout(() => { + is(notificationBox.getNotificationWithValue(value), null, + `We are expecting to not get a notification for ${input}`); + deferred.resolve(); + }, 1000); + } + return deferred.promise; +} + +function* runURLBarSearchTest({valueToOpen, expectSearch, expectNotification, aWindow=window}) { + aWindow.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; + } + aWindow.gURLBar.focus(); + let docLoadPromise = waitForDocLoadAndStopIt(expectedURI, aWindow.gBrowser.selectedBrowser); + EventUtils.synthesizeKey("VK_RETURN", {}, aWindow); + + yield Promise.all([ + docLoadPromise, + promiseNotification(aWindow.gBrowser, "keyword-uri-fixup", expectNotification, valueToOpen) + ]); +} + +add_task(function* test_navigate_full_domain() { + let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); + yield BrowserTestUtils.browserLoaded(tab.linkedBrowser); + yield* runURLBarSearchTest({ + valueToOpen: "www.mozilla.org", + expectSearch: false, + expectNotification: false, + }); + gBrowser.removeTab(tab); +}); + +add_task(function* test_navigate_decimal_ip() { + let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); + yield BrowserTestUtils.browserLoaded(tab.linkedBrowser); + yield* runURLBarSearchTest({ + valueToOpen: "1234", + expectSearch: true, + expectNotification: false, + }); + gBrowser.removeTab(tab); +}); + +add_task(function* test_navigate_decimal_ip_with_path() { + let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); + yield BrowserTestUtils.browserLoaded(tab.linkedBrowser); + yield* runURLBarSearchTest({ + valueToOpen: "1234/12", + expectSearch: true, + expectNotification: false, + }); + gBrowser.removeTab(tab); +}); + +add_task(function* test_navigate_large_number() { + let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); + yield BrowserTestUtils.browserLoaded(tab.linkedBrowser); + yield* runURLBarSearchTest({ + valueToOpen: "123456789012345", + expectSearch: true, + expectNotification: false + }); + gBrowser.removeTab(tab); +}); + +add_task(function* test_navigate_small_hex_number() { + let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); + yield BrowserTestUtils.browserLoaded(tab.linkedBrowser); + yield* runURLBarSearchTest({ + valueToOpen: "0x1f00ffff", + expectSearch: true, + expectNotification: false + }); + gBrowser.removeTab(tab); +}); + +add_task(function* test_navigate_large_hex_number() { + let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); + yield BrowserTestUtils.browserLoaded(tab.linkedBrowser); + yield* runURLBarSearchTest({ + valueToOpen: "0x7f0000017f000001", + expectSearch: true, + expectNotification: false + }); + gBrowser.removeTab(tab); +}); + +function get_test_function_for_localhost_with_hostname(hostName, isPrivate) { + return function* test_navigate_single_host() { + const pref = "browser.fixup.domainwhitelist.localhost"; + let win; + if (isPrivate) { + let promiseWin = BrowserTestUtils.waitForNewWindow(); + win = OpenBrowserWindow({private: true}); + yield promiseWin; + let deferredOpenFocus = Promise.defer(); + waitForFocus(deferredOpenFocus.resolve, win); + yield deferredOpenFocus.promise; + } else { + win = window; + } + let browser = win.gBrowser; + let tab = yield BrowserTestUtils.openNewForegroundTab(browser); + + Services.prefs.setBoolPref(pref, false); + yield* runURLBarSearchTest({ + valueToOpen: hostName, + expectSearch: true, + expectNotification: true, + aWindow: win, + }); + + let notificationBox = browser.getNotificationBox(tab.linkedBrowser); + let notification = notificationBox.getNotificationWithValue("keyword-uri-fixup"); + let docLoadPromise = waitForDocLoadAndStopIt("http://" + hostName + "/", tab.linkedBrowser); + notification.querySelector(".notification-button-default").click(); + + // check pref value + let prefValue = Services.prefs.getBoolPref(pref); + is(prefValue, !isPrivate, "Pref should have the correct state."); + + yield docLoadPromise; + browser.removeTab(tab); + + // Now try again with the pref set. + tab = browser.selectedTab = browser.addTab("about:blank"); + yield BrowserTestUtils.browserLoaded(tab.linkedBrowser); + // In a private window, the notification should appear again. + yield* runURLBarSearchTest({ + valueToOpen: hostName, + expectSearch: isPrivate, + expectNotification: isPrivate, + aWindow: win, + }); + browser.removeTab(tab); + if (isPrivate) { + info("Waiting for private window to close"); + yield BrowserTestUtils.closeWindow(win); + let deferredFocus = Promise.defer(); + info("Waiting for focus"); + waitForFocus(deferredFocus.resolve, window); + yield deferredFocus.promise; + } + } +} + +add_task(get_test_function_for_localhost_with_hostname("localhost")); +add_task(get_test_function_for_localhost_with_hostname("localhost.")); +add_task(get_test_function_for_localhost_with_hostname("localhost", true)); + +add_task(function* test_navigate_invalid_url() { + let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); + yield BrowserTestUtils.browserLoaded(tab.linkedBrowser); + yield* runURLBarSearchTest({ + valueToOpen: "mozilla is awesome", + expectSearch: true, + expectNotification: false, + }); + gBrowser.removeTab(tab); +}); |