Bug 952663 - Mochitests for expected tab strip scrolling behavior. r=jimm, a=test-only
authorSam Foster <sfoster@mozilla.com>
Mon, 06 Jan 2014 16:07:40 -0800
changeset 174814 23e2f7e842115534bcae7b18bdaa04bfe33859e7
parent 174813 1222ad5d15b402a10187678be338bc80f452f121
child 174815 0032a5a180ff737ecd9a704f00cd71b79fef7b13
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, test-only
bugs952663
milestone28.0a2
Bug 952663 - Mochitests for expected tab strip scrolling behavior. r=jimm, a=test-only
browser/metro/base/tests/mochitest/browser_inputsource.js
browser/metro/base/tests/mochitest/browser_tabs_container.js
browser/metro/base/tests/mochitest/head.js
browser/metro/base/tests/mochitest/metro.ini
--- a/browser/metro/base/tests/mochitest/browser_inputsource.js
+++ b/browser/metro/base/tests/mochitest/browser_inputsource.js
@@ -27,25 +27,16 @@ function testState(aState) {
     ok(!StyleSheetSvc.sheetRegistered(uri, Ci.nsIStyleSheetService.AGENT_SHEET), "cursor stylesheet registered");
   } else {
     ok(!InputSourceHelper.isPrecise, "InputSourceHelper");
     let uri = Util.makeURI("chrome://browser/content/cursor.css");
     ok(StyleSheetSvc.sheetRegistered(uri, Ci.nsIStyleSheetService.AGENT_SHEET), "cursor stylesheet registered");
   }
 }
 
-function notifyPrecise()
-{
-  Services.obs.notifyObservers(null, "metro_precise_input", null);
-}
-
-function notifyImprecise()
-{
-  Services.obs.notifyObservers(null, "metro_imprecise_input", null);
-}
 
 gTests.push({
   desc: "precise/imprecise input switcher",
   setUp: setUp,
   run: function () {
     notifyPrecise();
     testState("precise");
     notifyImprecise();
new file mode 100644
--- /dev/null
+++ b/browser/metro/base/tests/mochitest/browser_tabs_container.js
@@ -0,0 +1,114 @@
+// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+function test() {
+  runTests();
+}
+
+function setup() {
+  yield waitForCondition(function () {
+    return Elements.tabList && Elements.tabList.strip;
+  });
+
+  if (!ContextUI.tabbarVisible) {
+    ContextUI.displayTabs();
+  }
+}
+function tearDown() {
+  cleanUpOpenedTabs();
+}
+
+function isElementVisible(elm) {
+  return elm.ownerDocument.defaultView.getComputedStyle(elm).getPropertyValue("visibility") == "visible";
+}
+
+
+gTests.push({
+  desc: "No scrollbuttons when tab strip doesnt require overflow",
+  setUp: setup,
+  run: function () {
+    let tabStrip = Elements.tabList.strip;
+    let tabs = Elements.tabList.strip.querySelectorAll("documenttab");
+
+    // sanity check tab count:
+    is(tabs.length, 1, "1 tab present");
+
+    // test imprecise mode
+    let imprecisePromise = waitForObserver("metro_imprecise_input");
+    notifyImprecise();
+    yield imprecisePromise;
+
+    ok(!isElementVisible(tabStrip._scrollButtonUp), "left scrollbutton is hidden in imprecise mode");
+    ok(!isElementVisible(tabStrip._scrollButtonDown), "right scrollbutton is hidden in imprecise mode");
+
+    // test precise mode
+    let precisePromise = waitForObserver("metro_precise_input");
+    notifyPrecise();
+    yield precisePromise;
+
+    todo(!isElementVisible(tabStrip._scrollButtonUp), "Bug 952297 - left scrollbutton is hidden in precise mode");
+    ok(!isElementVisible(tabStrip._scrollButtonDown), "right scrollbutton is hidden in precise mode");
+  },
+  tearDown: tearDown
+});
+
+gTests.push({
+  desc: "Scrollbuttons not visible when tabstrip has overflow in imprecise input mode",
+  setUp: function(){
+    yield setup();
+    // ensure we're in imprecise mode
+    let imprecisePromise = waitForObserver("metro_imprecise_input");
+    notifyImprecise();
+    yield imprecisePromise;
+  },
+  run: function () {
+    // add enough tabs to get overflow in the tabstrip
+    let strip = Elements.tabList.strip;
+    ok(strip && strip.scrollClientSize && strip.scrollSize, "Sanity check tabstrip strip is present and expected properties available");
+
+    while (strip.scrollSize <= strip.scrollClientSize) {
+      yield addTab("about:mozilla");
+    }
+
+    ok(!isElementVisible(Elements.tabList.strip._scrollButtonUp), "left scrollbutton is hidden in imprecise mode");
+    ok(!isElementVisible(Elements.tabList.strip._scrollButtonDown), "right scrollbutton is hidden in imprecise mode");
+
+  }
+});
+
+gTests.push({
+  desc: "Scrollbuttons become visible when tabstrip has overflow in precise input mode",
+  setUp: function(){
+    yield setup();
+    // ensure we're in precise mode
+    let precisePromise = waitForObserver("metro_precise_input");
+    notifyPrecise();
+    yield precisePromise;
+  },
+  run: function () {
+    let strip = Elements.tabList.strip;
+    ok(strip && strip.scrollClientSize && strip.scrollSize, "Sanity check tabstrip is present and expected properties available");
+
+    // add enough tabs to get overflow in the tabstrip
+    while (strip.scrollSize <= strip.scrollClientSize) {
+      yield addTab("about:mozilla");
+    }
+
+    let tabs = Elements.tabList.strip.querySelectorAll("documenttab");
+    // select the first tab
+    Elements.tabs.selectedTab = tabs[0];
+    ok(isElementVisible(Elements.tabList.strip._scrollButtonDown), "right scrollbutton should be visible when tabList has overflow");
+    todo(!isElementVisible(Elements.tabList.strip._scrollButtonUp), "Bug 952297 - left scrollbutton should not visible when 1st tab is selected and tablist has overflow");
+
+
+    // select the last tab
+    Elements.tabs.selectedTab = tabs[tabs.length-1];
+    ok(isElementVisible(Elements.tabList.strip._scrollButtonUp), "left scrollbutton should be visible when tablist has overflow and last tab is selected");
+    todo(!isElementVisible(Elements.tabList.strip._scrollButtonDown), "Bug 952297 - right scrollbutton should not visible when last tab is selected and tablist has overflow");
+
+  }
+});
--- a/browser/metro/base/tests/mochitest/head.js
+++ b/browser/metro/base/tests/mochitest/head.js
@@ -551,16 +551,35 @@ function waitForObserver(aObsEvent, aTim
   Services.obs.addObserver(observeWatcher, aObsEvent, true);
   return deferred.promise;
 
   } catch (ex) {
     info(ex.message);
   }
 }
 
+
+/*=============================================================================
+ * Input mode helpers - these helpers notify observers to metro_precise_input
+ * and metro_imprecise_input respectively, triggering the same behaviour as user touch or mouse input
+ *
+ * Usage: let promise = waitForObservers("metro_imprecise_input");
+ *        notifyImprecise();
+ *        yield promise; // you are now in imprecise mode
+ *===========================================================================*/
+function notifyPrecise()
+{
+  Services.obs.notifyObservers(null, "metro_precise_input", null);
+}
+
+function notifyImprecise()
+{
+  Services.obs.notifyObservers(null, "metro_imprecise_input", null);
+}
+
 /*=============================================================================
  * Native input helpers - these helpers send input directly to the os
  * generating os level input events that get processed by widget and
  * apzc logic.
  *===========================================================================*/
 
 // Keyboard layouts for use with synthesizeNativeKey
 const usEnglish = 0x409;
--- a/browser/metro/base/tests/mochitest/metro.ini
+++ b/browser/metro/base/tests/mochitest/metro.ini
@@ -46,16 +46,17 @@ support-files =
 [browser_inputsource.js]
 [browser_link_click.js]
 [browser_onscreen_keyboard.js]
 [browser_prefs_ui.js]
 [browser_prompt.js]
 [browser_remotetabs.js]
 [browser_snappedState.js]
 [browser_tabs.js]
+[browser_tabs_container.js]
 [browser_test.js]
 [browser_tiles.js]
 [browser_topsites.js]
 [browser_urlbar.js]
 [browser_urlbar_highlightURLs.js]
 [browser_urlbar_trimURLs.js]
 [browser_apzc_basic.js]
 [browser_menu_hoverstate.js]