Bug 802026, r=dao
authorGavin Sharp <gavin@gavinsharp.com>
Wed, 12 Dec 2012 01:09:49 -0800
changeset 125264 83e7913cba52a6a931f60966bc09822ea628343d
parent 125263 f050eb79064f9ec750aa34c35452b9f72cabea64
child 125265 b35c960626b528f796ca63f5370c389f98a26a83
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs802026
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 802026, r=dao
browser/base/content/browser.js
browser/base/content/test/Makefile.in
browser/base/content/test/browser_URLBarSetURI.js
toolkit/content/Services.jsm
toolkit/content/tests/browser/browser_Services.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2316,16 +2316,20 @@ function BrowserPageInfo(doc, initialTab
 }
 
 function URLBarSetURI(aURI) {
   var value = gBrowser.userTypedValue;
   var valid = false;
 
   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).
     if (gInitialPages.indexOf(uri.spec) != -1)
       value = content.opener ? uri.spec : "";
     else
       value = losslessDecodeURI(uri);
 
@@ -3796,21 +3800,16 @@ var XULBrowserWindow = {
   get statusTextField () {
     delete this.statusTextField;
     return this.statusTextField = document.getElementById("statusbar-display");
   },
   get isImage () {
     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");
 
 #ifdef MOZ_E10S_COMPAT
     // Bug 666809 - SecurityUI support for e10s
 #else
     // Initialize the security button's state and tooltip text.  Remember to reset
@@ -4094,22 +4093,17 @@ var XULBrowserWindow = {
           location == "") {  // Second condition is for new tabs, otherwise
                              // reload function is enabled until tab is refreshed.
         this.reloadCommand.setAttribute("disabled", "true");
       } else {
         this.reloadCommand.removeAttribute("disabled");
       }
 
       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();
         SocialShareButton.updateShareState();
       }
 
       // Show or hide browser chrome based on the whitelist
       if (this.hideChromeForLocation(location)) {
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -284,16 +284,17 @@ endif
                  browser_bug818009.js \
                  browser_bug818118.js \
                  blockPluginVulnerableUpdatable.xml \
                  blockPluginVulnerableNoUpdate.xml \
                  blockNoPlugins.xml \
                  browser_utilityOverlay.js \
                  browser_bug676619.js \
                  download_page.html \
+                 browser_URLBarSetURI.js \
                  $(NULL)
 
 ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 _BROWSER_FILES += \
 		browser_bug462289.js \
 		$(NULL)
 else
 _BROWSER_FILES += \
new file mode 100644
--- /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);
+}
--- a/toolkit/content/Services.jsm
+++ b/toolkit/content/Services.jsm
@@ -58,14 +58,15 @@ let initTable = [
   ["vc", "@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"],
   ["wm", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"],
   ["ww", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"],
   ["startup", "@mozilla.org/toolkit/app-startup;1", "nsIAppStartup"],
   ["sysinfo", "@mozilla.org/system-info;1", "nsIPropertyBag2"],
   ["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])
   XPCOMUtils.defineLazyServiceGetter(Services, name, contract, intf));
 
 initTable = undefined;
--- a/toolkit/content/tests/browser/browser_Services.js
+++ b/toolkit/content/tests/browser/browser_Services.js
@@ -48,9 +48,10 @@ function checkServices() {
   checkService("startup", Ci.nsIAppStartup);
   checkService("appShell", Ci.nsIAppShellService);
   checkService("cache", Ci.nsICacheService);
   checkService("scriptSecurityManager", Ci.nsIScriptSecurityManager);
   checkService("domStorageManager", Ci.nsIDOMStorageManager);
   checkService("DOMRequest", Ci.nsIDOMRequestService);
   checkService("downloads", Ci.nsIDownloadManager);
   checkService("focus", Ci.nsIFocusManager);
+  checkService("uriFixup", Ci.nsIURIFixup);
 }