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

mercurial