Commit 8fa4a8f2 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[filesapp] Add DocumentsProvider file content in test

CL:1483697 added a mock arc::FileSystemInstance (ie Mojo interfaces to
interact with ARC container) for use with DocumentsProvider volumes in
test. Entries can be added to the test DocumentsProvider volume (works
fine) but the content of file entries is not shown in Quick View tests
per issue 1131298.

Fix this: arc::FileSystemInstance requires that the content of entries
is provided to it using its AddFile() API. Do that and update the test
added in CL:1483697 to verify the text file content is shown.

Test: browser_tests --gtest_filter="*openQuickViewDocumentsProvider"
Bug: 1131298, 1049966, 923991
Change-Id: I992dc69e3a9e7421e94a88e62edfed56b6d8e465
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2469336
Commit-Queue: Noel Gordon <noel@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Auto-Submit: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816890}
parent ae11335e
......@@ -15,6 +15,7 @@
#include "base/bind_helpers.h"
#include "base/containers/circular_deque.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/json/json_value_converter.h"
#include "base/json/json_writer.h"
......@@ -108,6 +109,7 @@
#include "ui/shell_dialogs/select_file_dialog.h"
#include "ui/shell_dialogs/select_file_dialog_factory.h"
#include "ui/shell_dialogs/select_file_policy.h"
#include "url/url_util.h"
using ::testing::_;
......@@ -1278,16 +1280,26 @@ class DocumentsProviderTestVolume : public TestVolume {
~DocumentsProviderTestVolume() override = default;
virtual void CreateEntry(const AddEntriesMessage::TestEntryInfo& entry) {
// Register a document to the fake FileSystemInstance.
// Create and add an entry Document to the fake arc::FileSystemInstance.
arc::FakeFileSystemInstance::Document document(
authority_, entry.name_text, root_document_id_, entry.name_text,
GetMimeType(entry), GetFileSize(entry),
entry.last_modified_time.ToJavaTime(), entry.capabilities.can_delete,
entry.capabilities.can_rename, entry.capabilities.can_add_children);
file_system_instance_->AddDocument(document);
if (entry.type != AddEntriesMessage::FILE)
return;
std::string canonical_url = base::StrCat(
{"content://", authority_, "/document/", EncodeURI(entry.name_text)});
file_system_instance_->AddFile(arc::FakeFileSystemInstance::File(
canonical_url, GetTestFileContent(entry.source_file_name),
GetMimeType(entry), arc::FakeFileSystemInstance::File::Seekable::NO));
}
virtual bool Mount(Profile* profile) {
// Register the volume root document.
RegisterRoot();
// Tell VolumeManager that a new DocumentsProvider volume is added.
......@@ -1303,12 +1315,10 @@ class DocumentsProviderTestVolume : public TestVolume {
const std::string root_document_id_;
const bool read_only_;
// Register a root document of this volume.
void RegisterRoot() {
arc::FakeFileSystemInstance::Document document(
authority_, root_document_id_, "", "", arc::kAndroidDirectoryMimeType,
0, 0);
file_system_instance_->AddDocument(document);
const auto* root_mime_type = arc::kAndroidDirectoryMimeType;
file_system_instance_->AddDocument(arc::FakeFileSystemInstance::Document(
authority_, root_document_id_, "", "", root_mime_type, 0, 0));
}
private:
......@@ -1329,6 +1339,21 @@ class DocumentsProviderTestVolume : public TestVolume {
: arc::kAndroidDirectoryMimeType;
}
std::string GetTestFileContent(const std::string& test_file_name) {
base::ScopedAllowBlockingForTesting allow_blocking;
std::string contents;
base::FilePath path = TestVolume::GetTestDataFilePath(test_file_name);
CHECK(base::ReadFileToString(path, &contents))
<< "failed reading test data file " << test_file_name;
return contents;
}
std::string EncodeURI(const std::string& component) {
url::RawCanonOutputT<char> encoded;
url::EncodeURIComponent(component.c_str(), component.size(), &encoded);
return std::string(encoded.data(), encoded.length());
}
DISALLOW_COPY_AND_ASSIGN(DocumentsProviderTestVolume);
};
......@@ -1751,9 +1776,8 @@ void FileManagerBrowserTestBase::SetUpOnMainThread() {
base::Unretained(this)));
if (arc::IsArcAvailable()) {
// When ARC is marked as available, we create fake FileSystemInstance and
// register it so that ARC-related services can work without real ARC
// container.
// When ARC is available, create and register a fake FileSystemInstance
// so ARC-related services work without a real ARC container.
arc_file_system_instance_ =
std::make_unique<arc::FakeFileSystemInstance>();
arc::ArcServiceManager::Get()
......
......@@ -529,9 +529,39 @@
// Open a DocumentsProvider file in Quick View.
await openQuickView(appId, ENTRIES.hello.nameText);
// crbug.com/1131298 The text file content is not displayed. The <webview>
// instead shows a "site cannot be reached" error.
return IGNORE_APP_ERRORS;
/**
* The text <webview> resides in the #quick-view shadow DOM, as a child of
* the #dialog element.
*/
const webView = ['#quick-view', '#dialog[open] webview.text-content'];
// Wait for the Quick View <webview> to load and display its content.
const caller = getCaller();
function checkWebViewTextLoaded(elements) {
let haveElements = Array.isArray(elements) && elements.length === 1;
if (haveElements) {
haveElements = elements[0].styles.display.includes('block');
}
if (!haveElements || !elements[0].attributes.src) {
return pending(caller, 'Waiting for <webview> to load.');
}
return;
}
await repeatUntil(async () => {
return checkWebViewTextLoaded(await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [webView, ['display']]));
});
// Wait until the <webview> displays the file's content.
await repeatUntil(async () => {
const getTextContent = 'window.document.body.textContent';
const text = await remoteCall.callRemoteTestUtil(
'deepExecuteScriptInWebView', appId, [webView, getTextContent]);
// Check: the content of text file should be shown.
if (!text || !text[0].includes('I like chocolate and chips.')) {
return pending(caller, 'Waiting for <webview> content.');
}
});
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment