From e01d3ab5079026ebe5457687c5620cc3d69b04aa Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Wed, 12 Dec 2012 01:09:49 -0800 Subject: [PATCH] Bug 802026, r=dao --HG-- extra : transplant_source : _%DEr6%3A%8A%40%AF%FE%5E/%C6N%82%00%0B%0FtU%DD --- browser/base/content/browser.js | 16 ++-- browser/base/content/test/Makefile.in | 1 + .../base/content/test/browser_URLBarSetURI.js | 82 +++++++++++++++++++ toolkit/content/Services.jsm | 1 + .../content/tests/browser/browser_Services.js | 1 + 5 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 browser/base/content/test/browser_URLBarSetURI.js diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 13231bfe633..b036ddfaa80 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2321,6 +2321,10 @@ function URLBarSetURI(aURI) { if (value == null) { let uri = aURI || gBrowser.currentURI; + // Strip off "wyciwyg://" and passwords for the location bar + try { + uri = Services.uriFixup.createExposableURI(uri); + } catch (e) {} // Replace initial page URIs with an empty string // only if there's no opener (bug 370555). @@ -3801,11 +3805,6 @@ var XULBrowserWindow = { delete this.isImage; return this.isImage = document.getElementById("isImage"); }, - get _uriFixup () { - delete this._uriFixup; - return this._uriFixup = Cc["@mozilla.org/docshell/urifixup;1"] - .getService(Ci.nsIURIFixup); - }, init: function () { this.throbberElement = document.getElementById("navigator-throbber"); @@ -4099,12 +4098,7 @@ var XULBrowserWindow = { } if (gURLBar) { - // Strip off "wyciwyg://" and passwords for the location bar - let uri = aLocationURI; - try { - uri = this._uriFixup.createExposableURI(uri); - } catch (e) {} - URLBarSetURI(uri); + URLBarSetURI(aLocationURI); // Update starring UI PlacesStarButton.updateState(); diff --git a/browser/base/content/test/Makefile.in b/browser/base/content/test/Makefile.in index 144ba957994..c51e7a4a868 100644 --- a/browser/base/content/test/Makefile.in +++ b/browser/base/content/test/Makefile.in @@ -289,6 +289,7 @@ _BROWSER_FILES = \ browser_utilityOverlay.js \ browser_bug676619.js \ download_page.html \ + browser_URLBarSetURI.js \ $(NULL) ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT)) diff --git a/browser/base/content/test/browser_URLBarSetURI.js b/browser/base/content/test/browser_URLBarSetURI.js new file mode 100644 index 00000000000..3b67e8ed016 --- /dev/null +++ b/browser/base/content/test/browser_URLBarSetURI.js @@ -0,0 +1,82 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +function test() { + waitForExplicitFinish(); + + // avoid prompting about phishing + Services.prefs.setIntPref(phishyUserPassPref, 32); + registerCleanupFunction(function () { + Services.prefs.clearUserPref(phishyUserPassPref); + }); + + nextTest(); +} + +const phishyUserPassPref = "network.http.phishy-userpass-length"; + +function nextTest() { + let test = tests.shift(); + if (test) { + test(function () { + executeSoon(nextTest); + }); + } else { + executeSoon(finish); + } +} + +let tests = [ + function revert(next) { + loadTabInWindow(window, function (tab) { + gURLBar.handleRevert(); + is(gURLBar.value, "example.com", "URL bar had user/pass stripped after reverting"); + gBrowser.removeTab(tab); + next(); + }); + }, + function customize(next) { + whenNewWindowLoaded(null, function (win) { + // Need to wait for delayedStartup for the customization part of the test, + // since that's where BrowserToolboxCustomizeDone is set. + whenDelayedStartupFinished(win, function () { + loadTabInWindow(win, function () { + openToolbarCustomizationUI(function () { + closeToolbarCustomizationUI(function () { + is(win.gURLBar.value, "example.com", "URL bar had user/pass stripped after customize"); + win.close(); + next(); + }, win); + }, win); + }); + }); + }); + }, + function pageloaderror(next) { + loadTabInWindow(window, function (tab) { + // Load a new URL and then immediately stop it, to simulate a page load + // error. + tab.linkedBrowser.loadURI("http://test1.example.com"); + tab.linkedBrowser.stop(); + is(gURLBar.value, "example.com", "URL bar had user/pass stripped after load error"); + gBrowser.removeTab(tab); + next(); + }); + } +]; + +function loadTabInWindow(win, callback) { + info("Loading tab"); + let url = "http://user:pass@example.com/"; + let tab = win.gBrowser.selectedTab = win.gBrowser.addTab(url); + tab.linkedBrowser.addEventListener("load", function listener() { + info("Tab loaded"); + if (tab.linkedBrowser.currentURI.spec != url) + return; + tab.linkedBrowser.removeEventListener("load", listener, true); + + is(win.gURLBar.value, "example.com", "URL bar had user/pass stripped initially"); + callback(tab); + }, true); +} diff --git a/toolkit/content/Services.jsm b/toolkit/content/Services.jsm index 6e97215e361..24d9f4357bc 100644 --- a/toolkit/content/Services.jsm +++ b/toolkit/content/Services.jsm @@ -63,6 +63,7 @@ let initTable = [ ["clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard"], ["DOMRequest", "@mozilla.org/dom/dom-request-service;1", "nsIDOMRequestService"], ["focus", "@mozilla.org/focus-manager;1", "nsIFocusManager"], + ["uriFixup", "@mozilla.org/docshell/urifixup;1", "nsIURIFixup"], ]; initTable.forEach(function ([name, contract, intf]) diff --git a/toolkit/content/tests/browser/browser_Services.js b/toolkit/content/tests/browser/browser_Services.js index c48f8505d94..0ed59262443 100644 --- a/toolkit/content/tests/browser/browser_Services.js +++ b/toolkit/content/tests/browser/browser_Services.js @@ -53,4 +53,5 @@ function checkServices() { checkService("DOMRequest", Ci.nsIDOMRequestService); checkService("downloads", Ci.nsIDownloadManager); checkService("focus", Ci.nsIFocusManager); + checkService("uriFixup", Ci.nsIURIFixup); }