Bug 628732 - Hitting Android Back in Awesome list opens right panel [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Thu, 27 Jan 2011 21:33:43 +0100
changeset 67321 034cd7eee8d2ea96384ff3e082e37b6f989e234f
parent 67320 02cb32b731e14c87a39ceac78e9bc6091e874a23
child 67322 53781acb5bdbc95987312adc09c62973db0bddbd
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
bugs628732
Bug 628732 - Hitting Android Back in Awesome list opens right panel [r=mfinkle]
mobile/chrome/content/tabs.xml
mobile/chrome/tests/browser_sidebars.js
--- a/mobile/chrome/content/tabs.xml
+++ b/mobile/chrome/content/tabs.xml
@@ -182,36 +182,40 @@
         ]]></body>
       </method>
 
       <method name="resize">
         <body>
           <![CDATA[
             let container = this.parentNode.getBoundingClientRect();
             let element   = this.children.getBoundingClientRect();
-
-            let height = (element.top - container.top) + ((container.top + container.height) - (element.top + element.height));
+            let undo = this._tabsUndo.getBoundingClientRect();
+            let lastChild = this.parentNode.lastChild.getBoundingClientRect();
+            
+            let height = window.innerHeight - element.top - (undo.bottom - undo.top) - (lastChild.top - element.bottom) - lastChild.height;
             this.children.style.height = height + "px";
 
             this._updateWidth();
           ]]>
         </body>
       </method>
 
       <field name="_columnsCount">0</field>
       <method name="_updateWidth">
         <body>
           <![CDATA[
             // XXX we can do better than using a constant
             const COLUMN_MARGIN = 20;
             let firstBox = this.children.firstChild.getBoundingClientRect();
             let lastBox = this.children.lastChild.getBoundingClientRect();
 
-            // XXX we can do better than using a constant here
-            let columnsCount = Math.ceil(this.children.childNodes.length / Math.floor(this.children.getBoundingClientRect().height / (firstBox.height + 4)));
+            // We can't rely on getBoundingClientRect() for this.children height
+            // it is not synced (sometimes, especially during resize) with the 
+            // style.height rule
+            let columnsCount = Math.ceil(this.children.childNodes.length / Math.floor(parseInt(this.children.style.height) / (firstBox.height + 4)));
             if (this._columnsCount != columnsCount && window.innerWidth > 1) { // > 1 to ignore column resizing while the main window is loading
               this.children.style.width = (columnsCount * (COLUMN_MARGIN + firstBox.width)) + "px";
               this._columnsCount = columnsCount;
             }
           ]]>
         </body>
       </method>
 
--- a/mobile/chrome/tests/browser_sidebars.js
+++ b/mobile/chrome/tests/browser_sidebars.js
@@ -15,16 +15,25 @@ function runNextTest() {
   }
   else {
     // Close the awesome panel just in case
     BrowserUI.activePanel = null;
     finish();
   }
 }
 
+function waitForNavigationPanel(aCallback, aWaitForHide) {
+  let evt = aWaitForHide ? "NavigationPanelHidden" : "NavigationPanelShown";
+  info("waitFor " + evt + "(" + Components.stack.caller + ")");
+  window.addEventListener(evt, function(aEvent) {
+    info("receive " + evt);
+    window.removeEventListener(aEvent.type, arguments.callee, false);
+    Util.executeSoon(aCallback);
+  }, false);
+}
 
 //------------------------------------------------------------------------------
 // Entry point (must be named "test")
 function test() {
   // This test is async
   waitForExplicitFinish();
 
   //Add new tab
@@ -33,37 +42,45 @@ function test() {
   ok(tabs._columnsCount == 1, "Tabs layout should be on one column");
 
   runNextTest();
 
 }
 
 function checkSidebars(aLeftVisible, aRightVisible) {
   let [leftVisibility, rightVisibility, leftWidth, rightWidth] = Browser.computeSidebarVisibility();
-  ok(Math.abs(leftVisibility - aLeftVisible) < 0.2, (leftWidth * aLeftVisible) + "px of the left sidebar should be visible");
-  ok(Math.abs(rightVisibility - aRightVisible) < 0.2, (rightWidth * aRightVisible) + "px of the right sidebar should be visible");
+  let left = Math.abs(leftVisibility - aLeftVisible),
+      right = Math.abs(rightVisibility - aRightVisible);
+  ok(left < 0.2, (leftWidth * aLeftVisible) + "px of the left sidebar should be visible (got " + left + ")");
+  ok(right < 0.2, (rightWidth * aRightVisible) + "px of the right sidebar should be visible (got " + right + ")");
 }
 
 function checkOnResize(aCallback) {
   let [leftVisibility, rightVisibility, leftWidth, rightWidth] = Browser.computeSidebarVisibility();
+  let oldLeftWidth = leftWidth;
 
-  window.addEventListener("resize", function() {
-    window.removeEventListener("resize", arguments.callee, false);
-    setTimeout(function() {
+  Elements.browsers.addEventListener("SizeChanged", function() {
+    Elements.browsers.removeEventListener("SizeChanged", arguments.callee, false);
+    setTimeout(function() { Util.executeSoon(function() {
       checkSidebars(leftVisibility, rightVisibility);
-      window.addEventListener("resize", function() {
-        window.removeEventListener("resize", arguments.callee, false);
+
+      Elements.browsers.addEventListener("SizeChanged", function() {
+        Elements.browsers.removeEventListener("SizeChanged", arguments.callee, false);
+
         setTimeout(function() {
           checkSidebars(leftVisibility, rightVisibility);
+          let [, , newLeftWidth, newRightWidth] = Browser.computeSidebarVisibility();
+          is(oldLeftWidth, newLeftWidth, "Size should be the same than the size before resizing");
           aCallback();
         }, 0);
       }, false);
       window.resizeTo(800, 480);
-    }, 0);
-  }, false);
+    }); }, 0)} 
+  , false);
+
   window.resizeTo(480, 800);
 }
 
 gTests.push({
   desc: "Testing horizontal positionning of the sidebars for one column",
 
   run: function() {
     checkSidebars(0, 0);
@@ -91,16 +108,17 @@ gTests.push({
   run: function() {
     newTabs.push(Browser.addTab(testURL_01, true));
     newTabs.push(Browser.addTab(testURL_01, true));
     newTabs.push(Browser.addTab(testURL_01, true));
     newTabs.push(Browser.addTab(testURL_01, true));
     newTabs.push(Browser.addTab(testURL_01, true));
     newTabs.push(Browser.addTab(testURL_01, true));
     newTabs.push(Browser.addTab(testURL_01, true));
+    newTabs.push(Browser.addTab(testURL_01, true));
     let tabs = document.getElementById("tabs");
     ok(tabs._columnsCount > 1, "Tabs layout should be on multiple columns");
 
     checkSidebars(0, 0);
     checkOnResize(gCurrentTest.checkLeftVisible);
   },
 
   checkLeftVisible: function() {
@@ -108,14 +126,51 @@ gTests.push({
     checkSidebars(1, 0);
     checkOnResize(gCurrentTest.checkRightVisible);
   },
 
   checkRightVisible: function() {
     let [,, leftWidth, rightWidth] = Browser.computeSidebarVisibility();
     Browser.controlsScrollboxScroller.scrollTo(leftWidth + rightWidth, 0);
     checkSidebars(0, 1);
-    checkOnResize(function() {
-      Browser.hideSidebars();
-      runNextTest();
-    });
+    checkOnResize(gCurrentTest.onFinish);
+  },
+
+  onFinish: function() {
+    Browser.hideSidebars();
+    runNextTest();
   }
 });
+
+gTests.push({
+  desc: "Testing horizontal positionning of the sidebars for multiple columns with awesome screen open",
+
+  run: function() {
+    let tabs = document.getElementById("tabs");
+    ok(tabs._columnsCount > 1, "Tabs layout should be on multiple columns");
+
+    checkSidebars(0, 0);
+    waitForNavigationPanel(function() {
+      checkOnResize(gCurrentTest.checkLeftVisible);
+    });
+    AllPagesList.doCommand();
+  },
+
+
+  checkLeftVisible: function() {
+    Browser.controlsScrollboxScroller.scrollTo(0, 0);
+    checkSidebars(1, 0);
+    checkOnResize(gCurrentTest.checkRightVisible);
+  },
+
+  checkRightVisible: function() {
+    let [,, leftWidth, rightWidth] = Browser.computeSidebarVisibility();
+    Browser.controlsScrollboxScroller.scrollTo(leftWidth + rightWidth, 0);
+    checkSidebars(0, 1);
+    checkOnResize(gCurrentTest.onFinish);
+  },
+
+  onFinish: function() {
+    Browser.hideSidebars();
+    runNextTest();
+  }
+});
+