Add test for issue #940
This commit is contained in:
parent
59b72290cc
commit
e867e0ab5b
2 changed files with 49 additions and 2 deletions
|
@ -18,14 +18,18 @@ module.exports = {
|
|||
});
|
||||
},
|
||||
|
||||
async openNewTab(tab) {
|
||||
async openNewTab(tab, options = {isAsync: true}) {
|
||||
background.browser.tabs.get.resolves(tab);
|
||||
background.browser.webRequest.onBeforeRequest.addListener.yield({
|
||||
frameId: 0,
|
||||
tabId: tab.id,
|
||||
url: tab.url
|
||||
url: tab.url,
|
||||
requestId: options.requestId
|
||||
});
|
||||
background.browser.tabs.onCreated.addListener.yield(tab);
|
||||
if (!options.isAsync) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
}
|
||||
},
|
||||
|
|
43
test/issues/940.test.js
Normal file
43
test/issues/940.test.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
describe("#940", () => {
|
||||
describe("when other onBeforeRequestHandlers are faster and redirect with the same requestId", () => {
|
||||
it("should not open two confirm pages", async () => {
|
||||
// init
|
||||
const activeTab = {
|
||||
id: 1,
|
||||
cookieStoreId: "firefox-container-1",
|
||||
url: "http://example.com",
|
||||
index: 0
|
||||
};
|
||||
await helper.browser.initializeWithTab(activeTab);
|
||||
// assign the activeTab.url
|
||||
await helper.popup.clickElementById("container-page-assigned");
|
||||
|
||||
// start request and don't await the requests at all
|
||||
// so the second request below is actually comparable to an actual redirect that also fires immediately
|
||||
const newTab = {
|
||||
id: 2,
|
||||
cookieStoreId: "firefox-default",
|
||||
url: activeTab.url,
|
||||
index: 1,
|
||||
active: true
|
||||
};
|
||||
helper.browser.openNewTab(newTab, {
|
||||
requestId: 1,
|
||||
isAsync: false
|
||||
});
|
||||
|
||||
// other addon sees the same request
|
||||
// and redirects to the https version of activeTab.url
|
||||
// since it's a redirect the request has the same requestId
|
||||
background.browser.webRequest.onBeforeRequest.addListener.yield({
|
||||
frameId: 0,
|
||||
tabId: newTab.id,
|
||||
url: "https://example.com",
|
||||
requestId: 1
|
||||
});
|
||||
await nextTick();
|
||||
|
||||
background.browser.tabs.create.should.have.been.calledOnce;
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue