Bug 600707 - Update back/forward buttons on every location change [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Thu, 30 Sep 2010 14:02:00 -0700
changeset 66758 035c05f70ad8e4ffe94d97693fc98d036d5d43d5
parent 66757 0212bef3da4dacf596bebbd7c40a9b1f8a04a22f
child 66759 4baff6ce200edca8a11dfa288bb72d186a721306
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs600707
Bug 600707 - Update back/forward buttons on every location change [r=mfinkle]
mobile/chrome/content/browser.js
mobile/chrome/tests/browser_navigation.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -2128,26 +2128,27 @@ ProgressController.prototype = {
     if (aWebProgress.windowId != this._tab.browser.contentWindowId)
       return;
 
     let spec = aLocationURI ? aLocationURI.spec : "";
     let location = spec.split("#")[0]; // Ignore fragment identifier changes.
 
     this._hostChanged = true;
 
+    if (this._tab == Browser.selectedTab)
+      BrowserUI.updateURI();
+
     if (location != this.browser.lastLocation) {
       TapHighlightHelper.hide();
 
       this.browser.lastLocation = location;
       Browser.removeTransientNotificationsForTab(this._tab);
       this._tab.resetZoomLevel();
 
       if (this._tab == Browser.selectedTab) {
-        BrowserUI.updateURI();
-
         // We're about to have new page content, so scroll the content area
         // to the top so the new paints will draw correctly.
         // (background tabs are delayed scrolled to top in _documentStop)
         Browser.scrollContentToTop();
       }
     }
   },
 
--- a/mobile/chrome/tests/browser_navigation.js
+++ b/mobile/chrome/tests/browser_navigation.js
@@ -3,16 +3,19 @@ var testURL_02 = "chrome://mochikit/cont
 var testURL_03 = "chrome://mochikit/content/browser/mobile/chrome/browser_english_title.html";
 var testURL_04 = "chrome://mochikit/content/browser/mobile/chrome/browser_no_title.html";
 var pngURL = "data:image/gif;base64,R0lGODlhCwALAIAAAAAA3pn/ZiH5BAEAAAEALAAAAAALAAsAAAIUhA+hkcuO4lmNVindo7qyrIXiGBYAOw==";
 
 // A queue to order the tests and a handle for each test
 var gTests = [];
 var gCurrentTest = null;
 
+var back = document.getElementById("tool-back");
+var forward = document.getElementById("tool-forward");
+
 function pageLoaded(url) {
   return function() {
     let tab = gCurrentTest._currentTab;
     return !tab.isLoading() && tab.browser.currentURI.spec == url;
   }
 }
 
 //------------------------------------------------------------------------------
@@ -60,21 +63,19 @@ gTests.push({
   },
 
   onPageReady: function() {
     // Test the mode
     let urlIcons = document.getElementById("urlbar-icons");
     is(urlIcons.getAttribute("mode"), "view", "URL Mode is set to 'view'");
 
     // Test back button state
-    let back = document.getElementById("tool-back");
     is(back.disabled, !gCurrentTest._currentTab.browser.canGoBack, "Back button check");
 
     // Test forward button state
-    let forward = document.getElementById("tool-forward");
     is(forward.disabled, !gCurrentTest._currentTab.browser.canGoForward, "Forward button check");
 
     // Focus the url edit
     let urlbarEdit = document.getElementById("urlbar-edit");
     EventUtils.synthesizeMouse(urlbarEdit, urlbarEdit.width / 2, urlbarEdit.height / 2, {});
 
     // Wait for the awesomebar to load, then do the test
     window.addEventListener("popupshown", gCurrentTest.onFocusReady, false);
@@ -83,21 +84,19 @@ gTests.push({
   onFocusReady: function() {
     window.removeEventListener("popupshown", gCurrentTest.onFocusReady, false);
 
     // Test mode
     let urlIcons = document.getElementById("urlbar-icons");
     is(urlIcons.getAttribute("mode"), "edit", "URL Mode is set to 'edit'");
 
     // Test back button state
-    let back = document.getElementById("tool-back");
     is(back.disabled, !gCurrentTest._currentTab.browser.canGoBack, "Back button check");
 
     // Test forward button state
-    let forward = document.getElementById("tool-forward");
     is(forward.disabled, !gCurrentTest._currentTab.browser.canGoForward, "Forward button check");
 
     // Check button states (url edit is focused)
     let search = document.getElementById("tool-search");
     let searchStyle = window.getComputedStyle(search, null);
     is(searchStyle.visibility, "visible", "SEARCH is visible");
 
     let stop = document.getElementById("tool-stop");
@@ -140,21 +139,19 @@ gTests.push({
     gCurrentTest._currentTab.browser.goBack();
 
     // Wait for the tab to load, then do the test
     waitFor(gCurrentTest.onPageBack, pageLoaded(testURL_01));
   },
 
   onPageBack: function() {
     // Test back button state
-    let back = document.getElementById("tool-back");
     is(back.disabled, !gCurrentTest._currentTab.browser.canGoBack, "Back button check");
 
     // Test forward button state
-    let forward = document.getElementById("tool-forward");
     is(forward.disabled, !gCurrentTest._currentTab.browser.canGoForward, "Forward button check");
 
     Browser.closeTab(gCurrentTest._currentTab);
     runNextTest();
   }
 });
 
 //------------------------------------------------------------------------------
@@ -262,8 +259,64 @@ gTests.push({
   onPageFinish: function(){
     let favicon = document.getElementById("urlbar-favicon");
     is(favicon.src, pngURL, "The page favicon must be loaded");
     Browser.closeTab(gCurrentTest._currentTab);
     runNextTest();
   }
 });
 
+// Bug 600707 - Back and forward buttons are updated when navigating within a page
+//
+// These tests use setTimeout instead of waitFor or addEventListener, because
+// in-page navigation does not fire any loading events or progress
+// notifications, and happens more or less instantly.
+gTests.push({
+  desc: "Navigating within a page via URI fragments",
+  _currentTab: null,
+
+  run: function() {
+    gCurrentTest._currentTab = Browser.addTab(testURL_01, true);
+    waitFor(gCurrentTest.onPageReady, pageLoaded(testURL_01));
+  },
+
+  onPageReady: function() {
+    ok(back.disabled, "Can't go back");
+    ok(forward.disabled, "Can't go forward");
+
+    messageManager.addMessageListener("WebProgress:LocationChange", gCurrentTest.onFragmentLoaded);
+    Browser.loadURI(testURL_01 + "#fragment");
+  },
+
+  onFragmentLoaded: function() {
+    messageManager.removeMessageListener("WebProgress:LocationChange", arguments.callee);
+
+    ok(!back.disabled, "Can go back");
+    ok(forward.disabled, "Can't go forward");
+
+    messageManager.addMessageListener("WebProgress:LocationChange", gCurrentTest.onBack);
+    CommandUpdater.doCommand("cmd_back");
+  },
+
+  onBack: function() {
+    messageManager.removeMessageListener("WebProgress:LocationChange", arguments.callee);
+
+    ok(back.disabled, "Can't go back");
+    ok(!forward.disabled, "Can go forward");
+
+    messageManager.addMessageListener("WebProgress:LocationChange", gCurrentTest.onForward);
+    CommandUpdater.doCommand("cmd_forward");
+  },
+
+  onForward: function() {
+    messageManager.removeMessageListener("WebProgress:LocationChange", arguments.callee);
+
+    ok(!back.disabled, "Can go back");
+    ok(forward.disabled, "Can't go forward");
+
+    gCurrentTest.finish();
+  },
+
+  finish: function() {
+    Browser.closeTab(gCurrentTest._currentTab);
+    runNextTest();
+  }
+});