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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial