Last active
December 1, 2018 05:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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