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