browser/components/tabview/test/browser_tabview_bug637840.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 let cw;
     6 function test() {
     7   requestLongerTimeout(2);
     8   waitForExplicitFinish();
    10   newWindowWithTabView(function(win) {
    11     cw = win.TabView.getContentWindow();
    13     let groupItemOne = cw.GroupItems.groupItems[0];
    14     is(groupItemOne.getChildren().length, 1, "Group one has 1 tab item");
    16     let groupItemTwo = createGroupItemWithBlankTabs(win, 300, 300, 40, 2);
    17     is(groupItemTwo.getChildren().length, 2, "Group two has 2 tab items");
    19     let groupItemThree = createGroupItemWithBlankTabs(win, 300, 300, 40, 2);
    20     is(groupItemThree.getChildren().length, 2, "Group three has 2 tab items");
    22     waitForFocus(() => {
    23       testMoreRecentlyUsedGroup(groupItemOne, groupItemTwo, function() {
    24         testMoreRecentlyUsedGroup(groupItemOne, groupItemThree, function() {
    25           testRemoveGroupAndCheckMoreRecentlyUsedGroup(groupItemOne, groupItemTwo);
    26         });
    27       });
    28     }, cw);
    29   });
    30 }
    32 function testMoreRecentlyUsedGroup(groupItemOne, otherGroupItem, callback) {
    33   let tabItem = otherGroupItem.getChild(1);
    34   cw.UI.setActive(tabItem);
    35   is(otherGroupItem.getActiveTab(), tabItem, "The second item in the other group is active");
    36   is(cw.GroupItems.getActiveGroupItem(), otherGroupItem, "The other group is active");
    38   let tabItemInGroupItemOne = groupItemOne.getChild(0);
    39   cw.UI.setActive(tabItemInGroupItemOne);
    40   is(groupItemOne.getActiveTab(), tabItemInGroupItemOne, "The first item in group one is active");
    41   is(cw.GroupItems.getActiveGroupItem(), groupItemOne, "The group one is active");
    43   groupItemOne.addSubscriber("groupHidden", function onHide() {
    44     groupItemOne.removeSubscriber("groupHidden", onHide);
    46     // group item three should have the focus
    47     is(otherGroupItem.getActiveTab(), tabItem, "The second item in the other group is active after group one is hidden");
    48     is(cw.GroupItems.getActiveGroupItem(), otherGroupItem, "The other group is active active after group one is hidden");
    50     groupItemOne.addSubscriber("groupShown", function onShown() {
    51       groupItemOne.removeSubscriber("groupShown", onShown);
    53       is(groupItemOne.getActiveTab(), tabItemInGroupItemOne, "The first item in group one is active after it is shown");
    54       is(cw.GroupItems.getActiveGroupItem(), groupItemOne, "The group one is active after it is shown");
    56       callback();
    57     });
    58     // click on the undo button
    59     EventUtils.sendMouseEvent(
    60       { type: "click" }, groupItemOne.$undoContainer[0], cw);
    61   });
    62   // click on the close button of group item one
    63   let closeButton = groupItemOne.container.getElementsByClassName("close");
    64   ok(closeButton[0], "Group item one close button exists");
    65   EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], cw);
    66 }
    68 function testRemoveGroupAndCheckMoreRecentlyUsedGroup(groupItemOne, groupItemTwo) {
    69   let tabItem = groupItemTwo.getChild(0);
    70   cw.UI.setActive(tabItem);
    72   is(groupItemTwo.getActiveTab(), tabItem, "The first item in the group two is active");
    73   is(cw.GroupItems.getActiveGroupItem(), groupItemTwo, "The group two is active");
    75   let tabItemInGroupItemOne = groupItemOne.getChild(0);
    77   tabItemInGroupItemOne.addSubscriber("close", function onClose() {
    78     tabItemInGroupItemOne.removeSubscriber("close", onClose);
    80     is(groupItemTwo.getActiveTab(), tabItem, "The first item in the group two is still active after group one is closed");
    81     is(cw.GroupItems.getActiveGroupItem(), groupItemTwo, "The group two is still active after group one is closed");
    83     promiseWindowClosed(cw.top).then(() => {
    84       cw = null;
    85       finish();
    86     });
    87   });
    88   // close the tab item and the group item
    89   let closeButton = tabItemInGroupItemOne.container.getElementsByClassName("close");
    90   ok(closeButton[0], "Tab item close button exists");
    91   EventUtils.sendMouseEvent({ type: "mousedown" }, closeButton[0], cw);
    92   EventUtils.sendMouseEvent({ type: "mouseup" }, closeButton[0], cw);
    93 }

mercurial