From e867e0ab5b65038e5cba924bb115dcb5f6a2e5b2 Mon Sep 17 00:00:00 2001 From: stoically Date: Fri, 9 Feb 2018 10:54:52 +0100 Subject: [PATCH] Add test for issue #940 --- test/helper.js | 8 ++++++-- test/issues/940.test.js | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test/issues/940.test.js diff --git a/test/helper.js b/test/helper.js index a19750b..1ce13b5 100644 --- a/test/helper.js +++ b/test/helper.js @@ -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(); } }, diff --git a/test/issues/940.test.js b/test/issues/940.test.js new file mode 100644 index 0000000..cf9a1ab --- /dev/null +++ b/test/issues/940.test.js @@ -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; + }); + }); +});