Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Window named getter behaves incorrectly in some cases when there are …
…duplicate frame names https://bugs.webkit.org/show_bug.cgi?id=258108 Reviewed by Darin Adler and Ryosuke Niwa. When several frames gave the same name, WebKit will generate unique frame names internally. As a result, if a frame gets created with the name "foo", it will get "foo" as unique name. If a second frame gets created with the name "foo", we will generate a unique name for this frame (in the "<!-- frame1 -->" format) instead if using the already taken "foo" name. The issue is that this is Web-observable when using the named property getter on Window. `window.foo` is supposed to return the *first* frame with the name "foo" in tree order. WebKit was previously looking up the frame "foo" via its unique name, as a result, it would return the frame was assigned the name "foo" first, which is not necessarily the first frame with the name "foo" in tree order. The same issue affects `window.open('', 'foo')`. To address the issue, we now look up the frame by name instead of unique name. This aligns our behavior with both Chrome and Firefox. The newly added tests are passing in Chrome & Firefox but fails in shipping Safari. * LayoutTests/http/tests/frames/frames-with-same-name-cross-origin-expected.txt: Added. * LayoutTests/http/tests/frames/frames-with-same-name-cross-origin.html: Added. * LayoutTests/http/tests/frames/frames-with-same-name-expected.txt: Added. * LayoutTests/http/tests/frames/frames-with-same-name.html: Added. * LayoutTests/http/tests/frames/resources/frames-with-same-name-cross-origin-frame.html: Added. * LayoutTests/http/tests/frames/resources/set-window-name-to-foo.html: Added. * Source/WebCore/bindings/js/JSDOMWindowProperties.cpp: (WebCore::jsDOMWindowPropertiesGetOwnPropertySlotNamedItemGetter): * Source/WebCore/bindings/js/JSLocalDOMWindowCustom.cpp: (WebCore::jsLocalDOMWindowGetOwnPropertySlotRestrictedAccess): * Source/WebCore/page/FrameTree.cpp: (WebCore::FrameTree::scopedChild const): (WebCore::FrameTree::scopedChildByUniqueName const): (WebCore::FrameTree::scopedChildByName const): * Source/WebCore/page/FrameTree.h: * Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp: (WebKit::WebAutomationSessionProxy::resolveChildFrameWithName): Canonical link: https://commits.webkit.org/265211@main
- Loading branch information
Showing
18 changed files
with
144 additions
and
45 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
LayoutTests/http/tests/frames/frames-with-same-name-cross-origin-expected.txt
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,11 @@ | ||
Make sure that frame lookup by name has correct ordering when duplicate names are involved. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS crossOriginWindow.foo === crossOriginWindow[0] is true | ||
PASS open('', 'foo') === crossOriginWindow.foo is true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
18 changes: 18 additions & 0 deletions
18
LayoutTests/http/tests/frames/frames-with-same-name-cross-origin.html
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,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<script src="/js-test-resources/js-test.js"></script> | ||
<iframe id="crossOriginFrame" src="http://localhost:8000/frames/resources/frames-with-same-name-cross-origin-frame.html"></iframe> | ||
<script> | ||
description("Make sure that frame lookup by name has correct ordering when duplicate names are involved."); | ||
|
||
onload = () => { | ||
crossOriginWindow = document.getElementById("crossOriginFrame").contentWindow; | ||
// Both frames have the same name "foo" so window.foo should return the first one in tree order, even | ||
// though the name of the first frame gets set after the name of the second frame. | ||
shouldBeTrue("crossOriginWindow.foo === crossOriginWindow[0]"); | ||
shouldBeTrue("open('', 'foo') === crossOriginWindow.foo"); | ||
}; | ||
</script> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
LayoutTests/http/tests/frames/frames-with-same-name-expected.txt
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,11 @@ | ||
Make sure that frame lookup by name has correct ordering when duplicate names are involved. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS window.foo is document.getElementById('firstFrame').contentWindow | ||
PASS open('', 'foo') is window.foo | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
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,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<script src="/js-test-resources/js-test.js"></script> | ||
<iframe id="firstFrame" src="resources/set-window-name-to-foo.html"></iframe> | ||
<iframe name="foo"></iframe> | ||
<script> | ||
description("Make sure that frame lookup by name has correct ordering when duplicate names are involved."); | ||
|
||
onload = () => { | ||
// Both frames have the same name "foo" so window.foo should return the first one in tree order, even | ||
// though the name of the first frame gets set after the name of the second frame. | ||
shouldBe("window.foo", "document.getElementById('firstFrame').contentWindow"); | ||
shouldBe("open('', 'foo')", "window.foo"); | ||
}; | ||
</script> | ||
</body> | ||
</html> |
7 changes: 7 additions & 0 deletions
7
LayoutTests/http/tests/frames/resources/frames-with-same-name-cross-origin-frame.html
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,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<iframe src="set-window-name-to-foo.html"></iframe> | ||
<iframe name="foo"></iframe> | ||
</body> | ||
</html> |
4 changes: 4 additions & 0 deletions
4
LayoutTests/http/tests/frames/resources/set-window-name-to-foo.html
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,4 @@ | ||
<!DOCTYPE html> | ||
<script> | ||
window.name = "foo"; | ||
</script> |
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
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
Oops, something went wrong.