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 / move_entry_unittest.cc
blob643f636986f589283325ed62f3314893abdb07a2
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/move_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_capabilities/file_system_provider_capabilities_handler.h"
18 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h"
19 #include "chrome/common/extensions/api/file_system_provider_internal.h"
20 #include "extensions/browser/event_router.h"
21 #include "storage/browser/fileapi/async_file_util.h"
22 #include "testing/gtest/include/gtest/gtest.h"
24 namespace chromeos {
25 namespace file_system_provider {
26 namespace operations {
27 namespace {
29 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
30 const char kFileSystemId[] = "testing-file-system";
31 const int kRequestId = 2;
32 const base::FilePath::CharType kSourcePath[] =
33 FILE_PATH_LITERAL("/bunny/and/bear/happy");
34 const base::FilePath::CharType kTargetPath[] =
35 FILE_PATH_LITERAL("/kitty/and/puppy/happy");
37 } // namespace
39 class FileSystemProviderOperationsMoveEntryTest : public testing::Test {
40 protected:
41 FileSystemProviderOperationsMoveEntryTest() {}
42 ~FileSystemProviderOperationsMoveEntryTest() override {}
44 void SetUp() override {
45 MountOptions mount_options(kFileSystemId, "" /* display_name */);
46 mount_options.writable = true;
47 file_system_info_ = ProvidedFileSystemInfo(
48 kExtensionId, mount_options, base::FilePath(), false /* configurable */,
49 true /* watchable */, extensions::SOURCE_FILE);
52 ProvidedFileSystemInfo file_system_info_;
55 TEST_F(FileSystemProviderOperationsMoveEntryTest, Execute) {
56 using extensions::api::file_system_provider::MoveEntryRequestedOptions;
58 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
59 util::StatusCallbackLog callback_log;
61 MoveEntry move_entry(NULL, file_system_info_, base::FilePath(kSourcePath),
62 base::FilePath(kTargetPath),
63 base::Bind(&util::LogStatusCallback, &callback_log));
64 move_entry.SetDispatchEventImplForTesting(
65 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
66 base::Unretained(&dispatcher)));
68 EXPECT_TRUE(move_entry.Execute(kRequestId));
70 ASSERT_EQ(1u, dispatcher.events().size());
71 extensions::Event* event = dispatcher.events()[0];
72 EXPECT_EQ(
73 extensions::api::file_system_provider::OnMoveEntryRequested::kEventName,
74 event->event_name);
75 base::ListValue* event_args = event->event_args.get();
76 ASSERT_EQ(1u, event_args->GetSize());
78 const base::DictionaryValue* options_as_value = NULL;
79 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
81 MoveEntryRequestedOptions options;
82 ASSERT_TRUE(MoveEntryRequestedOptions::Populate(*options_as_value, &options));
83 EXPECT_EQ(kFileSystemId, options.file_system_id);
84 EXPECT_EQ(kRequestId, options.request_id);
85 EXPECT_EQ(kSourcePath, options.source_path);
86 EXPECT_EQ(kTargetPath, options.target_path);
89 TEST_F(FileSystemProviderOperationsMoveEntryTest, Execute_NoListener) {
90 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
91 util::StatusCallbackLog callback_log;
93 MoveEntry move_entry(NULL, file_system_info_, base::FilePath(kSourcePath),
94 base::FilePath(kTargetPath),
95 base::Bind(&util::LogStatusCallback, &callback_log));
96 move_entry.SetDispatchEventImplForTesting(
97 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
98 base::Unretained(&dispatcher)));
100 EXPECT_FALSE(move_entry.Execute(kRequestId));
103 TEST_F(FileSystemProviderOperationsMoveEntryTest, Execute_ReadOnly) {
104 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
105 util::StatusCallbackLog callback_log;
107 const ProvidedFileSystemInfo read_only_file_system_info(
108 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
109 base::FilePath() /* mount_path */, false /* configurable */,
110 true /* watchable */, extensions::SOURCE_FILE);
112 MoveEntry move_entry(NULL, read_only_file_system_info,
113 base::FilePath(kSourcePath), base::FilePath(kTargetPath),
114 base::Bind(&util::LogStatusCallback, &callback_log));
115 move_entry.SetDispatchEventImplForTesting(
116 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
117 base::Unretained(&dispatcher)));
119 EXPECT_FALSE(move_entry.Execute(kRequestId));
122 TEST_F(FileSystemProviderOperationsMoveEntryTest, OnSuccess) {
123 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
124 util::StatusCallbackLog callback_log;
126 MoveEntry move_entry(NULL, file_system_info_, base::FilePath(kSourcePath),
127 base::FilePath(kTargetPath),
128 base::Bind(&util::LogStatusCallback, &callback_log));
129 move_entry.SetDispatchEventImplForTesting(
130 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
131 base::Unretained(&dispatcher)));
133 EXPECT_TRUE(move_entry.Execute(kRequestId));
135 move_entry.OnSuccess(kRequestId,
136 scoped_ptr<RequestValue>(new RequestValue()),
137 false /* has_more */);
138 ASSERT_EQ(1u, callback_log.size());
139 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
142 TEST_F(FileSystemProviderOperationsMoveEntryTest, OnError) {
143 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
144 util::StatusCallbackLog callback_log;
146 MoveEntry move_entry(NULL, file_system_info_, base::FilePath(kSourcePath),
147 base::FilePath(kTargetPath),
148 base::Bind(&util::LogStatusCallback, &callback_log));
149 move_entry.SetDispatchEventImplForTesting(
150 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
151 base::Unretained(&dispatcher)));
153 EXPECT_TRUE(move_entry.Execute(kRequestId));
155 move_entry.OnError(kRequestId,
156 scoped_ptr<RequestValue>(new RequestValue()),
157 base::File::FILE_ERROR_TOO_MANY_OPENED);
158 ASSERT_EQ(1u, callback_log.size());
159 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
162 } // namespace operations
163 } // namespace file_system_provider
164 } // namespace chromeos