browser/components/tabview/test/browser_tabview_undo_group.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 function test() {
michael@0 5 waitForExplicitFinish();
michael@0 6
michael@0 7 registerCleanupFunction(function() {
michael@0 8 while (gBrowser.tabs[1])
michael@0 9 gBrowser.removeTab(gBrowser.tabs[1]);
michael@0 10 hideTabView();
michael@0 11 });
michael@0 12 showTabView(onTabViewWindowLoaded);
michael@0 13 }
michael@0 14
michael@0 15 function onTabViewWindowLoaded() {
michael@0 16 ok(TabView.isVisible(), "Tab View is visible");
michael@0 17
michael@0 18 let contentWindow = TabView.getContentWindow();
michael@0 19
michael@0 20 registerCleanupFunction(function() {
michael@0 21 let groupItem = contentWindow.GroupItems.groupItem(groupItemId);
michael@0 22 if (groupItem)
michael@0 23 closeGroupItem(groupItem);
michael@0 24 });
michael@0 25
michael@0 26 // create a group item
michael@0 27 let groupItem = createGroupItemWithBlankTabs(window, 300, 300, 400, 1);
michael@0 28 let groupItemId = groupItem.id;
michael@0 29 is(groupItem.getChildren().length, 1, "The new group has a tab item");
michael@0 30 // start the tests
michael@0 31 waitForFocus(function() {
michael@0 32 testUndoGroup(contentWindow, groupItem);
michael@0 33 }, contentWindow);
michael@0 34 }
michael@0 35
michael@0 36 function testUndoGroup(contentWindow, groupItem) {
michael@0 37 groupItem.addSubscriber("groupHidden", function onHidden() {
michael@0 38 groupItem.removeSubscriber("groupHidden", onHidden);
michael@0 39
michael@0 40 // check the data of the group
michael@0 41 let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
michael@0 42 ok(theGroupItem, "The group item still exists");
michael@0 43 is(theGroupItem.getChildren().length, 1,
michael@0 44 "The tab item in the group still exists");
michael@0 45
michael@0 46 // check the visibility of the group element and undo element
michael@0 47 is(theGroupItem.container.style.display, "none",
michael@0 48 "The group element is hidden");
michael@0 49 ok(theGroupItem.$undoContainer, "Undo container is avaliable");
michael@0 50
michael@0 51 EventUtils.sendMouseEvent(
michael@0 52 { type: "click" }, theGroupItem.$undoContainer[0], contentWindow);
michael@0 53 });
michael@0 54
michael@0 55 groupItem.addSubscriber("groupShown", function onShown() {
michael@0 56 groupItem.removeSubscriber("groupShown", onShown);
michael@0 57
michael@0 58 // check the data of the group
michael@0 59 let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
michael@0 60 ok(theGroupItem, "The group item still exists");
michael@0 61 is(theGroupItem.getChildren().length, 1,
michael@0 62 "The tab item in the group still exists");
michael@0 63
michael@0 64 // check the visibility of the group element and undo element
michael@0 65 is(theGroupItem.container.style.display, "", "The group element is visible");
michael@0 66 ok(!theGroupItem.$undoContainer, "Undo container is not avaliable");
michael@0 67
michael@0 68 // start the next test
michael@0 69 testCloseUndoGroup(contentWindow, groupItem);
michael@0 70 });
michael@0 71
michael@0 72 let closeButton = groupItem.container.getElementsByClassName("close");
michael@0 73 ok(closeButton[0], "Group item close button exists");
michael@0 74 EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow);
michael@0 75 }
michael@0 76
michael@0 77 function testCloseUndoGroup(contentWindow, groupItem) {
michael@0 78 groupItem.addSubscriber("groupHidden", function onHidden() {
michael@0 79 groupItem.removeSubscriber("groupHidden", onHidden);
michael@0 80
michael@0 81 // check the data of the group
michael@0 82 let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
michael@0 83 ok(theGroupItem, "The group item still exists");
michael@0 84 is(theGroupItem.getChildren().length, 1,
michael@0 85 "The tab item in the group still exists");
michael@0 86
michael@0 87 // check the visibility of the group element and undo element
michael@0 88 is(theGroupItem.container.style.display, "none",
michael@0 89 "The group element is hidden");
michael@0 90 ok(theGroupItem.$undoContainer, "Undo container is avaliable");
michael@0 91
michael@0 92 // click on close
michael@0 93 let closeButton = theGroupItem.$undoContainer.find(".close");
michael@0 94 EventUtils.sendMouseEvent(
michael@0 95 { type: "click" }, closeButton[0], contentWindow);
michael@0 96 });
michael@0 97
michael@0 98 groupItem.addSubscriber("close", function onClose() {
michael@0 99 groupItem.removeSubscriber("close", onClose);
michael@0 100
michael@0 101 let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
michael@0 102 ok(!theGroupItem, "The group item doesn't exists");
michael@0 103
michael@0 104 // after the last selected tabitem is closed, there would be not active
michael@0 105 // tabitem on the UI so we set the active tabitem before toggling the
michael@0 106 // visibility of tabview
michael@0 107 let tabItems = contentWindow.TabItems.getItems();
michael@0 108 ok(tabItems[0], "A tab item exists");
michael@0 109 contentWindow.UI.setActive(tabItems[0]);
michael@0 110
michael@0 111 hideTabView(function() {
michael@0 112 ok(!TabView.isVisible(), "Tab View is hidden");
michael@0 113 finish();
michael@0 114 });
michael@0 115 });
michael@0 116
michael@0 117 let closeButton = groupItem.container.getElementsByClassName("close");
michael@0 118 ok(closeButton[0], "Group item close button exists");
michael@0 119 EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow);
michael@0 120 }

mercurial