Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / execute_action_unittest.cc
blobf89c4d274f4d1cefbcf7b202171cdb9c75621749
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 "base/memory/scoped_vector.h"
14 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
16 #include "chrome/common/extensions/api/file_system_provider.h"
17 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h"
18 #include "chrome/common/extensions/api/file_system_provider_internal.h"
19 #include "extensions/browser/event_router.h"
20 #include "storage/browser/fileapi/async_file_util.h"
21 #include "testing/gtest/include/gtest/gtest.h"
23 namespace chromeos {
24 namespace file_system_provider {
25 namespace operations {
26 namespace {
28 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
29 const char kFileSystemId[] = "testing-file-system";
30 const int kRequestId = 2;
31 const base::FilePath::CharType kEntryPath[] =
32 FILE_PATH_LITERAL("/kitty/and/puppy/happy");
33 const char kActionId[] = "SHARE";
35 } // namespace
37 class FileSystemProviderOperationsExecuteActionTest : public testing::Test {
38 protected:
39 FileSystemProviderOperationsExecuteActionTest() {}
40 ~FileSystemProviderOperationsExecuteActionTest() override {}
42 void SetUp() override {
43 file_system_info_ = ProvidedFileSystemInfo(
44 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
45 base::FilePath(), false /* configurable */, true /* watchable */,
46 extensions::SOURCE_FILE);
49 ProvidedFileSystemInfo file_system_info_;
52 TEST_F(FileSystemProviderOperationsExecuteActionTest, Execute) {
53 using extensions::api::file_system_provider::ExecuteActionRequestedOptions;
55 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
56 util::StatusCallbackLog callback_log;
58 ExecuteAction execute_action(
59 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId,
60 base::Bind(&util::LogStatusCallback, &callback_log));
61 execute_action.SetDispatchEventImplForTesting(
62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
63 base::Unretained(&dispatcher)));
65 EXPECT_TRUE(execute_action.Execute(kRequestId));
67 ASSERT_EQ(1u, dispatcher.events().size());
68 extensions::Event* event = dispatcher.events()[0];
69 EXPECT_EQ(extensions::api::file_system_provider::OnExecuteActionRequested::
70 kEventName,
71 event->event_name);
72 base::ListValue* event_args = event->event_args.get();
73 ASSERT_EQ(1u, event_args->GetSize());
75 const base::DictionaryValue* options_as_value = NULL;
76 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
78 ExecuteActionRequestedOptions options;
79 ASSERT_TRUE(
80 ExecuteActionRequestedOptions::Populate(*options_as_value, &options));
81 EXPECT_EQ(kFileSystemId, options.file_system_id);
82 EXPECT_EQ(kRequestId, options.request_id);
83 EXPECT_EQ(kEntryPath, options.entry_path);
84 EXPECT_EQ(kActionId, options.action_id);
87 TEST_F(FileSystemProviderOperationsExecuteActionTest, Execute_NoListener) {
88 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
89 util::StatusCallbackLog callback_log;
91 ExecuteAction execute_action(
92 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId,
93 base::Bind(&util::LogStatusCallback, &callback_log));
94 execute_action.SetDispatchEventImplForTesting(
95 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
96 base::Unretained(&dispatcher)));
98 EXPECT_FALSE(execute_action.Execute(kRequestId));
101 TEST_F(FileSystemProviderOperationsExecuteActionTest, OnSuccess) {
102 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
103 util::StatusCallbackLog callback_log;
105 ExecuteAction execute_action(
106 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId,
107 base::Bind(&util::LogStatusCallback, &callback_log));
108 execute_action.SetDispatchEventImplForTesting(
109 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
110 base::Unretained(&dispatcher)));
112 EXPECT_TRUE(execute_action.Execute(kRequestId));
114 execute_action.OnSuccess(kRequestId,
115 scoped_ptr<RequestValue>(new RequestValue()),
116 false /* has_more */);
117 ASSERT_EQ(1u, callback_log.size());
118 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
121 TEST_F(FileSystemProviderOperationsExecuteActionTest, OnError) {
122 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
123 util::StatusCallbackLog callback_log;
125 ExecuteAction execute_action(
126 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId,
127 base::Bind(&util::LogStatusCallback, &callback_log));
128 execute_action.SetDispatchEventImplForTesting(
129 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
130 base::Unretained(&dispatcher)));
132 EXPECT_TRUE(execute_action.Execute(kRequestId));
134 execute_action.OnError(kRequestId,
135 scoped_ptr<RequestValue>(new RequestValue()),
136 base::File::FILE_ERROR_TOO_MANY_OPENED);
137 ASSERT_EQ(1u, callback_log.size());
138 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
141 } // namespace operations
142 } // namespace file_system_provider
143 } // namespace chromeos