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