|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 |
|
7 newWindowWithTabView(onTabViewWindowLoaded); |
|
8 } |
|
9 |
|
10 function onTabViewWindowLoaded(win) { |
|
11 win.removeEventListener("tabviewshown", onTabViewWindowLoaded, false); |
|
12 |
|
13 ok(win.TabView.isVisible(), "Tab View is visible"); |
|
14 |
|
15 let contentWindow = win.document.getElementById("tab-view").contentWindow; |
|
16 let [originalTab] = win.gBrowser.visibleTabs; |
|
17 |
|
18 let currentGroup = contentWindow.GroupItems.getActiveGroupItem(); |
|
19 |
|
20 // Create a group and make it active |
|
21 let box = new contentWindow.Rect(100, 100, 370, 370); |
|
22 let group = new contentWindow.GroupItem([], { bounds: box }); |
|
23 ok(group.isEmpty(), "This group is empty"); |
|
24 contentWindow.UI.setActive(group); |
|
25 is(contentWindow.GroupItems.getActiveGroupItem(), group, "new group is active"); |
|
26 |
|
27 // Create a bunch of tabs in the group |
|
28 let bg = {inBackground: true}; |
|
29 let datatext = win.gBrowser.loadOneTab("data:text/plain,bug610242", bg); |
|
30 let datahtml = win.gBrowser.loadOneTab("data:text/html,<h1>hi!</h1>", bg); |
|
31 let mozilla = win.gBrowser.loadOneTab("about:mozilla", bg); |
|
32 let synclog = win.gBrowser.loadOneTab("about:sync-log", bg); |
|
33 let html = win.gBrowser.loadOneTab("http://example.com", bg); |
|
34 let png = win.gBrowser.loadOneTab("http://mochi.test:8888/browser/browser/base/content/test/general/moz.png", bg); |
|
35 let svg = win.gBrowser.loadOneTab("http://mochi.test:8888/browser/browser/base/content/test/general/title_test.svg", bg); |
|
36 |
|
37 ok(!group.shouldStack(group._children.length), "Group should not stack."); |
|
38 |
|
39 // PREPARE FINISH: |
|
40 group.addSubscriber("close", function onClose() { |
|
41 group.removeSubscriber("close", onClose); |
|
42 |
|
43 ok(group.isEmpty(), "The group is empty again"); |
|
44 |
|
45 contentWindow.UI.setActive(currentGroup); |
|
46 isnot(contentWindow.GroupItems.getActiveGroupItem(), null, "There is an active group"); |
|
47 is(win.gBrowser.tabs.length, 1, "There is only one tab left"); |
|
48 is(win.gBrowser.visibleTabs.length, 1, "There is also only one visible tab"); |
|
49 |
|
50 whenTabViewIsHidden(function() { |
|
51 win.close(); |
|
52 ok(win.closed, "new window is closed"); |
|
53 finish(); |
|
54 }, win); |
|
55 win.gBrowser.selectedTab = originalTab; |
|
56 |
|
57 win.TabView.hide(); |
|
58 }); |
|
59 |
|
60 function check(tab, label, visible) { |
|
61 let display = contentWindow.getComputedStyle(tab._tabViewTabItem.$fav[0], null).getPropertyValue("display"); |
|
62 if (visible) { |
|
63 is(display, "block", label + " has favicon"); |
|
64 } else { |
|
65 is(display, "none", label + " has no favicon"); |
|
66 } |
|
67 } |
|
68 |
|
69 afterAllTabsLoaded(function() { |
|
70 let children = group.getChildren(); |
|
71 let len = children.length; |
|
72 let iconUpdateCounter = 0; |
|
73 |
|
74 children.forEach(function(tabItem) { |
|
75 tabItem.addSubscriber("iconUpdated", function onIconUpdated() { |
|
76 tabItem.removeSubscriber("iconUpdated", onIconUpdated); |
|
77 |
|
78 if (++iconUpdateCounter == len) { |
|
79 check(datatext, "datatext", false); |
|
80 check(datahtml, "datahtml", false); |
|
81 check(mozilla, "about:mozilla", false); |
|
82 check(synclog, "about:sync-log", true); |
|
83 check(html, "html", true); |
|
84 check(png, "png", false); |
|
85 check(svg, "svg", true); |
|
86 |
|
87 // Get rid of the group and its children |
|
88 // The group close will trigger a finish(). |
|
89 closeGroupItem(group); |
|
90 } |
|
91 }); |
|
92 }); |
|
93 |
|
94 afterAllTabItemsUpdated(function () {}, win); |
|
95 }, win); |
|
96 } |