summaryrefslogtreecommitdiffstats
path: root/remote/cdp/test/browser/emulation/browser_setTouchEmulationEnabled.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /remote/cdp/test/browser/emulation/browser_setTouchEmulationEnabled.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/cdp/test/browser/emulation/browser_setTouchEmulationEnabled.js')
-rw-r--r--remote/cdp/test/browser/emulation/browser_setTouchEmulationEnabled.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/remote/cdp/test/browser/emulation/browser_setTouchEmulationEnabled.js b/remote/cdp/test/browser/emulation/browser_setTouchEmulationEnabled.js
new file mode 100644
index 0000000000..48315ed0e9
--- /dev/null
+++ b/remote/cdp/test/browser/emulation/browser_setTouchEmulationEnabled.js
@@ -0,0 +1,83 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const DOC_TOUCH = toDataURL("<div>Hello world");
+
+add_task(async function invalidEnabledType({ client }) {
+ const { Emulation } = client;
+
+ for (const enabled of [null, "", 1, [], {}]) {
+ let errorThrown = "";
+ try {
+ await Emulation.setTouchEmulationEnabled({ enabled });
+ } catch (e) {
+ errorThrown = e.message;
+ }
+ ok(
+ errorThrown.match(/enabled: boolean value expected/),
+ `Fails with invalid type: ${enabled}`
+ );
+ }
+});
+
+add_task(async function enableAndDisable({ client }) {
+ const { Emulation, Runtime } = client;
+ const url = toDataURL("<p>foo");
+
+ await enableRuntime(client);
+
+ let contextCreated = Runtime.executionContextCreated();
+ await loadURL(url);
+ let result = await contextCreated;
+ await assertTouchEnabled(client, result.context, false);
+
+ await Emulation.setTouchEmulationEnabled({ enabled: true });
+ contextCreated = Runtime.executionContextCreated();
+ await loadURL(url);
+ result = await contextCreated;
+ await assertTouchEnabled(client, result.context, true);
+
+ await Emulation.setTouchEmulationEnabled({ enabled: false });
+ contextCreated = Runtime.executionContextCreated();
+ await loadURL(url);
+ result = await contextCreated;
+ await assertTouchEnabled(client, result.context, false);
+});
+
+add_task(async function receiveTouchEventsWhenEnabled({ client }) {
+ const { Emulation, Runtime } = client;
+
+ await enableRuntime(client);
+
+ await Emulation.setTouchEmulationEnabled({ enabled: true });
+ const contextCreated = Runtime.executionContextCreated();
+ await loadURL(DOC_TOUCH);
+ const { context } = await contextCreated;
+
+ await assertTouchEnabled(client, context, true);
+
+ const { result } = await evaluate(client, context.id, () => {
+ return new Promise(resolve => {
+ window.ontouchstart = () => {
+ resolve(true);
+ };
+ window.dispatchEvent(new Event("touchstart"));
+ resolve(false);
+ });
+ });
+ is(result.value, true, "Received touch event");
+});
+
+async function assertTouchEnabled(client, context, expectedStatus) {
+ const { result } = await evaluate(client, context.id, () => {
+ return "ontouchstart" in window;
+ });
+
+ if (expectedStatus) {
+ ok(result.value, "Touch emulation enabled");
+ } else {
+ ok(!result.value, "Touch emulation disabled");
+ }
+}