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 0000000000000..e9b43b98bb565 --- /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 1ae8593908ac8..6c17882e8814f 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:
+ +