commit d6a24ccccb108abf4ff49730b26441f6ba321c2d
parent d93eec7d568dd381a64f0ffe6a1bc1a9bee7eed3
Author: Hiroyuki Ikezoe <hikezoe.birchill@mozilla.com>
Date: Thu, 23 Oct 2025 20:29:43 +0000
Bug 1994390 - Open a new document in an iframe to make sure accessible-caret works on desktops. r=TYLin
With this trick we can get a new PresShell enabling accessible-carets on
desktops.
Differential Revision: https://phabricator.services.mozilla.com/D269296
Diffstat:
3 files changed, 80 insertions(+), 39 deletions(-)
diff --git a/layout/base/tests/helper_re_enable_apz_on_blur.html b/layout/base/tests/helper_re_enable_apz_on_blur.html
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <style>
+ html {
+ user-select: none;
+ }
+ body {
+ margin: 0;
+ }
+ textarea {
+ width: 100%;
+ height: 100%;
+ position: fixed;
+ user-select: text;
+ }
+ </style>
+</head>
+<body>
+<textarea id="textarea" name="name" rows="1" cols="20" inputmode="none">text</textarea>
+</body>
+</html>
diff --git a/layout/base/tests/mochitest.toml b/layout/base/tests/mochitest.toml
@@ -297,6 +297,7 @@ support-files = ["preserve3d_sorting_hit_testing_iframe.html"]
support-files = ["preserve3d_sorting_hit_testing2_iframe.html"]
["test_re_enable_apz_on_blur.html"]
+support-files = ["helper_re_enable_apz_on_blur.html"]
skip-if = ["os == 'win'"]
["test_refreshDriver_hasPendingTick.html"]
diff --git a/layout/base/tests/test_re_enable_apz_on_blur.html b/layout/base/tests/test_re_enable_apz_on_blur.html
@@ -7,15 +7,10 @@
<script src="/tests/SimpleTest/paint_listener.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<style>
- html {
- user-select: none;
- }
- textarea {
- width: 100%;
- height: 20px;
- position: fixed;
- bottom: 20px;
- user-select: text;
+ iframe {
+ width: 100vw;
+ height: 100vh;
+ border: none;
}
</style>
</head>
@@ -23,50 +18,72 @@
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
-<textarea name="name" rows="1" cols="20" inputmode="none">text</textarea>
+<iframe></iframe>
</body>
<script>
-SimpleTest.waitForExplicitFinish();
-
-SpecialPowers.pushPrefEnv({
- set: [
- ["layout.accessiblecaret.enabled", true],
- ["layout.accessiblecaret.enabled_on_touch", true],
- ],
-}, async () => {
- await SpecialPowers.spawnChrome([], () => {
+// Open a new document in an iframe with enabling accessible-carets.
+add_setup(async () => {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["layout.accessiblecaret.enabled", true],
+ ["layout.accessiblecaret.enabled_on_touch", true],
+ ],
+ });
+ await SpecialPowers.spawnChrome([], async () => {
browsingContext.touchEventsOverride = "enabled";
});
- const utils = SpecialPowers.DOMWindowUtils;
- const target = document.querySelector("textarea");
+ const iframe = document.querySelector("iframe");
+ const loadPromise = new Promise(resolve => {
+ iframe.addEventListener("load", () => resolve());
+ });
+ iframe.src = "helper_re_enable_apz_on_blur.html";
+ await loadPromise;
+});
+
+add_task(async () => {
+ const iframe = document.querySelector("iframe");
- const selectionchangePromise = new Promise(resolve => {
- target.addEventListener("selectionchange", () => resolve());
+ // Setup a selectionchange event listner in the iframe.
+ const selectionchangePromise = SpecialPowers.spawn(iframe, [], () => {
+ return new Promise(resolve => {
+ content.document.querySelector("textarea").
+ addEventListener("selectionchange", () => resolve());
+ });
+ });
+ // To make sure the listener has been setup in the iframe context.
+ await SpecialPowers.spawn(iframe, [], async () => {
+ await new Promise(resolve => resolve());
});
- ok(!utils.isApzDisabledForElement(target),
- "APZ is not disabled on the textarea");
- // Tap on the text area.
- synthesizeTouch(target, 10, 10, { type: "touchstart" });
- synthesizeTouch(target, 10, 10, { type: "touchend" });
+ async function isApzDisabled() {
+ return SpecialPowers.spawn(iframe, [], () => {
+ return SpecialPowers.DOMWindowUtils.isApzDisabledForElement(
+ content.document.querySelector("textarea"));
+ });
+ }
- await selectionchangePromise;
+ ok(!await isApzDisabled(), "APZ is not disabled on the textarea");
- ok(utils.isApzDisabledForElement(target),
- "Now APZ is disabled on the textarea");
+ // Tap on the text area in the iframe.
+ synthesizeTouch(iframe, 10, 10, { type: "touchstart" });
+ synthesizeTouch(iframe, 10, 10, { type: "touchend" });
- const blurPromise = new Promise(resolve => {
- target.addEventListener("blur", () => resolve());
- });
- target.blur();
+ await selectionchangePromise;
- await blurPromise;
+ ok(await isApzDisabled(), "Now APZ is disabled on the textarea");
- ok(!utils.isApzDisabledForElement(target),
- "Now APZ is re-enabled on the textarea");
+ // Now blur the focus from the textarea.
+ await SpecialPowers.spawn(iframe, [], async () => {
+ const target = content.document.querySelector("textarea");
+ const blurPromise = new Promise(resolve => {
+ target.addEventListener("blur", () => resolve());
+ });
+ target.blur();
+ await blurPromise;
+ });
- SimpleTest.finish();
+ ok(!await isApzDisabled(), "Now APZ is re-enabled on the textarea");
});
</script>
</html>