Ctrl+Tab browser chrome tests
authorDão Gottwald <dao@mozilla.com>
Mon, 11 Aug 2008 22:40:45 +0200
changeset 16563 a2837ff832c9
parent 16562 116a48494857
child 16564 f5016884eec4
push id1136
push userdgottwald@mozilla.com
push dateMon, 11 Aug 2008 20:40:57 +0000
treeherdermozilla-central@a2837ff832c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.1a2pre
Ctrl+Tab browser chrome tests
browser/base/content/test/Makefile.in
browser/base/content/test/browser_ctrlTab.js
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -56,16 +56,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_bug409481.js \
                  browser_autodiscovery.js \
                  browser_bug420160.js \
                  autodiscovery.html \
                  moz.png \
                  browser_getshortcutoruri.js \
                  browser_page_style_menu.js \
                  page_style_sample.html \
+                 browser_ctrlTab.js \
     $(NULL)
 
 ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
 _BROWSER_FILES += browser_customize.js \
     $(NULL)
 endif
 
 # disable tests on linux for now..
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_ctrlTab.js
@@ -0,0 +1,62 @@
+function test() {
+  while (gBrowser.mTabs.length > 1)
+    gBrowser.removeCurrentTab();
+
+  gBrowser.addTab();
+  gBrowser.addTab();
+  gBrowser.addTab();
+
+  ctrlTabTest([2]      , 1, 0);
+  ctrlTabTest([2, 3, 1], 2, 2);
+  ctrlTabTest([]       , 4, 2);
+
+  gBrowser.removeTab(gBrowser.tabContainer.lastChild);
+
+  ctrlTabTest([2, 1, 0], 7, 1);
+
+  gBrowser.removeTab(gBrowser.tabContainer.lastChild);
+
+  ctrlTabTest([1]      , 1, 0);
+
+  gBrowser.removeTab(gBrowser.tabContainer.lastChild);
+}
+
+function ctrlTabTest(tabsToSelect, tabTimes, expectedIndex) {
+  tabsToSelect.forEach(function (index) {
+    gBrowser.selectedTab = gBrowser.mTabs[index];
+  });
+
+  var indexStart = gBrowser.tabContainer.selectedIndex;
+  var tabCount = gBrowser.mTabs.length;
+  var normalized = tabTimes % tabCount;
+  var where = normalized == 1 ? "back to the previously selected tab" :
+              normalized + " tabs back in most-recently-selected order";
+
+  for (let i = 0; i < tabTimes; i++) {
+    EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true });
+
+    if (tabCount > 2)
+     is(gBrowser.tabContainer.selectedIndex, indexStart,
+       "Selected tab doesn't change while tabbing");
+  }
+
+  if (tabCount > 2) {
+    ok(ctrlTab.panel.state == "showing" || ctrlTab.panel.state == "open",
+       "With " + tabCount + " tabs open, Ctrl+Tab opens the preview panel");
+
+    is(ctrlTab.label.value, gBrowser.mTabs[expectedIndex].label,
+       "Preview panel displays label of expected tab");
+
+    EventUtils.synthesizeKey("VK_CONTROL", { type: "keyup" });
+
+    ok(ctrlTab.panel.state == "hiding" || ctrlTab.panel.state == "closed",
+       "Releasing Ctrl closes the preview panel");
+  } else {
+    ok(ctrlTab.panel.state == "hiding" || ctrlTab.panel.state == "closed",
+       "With " + tabCount + " tabs open, Ctrl+Tab doesn't open the preview panel");
+  }
+
+  is(gBrowser.tabContainer.selectedIndex, expectedIndex,
+     "With "+ tabCount +" tabs open and tab " + indexStart
+     + " selected, Ctrl+Tab*" + tabTimes + " goes " + where);
+}