1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/tests/mochitest/browser_tabs_container.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +"use strict"; 1.10 + 1.11 +function test() { 1.12 + runTests(); 1.13 +} 1.14 + 1.15 +function setup() { 1.16 + yield waitForCondition(function () { 1.17 + return Elements.tabList && Elements.tabList.strip; 1.18 + }); 1.19 + 1.20 + if (!ContextUI.tabbarVisible) { 1.21 + ContextUI.displayTabs(); 1.22 + } 1.23 +} 1.24 +function tearDown() { 1.25 + cleanUpOpenedTabs(); 1.26 +} 1.27 + 1.28 +function isElementVisible(elm) { 1.29 + return elm.ownerDocument.defaultView.getComputedStyle(elm).getPropertyValue("visibility") == "visible"; 1.30 +} 1.31 + 1.32 + 1.33 +gTests.push({ 1.34 + desc: "No scrollbuttons when tab strip doesnt require overflow", 1.35 + setUp: setup, 1.36 + run: function () { 1.37 + let tabStrip = Elements.tabList.strip; 1.38 + let tabs = Elements.tabList.strip.querySelectorAll("documenttab"); 1.39 + 1.40 + // sanity check tab count: 1.41 + is(tabs.length, 1, "1 tab present"); 1.42 + 1.43 + // test imprecise mode 1.44 + let imprecisePromise = waitForObserver("metro_imprecise_input"); 1.45 + notifyImprecise(); 1.46 + yield imprecisePromise; 1.47 + 1.48 + ok(!isElementVisible(tabStrip._scrollButtonUp), "left scrollbutton is hidden in imprecise mode"); 1.49 + ok(!isElementVisible(tabStrip._scrollButtonDown), "right scrollbutton is hidden in imprecise mode"); 1.50 + 1.51 + // test precise mode 1.52 + let precisePromise = waitForObserver("metro_precise_input"); 1.53 + notifyPrecise(); 1.54 + yield precisePromise; 1.55 + 1.56 + ok(!isElementVisible(tabStrip._scrollButtonUp), "Bug 952297 - left scrollbutton is hidden in precise mode"); 1.57 + ok(!isElementVisible(tabStrip._scrollButtonDown), "right scrollbutton is hidden in precise mode"); 1.58 + }, 1.59 + tearDown: tearDown 1.60 +}); 1.61 + 1.62 +gTests.push({ 1.63 + desc: "Scrollbuttons not visible when tabstrip has overflow in imprecise input mode", 1.64 + setUp: function(){ 1.65 + yield setup(); 1.66 + // ensure we're in imprecise mode 1.67 + let imprecisePromise = waitForObserver("metro_imprecise_input"); 1.68 + notifyImprecise(); 1.69 + yield imprecisePromise; 1.70 + }, 1.71 + run: function () { 1.72 + // add enough tabs to get overflow in the tabstrip 1.73 + let strip = Elements.tabList.strip; 1.74 + ok(strip && strip.scrollClientSize && strip.scrollSize, "Sanity check tabstrip strip is present and expected properties available"); 1.75 + 1.76 + while (strip.scrollSize <= strip.scrollClientSize) { 1.77 + yield addTab("about:mozilla"); 1.78 + } 1.79 + 1.80 + ok(!isElementVisible(Elements.tabList.strip._scrollButtonUp), "left scrollbutton is hidden in imprecise mode"); 1.81 + ok(!isElementVisible(Elements.tabList.strip._scrollButtonDown), "right scrollbutton is hidden in imprecise mode"); 1.82 + 1.83 + } 1.84 +}); 1.85 + 1.86 +gTests.push({ 1.87 + desc: "Scrollbuttons become visible when tabstrip has overflow in precise input mode", 1.88 + setUp: function(){ 1.89 + yield setup(); 1.90 + // ensure we're in precise mode 1.91 + let precisePromise = waitForObserver("metro_precise_input"); 1.92 + notifyPrecise(); 1.93 + yield precisePromise; 1.94 + }, 1.95 + run: function () { 1.96 + let strip = Elements.tabList.strip; 1.97 + ok(strip && strip.scrollClientSize && strip.scrollSize, "Sanity check tabstrip is present and expected properties available"); 1.98 + 1.99 + // add enough tabs to get overflow in the tabstrip 1.100 + while (strip.scrollSize <= strip.scrollClientSize) { 1.101 + yield addTab("about:mozilla"); 1.102 + } 1.103 + 1.104 + ok(isElementVisible(Elements.tabList.strip._scrollButtonUp), "left scrollbutton should be visible in precise mode"); 1.105 + ok(isElementVisible(Elements.tabList.strip._scrollButtonDown), "right scrollbutton should be visible in precise mode"); 1.106 + 1.107 + // select the first tab 1.108 + Browser.selectedTab = Browser.tabs[0]; 1.109 + yield waitForMs(1000); // XXX maximum duration of arrowscrollbox _scrollAnim 1.110 + ok(Elements.tabList.strip._scrollButtonUp.disabled, "left scrollbutton should be disabled when 1st tab is selected and tablist has overflow"); 1.111 + ok(!Elements.tabList.strip._scrollButtonDown.disabled, "right scrollbutton should be enabled when 1st tab is selected and tablist has overflow"); 1.112 + 1.113 + // select the last tab 1.114 + Browser.selectedTab = Browser.tabs[Browser.tabs.length - 1]; 1.115 + yield waitForMs(1000); // XXX maximum duration of arrowscrollbox _scrollAnim 1.116 + ok(!Elements.tabList.strip._scrollButtonUp.disabled, "left scrollbutton should be enabled when 1st tab is selected and tablist has overflow"); 1.117 + ok(Elements.tabList.strip._scrollButtonDown.disabled, "right scrollbutton should be disabled when last tab is selected and tablist has overflow"); 1.118 + 1.119 + } 1.120 +});