Closed Bug 1578973 Opened 3 months ago Closed 3 months ago

autofocus shouldn't work in cross origin documents

Categories

(Core :: DOM: Core & HTML, defect, P2)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: hiro, Assigned: hiro)

References

(Blocks 1 open bug, )

Details

(Keywords: dev-doc-needed)

Attachments

(3 files)

There is a web platform test to check this and currently it fails.

We should do the same origin check before we call SetAutoFocusElement.

We should fix this for fission too.

Blocks: fission

I have a patch for this, but we need to rewrite browser/components/sessionstore/test/browser_formdata.js since it uses autofocus in two data URLs, and nika told me on Slack that we treat data URL is cross-origin.

See Also: → 1579247

We also use SpecialPowers.spawn to run the script to focus to the input element
so that it will work in fission world.

Note that I've confirmed no-cross-origin-autofocus.html works fine with
enabling fission on w3c-test.org.

Depends on D44949

Assignee: nobody → hikezoe.birchill
Priority: -- → P2

Note that the patch also fixes no-sandboxed-automatic-features.html.

Pushed by hikezoe.birchill@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/63a10d0c96ce
Don't use autofocus in data URL since the data URL is treated as cross-origin thus autofocus doesn't work there. r=mikedeboer
Pushed by hikezoe.birchill@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/5a021b9f8790
Don't do autofocus process if the target node of 'autofocus' is in a cross-origin document. r=nika
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/19037 for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.

Backed out changeset 5a021b9f8790 (bug 1578973) for browser-chrome failures at browser/base/content/test/forms/browser_selectpopup.js

Backout: https://hg.mozilla.org/integration/autoland/rev/baad7feb838cdfcb2793c089461308fd8333e369

Failure push: https://treeherder.mozilla.org/#/jobs?repo=autoland&revision=5a021b9f8790b0f6d39aefb29d9c65c2bc8f0ba3&selectedJob=266453393

Failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=266444993&repo=autoland&lineNumber=1073

task 2019-09-13T00:25:03.567Z] 00:25:03 INFO - TEST-PASS | browser/base/content/test/forms/browser_selectpopup.js | Popup hidden when tab is closed -
[task 2019-09-13T00:25:03.567Z] 00:25:03 INFO - Leaving test bound
[task 2019-09-13T00:25:03.567Z] 00:25:03 INFO - Entering test bound
[task 2019-09-13T00:25:03.567Z] 00:25:03 INFO - Console message: [JavaScript Error: "The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol." {file: "data:text/html,%3Chtml%3E%3Cbody%3E%3Cdiv%20id%3D%27div%27%3E%3Ciframe%20id%3D%27frame%27%20width%3D%27320%27%20height%3D%27295%27%20style%3D%27border%3A%20none%3B%27%20%20%20%20%20%20%20%20src%3D%27data%3Atext/html%2C%3Cselect%20id%3Dselect%20autofocus%3E%3Coption%3Ehe%20he%20he%3C/option%3E%3Coption%3Eboo%20boo%3C/option%3E%3Coption%3Ebaz%20baz%3C/option%3E%3C/select%3E%27%3C/iframe%3E%3C/div%3E%3C/body%3E%3C/html%3E" line: 0}]
[task 2019-09-13T00:25:03.568Z] 00:25:03 INFO - Buffered messages logged at 00:24:18
[task 2019-09-13T00:25:03.568Z] 00:25:03 INFO - Longer timeout required, waiting longer... Remaining timeouts: 1
[task 2019-09-13T00:25:03.568Z] 00:25:03 INFO - Buffered messages finished
[task 2019-09-13T00:25:03.568Z] 00:25:03 INFO - TEST-UNEXPECTED-FAIL | browser/base/content/test/forms/browser_selectpopup.js | Test timed out -
[task 2019-09-13T00:25:03.568Z] 00:25:03 INFO - GECKO(1639) | JavaScript error: resource://testing-common/PromiseTestUtils.jsm, line 112: uncaught exception: Object
[task 2019-09-13T00:25:03.568Z] 00:25:03 INFO - Console message: [JavaScript Error: "uncaught exception: Object" {file: "resource://testing-common/PromiseTestUtils.jsm" line: 112}]
[task 2019-09-13T00:25:03.569Z] 00:25:03 INFO - GECKO(1639) | MEMORY STAT vsizeMaxContiguous not supported in this build configuration.
[task 2019-09-13T00:25:03.569Z] 00:25:03 INFO - GECKO(1639) | MEMORY STAT | vsize 7596MB | residentFast 309MB | heapAllocated 75MB
[task 2019-09-13T00:25:03.569Z] 00:25:03 INFO - TEST-OK | browser/base/content/test/forms/browser_selectpopup.js | took 90047ms
[task 2019-09-13T00:25:03.569Z] 00:25:03 INFO - Not taking screenshot here: see the one that was previously logged
[task 2019-09-13T00:25:03.572Z] 00:25:03 INFO - TEST-UNEXPECTED-FAIL | browser/base/content/test/forms/browser_selectpopup.js | Found a tab after previous test timed out: data:text/html,%3Chtml%3E%3Cbody%3E%3Cdiv%20id%3D%27div%27%3E%3Ciframe%20id%3D%27frame%27%20width%3D%27320%27%20height%3D%27295%27%20style%3D%27border%3A%20none%3B%27%20%20%20%20%20%20%20%20src%3D%27data%3Atext/html%2C%3Cselect%20id%3Dselect%20autofocus%3E%3Coption%3Ehe%20he%20he%3C/option%3E%3Coption%3Eboo%20boo%3C/option%3E%3Coption%3Ebaz%20baz%3C/option%3E%3C/select%3E%27%3C/iframe%3E%3C/div%3E%3C/body%3E%3C/html%3E -
[task 2019-09-13T00:25:03.573Z] 00:25:03 INFO - checking window state
[task 2019-09-13T00:25:03.573Z] 00:25:03 INFO - TEST-START | browser/base/content/test/forms/browser_selectpopup_colors.js
[task 2019-09-13T00:25:03.857Z] 00:25:03 INFO - Not taking screenshot here: see the one that was previously logged
[task 2019-09-13T00:25:03.857Z] 00:25:03 INFO - Buffered messages logged at 00:25:03
[task 2019-09-13T00:25:03.857Z] 00:25:03 INFO - Entering test bound setup
[task 2019-09-13T00:25:03.858Z] 00:25:03 INFO - Leaving test bound setup
[task 2019-09-13T00:25:03.858Z] 00:25:03 INFO - Entering test bound test_colors_applied_to_popup_items
[task 2019-09-13T00:25:03.859Z] 00:25:03 INFO - Console message: [JavaScript Error: "The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol." {file: "data:text/html,%3Chtml%3E%3Chead%3E%3Cstyle%3E%20%20.blue%20%7B%20color%3A%20%23fff%3B%20background-color%3A%20%2300f%3B%20%7D%20%20.green%20%7B%20color%3A%20%23800080%3B%20background-color%3A%20green%3B%20%7D%20%20.defaultColor%20%7B%20color%3A%20-moz-ComboboxText%3B%20%7D%20%20.defaultBackground%20%7B%20background-color%3A%20-moz-Combobox%3B%20%7D%3C/style%3E%3Cbody%3E%3Cselect%20id%3D%27one%27%3E%20%20%3Coption%20value%3D%22One%22%20style%3D%22color%3A%20%23fff%3B%20background-color%3A%20%23f00%3B%22%3E%" line: 0}]
[task 2019-09-13T00:25:03.859Z] 00:25:03 INFO - Buffered messages finished
[task 2019-09-13T00:25:03.864Z] 00:25:03 INFO - TEST-UNEXPECTED-FAIL | browser/base/content/test/forms/browser_selectpopup.js | Uncaught exception received from previously timed out test - at chrome://mochitests/content/browser/browser/base/content/test/forms/head.js:3 - TypeError: ContentTask is null
[task 2019-09-13T00:25:03.865Z] 00:25:03 INFO - Stack trace:
[task 2019-09-13T00:25:03.865Z] 00:25:03 INFO - hideSelectPopup@chrome://mochitests/content/browser/browser/base/content/test/forms/head.js:3:29
[task 2019-09-13T00:25:03.865Z] 00:25:03 INFO - @chrome://mochitests/content/browser/browser/base/content/test/forms/browser_selectpopup.js:410:9
[task 2019-09-13T00:25:03.865Z] 00:25:03 INFO - AsyncTester_execTest/<@chrome://mochikit/content/browser-test.js:1350:34
[task 2019-09-13T00:25:03.865Z] 00:25:03 INFO - async
Tester_execTest@chrome://mochikit/content/browser-test.js:1385:11
[task 2019-09-13T00:25:03.865Z] 00:25:03 INFO - nextTest/<@chrome://mochikit/content/browser-test.js:1213:14
[task 2019-09-13T00:25:03.865Z] 00:25:03 INFO - SimpleTest.waitForFocus/waitForFocusInner/focusedOrLoaded/<@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:805:67

Flags: needinfo?(hikezoe.birchill)

Do'h! I missed somehow that browser_selectpopup.js uses autofocus in an iframe written in dataURL...

Flags: needinfo?(hikezoe.birchill)

Adding 'leave-open' since I did unintentionally land only D44949.

Keywords: leave-open
Upstream PR merged by moz-wptsync-bot
Pushed by hikezoe.birchill@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/598e48f70893
Don't do autofocus process if the target node of 'autofocus' is in a cross-origin document. r=nika

Do'h! Why D45779 didn't land?

Pushed by hikezoe.birchill@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/9f9ff7f7ff23
Don't use autofocus in data URL in browser_selectpopup.js. r=dao
Status: NEW → RESOLVED
Closed: 3 months ago
Keywords: leave-open
Resolution: --- → FIXED
Blocks: rendering-fission
No longer blocks: fission
You need to log in before you can comment on or make changes to this bug.