|
1 var tabs; |
|
2 |
|
3 function index(tab) Array.indexOf(gBrowser.tabs, tab); |
|
4 |
|
5 function indexTest(tab, expectedIndex, msg) { |
|
6 var diag = "tab " + tab + " should be at index " + expectedIndex; |
|
7 if (msg) |
|
8 msg = msg + " (" + diag + ")"; |
|
9 else |
|
10 msg = diag; |
|
11 is(index(tabs[tab]), expectedIndex, msg); |
|
12 } |
|
13 |
|
14 function PinUnpinHandler(tab, eventName) { |
|
15 this.eventCount = 0; |
|
16 var self = this; |
|
17 tab.addEventListener(eventName, function() { |
|
18 tab.removeEventListener(eventName, arguments.callee, true); |
|
19 |
|
20 self.eventCount++; |
|
21 }, true); |
|
22 gBrowser.tabContainer.addEventListener(eventName, function(e) { |
|
23 gBrowser.tabContainer.removeEventListener(eventName, arguments.callee, true); |
|
24 |
|
25 if (e.originalTarget == tab) { |
|
26 self.eventCount++; |
|
27 } |
|
28 }, true); |
|
29 } |
|
30 |
|
31 function test() { |
|
32 tabs = [gBrowser.selectedTab, gBrowser.addTab(), gBrowser.addTab(), gBrowser.addTab()]; |
|
33 indexTest(0, 0); |
|
34 indexTest(1, 1); |
|
35 indexTest(2, 2); |
|
36 indexTest(3, 3); |
|
37 |
|
38 var eh = new PinUnpinHandler(tabs[3], "TabPinned"); |
|
39 gBrowser.pinTab(tabs[3]); |
|
40 is(eh.eventCount, 2, "TabPinned event should be fired"); |
|
41 indexTest(0, 1); |
|
42 indexTest(1, 2); |
|
43 indexTest(2, 3); |
|
44 indexTest(3, 0); |
|
45 |
|
46 eh = new PinUnpinHandler(tabs[1], "TabPinned"); |
|
47 gBrowser.pinTab(tabs[1]); |
|
48 is(eh.eventCount, 2, "TabPinned event should be fired"); |
|
49 indexTest(0, 2); |
|
50 indexTest(1, 1); |
|
51 indexTest(2, 3); |
|
52 indexTest(3, 0); |
|
53 |
|
54 gBrowser.moveTabTo(tabs[3], 3); |
|
55 indexTest(3, 1, "shouldn't be able to mix a pinned tab into normal tabs"); |
|
56 |
|
57 gBrowser.moveTabTo(tabs[2], 0); |
|
58 indexTest(2, 2, "shouldn't be able to mix a normal tab into pinned tabs"); |
|
59 |
|
60 eh = new PinUnpinHandler(tabs[1], "TabUnpinned"); |
|
61 gBrowser.unpinTab(tabs[1]); |
|
62 is(eh.eventCount, 2, "TabUnpinned event should be fired"); |
|
63 indexTest(1, 1, "unpinning a tab should move a tab to the start of normal tabs"); |
|
64 |
|
65 eh = new PinUnpinHandler(tabs[3], "TabUnpinned"); |
|
66 gBrowser.unpinTab(tabs[3]); |
|
67 is(eh.eventCount, 2, "TabUnpinned event should be fired"); |
|
68 indexTest(3, 0, "unpinning a tab should move a tab to the start of normal tabs"); |
|
69 |
|
70 gBrowser.removeTab(tabs[1]); |
|
71 gBrowser.removeTab(tabs[2]); |
|
72 gBrowser.removeTab(tabs[3]); |
|
73 } |