browser/components/tabview/test/browser_tabview_layout.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
michael@0 7 // verify initial state
michael@0 8 ok(!TabView.isVisible(), "Tab View starts hidden");
michael@0 9
michael@0 10 window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
michael@0 11 TabView.toggle();
michael@0 12 }
michael@0 13
michael@0 14 let originalGroupItem = null;
michael@0 15 let originalTab = null;
michael@0 16 let contentWindow = null;
michael@0 17
michael@0 18 function onTabViewWindowLoaded() {
michael@0 19 window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
michael@0 20 ok(TabView.isVisible(), "Tab View is visible");
michael@0 21
michael@0 22 contentWindow = document.getElementById("tab-view").contentWindow;
michael@0 23
michael@0 24 is(contentWindow.GroupItems.groupItems.length, 1, "There is one group item on startup");
michael@0 25 originalGroupItem = contentWindow.GroupItems.groupItems[0];
michael@0 26 is(originalGroupItem.getChildren().length, 1, "There should be one Tab Item in that group.");
michael@0 27 contentWindow.UI.setActive(originalGroupItem);
michael@0 28
michael@0 29 [originalTab] = gBrowser.visibleTabs;
michael@0 30
michael@0 31 testEmptyGroupItem(contentWindow);
michael@0 32 }
michael@0 33
michael@0 34 function testEmptyGroupItem(contentWindow) {
michael@0 35 let groupItemCount = contentWindow.GroupItems.groupItems.length;
michael@0 36
michael@0 37 // Preparation
michael@0 38 //
michael@0 39
michael@0 40 // create empty group item
michael@0 41 let emptyGroupItem = createEmptyGroupItem(contentWindow, 253, 335, 100);
michael@0 42 ok(emptyGroupItem.isEmpty(), "This group is empty");
michael@0 43
michael@0 44 is(contentWindow.GroupItems.groupItems.length, ++groupItemCount,
michael@0 45 "The number of groups is increased by 1");
michael@0 46
michael@0 47 // add four blank items
michael@0 48 contentWindow.UI.setActive(emptyGroupItem);
michael@0 49
michael@0 50 let numNewTabs = 4;
michael@0 51 let items = [];
michael@0 52 for(let t=0; t<numNewTabs; t++) {
michael@0 53 let newItem = contentWindow.gBrowser.loadOneTab("about:blank")._tabViewTabItem;
michael@0 54 ok(newItem.container, "Created element "+t+":"+newItem.container);
michael@0 55 items.push(newItem);
michael@0 56 }
michael@0 57
michael@0 58 // Define main test function
michael@0 59 //
michael@0 60
michael@0 61 let mainTestFunc = function() {
michael@0 62 for(let j=0; j<numNewTabs; j++) {
michael@0 63 for(let i=0; i<numNewTabs; i++) {
michael@0 64 if (j!=i) {
michael@0 65 // make sure there is no overlap between j's title and i's box.
michael@0 66 let jitem = items[j];
michael@0 67 let iitem = items[i];
michael@0 68 let $jtitle = contentWindow.iQ(jitem.container).find(".tab-title");
michael@0 69 let jbounds = $jtitle.bounds();
michael@0 70 let ibounds = contentWindow.iQ(iitem.container).bounds();
michael@0 71
michael@0 72 ok(
michael@0 73 (jbounds.top+jbounds.height < ibounds.top) ||
michael@0 74 (jbounds.top > ibounds.top + ibounds.height) ||
michael@0 75 (jbounds.left+jbounds.width < ibounds.left) ||
michael@0 76 (jbounds.left > ibounds.left + ibounds.width),
michael@0 77 "Items do not overlap: "
michael@0 78 +jbounds.left+","+jbounds.top+","+jbounds.width+","+jbounds.height+" ; "
michael@0 79 +ibounds.left+","+ibounds.top+","+ibounds.width+","+ibounds.height);
michael@0 80 }
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 // Shut down
michael@0 85 emptyGroupItem.addSubscriber("close", function onClose() {
michael@0 86 emptyGroupItem.removeSubscriber("close", onClose);
michael@0 87
michael@0 88 // check the number of groups.
michael@0 89 is(contentWindow.GroupItems.groupItems.length, --groupItemCount,
michael@0 90 "The number of groups is decreased by 1");
michael@0 91
michael@0 92 let onTabViewHidden = function() {
michael@0 93 window.removeEventListener("tabviewhidden", onTabViewHidden, false);
michael@0 94 // assert that we're no longer in tab view
michael@0 95 ok(!TabView.isVisible(), "Tab View is hidden");
michael@0 96 finish();
michael@0 97 };
michael@0 98 window.addEventListener("tabviewhidden", onTabViewHidden, false);
michael@0 99
michael@0 100 TabView.toggle();
michael@0 101 });
michael@0 102
michael@0 103 let closeButton = emptyGroupItem.container.getElementsByClassName("close");
michael@0 104 ok(closeButton[0], "Group close button exists");
michael@0 105
michael@0 106 // click the close button
michael@0 107 EventUtils.synthesizeMouse(closeButton[0], 1, 1, {}, contentWindow);
michael@0 108 };
michael@0 109
michael@0 110 mainTestFunc();
michael@0 111 }

mercurial