|
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 // avoid prompting about phishing |
|
9 Services.prefs.setIntPref(phishyUserPassPref, 32); |
|
10 registerCleanupFunction(function () { |
|
11 Services.prefs.clearUserPref(phishyUserPassPref); |
|
12 }); |
|
13 |
|
14 nextTest(); |
|
15 } |
|
16 |
|
17 const phishyUserPassPref = "network.http.phishy-userpass-length"; |
|
18 |
|
19 function nextTest() { |
|
20 let test = tests.shift(); |
|
21 if (test) { |
|
22 test(function () { |
|
23 executeSoon(nextTest); |
|
24 }); |
|
25 } else { |
|
26 executeSoon(finish); |
|
27 } |
|
28 } |
|
29 |
|
30 let tests = [ |
|
31 function revert(next) { |
|
32 loadTabInWindow(window, function (tab) { |
|
33 gURLBar.handleRevert(); |
|
34 is(gURLBar.value, "example.com", "URL bar had user/pass stripped after reverting"); |
|
35 gBrowser.removeTab(tab); |
|
36 next(); |
|
37 }); |
|
38 }, |
|
39 function customize(next) { |
|
40 whenNewWindowLoaded(undefined, function (win) { |
|
41 // Need to wait for delayedStartup for the customization part of the test, |
|
42 // since that's where BrowserToolboxCustomizeDone is set. |
|
43 whenDelayedStartupFinished(win, function () { |
|
44 loadTabInWindow(win, function () { |
|
45 openToolbarCustomizationUI(function () { |
|
46 closeToolbarCustomizationUI(function () { |
|
47 is(win.gURLBar.value, "example.com", "URL bar had user/pass stripped after customize"); |
|
48 win.close(); |
|
49 next(); |
|
50 }, win); |
|
51 }, win); |
|
52 }); |
|
53 }); |
|
54 }); |
|
55 }, |
|
56 function pageloaderror(next) { |
|
57 loadTabInWindow(window, function (tab) { |
|
58 // Load a new URL and then immediately stop it, to simulate a page load |
|
59 // error. |
|
60 tab.linkedBrowser.loadURI("http://test1.example.com"); |
|
61 tab.linkedBrowser.stop(); |
|
62 is(gURLBar.value, "example.com", "URL bar had user/pass stripped after load error"); |
|
63 gBrowser.removeTab(tab); |
|
64 next(); |
|
65 }); |
|
66 } |
|
67 ]; |
|
68 |
|
69 function loadTabInWindow(win, callback) { |
|
70 info("Loading tab"); |
|
71 let url = "http://user:pass@example.com/"; |
|
72 let tab = win.gBrowser.selectedTab = win.gBrowser.addTab(url); |
|
73 tab.linkedBrowser.addEventListener("load", function listener() { |
|
74 info("Tab loaded"); |
|
75 if (tab.linkedBrowser.currentURI.spec != url) |
|
76 return; |
|
77 tab.linkedBrowser.removeEventListener("load", listener, true); |
|
78 |
|
79 is(win.gURLBar.value, "example.com", "URL bar had user/pass stripped initially"); |
|
80 callback(tab); |
|
81 }, true); |
|
82 } |