Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / copy_entry_unittest.cc
blob8a5654ed2a5273a5ba7c7680b4c69872667633a7
1 // Copyright 2014 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/copy_entry.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_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 kSourcePath[] =
31 FILE_PATH_LITERAL("/bunny/and/bear/happy");
32 const base::FilePath::CharType kTargetPath[] =
33 FILE_PATH_LITERAL("/kitty/and/puppy/happy");
35 } // namespace
37 class FileSystemProviderOperationsCopyEntryTest : public testing::Test {
38 protected:
39 FileSystemProviderOperationsCopyEntryTest() {}
40 ~FileSystemProviderOperationsCopyEntryTest() override {}
42 void SetUp() override {
43 MountOptions mount_options(kFileSystemId, "" /* display_name */);
44 mount_options.writable = true;
45 file_system_info_ =
46 ProvidedFileSystemInfo(kExtensionId, mount_options, base::FilePath());
49 ProvidedFileSystemInfo file_system_info_;
52 TEST_F(FileSystemProviderOperationsCopyEntryTest, Execute) {
53 using extensions::api::file_system_provider::CopyEntryRequestedOptions;
55 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
56 util::StatusCallbackLog callback_log;
58 CopyEntry copy_entry(NULL, file_system_info_, base::FilePath(kSourcePath),
59 base::FilePath(kTargetPath),
60 base::Bind(&util::LogStatusCallback, &callback_log));
61 copy_entry.SetDispatchEventImplForTesting(
62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
63 base::Unretained(&dispatcher)));
65 EXPECT_TRUE(copy_entry.Execute(kRequestId));
67 ASSERT_EQ(1u, dispatcher.events().size());
68 extensions::Event* event = dispatcher.events()[0];
69 EXPECT_EQ(
70 extensions::api::file_system_provider::OnCopyEntryRequested::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 CopyEntryRequestedOptions options;
79 ASSERT_TRUE(CopyEntryRequestedOptions::Populate(*options_as_value, &options));
80 EXPECT_EQ(kFileSystemId, options.file_system_id);
81 EXPECT_EQ(kRequestId, options.request_id);
82 EXPECT_EQ(kSourcePath, options.source_path);
83 EXPECT_EQ(kTargetPath, options.target_path);
86 TEST_F(FileSystemProviderOperationsCopyEntryTest, Execute_NoListener) {
87 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
88 util::StatusCallbackLog callback_log;
90 CopyEntry copy_entry(NULL, file_system_info_, base::FilePath(kSourcePath),
91 base::FilePath(kTargetPath),
92 base::Bind(&util::LogStatusCallback, &callback_log));
93 copy_entry.SetDispatchEventImplForTesting(
94 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
95 base::Unretained(&dispatcher)));
97 EXPECT_FALSE(copy_entry.Execute(kRequestId));
100 TEST_F(FileSystemProviderOperationsCopyEntryTest, Execute_ReadOnly) {
101 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
102 util::StatusCallbackLog callback_log;
104 const ProvidedFileSystemInfo read_only_file_system_info(
105 kExtensionId,
106 MountOptions(kFileSystemId, "" /* display_name */),
107 base::FilePath() /* mount_path */);
109 CopyEntry copy_entry(NULL, read_only_file_system_info,
110 base::FilePath(kSourcePath), base::FilePath(kTargetPath),
111 base::Bind(&util::LogStatusCallback, &callback_log));
112 copy_entry.SetDispatchEventImplForTesting(
113 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
114 base::Unretained(&dispatcher)));
116 EXPECT_FALSE(copy_entry.Execute(kRequestId));
119 TEST_F(FileSystemProviderOperationsCopyEntryTest, OnSuccess) {
120 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
121 util::StatusCallbackLog callback_log;
123 CopyEntry copy_entry(NULL, file_system_info_, base::FilePath(kSourcePath),
124 base::FilePath(kTargetPath),
125 base::Bind(&util::LogStatusCallback, &callback_log));
126 copy_entry.SetDispatchEventImplForTesting(
127 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
128 base::Unretained(&dispatcher)));
130 EXPECT_TRUE(copy_entry.Execute(kRequestId));
132 copy_entry.OnSuccess(kRequestId,
133 scoped_ptr<RequestValue>(new RequestValue()),
134 false /* has_more */);
135 ASSERT_EQ(1u, callback_log.size());
136 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
139 TEST_F(FileSystemProviderOperationsCopyEntryTest, OnError) {
140 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
141 util::StatusCallbackLog callback_log;
143 CopyEntry copy_entry(NULL, file_system_info_, base::FilePath(kSourcePath),
144 base::FilePath(kTargetPath),
145 base::Bind(&util::LogStatusCallback, &callback_log));
146 copy_entry.SetDispatchEventImplForTesting(
147 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
148 base::Unretained(&dispatcher)));
150 EXPECT_TRUE(copy_entry.Execute(kRequestId));
152 copy_entry.OnError(kRequestId,
153 scoped_ptr<RequestValue>(new RequestValue()),
154 base::File::FILE_ERROR_TOO_MANY_OPENED);
155 ASSERT_EQ(1u, callback_log.size());
156 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
159 } // namespace operations
160 } // namespace file_system_provider
161 } // namespace chromeos