browser/components/tabview/test/browser_tabview_bug631752.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:f9795846e7ec
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 function test() {
5 let cw;
6 let groupItem;
7
8 let getTabItemAspect = function (tabItem) {
9 let bounds = cw.iQ('.thumb', tabItem.container).bounds();
10 let padding = cw.TabItems.tabItemPadding;
11 return (bounds.height + padding.y) / (bounds.width + padding.x);
12 }
13
14 let getAspectRange = function () {
15 let aspect = cw.TabItems.tabAspect;
16 let variance = aspect / 100 * 1.5;
17 return new cw.Range(aspect - variance, aspect + variance);
18 }
19
20 let dragTabItem = function (tabItem) {
21 let doc = cw.document.documentElement;
22 let tabItem = groupItem.getChild(0);
23 let container = tabItem.container;
24 let aspectRange = getAspectRange();
25
26 EventUtils.synthesizeMouseAtCenter(container, {type: "mousedown"}, cw);
27 for (let x = 200; x <= 400; x += 100)
28 EventUtils.synthesizeMouse(doc, x, 100, {type: "mousemove"}, cw);
29 ok(aspectRange.contains(getTabItemAspect(tabItem)), "tabItem's aspect is correct");
30
31 ok(!groupItem.getBounds().intersects(tabItem.getBounds()), "tabItem was moved out of group bounds");
32 ok(!tabItem.parent, "tabItem is orphaned");
33
34 EventUtils.synthesizeMouseAtCenter(container, {type: "mouseup"}, cw);
35 ok(aspectRange.contains(getTabItemAspect(tabItem)), "tabItem's aspect is correct");
36 }
37
38 let testDragOutOfStackedGroup = function () {
39 dragTabItem();
40
41 let secondGroup = cw.GroupItems.groupItems[1];
42 closeGroupItem(secondGroup, testDragOutOfExpandedStackedGroup);
43 }
44
45 let testDragOutOfExpandedStackedGroup = function () {
46 groupItem.addSubscriber("expanded", function onExpanded() {
47 groupItem.removeSubscriber("expanded", onExpanded);
48 dragTabItem();
49 });
50
51 groupItem.addSubscriber("collapsed", function onCollapsed() {
52 groupItem.removeSubscriber("collapsed", onCollapsed);
53
54 let secondGroup = cw.GroupItems.groupItems[1];
55 closeGroupItem(secondGroup, function () hideTabView(finishTest));
56 });
57
58 groupItem.expand();
59 }
60
61 let finishTest = function () {
62 is(cw.GroupItems.groupItems.length, 1, "there is one groupItem");
63 is(gBrowser.tabs.length, 1, "there is one tab");
64 ok(!TabView.isVisible(), "tabview is hidden");
65
66 finish();
67 }
68
69 waitForExplicitFinish();
70
71 newWindowWithTabView(function (win) {
72 registerCleanupFunction(function () win.close());
73
74 cw = win.TabView.getContentWindow();
75
76 groupItem = cw.GroupItems.groupItems[0];
77 groupItem.setSize(200, 200, true);
78
79 for (let i = 0; i < 9; i++)
80 win.gBrowser.addTab();
81
82 ok(groupItem.isStacked(), "groupItem is stacked");
83 testDragOutOfStackedGroup();
84 });
85 }

mercurial