Bug 1333345 - Part 1: Add urlbar tests for Accel+Enter and Accel+Shift+Enter adding .com and .org suffixes to search string. r?mak draft
authorChris Peterson <cpeterson@mozilla.com>
Sat, 04 Feb 2017 23:24:10 -0800
changeset 490296 5540bd2025f72e85dc3d48ec7e7dbfcf80abe414
parent 490295 e1135c6fdc9bcd80d38f7285b269e030716dcb72
child 490297 de586d7787feee2fa430fffe23f733ca43a2ec29
push id47057
push usercpeterson@mozilla.com
push dateTue, 28 Feb 2017 02:48:55 +0000
reviewersmak
bugs1333345
milestone54.0a1
Bug 1333345 - Part 1: Add urlbar tests for Accel+Enter and Accel+Shift+Enter adding .com and .org suffixes to search string. r?mak We had tests for Shift+Enter adding a .net suffix, but not Accel+Enter or Accel+Shift+Enter. MozReview-Commit-ID: GMyD27bUvWp
browser/base/content/test/urlbar/browser_canonizeURL.js
--- a/browser/base/content/test/urlbar/browser_canonizeURL.js
+++ b/browser/base/content/test/urlbar/browser_canonizeURL.js
@@ -1,34 +1,43 @@
-var pairs = [
-  ["example", "http://www.example.net/"],
-  ["ex-ample", "http://www.ex-ample.net/"],
-  ["  example ", "http://www.example.net/"],
-  [" example/foo ", "http://www.example.net/foo"],
-  [" example/foo bar ", "http://www.example.net/foo%20bar"],
-  ["example.net", "http://example.net/"],
-  ["http://example", "http://example/"],
-  ["example:8080", "http://example:8080/"],
-  ["ex-ample.foo", "http://ex-ample.foo/"],
-  ["example.foo/bar ", "http://example.foo/bar"],
-  ["1.1.1.1", "http://1.1.1.1/"],
-  ["ftp://example", "ftp://example/"],
-  ["ftp.example.bar", "http://ftp.example.bar/"],
-  ["ex ample", Services.search.defaultEngine.getSubmission("ex ample", null, "keyword").uri.spec],
+"use strict";
+
+// Accel (Alt or Cmd) + Enter will add a .com suffix.
+// Shift + Enter will add a .net suffix.
+// Accel + Shift + Enter will add a .org suffix.
+const accelKey = { accelKey: true };
+const shiftKey = { shiftKey: true };
+const accelAndShiftKey = { accelKey: true, shiftKey: true };
+
+const tests = [
+  ["example", accelKey, "http://www.example.com/"],
+  ["ex-ample", shiftKey, "http://www.ex-ample.net/"],
+  ["  example ", accelAndShiftKey, "http://www.example.org/"],
+  [" example/foo ", accelKey, "http://www.example.com/foo"],
+  [" example/foo bar ", shiftKey, "http://www.example.net/foo%20bar"],
+  ["example.net", accelAndShiftKey, "http://example.net/"],
+  ["http://example", accelKey, "http://example/"],
+  ["example:8080", shiftKey, "http://example:8080/"],
+  ["ex-ample.foo", accelAndShiftKey, "http://ex-ample.foo/"],
+  ["example.foo/bar ", accelKey, "http://example.foo/bar"],
+  ["1.1.1.1", shiftKey, "http://1.1.1.1/"],
+  ["ftp://example", accelAndShiftKey, "ftp://example/"],
+  ["ftp.example.bar", accelKey, "http://ftp.example.bar/"],
+  ["ex ample", shiftKey, Services.search.defaultEngine.getSubmission("ex ample", null, "keyword").uri.spec],
 ];
 
 add_task(function*() {
   // Disable autoFill for this test, since it could mess up the results.
   let autoFill = Preferences.get("browser.urlbar.autoFill");
   Preferences.set("browser.urlbar.autoFill", false);
   registerCleanupFunction(() => {
     Preferences.set("browser.urlbar.autoFill", autoFill);
   });
 
-  for (let [inputValue, expectedURL] of pairs) {
+  for (let [inputValue, modifierKeys, expectedURL] of tests) {
     let promiseLoad = waitForDocLoadAndStopIt(expectedURL);
     gURLBar.focus();
     gURLBar.inputField.value = inputValue.slice(0, -1);
     EventUtils.synthesizeKey(inputValue.slice(-1), {});
-    EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true });
+    EventUtils.synthesizeKey("VK_RETURN", modifierKeys);
     yield promiseLoad;
   }
 });