OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/file_system_provider/operations/copy_entry.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/move_entry.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" | 14 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" |
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
16 #include "chrome/common/extensions/api/file_system_provider.h" | 16 #include "chrome/common/extensions/api/file_system_provider.h" |
17 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 17 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "webkit/browser/fileapi/async_file_util.h" | 20 #include "webkit/browser/fileapi/async_file_util.h" |
21 | 21 |
22 namespace chromeos { | 22 namespace chromeos { |
23 namespace file_system_provider { | 23 namespace file_system_provider { |
24 namespace operations { | 24 namespace operations { |
25 namespace { | 25 namespace { |
26 | 26 |
27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
28 const char kFileSystemId[] = "testing-file-system"; | 28 const char kFileSystemId[] = "testing-file-system"; |
29 const int kRequestId = 2; | 29 const int kRequestId = 2; |
30 const base::FilePath::CharType kSourcePath[] = "/bunny/and/bear/happy"; | 30 const base::FilePath::CharType kSourcePath[] = "/bunny/and/bear/happy"; |
31 const base::FilePath::CharType kTargetPath[] = "/kitty/and/puppy/happy"; | 31 const base::FilePath::CharType kTargetPath[] = "/kitty/and/puppy/happy"; |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 class FileSystemProviderOperationsCopyEntryTest : public testing::Test { | 35 class FileSystemProviderOperationsMoveEntryTest : public testing::Test { |
36 protected: | 36 protected: |
37 FileSystemProviderOperationsCopyEntryTest() {} | 37 FileSystemProviderOperationsMoveEntryTest() {} |
38 virtual ~FileSystemProviderOperationsCopyEntryTest() {} | 38 virtual ~FileSystemProviderOperationsMoveEntryTest() {} |
39 | 39 |
40 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() OVERRIDE { |
41 file_system_info_ = | 41 file_system_info_ = |
42 ProvidedFileSystemInfo(kExtensionId, | 42 ProvidedFileSystemInfo(kExtensionId, |
43 kFileSystemId, | 43 kFileSystemId, |
44 "" /* file_system_name */, | 44 "" /* file_system_name */, |
45 true /* writable */, | 45 true /* writable */, |
46 base::FilePath() /* mount_path */); | 46 base::FilePath() /* mount_path */); |
47 } | 47 } |
48 | 48 |
49 ProvidedFileSystemInfo file_system_info_; | 49 ProvidedFileSystemInfo file_system_info_; |
50 }; | 50 }; |
51 | 51 |
52 TEST_F(FileSystemProviderOperationsCopyEntryTest, Execute) { | 52 TEST_F(FileSystemProviderOperationsMoveEntryTest, Execute) { |
53 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 53 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
54 util::StatusCallbackLog callback_log; | 54 util::StatusCallbackLog callback_log; |
55 | 55 |
56 CopyEntry copy_entry(NULL, | 56 MoveEntry move_entry(NULL, |
57 file_system_info_, | 57 file_system_info_, |
58 base::FilePath::FromUTF8Unsafe(kSourcePath), | 58 base::FilePath::FromUTF8Unsafe(kSourcePath), |
59 base::FilePath::FromUTF8Unsafe(kTargetPath), | 59 base::FilePath::FromUTF8Unsafe(kTargetPath), |
60 base::Bind(&util::LogStatusCallback, &callback_log)); | 60 base::Bind(&util::LogStatusCallback, &callback_log)); |
61 copy_entry.SetDispatchEventImplForTesting( | 61 move_entry.SetDispatchEventImplForTesting( |
62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
63 base::Unretained(&dispatcher))); | 63 base::Unretained(&dispatcher))); |
64 | 64 |
65 EXPECT_TRUE(copy_entry.Execute(kRequestId)); | 65 EXPECT_TRUE(move_entry.Execute(kRequestId)); |
66 | 66 |
67 ASSERT_EQ(1u, dispatcher.events().size()); | 67 ASSERT_EQ(1u, dispatcher.events().size()); |
68 extensions::Event* event = dispatcher.events()[0]; | 68 extensions::Event* event = dispatcher.events()[0]; |
69 EXPECT_EQ( | 69 EXPECT_EQ( |
70 extensions::api::file_system_provider::OnCopyEntryRequested::kEventName, | 70 extensions::api::file_system_provider::OnMoveEntryRequested::kEventName, |
71 event->event_name); | 71 event->event_name); |
72 base::ListValue* event_args = event->event_args.get(); | 72 base::ListValue* event_args = event->event_args.get(); |
73 ASSERT_EQ(1u, event_args->GetSize()); | 73 ASSERT_EQ(1u, event_args->GetSize()); |
74 | 74 |
75 base::DictionaryValue* options = NULL; | 75 base::DictionaryValue* options = NULL; |
76 ASSERT_TRUE(event_args->GetDictionary(0, &options)); | 76 ASSERT_TRUE(event_args->GetDictionary(0, &options)); |
77 | 77 |
78 std::string event_file_system_id; | 78 std::string event_file_system_id; |
79 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); | 79 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); |
80 EXPECT_EQ(kFileSystemId, event_file_system_id); | 80 EXPECT_EQ(kFileSystemId, event_file_system_id); |
81 | 81 |
82 int event_request_id = -1; | 82 int event_request_id = -1; |
83 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | 83 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); |
84 EXPECT_EQ(kRequestId, event_request_id); | 84 EXPECT_EQ(kRequestId, event_request_id); |
85 | 85 |
86 std::string event_source_path; | 86 std::string event_source_path; |
87 EXPECT_TRUE(options->GetString("sourcePath", &event_source_path)); | 87 EXPECT_TRUE(options->GetString("sourcePath", &event_source_path)); |
88 EXPECT_EQ(kSourcePath, event_source_path); | 88 EXPECT_EQ(kSourcePath, event_source_path); |
89 | 89 |
90 std::string event_target_path; | 90 std::string event_target_path; |
91 EXPECT_TRUE(options->GetString("targetPath", &event_target_path)); | 91 EXPECT_TRUE(options->GetString("targetPath", &event_target_path)); |
92 EXPECT_EQ(kTargetPath, event_target_path); | 92 EXPECT_EQ(kTargetPath, event_target_path); |
93 } | 93 } |
94 | 94 |
95 TEST_F(FileSystemProviderOperationsCopyEntryTest, Execute_NoListener) { | 95 TEST_F(FileSystemProviderOperationsMoveEntryTest, Execute_NoListener) { |
96 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 96 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
97 util::StatusCallbackLog callback_log; | 97 util::StatusCallbackLog callback_log; |
98 | 98 |
99 CopyEntry copy_entry(NULL, | 99 MoveEntry move_entry(NULL, |
100 file_system_info_, | 100 file_system_info_, |
101 base::FilePath::FromUTF8Unsafe(kSourcePath), | 101 base::FilePath::FromUTF8Unsafe(kSourcePath), |
102 base::FilePath::FromUTF8Unsafe(kTargetPath), | 102 base::FilePath::FromUTF8Unsafe(kTargetPath), |
103 base::Bind(&util::LogStatusCallback, &callback_log)); | 103 base::Bind(&util::LogStatusCallback, &callback_log)); |
104 copy_entry.SetDispatchEventImplForTesting( | 104 move_entry.SetDispatchEventImplForTesting( |
105 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 105 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
106 base::Unretained(&dispatcher))); | 106 base::Unretained(&dispatcher))); |
107 | 107 |
108 EXPECT_FALSE(copy_entry.Execute(kRequestId)); | 108 EXPECT_FALSE(move_entry.Execute(kRequestId)); |
109 } | 109 } |
110 | 110 |
111 TEST_F(FileSystemProviderOperationsCopyEntryTest, OnSuccess) { | 111 TEST_F(FileSystemProviderOperationsMoveEntryTest, OnSuccess) { |
112 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 112 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
113 util::StatusCallbackLog callback_log; | 113 util::StatusCallbackLog callback_log; |
114 | 114 |
115 CopyEntry copy_entry(NULL, | 115 MoveEntry move_entry(NULL, |
116 file_system_info_, | 116 file_system_info_, |
117 base::FilePath::FromUTF8Unsafe(kSourcePath), | 117 base::FilePath::FromUTF8Unsafe(kSourcePath), |
118 base::FilePath::FromUTF8Unsafe(kTargetPath), | 118 base::FilePath::FromUTF8Unsafe(kTargetPath), |
119 base::Bind(&util::LogStatusCallback, &callback_log)); | 119 base::Bind(&util::LogStatusCallback, &callback_log)); |
120 copy_entry.SetDispatchEventImplForTesting( | 120 move_entry.SetDispatchEventImplForTesting( |
121 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 121 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
122 base::Unretained(&dispatcher))); | 122 base::Unretained(&dispatcher))); |
123 | 123 |
124 EXPECT_TRUE(copy_entry.Execute(kRequestId)); | 124 EXPECT_TRUE(move_entry.Execute(kRequestId)); |
125 | 125 |
126 copy_entry.OnSuccess(kRequestId, | 126 move_entry.OnSuccess(kRequestId, |
127 scoped_ptr<RequestValue>(new RequestValue()), | 127 scoped_ptr<RequestValue>(new RequestValue()), |
128 false /* has_more */); | 128 false /* has_more */); |
129 ASSERT_EQ(1u, callback_log.size()); | 129 ASSERT_EQ(1u, callback_log.size()); |
130 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); | 130 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); |
131 } | 131 } |
132 | 132 |
133 TEST_F(FileSystemProviderOperationsCopyEntryTest, OnError) { | 133 TEST_F(FileSystemProviderOperationsMoveEntryTest, OnError) { |
134 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 134 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
135 util::StatusCallbackLog callback_log; | 135 util::StatusCallbackLog callback_log; |
136 | 136 |
137 CopyEntry copy_entry(NULL, | 137 MoveEntry move_entry(NULL, |
138 file_system_info_, | 138 file_system_info_, |
139 base::FilePath::FromUTF8Unsafe(kSourcePath), | 139 base::FilePath::FromUTF8Unsafe(kSourcePath), |
140 base::FilePath::FromUTF8Unsafe(kTargetPath), | 140 base::FilePath::FromUTF8Unsafe(kTargetPath), |
141 base::Bind(&util::LogStatusCallback, &callback_log)); | 141 base::Bind(&util::LogStatusCallback, &callback_log)); |
142 copy_entry.SetDispatchEventImplForTesting( | 142 move_entry.SetDispatchEventImplForTesting( |
143 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 143 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
144 base::Unretained(&dispatcher))); | 144 base::Unretained(&dispatcher))); |
145 | 145 |
146 EXPECT_TRUE(copy_entry.Execute(kRequestId)); | 146 EXPECT_TRUE(move_entry.Execute(kRequestId)); |
147 | 147 |
148 copy_entry.OnError(kRequestId, | 148 move_entry.OnError(kRequestId, |
149 scoped_ptr<RequestValue>(new RequestValue()), | 149 scoped_ptr<RequestValue>(new RequestValue()), |
150 base::File::FILE_ERROR_TOO_MANY_OPENED); | 150 base::File::FILE_ERROR_TOO_MANY_OPENED); |
151 ASSERT_EQ(1u, callback_log.size()); | 151 ASSERT_EQ(1u, callback_log.size()); |
152 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 152 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
153 } | 153 } |
154 | 154 |
155 } // namespace operations | 155 } // namespace operations |
156 } // namespace file_system_provider | 156 } // namespace file_system_provider |
157 } // namespace chromeos | 157 } // namespace chromeos |
OLD | NEW |