Bug 1394304: Part 2 - Add tests for _whereToOpen. r=adw
authorYuri Khan <yuri.v.khan@gmail.com>
Sun, 04 Feb 2018 18:42:54 +0700
changeset 402518 420221f11352798df551b529727f0dfc8830b65e
parent 402517 6c3394c9aec3d9d8e4f78aeb7a69045374886642
child 402519 d8ad38aef8866ba2ac70862c78bbb67ef8349890
push id99585
push usercsabou@mozilla.com
push dateTue, 06 Feb 2018 11:04:29 +0000
treeherdermozilla-inbound@420221f11352 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1394304
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 1394304: Part 2 - Add tests for _whereToOpen. r=adw
browser/base/content/test/urlbar/browser.ini
browser/base/content/test/urlbar/browser_urlbar_whereToOpen.js
--- a/browser/base/content/test/urlbar/browser.ini
+++ b/browser/base/content/test/urlbar/browser.ini
@@ -63,16 +63,17 @@ support-files =
 [browser_urlbarAutoFillTrimURLs.js]
 [browser_urlbarCopying.js]
 subsuite = clipboard
 support-files =
   authenticate.sjs
 [browser_urlbarDecode.js]
 [browser_urlbarDelete.js]
 [browser_urlbarEnter.js]
+[browser_urlbar_whereToOpen.js]
 [browser_urlbarEnterAfterMouseOver.js]
 skip-if = os == "linux" # Bug 1073339 - Investigate autocomplete test unreliability on Linux/e10s
 [browser_urlbarFocusedCmdK.js]
 [browser_urlbarHashChangeProxyState.js]
 [browser_urlbarKeepStateAcrossTabSwitches.js]
 [browser_urlbarOneOffs.js]
 support-files =
   searchSuggestionEngine.xml
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/urlbar/browser_urlbar_whereToOpen.js
@@ -0,0 +1,112 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const NON_EMPTY_TAB = "example.com/non-empty";
+const EMPTY_TAB = "about:blank";
+const META_KEY = AppConstants.platform == "macosx" ? "metaKey" : "ctrlKey";
+const ENTER = new KeyboardEvent("keydown", {});
+const ALT_ENTER = new KeyboardEvent("keydown", {altKey: true});
+const CLICK = new MouseEvent("click", {button: 0});
+const META_CLICK = new MouseEvent("click", {button: 0, [META_KEY]: true});
+const MIDDLE_CLICK = new MouseEvent("click", {button: 1});
+
+
+let old_openintab = Preferences.get("browser.urlbar.openintab");
+registerCleanupFunction(async function() {
+  Preferences.set("browser.urlbar.openintab", old_openintab);
+});
+
+add_task(async function openInTab() {
+  // Open a non-empty tab.
+  let tab = gBrowser.selectedTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, NON_EMPTY_TAB);
+
+  for (let test of [{pref: false, event: ALT_ENTER,
+                     desc: "Alt+Enter, non-empty tab, default prefs"},
+                    {pref: false, event: META_CLICK,
+                     desc: "Meta+click, non-empty tab, default prefs"},
+                    {pref: false, event: MIDDLE_CLICK,
+                     desc: "Middle click, non-empty tab, default prefs"},
+                    {pref: true, event: ENTER,
+                     desc: "Enter, non-empty tab, openInTab"},
+                    {pref: true, event: CLICK,
+                     desc: "Normal click, non-empty tab, openInTab"}]) {
+    info(test.desc);
+
+    Preferences.set("browser.urlbar.openintab", test.pref);
+    let where = gURLBar._whereToOpen(test.event);
+    is(where, "tab", "URL would be loaded in a new tab");
+  }
+
+  // Clean up.
+  await BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function keepEmptyTab() {
+  // Open an empty tab.
+  let tab = gBrowser.selectedTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, EMPTY_TAB);
+
+  for (let test of [{pref: false, event: META_CLICK,
+                     desc: "Meta+click, empty tab, default prefs"},
+                    {pref: false, event: MIDDLE_CLICK,
+                     desc: "Middle click, empty tab, default prefs"}]) {
+    info(test.desc);
+
+    Preferences.set("browser.urlbar.openintab", test.pref);
+    let where = gURLBar._whereToOpen(test.event);
+    is(where, "tab", "URL would be loaded in a new tab");
+  }
+
+  // Clean up.
+  await BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function reuseEmptyTab() {
+  // Open an empty tab.
+  let tab = gBrowser.selectedTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, EMPTY_TAB);
+
+  for (let test of [{pref: false, event: ALT_ENTER,
+                     desc: "Alt+Enter, empty tab, default prefs"},
+                    {pref: true, event: ENTER,
+                     desc: "Enter, empty tab, openInTab"},
+                    {pref: true, event: CLICK,
+                     desc: "Normal click, empty tab, openInTab"}]) {
+    info(test.desc);
+    Preferences.set("browser.urlbar.openintab", test.pref);
+    let where = gURLBar._whereToOpen(test.event);
+    is(where, "current", "New URL would reuse the current empty tab");
+  }
+
+  // Clean up.
+  await BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function openInCurrentTab() {
+  for (let test of [{pref: false, url: NON_EMPTY_TAB, event: ENTER,
+                     desc: "Enter, non-empty tab, default prefs"},
+                    {pref: false, url: NON_EMPTY_TAB, event: CLICK,
+                     desc: "Normal click, non-empty tab, default prefs"},
+                    {pref: false, url: EMPTY_TAB, event: ENTER,
+                     desc: "Enter, empty tab, default prefs"},
+                    {pref: false, url: EMPTY_TAB, event: CLICK,
+                     desc: "Normal click, empty tab, default prefs"},
+                    {pref: true, url: NON_EMPTY_TAB, event: ALT_ENTER,
+                     desc: "Alt+Enter, non-empty tab, openInTab"},
+                    {pref: true, url: NON_EMPTY_TAB, event: META_CLICK,
+                     desc: "Meta+click, non-empty tab, openInTab"},
+                    {pref: true, url: NON_EMPTY_TAB, event: MIDDLE_CLICK,
+                     desc: "Middle click, non-empty tab, openInTab"}]) {
+    info(test.desc);
+
+    // Open a new tab.
+    let tab = gBrowser.selectedTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, test.url);
+
+    Preferences.set("browser.urlbar.openintab", test.pref);
+    let where = gURLBar._whereToOpen(test.event);
+    is(where, "current", "URL would open in the current tab");
+
+    // Clean up.
+    await BrowserTestUtils.removeTab(tab);
+  }
+});