Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* Any copyright is dedicated to the Public Domain.
4 http://creativecommons.org/publicdomain/zero/1.0/ */
6 "use strict";
8 const kTrimPref = "browser.urlbar.trimURLs";
9 var gTrimPrefValue;
11 function test() {
12 runTests();
13 }
15 function setUp() {
16 gTrimPrefValue = SpecialPowers.getBoolPref(kTrimPref);
17 SpecialPowers.setBoolPref(kTrimPref, true);
18 yield addTab("about:blank");
19 }
21 function tearDown() {
22 SpecialPowers.setBoolPref(kTrimPref, gTrimPrefValue);
23 Browser.closeTab(Browser.selectedTab, { forceClose: true });
24 }
26 function testTrim(aOriginal, aTarget) {
27 let urlbar = BrowserUI._edit;
28 urlbar.value = aOriginal;
29 urlbar.valueIsTyped = false;
30 is(urlbar.value, aTarget || aOriginal, "url bar value set");
31 }
33 gTests.push({
34 desc: "URIs - trimming (pref enabled)",
35 setUp: setUp,
36 tearDown: tearDown,
37 run: function () {
38 let testcases = [
39 ["http://mozilla.org/", "mozilla.org"],
40 ["https://mozilla.org/", "https://mozilla.org"],
41 ["http://mözilla.org/", "mözilla.org"],
42 ["http://mozilla.imaginatory/", "mozilla.imaginatory"],
43 ["http://www.mozilla.org/", "www.mozilla.org"],
44 ["http://sub.mozilla.org/", "sub.mozilla.org"],
45 ["http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org"],
46 ["http://mozilla.org/file.ext", "mozilla.org/file.ext"],
47 ["http://mozilla.org/sub/", "mozilla.org/sub/"],
49 ["http://ftp.mozilla.org/", "http://ftp.mozilla.org"],
50 ["http://ftp1.mozilla.org/", "http://ftp1.mozilla.org"],
51 ["http://ftp42.mozilla.org/", "http://ftp42.mozilla.org"],
52 ["http://ftpx.mozilla.org/", "ftpx.mozilla.org"],
53 ["ftp://ftp.mozilla.org/", "ftp://ftp.mozilla.org"],
54 ["ftp://ftp1.mozilla.org/", "ftp://ftp1.mozilla.org"],
55 ["ftp://ftp42.mozilla.org/", "ftp://ftp42.mozilla.org"],
56 ["ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org"],
58 ["https://user:pass@mozilla.org/", "https://user:pass@mozilla.org"],
59 ["http://user:pass@mozilla.org/", "http://user:pass@mozilla.org"],
60 ["http://sub.mozilla.org:666/", "sub.mozilla.org:666"],
62 ["https://[fe80::222:19ff:fe11:8c76]/file.ext"],
63 ["http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]"],
64 ["https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"],
65 ["http://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"],
67 ["mailto:admin@mozilla.org"],
68 ["gopher://mozilla.org/"],
69 ["about:config"],
70 ["jar:http://mozilla.org/example.jar!/"],
71 ["view-source:http://mozilla.org/"]
72 ];
74 for (let [original, target] of testcases)
75 testTrim(original, target);
76 }
77 });
79 gTests.push({
80 desc: "URIs - no trimming (pref disabled)",
81 setUp: setUp,
82 tearDown: tearDown,
83 run: function () {
84 SpecialPowers.setBoolPref(kTrimPref, false);
85 testTrim("http://mozilla.org/");
87 SpecialPowers.setBoolPref(kTrimPref, true);
88 testTrim("http://mozilla.org/", "mozilla.org");
89 }
90 });
92 gTests.push({
93 desc: "Loaded URI - copy/paste behavior",
94 setUp: setUp,
95 tearDown: tearDown,
96 run: function () {
97 let urlbar = BrowserUI._edit;
99 BrowserUI.goToURI("http://example.com/");
100 let pageLoaded = yield waitForCondition(
101 () => Browser.selectedBrowser.currentURI.spec == "http://example.com/");
103 ok(pageLoaded, "expected page should have loaded");
104 is(urlbar.value, "example.com", "trimmed value set");
106 yield showNavBar();
108 function clipboardCondition(aExpected) {
109 return () => aExpected == SpecialPowers.getClipboardData("text/unicode");
110 }
112 // Value set by browser -- should copy entire url (w/ scheme) on full select
114 urlbar.focus();
115 urlbar.select();
116 CommandUpdater.doCommand("cmd_copy");
118 let copy = yield waitForCondition(clipboardCondition("http://example.com/"));
119 ok(copy, "should copy entire url (w/ scheme) on full select");
121 // Value set by browser -- should copy selected text on partial select
123 urlbar.focus();
124 urlbar.select();
125 urlbar.selectionStart = 2;
126 CommandUpdater.doCommand("cmd_copy");
128 copy = yield waitForCondition(clipboardCondition("ample.com"));
129 ok(copy, "should copy selected text on partial select");
131 // Value set by user -- should not copy full string
133 urlbar.valueIsTyped = true;
134 urlbar.focus();
135 urlbar.select();
136 CommandUpdater.doCommand("cmd_copy");
138 copy = yield waitForCondition(clipboardCondition("example.com"));
139 ok(copy, "should not copy full string");
140 }
141 });