summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-share/resources
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/web-share/resources
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/web-share/resources')
-rw-r--r--testing/web-platform/tests/web-share/resources/blank.html2
-rw-r--r--testing/web-platform/tests/web-share/resources/manual-helper.js100
-rw-r--r--testing/web-platform/tests/web-share/resources/post-message.html35
3 files changed, 137 insertions, 0 deletions
diff --git a/testing/web-platform/tests/web-share/resources/blank.html b/testing/web-platform/tests/web-share/resources/blank.html
new file mode 100644
index 0000000000..84f43b333a
--- /dev/null
+++ b/testing/web-platform/tests/web-share/resources/blank.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
diff --git a/testing/web-platform/tests/web-share/resources/manual-helper.js b/testing/web-platform/tests/web-share/resources/manual-helper.js
new file mode 100644
index 0000000000..15bb17936e
--- /dev/null
+++ b/testing/web-platform/tests/web-share/resources/manual-helper.js
@@ -0,0 +1,100 @@
+// Internal function. Returns [instruction, list] DOM elements.
+function setupManualShareTestCommon() {
+ const div = document.createElement('div');
+ document.body.appendChild(div);
+
+ const instruction = document.createElement('div');
+ instruction.id = 'instruction';
+ div.appendChild(instruction);
+
+ const shareButton = document.createElement('input');
+ shareButton.id = 'share_button';
+ shareButton.value = 'Share button';
+ shareButton.type = 'button';
+ div.appendChild(shareButton);
+
+ let heading = document.createElement('h2');
+ heading.innerText = 'Instructions:';
+ instruction.appendChild(heading);
+ let list = document.createElement('ol');
+ instruction.appendChild(list);
+ let item = document.createElement('li');
+ list.appendChild(item);
+ item.innerText = 'Click the Share button.';
+
+ return [instruction, list];
+}
+
+// Sets up the page for running manual tests. Automatically creates the
+// instructions (based on the parameters) and the share button.
+function setupManualShareTest(expected_share_data) {
+ const {title, text, url, files} = expected_share_data;
+ let [instruction, list] = setupManualShareTestCommon();
+ let item = document.createElement('li');
+ list.appendChild(item);
+ item.innerText = 'Choose a valid share target.';
+
+ heading = document.createElement('h2');
+ heading.innerText = 'Pass the test iff the target app received:';
+ instruction.appendChild(heading);
+
+ list = document.createElement('ul');
+ instruction.appendChild(list);
+
+ item = document.createElement('li');
+ list.appendChild(item);
+ item.innerText = `title = "${title}"`;
+ item = document.createElement('li');
+ list.appendChild(item);
+ item.innerText = `text = "${text}"`;
+ item = document.createElement('li');
+ list.appendChild(item);
+ item.innerText = `url = "${url}"`;
+ if (files) {
+ item = document.createElement('li');
+ list.appendChild(item);
+ item.innerText = `files = ${files.length} file(s)`;
+ for (let file of files) {
+ const div = document.createElement('div');
+ if (file.type.startsWith('text/')) {
+ const reader = new FileReader();
+ reader.onload = () => {
+ div.textContent = reader.result;
+ };
+ reader.readAsText(file);
+ } else if (file.type.startsWith('image/')) {
+ const image = document.createElement('img');
+ image.src = URL.createObjectURL(file);
+ image.alt = file.name;
+ div.appendChild(image);
+ }
+ item.appendChild(div);
+ }
+ }
+}
+
+function setupManualShareTestRequiringCancellation() {
+ const [instruction, list] = setupManualShareTestCommon();
+ const item = document.createElement('li');
+ list.appendChild(item);
+ item.innerText = 'Cancel the share dialog.';
+}
+
+// Returns a promise. When the user clicks the button, calls
+// |click_handler| and resolves the promise with the result.
+function callWhenButtonClicked(click_handler) {
+ return new Promise((resolve, reject) => {
+ document.querySelector('#share_button').onclick = () => {
+ try {
+ const result = click_handler();
+ resolve(result);
+ } catch (e) {
+ reject(e);
+ }
+ };
+ });
+}
+
+function getAbsoluteUrl(url) {
+ return new URL(url, document.baseURI).toString();
+}
diff --git a/testing/web-platform/tests/web-share/resources/post-message.html b/testing/web-platform/tests/web-share/resources/post-message.html
new file mode 100644
index 0000000000..30134e2901
--- /dev/null
+++ b/testing/web-platform/tests/web-share/resources/post-message.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script>
+ window.addEventListener("message", async (event) => {
+ const {
+ data: { action, data },
+ } = event;
+ const response = {};
+ try {
+ switch (action) {
+ case "share":
+ await test_driver.bless("share");
+ await navigator.share(data);
+ response.result = "unreached";
+ break;
+ case "canShare":
+ response.result = navigator.canShare(data);
+ break;
+ }
+ } catch (error) {
+ response.result = "error";
+ response.error = error.name;
+ } finally {
+ event.source.postMessage({ ...response, action }, "*");
+ }
+ });
+
+ // send message to parent that we loaded
+ function sendLoadMessage() {
+ window.parent.postMessage({ action: "loaded" }, "*");
+ }
+</script>
+<body onload="sendLoadMessage()"></body>