Bug 620061 - followup + tests [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Wed, 22 Dec 2010 18:50:49 +0100
changeset 67154 60257da121d99f3a3e703aa8e31cd597fd80ce56
parent 67153 2c1bd80f820041737232b439d701e71d63a832b8
child 67155 e505487cc15e9fbb1daf3ca47c5a3bacf7de03e1
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
bugs620061
Bug 620061 - followup + tests [r=mfinkle]
mobile/chrome/content/tabs.xml
mobile/chrome/tests/browser_tabs.js
--- a/mobile/chrome/content/tabs.xml
+++ b/mobile/chrome/content/tabs.xml
@@ -202,21 +202,18 @@
           <![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)));
-            if (this._columnsCount != columnsCount && (firstBox.left != lastBox.left)) {
-              let width = Math.max(lastBox.right - firstBox.left, firstBox.right - lastBox.left);
-              width -= this._columnsCount * COLUMN_MARGIN;
-
-              this.children.style.width = (width + columnsCount * COLUMN_MARGIN) + "px";
+            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>
 
     </implementation>
   </binding>
--- a/mobile/chrome/tests/browser_tabs.js
+++ b/mobile/chrome/tests/browser_tabs.js
@@ -3,26 +3,44 @@ let testURL_02 = chromeRoot + "browser_b
 let testURL_03 = chromeRoot + "browser_blank_01.html#tab3";
 
 let new_tab_01;
 let new_tab_02;
 let new_tab_03;
 let new_tab_04;
 let new_tab_05;
 
+// XXX This is synced with the value of the COLUMN_MARGIN const in chrome/content/tabs.xml
+const COLUMN_MARGIN = 20;
+
+function checkExpectedSize() {
+  let tabs = document.getElementById("tabs");
+  let tabRect = tabs.children.firstChild.getBoundingClientRect();
+  let expectedSize = (tabs._columnsCount * (COLUMN_MARGIN + tabRect.width));
+
+  let tabsRect = tabs.children.getBoundingClientRect();
+  is(tabsRect.width, expectedSize, "Tabs container size should be equal to the number of columns and margins");
+}
+
 //------------------------------------------------------------------------------
 // Entry point (must be named "test")
 function test() {
   // This test is async
   waitForExplicitFinish();
   
   //Add new tab
   var new_tab = Browser.addTab(testURL_01,true);
   ok(new_tab, "Tab Opened");	
 
+  // Ensure columnsCount is not equal to 0
+  isnot(document.getElementById("tabs")._columnsCount, 0, "Tabs columns count should not be equal to 0");
+
+  // Check the size of the tabs container sidebar
+  checkExpectedSize();
+
   //Check currentURI.spec
   new_tab.browser.addEventListener("load", load_tabs , true);
 }
 
 function load_tabs() {
   var tabs_size_old = Browser._tabs.length -1; 
   var new_tab = Browser.getTabAtIndex(1); 
   var new_tab_URI = Browser.selectedTab.browser.currentURI.spec;
@@ -30,100 +48,108 @@ function load_tabs() {
 
   //Close new tab 
   var close_tab = Browser.closeTab(new_tab);
   var tabs_size_new = Browser._tabs.length; 	
   is(tabs_size_new, tabs_size_old, "Tab Closed");
 
   //Add new tab
   new_tab_01 = Browser.addTab(testURL_01,false);
+  checkExpectedSize();
 
   //Check tab switch
   new_tab_01.browser.addEventListener("load", tab_switch_01, true);
 }
 
 function tab_switch_01() {
   BrowserUI.selectTab(new_tab_01);
   is(Browser.selectedTab.browser.currentURI.spec, testURL_01, "Tab Switch 01 URL Matches");
   is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser");
 
   //Add new tab
   new_tab_02 =  Browser.addTab(testURL_02,false);
+  checkExpectedSize();
+
   new_tab_02.browser.addEventListener("load", tab_switch_02, true);
   is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser");
 }
 
 function tab_switch_02() {
   BrowserUI.selectTab(new_tab_02);
   is(Browser.selectedTab.browser.currentURI.spec, testURL_02, "Tab Switch 02 URL Matches");
   is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser");
 
   BrowserUI.selectTab(new_tab_01);
   is(Browser.selectedTab.browser.currentURI.spec, testURL_01, "Tab Switch 01 URL Matches");
   is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser");
 
   //Add new tab
   new_tab_03 = Browser.addTab(testURL_03, true, new_tab_01);
+  checkExpectedSize();
   new_tab_03.browser.addEventListener("load", tab_switch_03, true);
 }
 
 function tab_switch_03() {
   is(Browser.selectedTab.browser.currentURI.spec, testURL_03, "Tab Switch 03 URL Matches"); 
   is(new_tab_03.owner, new_tab_01, "Tab 03 owned by tab 01");
   is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser");
 
   Browser.closeTab(new_tab_03);
   is(Browser.selectedTab, new_tab_01, "Closing tab 03 returns to owner");
   is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser");
 
   new_tab_03 = Browser.addTab(testURL_03, true, new_tab_01);
+  checkExpectedSize();
   new_tab_03.browser.addEventListener("load", tab_switch_04, true);
 }
 
 function tab_switch_04() {
   is(Browser.selectedTab.browser.currentURI.spec, testURL_03, "Tab Switch 03 URL Matches"); 
   is(new_tab_03.owner, new_tab_01, "Tab 03 owned by tab 01");
   is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser");
 
   Browser.closeTab(new_tab_01);
   is(Browser.selectedTab, new_tab_03, "Closing tab 01 keeps selectedTab");
   is(new_tab_03.owner, null, "Closing tab 01 nulls tab3 owner");
   is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser");
 
   // Add a tab then close it
   new_tab_04 = Browser.addTab("about:home", true);
+  checkExpectedSize();
   new_tab_04.browser.addEventListener("load", function() {
     new_tab_04.browser.removeEventListener("load", arguments.callee, true);
     Browser.closeTab(new_tab_04);
     tab_undo();
   }, true);
 }
 
 function tab_undo() {
   let undoBox = document.getElementById("tabs")._tabsUndo;
   ok(undoBox.firstChild, "It should be a tab in the undo box");
 
   undoBox.firstChild._onUndo();
   new_tab_04 = Browser.selectedTab;
   new_tab_05 = Browser.addTab("about:blank", true);
+  checkExpectedSize();
   tab_on_undo();
 }
 
 function tab_on_undo() {
   let undoBox = document.getElementById("tabs")._tabsUndo;
   is(undoBox.firstChild, null, "It should be no tab in the undo box");
 
   Browser.loadURI("about:firstrun");
   is(undoBox.firstChild, null, "It should be no tab in the undo box when opening a new local page");
 
   Browser.closeTab(new_tab_01);
   Browser.closeTab(new_tab_02);
   Browser.closeTab(new_tab_03);
   Browser.closeTab(new_tab_04);
   Browser.closeTab(new_tab_05);
+  checkExpectedSize();
 
   tab_about_empty();
 }
 
 function tab_about_empty() {
   new_tab_01 = Browser.addTab("about:empty", true);
   ok(new_tab_01, "Tab Opened");
   is(new_tab_01.browser.getAttribute("remote"), "true", "about:empty opened in a remote tab");