Commit ba2b3055 authored by Satoshi Niwa's avatar Satoshi Niwa Committed by Commit Bot

Small mojo change for ARC file picker

- New field SelectFilesResult->picker_activity
- New enum value FileSelectorEventType::CLICK_CANCEL

SelectFilesResult and FileSelectorEventType are not used in released
clients yet, so it's safe to modify them

Design doc : go/arc-file-picker-get-content

BUG=b:130204519
TEST=unit_tests --gtest_filter="ArcSelectFilesHandlerTest.*"

Debug File Manager GET_CONTENT implementation

Change-Id: Id28bda1e1f96dc11072c34db9b4edcda9d14c50a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1580692
Commit-Queue: Satoshi Niwa <niwa@chromium.org>
Auto-Submit: Satoshi Niwa <niwa@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Reviewed-by: default avatarGreg Kerr <kerrnel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658409}
parent fb4105a3
......@@ -13,6 +13,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_select_files_util.h"
#include "chrome/browser/chromeos/file_manager/app_id.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/file_manager/path_util.h"
......@@ -36,6 +37,10 @@ namespace arc {
const char kScriptClickOk[] =
"(function() { document.querySelector('#ok-button').click(); })();";
// Script for clicking Cancel button on the selector.
const char kScriptClickCancel[] =
"(function() { document.querySelector('#cancel-button').click(); })();";
// Script for clicking a directory element in the left pane of the selector.
// %s should be replaced by the target directory name wrapped by double-quotes.
const char kScriptClickDirectory[] =
......@@ -183,6 +188,17 @@ void ArcSelectFilesHandler::FileSelected(const base::FilePath& path,
int index,
void* params) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(callback_);
const std::string& activity = ConvertFilePathToAndroidActivity(path);
if (!activity.empty()) {
// The user selected an Android picker activity instead of a file.
mojom::SelectFilesResultPtr result = mojom::SelectFilesResult::New();
result->picker_activity = activity;
std::move(callback_).Run(std::move(result));
return;
}
std::vector<base::FilePath> files;
files.push_back(path);
FilesSelectedInternal(files, params);
......@@ -236,6 +252,9 @@ void ArcSelectFilesHandler::OnFileSelectorEvent(
case mojom::FileSelectorEventType::CLICK_OK:
script = kScriptClickOk;
break;
case mojom::FileSelectorEventType::CLICK_CANCEL:
script = kScriptClickCancel;
break;
case mojom::FileSelectorEventType::CLICK_DIRECTORY:
script = base::StringPrintf(kScriptClickDirectory,
quotedClickTargetName.c_str());
......
......@@ -27,6 +27,7 @@ class SelectFileDialogHolder;
// Exposed for testing.
extern const char kScriptClickOk[];
extern const char kScriptClickCancel[];
extern const char kScriptClickDirectory[];
extern const char kScriptClickFile[];
extern const char kScriptGetElements[];
......
......@@ -9,6 +9,7 @@
#include "base/json/json_reader.h"
#include "base/strings/stringprintf.h"
#include "base/test/mock_callback.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_select_files_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "chrome/test/base/testing_browser_process.h"
......@@ -44,6 +45,15 @@ MATCHER_P(FilePathMatcher, expected, "") {
return true;
}
MATCHER_P(SelectFilesResultMatcher, expected, "") {
EXPECT_EQ(expected->urls.size(), arg->urls.size());
for (size_t i = 0; i < expected->urls.size(); ++i) {
EXPECT_EQ(expected->urls[i], arg->urls[i]);
}
EXPECT_EQ(expected->picker_activity, arg->picker_activity);
return true;
}
MATCHER_P(FileSelectorElementsMatcher, expected, "") {
EXPECT_EQ(expected->directory_elements.size(),
arg->directory_elements.size());
......@@ -225,6 +235,29 @@ TEST_F(ArcSelectFilesHandlerTest, FileSelected_CallbackCalled) {
arc_select_files_handler_->FileSelected(base::FilePath(), 0, nullptr);
}
TEST_F(ArcSelectFilesHandlerTest, FileSelected_PickerActivitySelected) {
std::string package_name = "com.google.photos";
std::string activity_name = ".PickerActivity";
SelectFilesRequestPtr request = SelectFilesRequest::New();
request->action_type = SelectFilesActionType::OPEN_DOCUMENT;
base::MockCallback<SelectFilesCallback> callback;
arc_select_files_handler_->SelectFiles(request, callback.Get());
mojom::SelectFilesResultPtr expected_result = mojom::SelectFilesResult::New();
expected_result->picker_activity =
base::StringPrintf("%s/%s", package_name.c_str(), activity_name.c_str());
EXPECT_CALL(std::move(callback),
Run(SelectFilesResultMatcher(expected_result.get())))
.Times(1);
arc_select_files_handler_->FileSelected(
ConvertAndroidActivityToFilePath(package_name, activity_name), 0,
nullptr);
}
TEST_F(ArcSelectFilesHandlerTest, FileSelectionCanceled_CallbackCalled) {
SelectFilesRequestPtr request = SelectFilesRequest::New();
request->action_type = SelectFilesActionType::OPEN_DOCUMENT;
......@@ -232,13 +265,19 @@ TEST_F(ArcSelectFilesHandlerTest, FileSelectionCanceled_CallbackCalled) {
base::MockCallback<SelectFilesCallback> callback;
arc_select_files_handler_->SelectFiles(request, callback.Get());
EXPECT_CALL(std::move(callback), Run(_)).Times(1);
mojom::SelectFilesResultPtr expected_result = mojom::SelectFilesResult::New();
EXPECT_CALL(std::move(callback),
Run(SelectFilesResultMatcher(expected_result.get())))
.Times(1);
arc_select_files_handler_->FileSelectionCanceled(nullptr);
}
TEST_F(ArcSelectFilesHandlerTest, OnFileSelectorEvent) {
CallOnFileSelectorEventAndCheckScript(mojom::FileSelectorEventType::CLICK_OK,
"", kScriptClickOk);
CallOnFileSelectorEventAndCheckScript(
mojom::FileSelectorEventType::CLICK_CANCEL, "", kScriptClickCancel);
CallOnFileSelectorEventAndCheckScript(
mojom::FileSelectorEventType::CLICK_DIRECTORY, "Click Target",
base::StringPrintf(kScriptClickDirectory, "\"Click Target\""));
......
......@@ -181,6 +181,11 @@ struct SelectFilesResult {
// Content URLs of the selected files.
// Empty if the user closes the file selector without selecting any files.
array<url.mojom.Url> urls;
// Name of the selected Android picker activity.
// Filled only when the user selected an Android picker activity instead of
// selecting files. (e.g. "com.google.photos/.PickerActivity")
string? picker_activity;
};
// UI event to be dispatched to ChromeOS file selector.
......@@ -198,6 +203,7 @@ enum FileSelectorEventType {
CLICK_OK, // Clicks OK button.
CLICK_DIRECTORY, // Clicks a directory in the left pane.
CLICK_FILE, // Clicks a file in the right pane.
CLICK_CANCEL, // Clicks Cancel button.
};
// Represents a clickable UI element shown on ChromeOS file selector.
......
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