Skip to content

Instantly share code, notes, and snippets.

@piroor piroor/prepare.js
Last active Dec 1, 2018

Embed
What would you like to do?
Preparation script for running of tests at https://hg.mozilla.org/mozilla-central/rev/cd420001c8ea#l5.145
/*
Usage:
1. Install something addon with "tabs" permission.
2. Go to "about:debugging" and open a debugger for the addon.
3. Go to the console.
4. Run.
*/
(async (global) => {
const windowId = (await browser.windows.create({})).id;
const tabIds = [];
const tabNames = 'ABCDEFGH'.split('');
const idToName = (id) => tabNames[tabIds.indexOf(id)] || '-';
const indexToName = (index) => tabNames[index] || '-';
for (let i = 0; i < 8; i++) {
tabIds.push((await browser.tabs.create({ windowId, url: `about:blank?${indexToName(i)}` })).id);
}
tabNames.forEach((name, index) => {
global[name] = tabIds[index];
});
const allTabs = await browser.tabs.query({ windowId });
allTabs.filter(tab => !tabIds.includes(tab.id))
.forEach(tab => browser.tabs.remove(tab.id));
global.toTabIds = (index) => tabIds[index];
global.setSuccessors = async (indexes) => {
const ids = indexes.map(toTabIds);
for (let index = 0; index < 8; index++) {
await browser.tabs.update(tabIds[index], { successorTabId: ids[index] || -1 });
}
dumpSuccessions();
};
global.setSuccessorsById = async (ids) => {
for (let index = 0; index < 8; index++) {
await browser.tabs.update(tabIds[index], { successorTabId: ids[index] || -1 });
}
dumpSuccessions();
};
global.dumpSuccessions = async () => {
const tabs = await browser.tabs.query({windowId});
console.log(tabs.map(tab => tabIds.indexOf(tab.successorTabId)));
console.log(tabs.map(tab => idToName(tab.successorTabId)).join(', '));
};
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.