1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_URLBarSetURI.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function test() { 1.9 + waitForExplicitFinish(); 1.10 + 1.11 + // avoid prompting about phishing 1.12 + Services.prefs.setIntPref(phishyUserPassPref, 32); 1.13 + registerCleanupFunction(function () { 1.14 + Services.prefs.clearUserPref(phishyUserPassPref); 1.15 + }); 1.16 + 1.17 + nextTest(); 1.18 +} 1.19 + 1.20 +const phishyUserPassPref = "network.http.phishy-userpass-length"; 1.21 + 1.22 +function nextTest() { 1.23 + let test = tests.shift(); 1.24 + if (test) { 1.25 + test(function () { 1.26 + executeSoon(nextTest); 1.27 + }); 1.28 + } else { 1.29 + executeSoon(finish); 1.30 + } 1.31 +} 1.32 + 1.33 +let tests = [ 1.34 + function revert(next) { 1.35 + loadTabInWindow(window, function (tab) { 1.36 + gURLBar.handleRevert(); 1.37 + is(gURLBar.value, "example.com", "URL bar had user/pass stripped after reverting"); 1.38 + gBrowser.removeTab(tab); 1.39 + next(); 1.40 + }); 1.41 + }, 1.42 + function customize(next) { 1.43 + whenNewWindowLoaded(undefined, function (win) { 1.44 + // Need to wait for delayedStartup for the customization part of the test, 1.45 + // since that's where BrowserToolboxCustomizeDone is set. 1.46 + whenDelayedStartupFinished(win, function () { 1.47 + loadTabInWindow(win, function () { 1.48 + openToolbarCustomizationUI(function () { 1.49 + closeToolbarCustomizationUI(function () { 1.50 + is(win.gURLBar.value, "example.com", "URL bar had user/pass stripped after customize"); 1.51 + win.close(); 1.52 + next(); 1.53 + }, win); 1.54 + }, win); 1.55 + }); 1.56 + }); 1.57 + }); 1.58 + }, 1.59 + function pageloaderror(next) { 1.60 + loadTabInWindow(window, function (tab) { 1.61 + // Load a new URL and then immediately stop it, to simulate a page load 1.62 + // error. 1.63 + tab.linkedBrowser.loadURI("http://test1.example.com"); 1.64 + tab.linkedBrowser.stop(); 1.65 + is(gURLBar.value, "example.com", "URL bar had user/pass stripped after load error"); 1.66 + gBrowser.removeTab(tab); 1.67 + next(); 1.68 + }); 1.69 + } 1.70 +]; 1.71 + 1.72 +function loadTabInWindow(win, callback) { 1.73 + info("Loading tab"); 1.74 + let url = "http://user:pass@example.com/"; 1.75 + let tab = win.gBrowser.selectedTab = win.gBrowser.addTab(url); 1.76 + tab.linkedBrowser.addEventListener("load", function listener() { 1.77 + info("Tab loaded"); 1.78 + if (tab.linkedBrowser.currentURI.spec != url) 1.79 + return; 1.80 + tab.linkedBrowser.removeEventListener("load", listener, true); 1.81 + 1.82 + is(win.gURLBar.value, "example.com", "URL bar had user/pass stripped initially"); 1.83 + callback(tab); 1.84 + }, true); 1.85 +}