-
Notifications
You must be signed in to change notification settings - Fork 6
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(bg/tabEvents): don't clear sessions on iframe navigation #831
Open
sidvishnoi
wants to merge
8
commits into
main
Choose a base branch
from
bug-iframe-navigate-notMonetized
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−2
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
191c1f8
add e2e tests
sidvishnoi 63bbca4
mark test as failing
sidvishnoi d4f396a
enable noUnusedVariables linter rule
sidvishnoi 7298393
remove unused vars
sidvishnoi d632e51
Merge branch 'main' into bug-iframe-navigate-notMonetized
sidvishnoi 8329e57
fail safely correctly
sidvishnoi 0eb8f7d
`changeInfo.url` is set only actual tab navigation
sidvishnoi 0d50cd2
don't expect test to fail anymore
sidvishnoi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { spy } from 'tinyspy'; | ||
import { test, expect } from './fixtures/connected'; | ||
|
||
test('iframe add/remove does not de-monetize main page', async ({ | ||
page, | ||
popup, | ||
}) => { | ||
const walletAddressUrl = process.env.TEST_WALLET_ADDRESS_URL; | ||
const playgroundUrl = 'https://webmonetization.org/play/'; | ||
|
||
await test.step('prepare', async () => { | ||
await expect(popup.getByTestId('not-monetized-message')).toBeVisible(); | ||
|
||
await page.goto(playgroundUrl); | ||
|
||
const monetizationCallback = spy<[Event], void>(); | ||
await page.exposeFunction('monetizationCallback', monetizationCallback); | ||
await page.evaluate(() => { | ||
window.addEventListener('monetization', monetizationCallback); | ||
}); | ||
|
||
await page | ||
.getByLabel('Wallet address/Payment pointer') | ||
.fill(walletAddressUrl); | ||
await page.getByRole('button', { name: 'Add monetization link' }).click(); | ||
|
||
await page.$eval( | ||
'link[rel="monetization"]', | ||
(el) => new Promise((res) => el.addEventListener('load', res)), | ||
); | ||
|
||
await page.waitForTimeout(2000); | ||
await expect(monetizationCallback).toHaveBeenCalledTimes(1); | ||
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({ | ||
paymentPointer: walletAddressUrl, | ||
}); | ||
|
||
await expect(popup.getByTestId('home-page')).toBeVisible(); | ||
|
||
return monetizationCallback; | ||
}); | ||
|
||
await test.step('add iframe', async () => { | ||
await page.evaluate(() => { | ||
return new Promise((resolve) => { | ||
const iframe = document.createElement('iframe'); | ||
iframe.id = 'cross-origin-iframe'; | ||
iframe.src = 'https://example.com'; | ||
document.body.prepend(iframe); | ||
iframe.addEventListener('load', resolve); | ||
}); | ||
}); | ||
|
||
await expect(page.locator('#cross-origin-iframe')).toBeVisible(); | ||
await expect(popup.getByTestId('home-page')).toBeVisible(); | ||
}); | ||
|
||
await test.step('remove iframe', async () => { | ||
await page.evaluate(() => { | ||
const iframe = document.getElementById('cross-origin-iframe'); | ||
iframe?.remove(); | ||
}); | ||
await expect(page.locator('#cross-origin-iframe')).not.toBeAttached(); | ||
|
||
await expect(popup.getByTestId('not-monetized-message')).not.toBeVisible(); | ||
await expect(popup.getByTestId('home-page')).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test('iframe navigate does not de-monetize main page', async ({ | ||
page, | ||
popup, | ||
}) => { | ||
test.fail( | ||
true, | ||
'https://github.com/interledger/web-monetization-extension/issues/819', | ||
); | ||
const walletAddressUrl = process.env.TEST_WALLET_ADDRESS_URL; | ||
const playgroundUrl = 'https://webmonetization.org/play/'; | ||
|
||
await test.step('prepare', async () => { | ||
await expect(popup.getByTestId('not-monetized-message')).toBeVisible(); | ||
|
||
await page.goto(playgroundUrl); | ||
|
||
const monetizationCallback = spy<[Event], void>(); | ||
await page.exposeFunction('monetizationCallback', monetizationCallback); | ||
await page.evaluate(() => { | ||
window.addEventListener('monetization', monetizationCallback); | ||
}); | ||
|
||
await page | ||
.getByLabel('Wallet address/Payment pointer') | ||
.fill(walletAddressUrl); | ||
await page.getByRole('button', { name: 'Add monetization link' }).click(); | ||
|
||
await page.$eval( | ||
'link[rel="monetization"]', | ||
(el) => new Promise((res) => el.addEventListener('load', res)), | ||
); | ||
|
||
await page.waitForTimeout(2000); | ||
await expect(monetizationCallback).toHaveBeenCalledTimes(1); | ||
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({ | ||
paymentPointer: walletAddressUrl, | ||
}); | ||
|
||
await expect(popup.getByTestId('home-page')).toBeVisible(); | ||
|
||
return monetizationCallback; | ||
}); | ||
|
||
await test.step('add iframe', async () => { | ||
await page.evaluate(() => { | ||
return new Promise((resolve) => { | ||
const iframe = document.createElement('iframe'); | ||
iframe.id = 'cross-origin-iframe'; | ||
iframe.src = 'https://example.com'; | ||
document.body.prepend(iframe); | ||
iframe.addEventListener('load', resolve, { once: true }); | ||
}); | ||
}); | ||
}); | ||
|
||
await test.step('navigate iframe', async () => { | ||
await page.evaluate(() => { | ||
return new Promise((resolve, reject) => { | ||
const iframe = document.getElementById('cross-origin-iframe'); | ||
if (!iframe) { | ||
reject(new Error('iframe not found')); | ||
return; | ||
} | ||
iframe.addEventListener('load', resolve, { once: true }); | ||
iframe.addEventListener('error', resolve, { once: true }); | ||
iframe.setAttribute('src', 'https://example.net'); | ||
}); | ||
}); | ||
|
||
// this fails | ||
await expect(popup.getByTestId('not-monetized-message')).not.toBeVisible(); | ||
await expect(popup.getByTestId('home-page')).toBeVisible(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so I can understand, when clicking in an iframe,
onUpdated
is triggered?