Bug 559991. Zoom flicker when switching quickly between tabs. r=gavin.sharp a=blocking-betaN
authorFelipe Gomes <felipc@gmail.com>
Thu, 02 Sep 2010 18:50:32 -0300
changeset 51933 26cb1dc486377973880d5db9f5db705b04ab4b9a
parent 51932 29c3f6e7c48e0081543d57ac397b9e5e3695b4cc
child 51934 a5d1b45234b8f9681a6418e41a154dc78b962fab
push idunknown
push userunknown
push dateunknown
reviewersgavin.sharp, blocking-betaN
bugs559991
milestone2.0b6pre
Bug 559991. Zoom flicker when switching quickly between tabs. r=gavin.sharp a=blocking-betaN
browser/base/content/browser-fullZoom.js
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug559991.js
--- a/browser/base/content/browser-fullZoom.js
+++ b/browser/base/content/browser-fullZoom.js
@@ -251,20 +251,20 @@ var FullZoom = {
     if (aURI.spec == "about:blank") {
       this._applyPrefToSetting(undefined, aBrowser);
       return;
     }
 
     var self = this;
     Services.contentPrefs.getPref(aURI, this.name, function (aResult) {
       // Check that we're still where we expect to be in case this took a while.
-      let isSaneURI = (aBrowser && aBrowser.currentURI) ?
-        aURI.equals(aBrowser.currentURI) : false;
-      if (!aBrowser || isSaneURI)
-        self._applyPrefToSetting(aResult, aBrowser);
+      let browser = aBrowser || gBrowser.selectedBrowser;
+      if (aURI.equals(browser.currentURI)) {
+        self._applyPrefToSetting(aResult, browser);
+      }
     });
   },
 
   // update state of zoom type menu item
 
   updateMenu: function FullZoom_updateMenu() {
     var menuItem = document.getElementById("toggle_zoom");
 
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -133,16 +133,17 @@ endif
                  browser_bug520538.js \
                  browser_bug521216.js \
                  browser_bug537474.js \
                  browser_bug550565.js \
                  browser_bug553455.js \
                  browser_bug555224.js \
                  browser_bug555767.js \
                  browser_bug556061.js \
+                 browser_bug559991.js \
                  browser_bug561623.js \
                  browser_bug562649.js \
                  browser_bug563588.js \
                  browser_bug577121.js \
                  browser_bug579872.js \
                  browser_bug580956.js \
                  browser_bug581242.js \
                  browser_bug581947.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug559991.js
@@ -0,0 +1,64 @@
+function test() {
+
+  // ----------
+  // Test setup
+
+  waitForExplicitFinish();
+
+  let oldOLC = FullZoom.onLocationChange;
+  FullZoom.onLocationChange = function(aURI, aIsTabSwitch, aBrowser) {
+    // Ignore calls that are not about tab switching on this test
+    if (aIsTabSwitch)
+      oldOLC.call(FullZoom, aURI, aIsTabSwitch, aBrowser);
+  };
+
+  gPrefService.setBoolPref("browser.zoom.updateBackgroundTabs", true);
+  gPrefService.setBoolPref("browser.zoom.siteSpecific", true);
+
+  let oldAPTS = FullZoom._applyPrefToSetting;
+  let uri = "http://example.org/browser/browser/base/content/test/dummy_page.html";
+
+  // ------------------------------------------------------
+  // Test 1 - Zoom should not be called if URIs don't match
+  FullZoom._applyPrefToSetting = function() {
+    ok(false, "This should not be called");
+  };
+  FullZoom.onLocationChange(makeURI(uri), true);
+
+  let tab = gBrowser.addTab();
+  tab.linkedBrowser.addEventListener("load", function(event) {
+    tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
+
+    // -------------------------------------------------------------------
+    // Test 2 - Trigger a tab switch that should now update the zoom level
+    FullZoom._applyPrefToSetting = function() {
+      ok(true, "applyPrefToSetting was called");
+      endTest();
+    }
+    gBrowser.selectedTab = tab;
+
+  }, true); 
+  tab.linkedBrowser.loadURI(uri);
+
+  // -------------
+  // Test clean-up
+  function endTest() {
+    gBrowser.removeTab(tab);
+    FullZoom._applyPrefToSetting = oldAPTS;
+    FullZoom.onLocationChange = oldOLC;
+
+    oldAPTS = null;
+    oldOLC = null;
+    tab = null;
+
+    if (gPrefService.prefHasUserValue("browser.zoom.updateBackgroundTabs"))
+      gPrefService.clearUserPref("browser.zoom.updateBackgroundTabs");
+
+    if (gPrefService.prefHasUserValue("browser.zoom.siteSpecific"))
+      gPrefService.clearUserPref("browser.zoom.siteSpecific");
+
+    finish();
+  }
+
+}
+