Wed, 31 Dec 2014 06:09:35 +0100
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 win; |
michael@0 | 7 | let groupItemId; |
michael@0 | 8 | let prefix = 'start'; |
michael@0 | 9 | |
michael@0 | 10 | let assertTabViewIsHidden = function () { |
michael@0 | 11 | ok(!win.TabView.isVisible(), prefix + ': tabview is hidden'); |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | let assertNumberOfGroups = function (num) { |
michael@0 | 15 | is(cw.GroupItems.groupItems.length, num, prefix + ': there should be ' + num + ' groups'); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | let assertNumberOfTabs = function (num) { |
michael@0 | 19 | is(win.gBrowser.visibleTabs.length, num, prefix + ': there should be ' + num + ' tabs'); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | let assertNumberOfPinnedTabs = function (num) { |
michael@0 | 23 | is(win.gBrowser._numPinnedTabs, num, prefix + ': there should be ' + num + ' pinned tabs'); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | let assertGroupItemPreserved = function () { |
michael@0 | 27 | is(cw.GroupItems.groupItems[0].id, groupItemId, prefix + ': groupItem was preserved'); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | let assertValidPrerequisites = function () { |
michael@0 | 31 | assertNumberOfTabs(1); |
michael@0 | 32 | assertNumberOfGroups(1); |
michael@0 | 33 | assertNumberOfPinnedTabs(0); |
michael@0 | 34 | assertTabViewIsHidden(); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | let createTab = function (url) { |
michael@0 | 38 | return win.gBrowser.loadOneTab(url || 'http://mochi.test:8888/', {inBackground: true}); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | let createBlankTab = function () { |
michael@0 | 42 | return createTab('about:blank'); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | let finishTest = function () { |
michael@0 | 46 | prefix = 'finish'; |
michael@0 | 47 | assertValidPrerequisites(); |
michael@0 | 48 | promiseWindowClosed(win).then(finish); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | let testUndoCloseWithSelectedBlankTab = function () { |
michael@0 | 52 | prefix = 'unpinned'; |
michael@0 | 53 | let tab = createTab(); |
michael@0 | 54 | assertNumberOfTabs(2); |
michael@0 | 55 | |
michael@0 | 56 | afterAllTabsLoaded(function () { |
michael@0 | 57 | win.gBrowser.removeTab(tab); |
michael@0 | 58 | assertNumberOfTabs(1); |
michael@0 | 59 | assertNumberOfPinnedTabs(0); |
michael@0 | 60 | |
michael@0 | 61 | restoreTab(function () { |
michael@0 | 62 | prefix = 'unpinned-restored'; |
michael@0 | 63 | assertValidPrerequisites(); |
michael@0 | 64 | assertGroupItemPreserved(); |
michael@0 | 65 | |
michael@0 | 66 | createBlankTab(); |
michael@0 | 67 | afterAllTabsLoaded(testUndoCloseWithSelectedBlankPinnedTab, win); |
michael@0 | 68 | }, 0, win); |
michael@0 | 69 | }, win); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | let testUndoCloseWithSelectedBlankPinnedTab = function () { |
michael@0 | 73 | prefix = 'pinned'; |
michael@0 | 74 | assertNumberOfTabs(2); |
michael@0 | 75 | |
michael@0 | 76 | afterAllTabsLoaded(function () { |
michael@0 | 77 | win.gBrowser.removeTab(win.gBrowser.tabs[0]); |
michael@0 | 78 | win.gBrowser.pinTab(win.gBrowser.tabs[0]); |
michael@0 | 79 | |
michael@0 | 80 | assertNumberOfTabs(1); |
michael@0 | 81 | assertNumberOfPinnedTabs(1); |
michael@0 | 82 | |
michael@0 | 83 | restoreTab(function () { |
michael@0 | 84 | prefix = 'pinned-restored'; |
michael@0 | 85 | assertValidPrerequisites(); |
michael@0 | 86 | assertGroupItemPreserved(); |
michael@0 | 87 | |
michael@0 | 88 | createBlankTab(); |
michael@0 | 89 | win.gBrowser.removeTab(win.gBrowser.tabs[0]); |
michael@0 | 90 | |
michael@0 | 91 | afterAllTabsLoaded(finishTest, win); |
michael@0 | 92 | }, 0, win); |
michael@0 | 93 | }, win); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | waitForExplicitFinish(); |
michael@0 | 97 | |
michael@0 | 98 | newWindowWithTabView(window => { |
michael@0 | 99 | win = window; |
michael@0 | 100 | |
michael@0 | 101 | hideTabView(function () { |
michael@0 | 102 | cw = win.TabView.getContentWindow(); |
michael@0 | 103 | groupItemId = cw.GroupItems.groupItems[0].id; |
michael@0 | 104 | |
michael@0 | 105 | assertValidPrerequisites(); |
michael@0 | 106 | testUndoCloseWithSelectedBlankTab(); |
michael@0 | 107 | }, win); |
michael@0 | 108 | }); |
michael@0 | 109 | } |