Skip to content

Instantly share code, notes, and snippets.

@piroor
Last active December 1, 2018 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piroor/f26a718f55c9790021c9e75080d91294 to your computer and use it in GitHub Desktop.
Save piroor/f26a718f55c9790021c9e75080d91294 to your computer and use it in GitHub Desktop.
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