Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/1202 first page is missing content #1208

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions add-on/src/lib/redirect-handler/blockOrObserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ export function addRuleToDynamicRuleSetGenerator (
removeRuleIds
}
)

// refresh the tab to apply the new rule.
const tabs = await browser.tabs.query({ url: originUrl })
await Promise.all(tabs.map(async tab => await browser.tabs.reload(tab.id)))
}

setupListeners(async (): Promise<void> => await reconcileRulesAndRemoveOld(getState()))
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions test/functional/lib/redirect-handler/blockOrObserve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,32 @@ describe('lib/redirect-handler/blockOrObserve', () => {

beforeEach(() => {
sinonSandbox.restore()
browserMock.flush()
browserMock.tabs.query.resolves([{ id: 1234 }])
browserMock.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock())
})

it('Should not redirect requests from localhost', () => {
it('Should not redirect requests from localhost', async () => {
// when both redirectUrl and originUrl are same.
addRuleToDynamicRuleSet({ originUrl: 'http://localhost:8080', redirectUrl: 'http://localhost:8080' })
await addRuleToDynamicRuleSet({ originUrl: 'http://localhost:8080', redirectUrl: 'http://localhost:8080' })
expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.false

// when redirectUrl is different from originUrl, but both are localhost.
addRuleToDynamicRuleSet({ originUrl: 'http://localhost:9001/foo', redirectUrl: 'http://localhost:9001/bar' })
await addRuleToDynamicRuleSet({ originUrl: 'http://localhost:9001/foo', redirectUrl: 'http://localhost:9001/bar' })
expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.false
})

it('Should allow pages to be recovered', () => {
it('Should allow pages to be recovered', async () => {
// when redirecting to recovery page
addRuleToDynamicRuleSet({
await addRuleToDynamicRuleSet({
originUrl: 'http://localhost:8080',
redirectUrl: 'chrome-extension://some-path/dist/recover/recovery.html'
})
expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true
})

it('Should add redirect rules for local gateway', () => {
addRuleToDynamicRuleSet({
it('Should add redirect rules for local gateway', async () => {
await addRuleToDynamicRuleSet({
originUrl: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org',
redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org'
})
Expand All @@ -104,8 +106,8 @@ describe('lib/redirect-handler/blockOrObserve', () => {
expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/ipfs\\.io((?:[^\\.]|$).*)$'))
})

it('Should add redirect for local gateway where originUrl is similar to redirectUrl', () => {
addRuleToDynamicRuleSet({
it('Should add redirect for local gateway where originUrl is similar to redirectUrl', async () => {
await addRuleToDynamicRuleSet({
originUrl: 'https://docs.ipfs.tech',
redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech'
})
Expand All @@ -123,5 +125,14 @@ describe('lib/redirect-handler/blockOrObserve', () => {
})
expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/docs\\.ipfs\\.tech((?:[^\\.]|$).*)$'))
})

it('Should refresh the tab when redirect URL is added', async () => {
await addRuleToDynamicRuleSet({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async/await was not an issue before, in this case it was flaky. so added it everywhere for sanity.

originUrl: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org',
redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org'
})
expect(browserMock.tabs.query.calledWith({ url: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org' })).to.be.true
expect(browserMock.tabs.reload.calledWith(1234)).to.be.true
})
})
})