From fd8ca9bb66bbe7a124251e64f05a79e27664e732 Mon Sep 17 00:00:00 2001
From: Clifford Cheng
Date: Fri, 16 Dec 2022 23:54:11 +0000
Subject: [PATCH] [dpwa] Update the file handler app to load .foo (txt) files.
The file name and the content will be displayed in the app after
finished loading.
Bug: 1401133
Change-Id: I90af66fcc5da12b6573ec244cc41093d2165052a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4108946
Reviewed-by: Daniel Murphy
Commit-Queue: Clifford Cheng
Cr-Commit-Position: refs/heads/main@{#1084607}
---
.../webapps_integration/file_handler/app.js | 55 +++++++++++++++++++
.../{image_handler.html => bar_handler.html} | 0
.../{text_handler.html => foo_handler.html} | 16 ++++++
3 files changed, 71 insertions(+)
create mode 100644 chrome/test/data/webapps_integration/file_handler/app.js
rename chrome/test/data/webapps_integration/file_handler/{image_handler.html => bar_handler.html} (100%)
rename chrome/test/data/webapps_integration/file_handler/{text_handler.html => foo_handler.html} (60%)
diff --git a/chrome/test/data/webapps_integration/file_handler/app.js b/chrome/test/data/webapps_integration/file_handler/app.js
new file mode 100644
index 00000000000000..e9b43b98bb5650
--- /dev/null
+++ b/chrome/test/data/webapps_integration/file_handler/app.js
@@ -0,0 +1,55 @@
+// Copyright 2022 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+const openedFilesContainer = document.getElementById(
+ "opened-files-container"
+);
+
+const makeFileViewer = async (launchFile) => {
+ const readHandle = await launchFile.getFile();
+
+ const template = document.getElementById("file-viewer-template");
+ const fullName = readHandle.name;
+ const element = template.content.cloneNode(true);
+ const nameContainer = element.querySelector("[name='file-name']");
+ nameContainer.innerText = fullName;
+
+ const contentContainer = element.querySelector("[name='file-contents']");
+ contentContainer.innerText = "Loading...";
+ // Asynchronously load in the file contents.
+ try {
+ contentContainer.value = await readHandle.text();
+ } catch (err) {
+ console.log(`Failed to load contents for file: ${readHandle.name}`, err);
+ }
+
+ return element;
+};
+
+var resolveLaunchFinished;
+
+var launchFinishedPromise = new Promise(resolve => {
+ window.launchQueue.setConsumer(async (launchParams) => {
+ console.log("Launched with: ", launchParams);
+ const viewersContainer = document.getElementById("viewers-container");
+ if (!launchParams.files.length) {
+ viewersContainer.innerText =
+ "Oh poo, no files. Consider granting the permission next time!";
+ return;
+ }
+
+ for (const launchFile of launchParams.files) {
+ const editor = await makeFileViewer(launchFile);
+ openedFilesContainer.appendChild(editor);
+ }
+ let results = [];
+ const fileContents = openedFilesContainer.querySelectorAll(
+ "[name='file-contents']");
+ for (const fileContent of fileContents) {
+ results.push(fileContent.value);
+ }
+ resolve(results);
+ })
+ });
diff --git a/chrome/test/data/webapps_integration/file_handler/image_handler.html b/chrome/test/data/webapps_integration/file_handler/bar_handler.html
similarity index 100%
rename from chrome/test/data/webapps_integration/file_handler/image_handler.html
rename to chrome/test/data/webapps_integration/file_handler/bar_handler.html
diff --git a/chrome/test/data/webapps_integration/file_handler/text_handler.html b/chrome/test/data/webapps_integration/file_handler/foo_handler.html
similarity index 60%
rename from chrome/test/data/webapps_integration/file_handler/text_handler.html
rename to chrome/test/data/webapps_integration/file_handler/foo_handler.html
index 1ae8593908ac8a..6c17882e8814f3 100644
--- a/chrome/test/data/webapps_integration/file_handler/text_handler.html
+++ b/chrome/test/data/webapps_integration/file_handler/foo_handler.html
@@ -3,6 +3,7 @@
File Handler - Text Handler
+
File Handler - Text Handler
@@ -16,5 +17,20 @@ File Handler - Text Handler
href="https://chromium.googlesource.com/chromium/src/+/main/docs/webapps/integration-testing-framework.md">https://chromium.googlesource.com/chromium/src/+/main/docs/webapps/integration-testing-framework.md
+
+
+
+
+
+