Bug 475203 - regression tests for tabstrip scrolling. r=dao
☠☠ backed out by 87948ecedc84 ☠ ☠
authorNochum Sossonko <highmind63@gmail.com>
Thu, 12 Mar 2009 13:10:38 +0100
changeset 26092 2d7dde25e45fdf7925be675a2e803b7446c73cfc
parent 26091 2752d979b84f59e3b8d742816d35c82efa0d3c7f
child 26093 f01a5fd071f3b55a5a4a6b928a883e853637cda8
child 26098 87948ecedc84b4315899303392cc10ed435c7eef
push idunknown
push userunknown
push dateunknown
reviewersdao
bugs475203
milestone1.9.2a1pre
Bug 475203 - regression tests for tabstrip scrolling. r=dao
browser/base/content/test/Makefile.in
browser/base/content/test/browser_overflowScroll.js
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -94,16 +94,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_bug386835.js \
                  dummy_page.html \
                  browser_bug422590.js \
                  browser_sanitize-sitepermissions.js \
                  browser_bug356571.js \
                  browser_sanitize-passwordDisabledHosts.js \
                  browser_bug479408.js \
                  browser_bug479408_sample.html \
+                 browser_overflowScroll.js \
     $(NULL)
 
 ifeq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
 _BROWSER_FILES += browser_bug462289.js
 else
 _BROWSER_FILES += browser_customize.js
 endif
 
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_overflowScroll.js
@@ -0,0 +1,56 @@
+const tabContainer = gBrowser.tabContainer;
+const tabStrip = tabContainer.mTabstrip;
+
+function runOverflowTests(aEvent) {
+
+  if (aEvent.detail != 1)
+    return;
+  tabStrip.removeEventListener("overflow", runOverflowTests, false);
+  var firstTab = tabContainer.firstChild;
+  var lastTab = tabContainer.lastChild;
+  var upButton = tabStrip._scrollButtonUp;
+  var upButtonRect = upButton.getBoundingClientRect();
+  var downButton = tabStrip._scrollButtonDown;
+  var downButtonRect = downButton.getBoundingClientRect();
+
+  tabStrip.ensureElementIsVisible(firstTab);
+  var rect = firstTab.getBoundingClientRect();
+  is(rect.left, upButtonRect.right, "Tab should scroll into view");
+  tabStrip.scrollByIndex(1);
+  rect = lastTab.getBoundingClientRect();
+  is(rect.right, downButtonRect.left, "Tab should scroll into view");
+  var element = tabStrip._elementFromPoint(upButtonRect.right);
+  if (element.getBoundingClientRect().left == upButtonRect.right)
+    element = element.previousSibling;
+  EventUtils.synthesizeMouse(upButton, 0, 0, {clickCount: 1});
+  rect = element.getBoundingClientRect();
+  is(rect.left, upButtonRect.right, "One tab should have been scrolled");
+  EventUtils.synthesizeMouse(upButton, 0, 0, {clickCount: 2});
+  EventUtils.synthesizeMouse(upButton, 0, 0, {clickCount: 3, detail: 3, originalTarget: upButton});
+  rect = firstTab.getBoundingClientRect();
+  is(rect.left, upButtonRect.right, "Tabs should scroll to start");
+  element = tabStrip._elementFromPoint(rect.left);
+  ok(element == firstTab, "_elementFromPoint should recognize the tabs");
+
+  while (tabContainer.childNodes.length > 1)
+    gBrowser.removeTab(tabContainer.lastChild);
+
+  finish();
+}
+
+function test() {
+  waitForExplicitFinish();
+
+  tabStrip.smoothScroll = false;
+  let tabMinWidth = Components.classes['@mozilla.org/preferences-service;1']
+                              .getService(Components.interfaces.nsIPrefBranch2)
+                              .getIntPref("browser.tabs.tabMinWidth");
+  var tabCountForOverflow =
+    Math.floor(tabStrip.getBoundingClientRect().width / tabMinWidth);
+  while (tabContainer.childNodes.length < tabCountForOverflow)
+    gBrowser.addTab();
+  gBrowser.addTab();
+  gBrowser.selectedTab = tabContainer.lastChild.previousSibling;
+
+  tabStrip.addEventListener("overflow", runOverflowTests, false);
+}