-
-
Notifications
You must be signed in to change notification settings - Fork 952
web: Polyfill document.embeds to return ruffle-embeds too #22449
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
Open
danielhjacobs
wants to merge
7
commits into
ruffle-rs:master
Choose a base branch
from
danielhjacobs:polyfill-document-embeds
base: master
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.
+261
−0
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0692a6d
web: Polyfill document.embeds to return ruffle-embeds too
danielhjacobs 3798eda
web: Add test for document.embeds
danielhjacobs 29b8cf0
web: For document embeds test, use asserts instead of DOM appending
danielhjacobs de05e18
web: Use Proxy instead of fake HTMLCollection for document.embeds
danielhjacobs b99de28
web: Address review comments for document.embeds polyfill
danielhjacobs 394f1ed
web: Address more review comments related to document.embeds
danielhjacobs 02c65c7
web: Refactor document.embeds polyfill to its own function
danielhjacobs 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 hidden or 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
15 changes: 15 additions & 0 deletions
15
web/packages/selfhosted/test/polyfill/document_embeds/index.html
This file contains hidden or 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,15 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>DOCUMENT EMBEDS</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="test-container"> | ||
| <embed id="emb1" name="alpha" src="/test_assets/example.swf" width="200" height="200"></embed> | ||
| <embed id="emb2" name="beta" src="/test_assets/example.swf" width="200" height="200"></embed> | ||
| <embed id="emb3" name="beta" src="/test_assets/example.swf" width="200" height="200"></embed> | ||
| </div> | ||
| </body> | ||
| </html> |
136 changes: 136 additions & 0 deletions
136
web/packages/selfhosted/test/polyfill/document_embeds/test.ts
This file contains hidden or 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,136 @@ | ||
| import { injectRuffleAndWait, openTest } from "../../utils.js"; | ||
| import { expect } from "chai"; | ||
|
|
||
| describe("Document embeds", () => { | ||
| beforeEach(async () => { | ||
| await openTest(browser, `polyfill/document_embeds`); | ||
| await injectRuffleAndWait(browser); | ||
|
|
||
| await browser | ||
| .$("#test-container") | ||
| .$("ruffle-embed#emb1") | ||
| .waitForExist(); | ||
| await browser | ||
| .$("#test-container") | ||
| .$("ruffle-embed#emb2") | ||
| .waitForExist(); | ||
| await browser | ||
| .$("#test-container") | ||
| .$("ruffle-embed#emb3") | ||
| .waitForExist(); | ||
| }); | ||
|
|
||
| it("accesses the right number of elements with ruffle", async () => { | ||
| async function removeEl(selector: string) { | ||
| const el = await $(selector); | ||
| await browser.execute((element) => { | ||
| element.remove(); | ||
| }, el); | ||
| } | ||
|
|
||
| expect( | ||
| await browser.execute(() => document.embeds === document.embeds), | ||
| ).to.equal(true); | ||
|
|
||
| expect( | ||
| await browser.execute(() => document.embeds?.length ?? 0), | ||
| ).to.equal(3); | ||
|
|
||
| await removeEl("#emb1"); | ||
|
|
||
| expect( | ||
| await browser.execute(() => document.embeds?.length ?? 0), | ||
| ).to.equal(2); | ||
|
|
||
| await browser.execute(() => { | ||
| const embed = document.createElement("embed"); | ||
| embed.src = "about:blank"; | ||
| embed.type = "text/html"; | ||
| document.body.appendChild(embed); | ||
| }); | ||
|
|
||
| expect( | ||
| await browser.execute(() => document.embeds?.length ?? 0), | ||
| ).to.equal(3); | ||
| }); | ||
|
|
||
| it("supports index-based access", async () => { | ||
| const ids = await browser.execute(() => [ | ||
| document.embeds.item(0)?.id, | ||
| document.embeds[1]?.id, | ||
| document.embeds.item(2)?.id, | ||
| ]); | ||
|
|
||
| expect(ids).to.deep.equal(["emb1", "emb2", "emb3"]); | ||
| }); | ||
|
|
||
| it("supports namedItem(name)", async () => { | ||
| const result = await browser.execute(() => { | ||
| return { | ||
| alpha: document.embeds.namedItem("alpha")?.id, | ||
| beta: document.embeds.namedItem("beta")?.id, | ||
| missing: document.embeds.namedItem("nope"), | ||
| }; | ||
| }); | ||
|
|
||
| expect(result).to.deep.equal({ | ||
| alpha: "emb1", | ||
| beta: "emb2", // first match | ||
| missing: null, | ||
| }); | ||
| }); | ||
|
|
||
| it("namedItem falls back to id", async () => { | ||
| const idMatch = await browser.execute( | ||
| () => document.embeds.namedItem("emb3")?.id, | ||
| ); | ||
|
|
||
| expect(idMatch).to.equal("emb3"); | ||
| }); | ||
|
|
||
| it("is iterable", async () => { | ||
| const ids = await browser.execute(() => { | ||
| const result = []; | ||
| for (const el of document.embeds) { | ||
| result.push(el.id); | ||
| } | ||
| return result; | ||
| }); | ||
|
|
||
| expect(ids).to.deep.equal(["emb1", "emb2", "emb3"]); | ||
| }); | ||
|
|
||
| it("updates index order after removal", async () => { | ||
| await browser.execute(() => { | ||
| document.getElementById("emb2")?.remove(); | ||
| }); | ||
|
|
||
| const ids = await browser.execute(() => | ||
| Array.from(document.embeds).map((e) => e.id), | ||
| ); | ||
|
|
||
| expect(ids).to.deep.equal(["emb1", "emb3"]); | ||
| }); | ||
|
|
||
| it("includes newly added embeds in order", async () => { | ||
| await browser.execute(() => { | ||
| const e = document.createElement("embed"); | ||
| e.id = "emb4"; | ||
| e.name = "gamma"; | ||
| e.src = "about:blank"; | ||
| document.body.appendChild(e); | ||
| }); | ||
|
|
||
| const data = await browser.execute(() => ({ | ||
| length: document.embeds.length, | ||
| lastId: document.embeds.item(3)?.id, | ||
| gamma: document.embeds.namedItem("gamma")?.id, | ||
| })); | ||
|
|
||
| expect(data).to.deep.equal({ | ||
| length: 4, | ||
| lastId: "emb4", | ||
| gamma: "emb4", | ||
| }); | ||
| }); | ||
| }); |
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.
I guess I have one more question: why doesn't it refer back to
embedsfor unknown keys?Let's say that a website uses another extension (called foo) that makes some embeds work, and suppose it works similarly to Ruffle, changing
embedtofoo-embed.foowill also have to polyfillDocument.embedsbecause of the same reasons, but by using the current approach those two polyfills will conflict with each other.If I were to write this polyfill, I would assume that
Document.embedscontains all non-Ruffle embeds, and then refer to it for length and unknown keys, at the same time making sure I don't polyfill it for the second time. Doesn't it make sense?