|
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/ */ |
|
5 |
|
6 "use strict"; |
|
7 |
|
8 const kTrimPref = "browser.urlbar.trimURLs"; |
|
9 var gTrimPrefValue; |
|
10 |
|
11 function test() { |
|
12 runTests(); |
|
13 } |
|
14 |
|
15 function setUp() { |
|
16 gTrimPrefValue = SpecialPowers.getBoolPref(kTrimPref); |
|
17 SpecialPowers.setBoolPref(kTrimPref, true); |
|
18 yield addTab("about:blank"); |
|
19 } |
|
20 |
|
21 function tearDown() { |
|
22 SpecialPowers.setBoolPref(kTrimPref, gTrimPrefValue); |
|
23 Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
|
24 } |
|
25 |
|
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 } |
|
32 |
|
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/"], |
|
48 |
|
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"], |
|
57 |
|
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"], |
|
61 |
|
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"], |
|
66 |
|
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 ]; |
|
73 |
|
74 for (let [original, target] of testcases) |
|
75 testTrim(original, target); |
|
76 } |
|
77 }); |
|
78 |
|
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/"); |
|
86 |
|
87 SpecialPowers.setBoolPref(kTrimPref, true); |
|
88 testTrim("http://mozilla.org/", "mozilla.org"); |
|
89 } |
|
90 }); |
|
91 |
|
92 gTests.push({ |
|
93 desc: "Loaded URI - copy/paste behavior", |
|
94 setUp: setUp, |
|
95 tearDown: tearDown, |
|
96 run: function () { |
|
97 let urlbar = BrowserUI._edit; |
|
98 |
|
99 BrowserUI.goToURI("http://example.com/"); |
|
100 let pageLoaded = yield waitForCondition( |
|
101 () => Browser.selectedBrowser.currentURI.spec == "http://example.com/"); |
|
102 |
|
103 ok(pageLoaded, "expected page should have loaded"); |
|
104 is(urlbar.value, "example.com", "trimmed value set"); |
|
105 |
|
106 yield showNavBar(); |
|
107 |
|
108 function clipboardCondition(aExpected) { |
|
109 return () => aExpected == SpecialPowers.getClipboardData("text/unicode"); |
|
110 } |
|
111 |
|
112 // Value set by browser -- should copy entire url (w/ scheme) on full select |
|
113 |
|
114 urlbar.focus(); |
|
115 urlbar.select(); |
|
116 CommandUpdater.doCommand("cmd_copy"); |
|
117 |
|
118 let copy = yield waitForCondition(clipboardCondition("http://example.com/")); |
|
119 ok(copy, "should copy entire url (w/ scheme) on full select"); |
|
120 |
|
121 // Value set by browser -- should copy selected text on partial select |
|
122 |
|
123 urlbar.focus(); |
|
124 urlbar.select(); |
|
125 urlbar.selectionStart = 2; |
|
126 CommandUpdater.doCommand("cmd_copy"); |
|
127 |
|
128 copy = yield waitForCondition(clipboardCondition("ample.com")); |
|
129 ok(copy, "should copy selected text on partial select"); |
|
130 |
|
131 // Value set by user -- should not copy full string |
|
132 |
|
133 urlbar.valueIsTyped = true; |
|
134 urlbar.focus(); |
|
135 urlbar.select(); |
|
136 CommandUpdater.doCommand("cmd_copy"); |
|
137 |
|
138 copy = yield waitForCondition(clipboardCondition("example.com")); |
|
139 ok(copy, "should not copy full string"); |
|
140 } |
|
141 }); |