browser/metro/base/tests/mochitest/browser_tabs_container.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 "use strict";
michael@0 7
michael@0 8 function test() {
michael@0 9 runTests();
michael@0 10 }
michael@0 11
michael@0 12 function setup() {
michael@0 13 yield waitForCondition(function () {
michael@0 14 return Elements.tabList && Elements.tabList.strip;
michael@0 15 });
michael@0 16
michael@0 17 if (!ContextUI.tabbarVisible) {
michael@0 18 ContextUI.displayTabs();
michael@0 19 }
michael@0 20 }
michael@0 21 function tearDown() {
michael@0 22 cleanUpOpenedTabs();
michael@0 23 }
michael@0 24
michael@0 25 function isElementVisible(elm) {
michael@0 26 return elm.ownerDocument.defaultView.getComputedStyle(elm).getPropertyValue("visibility") == "visible";
michael@0 27 }
michael@0 28
michael@0 29
michael@0 30 gTests.push({
michael@0 31 desc: "No scrollbuttons when tab strip doesnt require overflow",
michael@0 32 setUp: setup,
michael@0 33 run: function () {
michael@0 34 let tabStrip = Elements.tabList.strip;
michael@0 35 let tabs = Elements.tabList.strip.querySelectorAll("documenttab");
michael@0 36
michael@0 37 // sanity check tab count:
michael@0 38 is(tabs.length, 1, "1 tab present");
michael@0 39
michael@0 40 // test imprecise mode
michael@0 41 let imprecisePromise = waitForObserver("metro_imprecise_input");
michael@0 42 notifyImprecise();
michael@0 43 yield imprecisePromise;
michael@0 44
michael@0 45 ok(!isElementVisible(tabStrip._scrollButtonUp), "left scrollbutton is hidden in imprecise mode");
michael@0 46 ok(!isElementVisible(tabStrip._scrollButtonDown), "right scrollbutton is hidden in imprecise mode");
michael@0 47
michael@0 48 // test precise mode
michael@0 49 let precisePromise = waitForObserver("metro_precise_input");
michael@0 50 notifyPrecise();
michael@0 51 yield precisePromise;
michael@0 52
michael@0 53 ok(!isElementVisible(tabStrip._scrollButtonUp), "Bug 952297 - left scrollbutton is hidden in precise mode");
michael@0 54 ok(!isElementVisible(tabStrip._scrollButtonDown), "right scrollbutton is hidden in precise mode");
michael@0 55 },
michael@0 56 tearDown: tearDown
michael@0 57 });
michael@0 58
michael@0 59 gTests.push({
michael@0 60 desc: "Scrollbuttons not visible when tabstrip has overflow in imprecise input mode",
michael@0 61 setUp: function(){
michael@0 62 yield setup();
michael@0 63 // ensure we're in imprecise mode
michael@0 64 let imprecisePromise = waitForObserver("metro_imprecise_input");
michael@0 65 notifyImprecise();
michael@0 66 yield imprecisePromise;
michael@0 67 },
michael@0 68 run: function () {
michael@0 69 // add enough tabs to get overflow in the tabstrip
michael@0 70 let strip = Elements.tabList.strip;
michael@0 71 ok(strip && strip.scrollClientSize && strip.scrollSize, "Sanity check tabstrip strip is present and expected properties available");
michael@0 72
michael@0 73 while (strip.scrollSize <= strip.scrollClientSize) {
michael@0 74 yield addTab("about:mozilla");
michael@0 75 }
michael@0 76
michael@0 77 ok(!isElementVisible(Elements.tabList.strip._scrollButtonUp), "left scrollbutton is hidden in imprecise mode");
michael@0 78 ok(!isElementVisible(Elements.tabList.strip._scrollButtonDown), "right scrollbutton is hidden in imprecise mode");
michael@0 79
michael@0 80 }
michael@0 81 });
michael@0 82
michael@0 83 gTests.push({
michael@0 84 desc: "Scrollbuttons become visible when tabstrip has overflow in precise input mode",
michael@0 85 setUp: function(){
michael@0 86 yield setup();
michael@0 87 // ensure we're in precise mode
michael@0 88 let precisePromise = waitForObserver("metro_precise_input");
michael@0 89 notifyPrecise();
michael@0 90 yield precisePromise;
michael@0 91 },
michael@0 92 run: function () {
michael@0 93 let strip = Elements.tabList.strip;
michael@0 94 ok(strip && strip.scrollClientSize && strip.scrollSize, "Sanity check tabstrip is present and expected properties available");
michael@0 95
michael@0 96 // add enough tabs to get overflow in the tabstrip
michael@0 97 while (strip.scrollSize <= strip.scrollClientSize) {
michael@0 98 yield addTab("about:mozilla");
michael@0 99 }
michael@0 100
michael@0 101 ok(isElementVisible(Elements.tabList.strip._scrollButtonUp), "left scrollbutton should be visible in precise mode");
michael@0 102 ok(isElementVisible(Elements.tabList.strip._scrollButtonDown), "right scrollbutton should be visible in precise mode");
michael@0 103
michael@0 104 // select the first tab
michael@0 105 Browser.selectedTab = Browser.tabs[0];
michael@0 106 yield waitForMs(1000); // XXX maximum duration of arrowscrollbox _scrollAnim
michael@0 107 ok(Elements.tabList.strip._scrollButtonUp.disabled, "left scrollbutton should be disabled when 1st tab is selected and tablist has overflow");
michael@0 108 ok(!Elements.tabList.strip._scrollButtonDown.disabled, "right scrollbutton should be enabled when 1st tab is selected and tablist has overflow");
michael@0 109
michael@0 110 // select the last tab
michael@0 111 Browser.selectedTab = Browser.tabs[Browser.tabs.length - 1];
michael@0 112 yield waitForMs(1000); // XXX maximum duration of arrowscrollbox _scrollAnim
michael@0 113 ok(!Elements.tabList.strip._scrollButtonUp.disabled, "left scrollbutton should be enabled when 1st tab is selected and tablist has overflow");
michael@0 114 ok(Elements.tabList.strip._scrollButtonDown.disabled, "right scrollbutton should be disabled when last tab is selected and tablist has overflow");
michael@0 115
michael@0 116 }
michael@0 117 });

mercurial