|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 showTabView(onTabViewShown); |
|
7 } |
|
8 |
|
9 function onTabViewShown() { |
|
10 let contentWindow = TabView.getContentWindow(); |
|
11 let [originalTab] = gBrowser.visibleTabs; |
|
12 |
|
13 ok(TabView.isVisible(), "Tab View is visible"); |
|
14 is(contentWindow.GroupItems.groupItems.length, 1, "There is only one group"); |
|
15 let currentActiveGroup = contentWindow.GroupItems.getActiveGroupItem(); |
|
16 |
|
17 let endGame = function() { |
|
18 ok(TabView.isVisible(), "TabView is shown"); |
|
19 gBrowser.selectedTab = originalTab; |
|
20 |
|
21 hideTabView(function () { |
|
22 ok(!TabView.isVisible(), "TabView is hidden"); |
|
23 finish(); |
|
24 }); |
|
25 } |
|
26 |
|
27 // we need to stop the setBounds() css animation or else the test will |
|
28 // fail in single-mode because the group is newly created "ontabshown". |
|
29 let $container = contentWindow.iQ(currentActiveGroup.container); |
|
30 $container.css("transition-property", "none"); |
|
31 |
|
32 currentActiveGroup.setPosition(40, 40, true); |
|
33 currentActiveGroup.arrange({animate: false}); |
|
34 |
|
35 // move down 20 so we're far enough away from the top. |
|
36 checkSnap(currentActiveGroup, 0, 20, contentWindow, function(snapped){ |
|
37 is(currentActiveGroup.getBounds().top, 60, "group.top is 60px"); |
|
38 ok(!snapped,"Move away from the edge"); |
|
39 |
|
40 // Just pick it up and drop it. |
|
41 checkSnap(currentActiveGroup, 0, 0, contentWindow, function(snapped){ |
|
42 is(currentActiveGroup.getBounds().top, 60, "group.top is 60px"); |
|
43 ok(!snapped,"Just pick it up and drop it"); |
|
44 |
|
45 checkSnap(currentActiveGroup, 0, 1, contentWindow, function(snapped){ |
|
46 is(currentActiveGroup.getBounds().top, 60, "group.top is 60px"); |
|
47 ok(snapped,"Drag one pixel: should snap"); |
|
48 |
|
49 checkSnap(currentActiveGroup, 0, 5, contentWindow, function(snapped){ |
|
50 is(currentActiveGroup.getBounds().top, 65, "group.top is 65px"); |
|
51 ok(!snapped,"Moving five pixels: shouldn't snap"); |
|
52 endGame(); |
|
53 }); |
|
54 }); |
|
55 }); |
|
56 }); |
|
57 } |
|
58 |
|
59 function simulateDragDrop(item, offsetX, offsetY, contentWindow) { |
|
60 let target = item.container; |
|
61 |
|
62 EventUtils.synthesizeMouse(target, 1, 1, {type: "mousedown"}, contentWindow); |
|
63 EventUtils.synthesizeMouse(target, 1 + offsetX, 1 + offsetY, {type: "mousemove"}, contentWindow); |
|
64 EventUtils.synthesizeMouse(target, 1, 1, {type: "mouseup"}, contentWindow); |
|
65 } |
|
66 |
|
67 function checkSnap(item, offsetX, offsetY, contentWindow, callback) { |
|
68 let firstTop = item.getBounds().top; |
|
69 let firstLeft = item.getBounds().left; |
|
70 |
|
71 simulateDragDrop(item, offsetX, offsetY, contentWindow); |
|
72 |
|
73 let snapped = false; |
|
74 if (item.getBounds().top != firstTop + offsetY) |
|
75 snapped = true; |
|
76 if (item.getBounds().left != firstLeft + offsetX) |
|
77 snapped = true; |
|
78 |
|
79 callback(snapped); |
|
80 } |