|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 function test() { |
|
6 waitForExplicitFinish(); |
|
7 |
|
8 let charsToDelete, deletedURLTab, fullURLTab, partialURLTab, testPartialURL, testURL; |
|
9 |
|
10 charsToDelete = 5; |
|
11 deletedURLTab = gBrowser.addTab(); |
|
12 fullURLTab = gBrowser.addTab(); |
|
13 partialURLTab = gBrowser.addTab(); |
|
14 testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; |
|
15 |
|
16 function cleanUp() { |
|
17 gBrowser.removeTab(fullURLTab); |
|
18 gBrowser.removeTab(partialURLTab); |
|
19 gBrowser.removeTab(deletedURLTab); |
|
20 } |
|
21 |
|
22 function cycleTabs() { |
|
23 gBrowser.selectedTab = fullURLTab; |
|
24 is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab'); |
|
25 |
|
26 gBrowser.selectedTab = partialURLTab; |
|
27 is(gURLBar.value, testPartialURL, 'gURLBar.value should be testPartialURL after switching back to partialURLTab'); |
|
28 |
|
29 gBrowser.selectedTab = deletedURLTab; |
|
30 is(gURLBar.value, '', 'gURLBar.value should be "" after switching back to deletedURLTab'); |
|
31 |
|
32 gBrowser.selectedTab = fullURLTab; |
|
33 is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab'); |
|
34 } |
|
35 |
|
36 // function borrowed from browser_bug386835.js |
|
37 function load(tab, url, cb) { |
|
38 tab.linkedBrowser.addEventListener("load", function (event) { |
|
39 event.currentTarget.removeEventListener("load", arguments.callee, true); |
|
40 cb(); |
|
41 }, true); |
|
42 tab.linkedBrowser.loadURI(url); |
|
43 } |
|
44 |
|
45 function urlbarBackspace(cb) { |
|
46 gBrowser.selectedBrowser.focus(); |
|
47 gURLBar.addEventListener("focus", function () { |
|
48 gURLBar.removeEventListener("focus", arguments.callee, false); |
|
49 gURLBar.addEventListener("input", function () { |
|
50 gURLBar.removeEventListener("input", arguments.callee, false); |
|
51 cb(); |
|
52 }, false); |
|
53 executeSoon(function () { |
|
54 EventUtils.synthesizeKey("VK_BACK_SPACE", {}); |
|
55 }); |
|
56 }, false); |
|
57 gURLBar.focus(); |
|
58 } |
|
59 |
|
60 function prepareDeletedURLTab(cb) { |
|
61 gBrowser.selectedTab = deletedURLTab; |
|
62 is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to deletedURLTab'); |
|
63 |
|
64 // simulate the user removing the whole url from the location bar |
|
65 gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", true); |
|
66 |
|
67 urlbarBackspace(function () { |
|
68 is(gURLBar.value, "", 'gURLBar.value should be "" (just set)'); |
|
69 if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll")) |
|
70 gPrefService.clearUserPref("browser.urlbar.clickSelectsAll"); |
|
71 cb(); |
|
72 }); |
|
73 } |
|
74 |
|
75 function prepareFullURLTab(cb) { |
|
76 gBrowser.selectedTab = fullURLTab; |
|
77 is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to fullURLTab'); |
|
78 cb(); |
|
79 } |
|
80 |
|
81 function preparePartialURLTab(cb) { |
|
82 gBrowser.selectedTab = partialURLTab; |
|
83 is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to partialURLTab'); |
|
84 |
|
85 // simulate the user removing part of the url from the location bar |
|
86 gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", false); |
|
87 |
|
88 var deleted = 0; |
|
89 urlbarBackspace(function () { |
|
90 deleted++; |
|
91 if (deleted < charsToDelete) { |
|
92 urlbarBackspace(arguments.callee); |
|
93 } else { |
|
94 is(gURLBar.value, testPartialURL, "gURLBar.value should be testPartialURL (just set)"); |
|
95 if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll")) |
|
96 gPrefService.clearUserPref("browser.urlbar.clickSelectsAll"); |
|
97 cb(); |
|
98 } |
|
99 }); |
|
100 } |
|
101 |
|
102 function runTests() { |
|
103 testURL = gURLBar.trimValue(testURL); |
|
104 testPartialURL = testURL.substr(0, (testURL.length - charsToDelete)); |
|
105 |
|
106 // prepare the three tabs required by this test |
|
107 prepareFullURLTab(function () { |
|
108 preparePartialURLTab(function () { |
|
109 prepareDeletedURLTab(function () { |
|
110 // now cycle the tabs and make sure everything looks good |
|
111 cycleTabs(); |
|
112 cleanUp(); |
|
113 finish(); |
|
114 }); |
|
115 }); |
|
116 }); |
|
117 } |
|
118 |
|
119 load(deletedURLTab, testURL, function() { |
|
120 load(fullURLTab, testURL, function() { |
|
121 load(partialURLTab, testURL, runTests); |
|
122 }); |
|
123 }); |
|
124 } |
|
125 |