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.

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

mercurial