michael@0: var tabs; michael@0: michael@0: function index(tab) Array.indexOf(gBrowser.tabs, tab); michael@0: michael@0: function indexTest(tab, expectedIndex, msg) { michael@0: var diag = "tab " + tab + " should be at index " + expectedIndex; michael@0: if (msg) michael@0: msg = msg + " (" + diag + ")"; michael@0: else michael@0: msg = diag; michael@0: is(index(tabs[tab]), expectedIndex, msg); michael@0: } michael@0: michael@0: function PinUnpinHandler(tab, eventName) { michael@0: this.eventCount = 0; michael@0: var self = this; michael@0: tab.addEventListener(eventName, function() { michael@0: tab.removeEventListener(eventName, arguments.callee, true); michael@0: michael@0: self.eventCount++; michael@0: }, true); michael@0: gBrowser.tabContainer.addEventListener(eventName, function(e) { michael@0: gBrowser.tabContainer.removeEventListener(eventName, arguments.callee, true); michael@0: michael@0: if (e.originalTarget == tab) { michael@0: self.eventCount++; michael@0: } michael@0: }, true); michael@0: } michael@0: michael@0: function test() { michael@0: tabs = [gBrowser.selectedTab, gBrowser.addTab(), gBrowser.addTab(), gBrowser.addTab()]; michael@0: indexTest(0, 0); michael@0: indexTest(1, 1); michael@0: indexTest(2, 2); michael@0: indexTest(3, 3); michael@0: michael@0: var eh = new PinUnpinHandler(tabs[3], "TabPinned"); michael@0: gBrowser.pinTab(tabs[3]); michael@0: is(eh.eventCount, 2, "TabPinned event should be fired"); michael@0: indexTest(0, 1); michael@0: indexTest(1, 2); michael@0: indexTest(2, 3); michael@0: indexTest(3, 0); michael@0: michael@0: eh = new PinUnpinHandler(tabs[1], "TabPinned"); michael@0: gBrowser.pinTab(tabs[1]); michael@0: is(eh.eventCount, 2, "TabPinned event should be fired"); michael@0: indexTest(0, 2); michael@0: indexTest(1, 1); michael@0: indexTest(2, 3); michael@0: indexTest(3, 0); michael@0: michael@0: gBrowser.moveTabTo(tabs[3], 3); michael@0: indexTest(3, 1, "shouldn't be able to mix a pinned tab into normal tabs"); michael@0: michael@0: gBrowser.moveTabTo(tabs[2], 0); michael@0: indexTest(2, 2, "shouldn't be able to mix a normal tab into pinned tabs"); michael@0: michael@0: eh = new PinUnpinHandler(tabs[1], "TabUnpinned"); michael@0: gBrowser.unpinTab(tabs[1]); michael@0: is(eh.eventCount, 2, "TabUnpinned event should be fired"); michael@0: indexTest(1, 1, "unpinning a tab should move a tab to the start of normal tabs"); michael@0: michael@0: eh = new PinUnpinHandler(tabs[3], "TabUnpinned"); michael@0: gBrowser.unpinTab(tabs[3]); michael@0: is(eh.eventCount, 2, "TabUnpinned event should be fired"); michael@0: indexTest(3, 0, "unpinning a tab should move a tab to the start of normal tabs"); michael@0: michael@0: gBrowser.removeTab(tabs[1]); michael@0: gBrowser.removeTab(tabs[2]); michael@0: gBrowser.removeTab(tabs[3]); michael@0: }