browser/components/tabview/test/browser_tabview_bug626791.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 Cu.import("resource:///modules/CustomizableUI.jsm");
michael@0 5
michael@0 6
michael@0 7 function test() {
michael@0 8 let cw;
michael@0 9 let win;
michael@0 10 let prefix;
michael@0 11
michael@0 12 let getToolbar = function () {
michael@0 13 return win.document.getElementById("TabsToolbar");
michael@0 14 }
michael@0 15
michael@0 16 let assertToolbarButtonExists = function () {
michael@0 17 isnot(getToolbar().currentSet.indexOf("tabview-button"), -1,
michael@0 18 prefix + ": panorama button should be in the toolbar");
michael@0 19 }
michael@0 20
michael@0 21 let assertToolbarButtonNotExists = function () {
michael@0 22 is(getToolbar().currentSet.indexOf("tabview-button"), -1,
michael@0 23 prefix + ": panorama button should not be in the toolbar");
michael@0 24 }
michael@0 25
michael@0 26 let assertNumberOfTabs = function (num) {
michael@0 27 is(win.gBrowser.tabs.length, num, prefix + ': there are ' + num + ' tabs');
michael@0 28 }
michael@0 29
michael@0 30 let removeToolbarButton = function () {
michael@0 31 let toolbar = getToolbar();
michael@0 32 let currentSet = toolbar.currentSet.split(",");
michael@0 33 let buttonId = "tabview-button";
michael@0 34 let pos = currentSet.indexOf(buttonId);
michael@0 35
michael@0 36 if (-1 < pos) {
michael@0 37 CustomizableUI.removeWidgetFromArea("tabview-button");
michael@0 38 }
michael@0 39 }
michael@0 40
michael@0 41 let testNameGroup = function () {
michael@0 42 prefix = 'name-group';
michael@0 43 assertToolbarButtonNotExists();
michael@0 44 let groupItem = cw.GroupItems.groupItems[0];
michael@0 45
michael@0 46 groupItem.setTitle('title');
michael@0 47 assertToolbarButtonNotExists();
michael@0 48 groupItem.setTitle('');
michael@0 49
michael@0 50 EventUtils.synthesizeMouseAtCenter(groupItem.$titleShield[0], {}, cw);
michael@0 51 EventUtils.synthesizeKey('t', {}, cw);
michael@0 52 groupItem.$title[0].blur();
michael@0 53
michael@0 54 assertToolbarButtonExists();
michael@0 55 next();
michael@0 56 }
michael@0 57
michael@0 58 let testDragToCreateGroup = function () {
michael@0 59 prefix = 'drag-to-create-group';
michael@0 60 assertToolbarButtonNotExists();
michael@0 61 let width = cw.innerWidth;
michael@0 62 let height = cw.innerHeight;
michael@0 63
michael@0 64 let body = cw.document.body;
michael@0 65 EventUtils.synthesizeMouse(body, width - 10, height - 10, {type: 'mousedown'}, cw);
michael@0 66 EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mousemove'}, cw);
michael@0 67 EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mouseup'}, cw);
michael@0 68
michael@0 69 assertToolbarButtonExists();
michael@0 70 next();
michael@0 71 }
michael@0 72
michael@0 73 let testCreateOrphan = function (tab) {
michael@0 74 prefix = 'create-orphan';
michael@0 75 assertNumberOfTabs(1);
michael@0 76 assertToolbarButtonNotExists();
michael@0 77
michael@0 78 let width = cw.innerWidth;
michael@0 79 let height = cw.innerHeight;
michael@0 80
michael@0 81 let body = cw.document.body;
michael@0 82 EventUtils.synthesizeMouse(body, width - 10, height - 10, { clickCount: 2 }, cw);
michael@0 83
michael@0 84 whenTabViewIsHidden(function () {
michael@0 85 assertNumberOfTabs(2);
michael@0 86 assertToolbarButtonExists();
michael@0 87
michael@0 88 next();
michael@0 89 }, win);
michael@0 90 }
michael@0 91
michael@0 92 let testDragToCreateOrphan = function (tab) {
michael@0 93 if (!tab) {
michael@0 94 let tab = win.gBrowser.loadOneTab('about:blank', {inBackground: true});
michael@0 95 afterAllTabsLoaded(function () testDragToCreateOrphan(tab), win);
michael@0 96 return;
michael@0 97 }
michael@0 98
michael@0 99 prefix = 'drag-to-create-orphan';
michael@0 100 assertNumberOfTabs(2);
michael@0 101 assertToolbarButtonNotExists();
michael@0 102
michael@0 103 let width = cw.innerWidth;
michael@0 104 let height = cw.innerHeight;
michael@0 105
michael@0 106 let target = tab._tabViewTabItem.container;
michael@0 107 let rect = target.getBoundingClientRect();
michael@0 108 EventUtils.synthesizeMouseAtCenter(target, {type: 'mousedown'}, cw);
michael@0 109 EventUtils.synthesizeMouse(target, rect.width - 10, rect.height - 10, {type: 'mousemove'}, cw);
michael@0 110 EventUtils.synthesizeMouse(target, width - 300, height - 300, {type: 'mousemove'}, cw);
michael@0 111 EventUtils.synthesizeMouse(target, width - 200, height - 200, {type: 'mousemove'}, cw);
michael@0 112 EventUtils.synthesizeMouseAtCenter(target, {type: 'mouseup'}, cw);
michael@0 113
michael@0 114 assertToolbarButtonExists();
michael@0 115 next();
michael@0 116 }
michael@0 117
michael@0 118 let testReAddingAfterRemoval = function () {
michael@0 119 prefix = 're-adding-after-removal';
michael@0 120 assertToolbarButtonNotExists();
michael@0 121
michael@0 122 win.TabView.firstUseExperienced = true;
michael@0 123 assertToolbarButtonExists();
michael@0 124 removeToolbarButton();
michael@0 125 assertToolbarButtonNotExists();
michael@0 126
michael@0 127 win.close();
michael@0 128
michael@0 129 newWindowWithTabView(function (newWin) {
michael@0 130 win = newWin;
michael@0 131 win.TabView.firstUseExperienced = true;
michael@0 132 assertToolbarButtonNotExists();
michael@0 133 next();
michael@0 134 });
michael@0 135 }
michael@0 136
michael@0 137 let tests = [testNameGroup, testDragToCreateGroup, testCreateOrphan,
michael@0 138 testDragToCreateOrphan, testReAddingAfterRemoval];
michael@0 139
michael@0 140 let next = function () {
michael@0 141 if (win)
michael@0 142 win.close();
michael@0 143
michael@0 144 let test = tests.shift();
michael@0 145
michael@0 146 if (!test) {
michael@0 147 finish();
michael@0 148 return;
michael@0 149 }
michael@0 150
michael@0 151 TabView.firstUseExperienced = false;
michael@0 152
michael@0 153 let onLoad = function (newWin) {
michael@0 154 win = newWin;
michael@0 155 removeToolbarButton();
michael@0 156 };
michael@0 157
michael@0 158 let onShow = function () {
michael@0 159 cw = win.TabView.getContentWindow();
michael@0 160
michael@0 161 let groupItem = cw.GroupItems.groupItems[0];
michael@0 162 groupItem.setSize(200, 200, true);
michael@0 163 groupItem.setUserSize();
michael@0 164
michael@0 165 SimpleTest.waitForFocus(function () {
michael@0 166 assertToolbarButtonNotExists();
michael@0 167 test();
michael@0 168 }, cw);
michael@0 169 };
michael@0 170
michael@0 171 newWindowWithTabView(onShow, onLoad);
michael@0 172 }
michael@0 173
michael@0 174 waitForExplicitFinish();
michael@0 175 requestLongerTimeout(2);
michael@0 176
michael@0 177 next();
michael@0 178 }

mercurial