Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / execute_action_unittest.cc
blob7c8eb35227dff59ff988eb1ce1ca186ea090c92a
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/file_system_provider/operations/execute_action.h"
7 #include <string>
8 #include <vector>
10 #include "base/files/file.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
15 #include "chrome/common/extensions/api/file_system_provider.h"
16 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h"
17 #include "chrome/common/extensions/api/file_system_provider_internal.h"
18 #include "extensions/browser/event_router.h"
19 #include "storage/browser/fileapi/async_file_util.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 namespace chromeos {
23 namespace file_system_provider {
24 namespace operations {
25 namespace {
27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
28 const char kFileSystemId[] = "testing-file-system";
29 const int kRequestId = 2;
30 const base::FilePath::CharType kEntryPath[] =
31 FILE_PATH_LITERAL("/kitty/and/puppy/happy");
32 const char kActionId[] = "SHARE";
34 } // namespace
36 class FileSystemProviderOperationsExecuteActionTest : public testing::Test {
37 protected:
38 FileSystemProviderOperationsExecuteActionTest() {}
39 ~FileSystemProviderOperationsExecuteActionTest() override {}
41 void SetUp() override {
42 file_system_info_ = ProvidedFileSystemInfo(
43 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
44 base::FilePath(), false /* configurable */, true /* watchable */,
45 extensions::SOURCE_FILE);
48 ProvidedFileSystemInfo file_system_info_;
51 TEST_F(FileSystemProviderOperationsExecuteActionTest, Execute) {
52 using extensions::api::file_system_provider::ExecuteActionRequestedOptions;
54 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
55 util::StatusCallbackLog callback_log;
57 ExecuteAction execute_action(
58 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId,
59 base::Bind(&util::LogStatusCallback, &callback_log));
60 execute_action.SetDispatchEventImplForTesting(
61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
62 base::Unretained(&dispatcher)));
64 EXPECT_TRUE(execute_action.Execute(kRequestId));
66 ASSERT_EQ(1u, dispatcher.events().size());
67 extensions::Event* event = dispatcher.events()[0];
68 EXPECT_EQ(extensions::api::file_system_provider::OnExecuteActionRequested::
69 kEventName,
70 event->event_name);
71 base::ListValue* event_args = event->event_args.get();
72 ASSERT_EQ(1u, event_args->GetSize());
74 const base::DictionaryValue* options_as_value = NULL;
75 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
77 ExecuteActionRequestedOptions options;
78 ASSERT_TRUE(
79 ExecuteActionRequestedOptions::Populate(*options_as_value, &options));
80 EXPECT_EQ(kFileSystemId, options.file_system_id);
81 EXPECT_EQ(kRequestId, options.request_id);
82 EXPECT_EQ(kEntryPath, options.entry_path);
83 EXPECT_EQ(kActionId, options.action_id);
86 TEST_F(FileSystemProviderOperationsExecuteActionTest, Execute_NoListener) {
87 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
88 util::StatusCallbackLog callback_log;
90 ExecuteAction execute_action(
91 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId,
92 base::Bind(&util::LogStatusCallback, &callback_log));
93 execute_action.SetDispatchEventImplForTesting(
94 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
95 base::Unretained(&dispatcher)));
97 EXPECT_FALSE(execute_action.Execute(kRequestId));
100 TEST_F(FileSystemProviderOperationsExecuteActionTest, OnSuccess) {
101 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
102 util::StatusCallbackLog callback_log;
104 ExecuteAction execute_action(
105 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId,
106 base::Bind(&util::LogStatusCallback, &callback_log));
107 execute_action.SetDispatchEventImplForTesting(
108 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
109 base::Unretained(&dispatcher)));
111 EXPECT_TRUE(execute_action.Execute(kRequestId));
113 execute_action.OnSuccess(kRequestId,
114 scoped_ptr<RequestValue>(new RequestValue()),
115 false /* has_more */);
116 ASSERT_EQ(1u, callback_log.size());
117 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
120 TEST_F(FileSystemProviderOperationsExecuteActionTest, OnError) {
121 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
122 util::StatusCallbackLog callback_log;
124 ExecuteAction execute_action(
125 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId,
126 base::Bind(&util::LogStatusCallback, &callback_log));
127 execute_action.SetDispatchEventImplForTesting(
128 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
129 base::Unretained(&dispatcher)));
131 EXPECT_TRUE(execute_action.Execute(kRequestId));
133 execute_action.OnError(kRequestId,
134 scoped_ptr<RequestValue>(new RequestValue()),
135 base::File::FILE_ERROR_TOO_MANY_OPENED);
136 ASSERT_EQ(1u, callback_log.size());
137 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
140 } // namespace operations
141 } // namespace file_system_provider
142 } // namespace chromeos