1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
var tabs;
function index(tab) {
return Array.prototype.indexOf.call(gBrowser.tabs, tab);
}
function indexTest(tab, expectedIndex, msg) {
var diag = "tab " + tab + " should be at index " + expectedIndex;
if (msg) {
msg = msg + " (" + diag + ")";
} else {
msg = diag;
}
is(index(tabs[tab]), expectedIndex, msg);
}
function PinUnpinHandler(tab, eventName) {
this.eventCount = 0;
var self = this;
tab.addEventListener(
eventName,
function () {
self.eventCount++;
},
{ capture: true, once: true }
);
gBrowser.tabContainer.addEventListener(
eventName,
function (e) {
if (e.originalTarget == tab) {
self.eventCount++;
}
},
{ capture: true, once: true }
);
}
function test() {
tabs = [
gBrowser.selectedTab,
BrowserTestUtils.addTab(gBrowser),
BrowserTestUtils.addTab(gBrowser),
BrowserTestUtils.addTab(gBrowser),
];
indexTest(0, 0);
indexTest(1, 1);
indexTest(2, 2);
indexTest(3, 3);
// Discard one of the test tabs to verify that pinning/unpinning
// discarded tabs does not regress (regression test for Bug 1852391).
gBrowser.discardBrowser(tabs[1], true);
var eh = new PinUnpinHandler(tabs[3], "TabPinned");
gBrowser.pinTab(tabs[3]);
is(eh.eventCount, 2, "TabPinned event should be fired");
indexTest(0, 1);
indexTest(1, 2);
indexTest(2, 3);
indexTest(3, 0);
eh = new PinUnpinHandler(tabs[1], "TabPinned");
gBrowser.pinTab(tabs[1]);
is(eh.eventCount, 2, "TabPinned event should be fired");
indexTest(0, 2);
indexTest(1, 1);
indexTest(2, 3);
indexTest(3, 0);
gBrowser.moveTabTo(tabs[3], 3);
indexTest(3, 1, "shouldn't be able to mix a pinned tab into normal tabs");
gBrowser.moveTabTo(tabs[2], 0);
indexTest(2, 2, "shouldn't be able to mix a normal tab into pinned tabs");
eh = new PinUnpinHandler(tabs[1], "TabUnpinned");
gBrowser.unpinTab(tabs[1]);
is(eh.eventCount, 2, "TabUnpinned event should be fired");
indexTest(
1,
1,
"unpinning a tab should move a tab to the start of normal tabs"
);
eh = new PinUnpinHandler(tabs[3], "TabUnpinned");
gBrowser.unpinTab(tabs[3]);
is(eh.eventCount, 2, "TabUnpinned event should be fired");
indexTest(
3,
0,
"unpinning a tab should move a tab to the start of normal tabs"
);
gBrowser.removeTab(tabs[1]);
gBrowser.removeTab(tabs[2]);
gBrowser.removeTab(tabs[3]);
}
|