browser/components/tabview/test/browser_tabview_bug628270.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 let cw;
michael@0 6 let prefix = 'start';
michael@0 7
michael@0 8 let createGroupItem = function () {
michael@0 9 let bounds = new cw.Rect(20, 20, 200, 200);
michael@0 10 let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true});
michael@0 11
michael@0 12 cw.UI.setActive(groupItem);
michael@0 13 gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
michael@0 14 gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
michael@0 15
michael@0 16 let groupItemId = groupItem.id;
michael@0 17 registerCleanupFunction(function() {
michael@0 18 let groupItem = cw.GroupItems.groupItem(groupItemId);
michael@0 19 if (groupItem)
michael@0 20 groupItem.close();
michael@0 21 });
michael@0 22 }
michael@0 23
michael@0 24 let getGroupItem = function (index) {
michael@0 25 return cw.GroupItems.groupItems[index];
michael@0 26 }
michael@0 27
michael@0 28 let activateFirstGroupItem = function () {
michael@0 29 let activeTabItem = getGroupItem(0).getChild(0);
michael@0 30 cw.GroupItems.updateActiveGroupItemAndTabBar(activeTabItem);
michael@0 31 }
michael@0 32
michael@0 33 let assertTabViewIsHidden = function () {
michael@0 34 ok(!TabView.isVisible(), prefix + ': tabview is hidden');
michael@0 35 }
michael@0 36
michael@0 37 let assertNumberOfGroups = function (num) {
michael@0 38 is(cw.GroupItems.groupItems.length, num, prefix + ': there are ' + num + ' groups');
michael@0 39 }
michael@0 40
michael@0 41 let assertNumberOfTabs = function (num) {
michael@0 42 is(gBrowser.visibleTabs.length, num, prefix + ': there are ' + num + ' tabs');
michael@0 43 }
michael@0 44
michael@0 45 let assertNumberOfPinnedTabs = function (num) {
michael@0 46 is(gBrowser._numPinnedTabs, num, prefix + ': there are ' + num + ' pinned tabs');
michael@0 47 }
michael@0 48
michael@0 49 let assertNumberOfTabsInGroup = function (groupItem, num) {
michael@0 50 is(groupItem.getChildren().length, num, prefix + ': there are ' + num + ' tabs in the group');
michael@0 51 }
michael@0 52
michael@0 53 let assertValidPrerequisites = function () {
michael@0 54 assertNumberOfTabs(1);
michael@0 55 assertNumberOfGroups(1);
michael@0 56 assertNumberOfPinnedTabs(0);
michael@0 57 }
michael@0 58
michael@0 59 let finishTest = function () {
michael@0 60 prefix = 'finish';
michael@0 61 assertValidPrerequisites();
michael@0 62 assertTabViewIsHidden();
michael@0 63 finish();
michael@0 64 }
michael@0 65
michael@0 66 let testRestoreTabFromInactiveGroup = function () {
michael@0 67 prefix = 'restore';
michael@0 68 activateFirstGroupItem();
michael@0 69
michael@0 70 let groupItem = getGroupItem(1);
michael@0 71 let tabItem = groupItem.getChild(0);
michael@0 72
michael@0 73 EventUtils.synthesizeMouseAtCenter(
michael@0 74 tabItem.$close[0], {}, TabView.getContentWindow());
michael@0 75 assertNumberOfTabsInGroup(groupItem, 1);
michael@0 76
michael@0 77 restoreTab(function () {
michael@0 78 assertNumberOfTabsInGroup(groupItem, 2);
michael@0 79
michael@0 80 activateFirstGroupItem();
michael@0 81 gBrowser.removeTab(gBrowser.tabs[1]);
michael@0 82 gBrowser.removeTab(gBrowser.tabs[1]);
michael@0 83 hideTabView(finishTest);
michael@0 84 });
michael@0 85 }
michael@0 86
michael@0 87 waitForExplicitFinish();
michael@0 88 assertTabViewIsHidden();
michael@0 89 registerCleanupFunction(function () TabView.hide());
michael@0 90
michael@0 91 showTabView(function () {
michael@0 92 cw = TabView.getContentWindow();
michael@0 93 assertValidPrerequisites();
michael@0 94
michael@0 95 createGroupItem();
michael@0 96 afterAllTabsLoaded(testRestoreTabFromInactiveGroup);
michael@0 97 });
michael@0 98 }

mercurial