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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 private: | 43 private: |
44 ScopedVector<extensions::Event> events_; | 44 ScopedVector<extensions::Event> events_; |
45 bool dispatch_reply_; | 45 bool dispatch_reply_; |
46 | 46 |
47 DISALLOW_COPY_AND_ASSIGN(LoggingDispatchEventImpl); | 47 DISALLOW_COPY_AND_ASSIGN(LoggingDispatchEventImpl); |
48 }; | 48 }; |
49 | 49 |
50 // Callback invocation logger. Acts as a fileapi end-point. | 50 // Callback invocation logger. Acts as a fileapi end-point. |
51 class CallbackLogger { | 51 class CallbackLogger { |
52 public: | 52 public: |
53 CallbackLogger() : weak_ptr_factory_(this) {} | 53 CallbackLogger() {} |
54 virtual ~CallbackLogger() {} | 54 virtual ~CallbackLogger() {} |
55 | 55 |
56 void OnUnmount(base::File::Error result) { events_.push_back(result); } | 56 void OnUnmount(base::File::Error result) { events_.push_back(result); } |
57 | 57 |
58 std::vector<base::File::Error>& events() { return events_; } | 58 std::vector<base::File::Error>& events() { return events_; } |
59 | 59 |
60 base::WeakPtr<CallbackLogger> GetWeakPtr() { | |
61 return weak_ptr_factory_.GetWeakPtr(); | |
62 } | |
63 | |
64 private: | 60 private: |
65 std::vector<base::File::Error> events_; | 61 std::vector<base::File::Error> events_; |
66 bool dispatch_reply_; | 62 bool dispatch_reply_; |
67 base::WeakPtrFactory<CallbackLogger> weak_ptr_factory_; | |
68 | 63 |
69 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); | 64 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); |
70 }; | 65 }; |
71 | 66 |
72 } // namespace | 67 } // namespace |
73 | 68 |
74 class FileSystemProviderOperationsUnmountTest : public testing::Test { | 69 class FileSystemProviderOperationsUnmountTest : public testing::Test { |
75 protected: | 70 protected: |
76 FileSystemProviderOperationsUnmountTest() {} | 71 FileSystemProviderOperationsUnmountTest() {} |
77 virtual ~FileSystemProviderOperationsUnmountTest() {} | 72 virtual ~FileSystemProviderOperationsUnmountTest() {} |
78 | 73 |
79 virtual void SetUp() OVERRIDE { | 74 virtual void SetUp() OVERRIDE { |
80 file_system_info_ = | 75 file_system_info_ = |
81 ProvidedFileSystemInfo(kExtensionId, | 76 ProvidedFileSystemInfo(kExtensionId, |
82 kFileSystemId, | 77 kFileSystemId, |
83 "" /* file_system_name */, | 78 "" /* file_system_name */, |
84 base::FilePath() /* mount_path */); | 79 base::FilePath() /* mount_path */); |
85 } | 80 } |
86 | 81 |
87 ProvidedFileSystemInfo file_system_info_; | 82 ProvidedFileSystemInfo file_system_info_; |
88 }; | 83 }; |
89 | 84 |
90 TEST_F(FileSystemProviderOperationsUnmountTest, Execute) { | 85 TEST_F(FileSystemProviderOperationsUnmountTest, Execute) { |
91 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 86 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
92 CallbackLogger callback_logger; | 87 CallbackLogger callback_logger; |
93 | 88 |
94 Unmount unmount( | 89 Unmount unmount(NULL, |
95 NULL, | 90 file_system_info_, |
96 file_system_info_, | 91 base::Bind(&CallbackLogger::OnUnmount, |
97 base::Bind(&CallbackLogger::OnUnmount, callback_logger.GetWeakPtr())); | 92 base::Unretained(&callback_logger))); |
98 unmount.SetDispatchEventImplForTesting( | 93 unmount.SetDispatchEventImplForTesting( |
99 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 94 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
100 base::Unretained(&dispatcher))); | 95 base::Unretained(&dispatcher))); |
101 | 96 |
102 EXPECT_TRUE(unmount.Execute(kRequestId)); | 97 EXPECT_TRUE(unmount.Execute(kRequestId)); |
103 | 98 |
104 ASSERT_EQ(1u, dispatcher.events().size()); | 99 ASSERT_EQ(1u, dispatcher.events().size()); |
105 extensions::Event* event = dispatcher.events()[0]; | 100 extensions::Event* event = dispatcher.events()[0]; |
106 EXPECT_EQ( | 101 EXPECT_EQ( |
107 extensions::api::file_system_provider::OnUnmountRequested::kEventName, | 102 extensions::api::file_system_provider::OnUnmountRequested::kEventName, |
(...skipping 10 matching lines...) Expand all Loading... |
118 | 113 |
119 int event_request_id = -1; | 114 int event_request_id = -1; |
120 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | 115 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); |
121 EXPECT_EQ(kRequestId, event_request_id); | 116 EXPECT_EQ(kRequestId, event_request_id); |
122 } | 117 } |
123 | 118 |
124 TEST_F(FileSystemProviderOperationsUnmountTest, Execute_NoListener) { | 119 TEST_F(FileSystemProviderOperationsUnmountTest, Execute_NoListener) { |
125 LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 120 LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
126 CallbackLogger callback_logger; | 121 CallbackLogger callback_logger; |
127 | 122 |
128 Unmount unmount( | 123 Unmount unmount(NULL, |
129 NULL, | 124 file_system_info_, |
130 file_system_info_, | 125 base::Bind(&CallbackLogger::OnUnmount, |
131 base::Bind(&CallbackLogger::OnUnmount, callback_logger.GetWeakPtr())); | 126 base::Unretained(&callback_logger))); |
132 unmount.SetDispatchEventImplForTesting( | 127 unmount.SetDispatchEventImplForTesting( |
133 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 128 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
134 base::Unretained(&dispatcher))); | 129 base::Unretained(&dispatcher))); |
135 | 130 |
136 EXPECT_FALSE(unmount.Execute(kRequestId)); | 131 EXPECT_FALSE(unmount.Execute(kRequestId)); |
137 } | 132 } |
138 | 133 |
139 TEST_F(FileSystemProviderOperationsUnmountTest, OnSuccess) { | 134 TEST_F(FileSystemProviderOperationsUnmountTest, OnSuccess) { |
140 using extensions::api::file_system_provider_internal:: | 135 using extensions::api::file_system_provider_internal:: |
141 UnmountRequestedSuccess::Params; | 136 UnmountRequestedSuccess::Params; |
142 | 137 |
143 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 138 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
144 CallbackLogger callback_logger; | 139 CallbackLogger callback_logger; |
145 | 140 |
146 Unmount unmount( | 141 Unmount unmount(NULL, |
147 NULL, | 142 file_system_info_, |
148 file_system_info_, | 143 base::Bind(&CallbackLogger::OnUnmount, |
149 base::Bind(&CallbackLogger::OnUnmount, callback_logger.GetWeakPtr())); | 144 base::Unretained(&callback_logger))); |
150 unmount.SetDispatchEventImplForTesting( | 145 unmount.SetDispatchEventImplForTesting( |
151 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 146 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
152 base::Unretained(&dispatcher))); | 147 base::Unretained(&dispatcher))); |
153 | 148 |
154 EXPECT_TRUE(unmount.Execute(kRequestId)); | 149 EXPECT_TRUE(unmount.Execute(kRequestId)); |
155 | 150 |
156 unmount.OnSuccess(kRequestId, | 151 unmount.OnSuccess(kRequestId, |
157 scoped_ptr<RequestValue>(new RequestValue()), | 152 scoped_ptr<RequestValue>(new RequestValue()), |
158 false /* has_more */); | 153 false /* has_more */); |
159 ASSERT_EQ(1u, callback_logger.events().size()); | 154 ASSERT_EQ(1u, callback_logger.events().size()); |
160 base::File::Error event_result = callback_logger.events()[0]; | 155 base::File::Error event_result = callback_logger.events()[0]; |
161 EXPECT_EQ(base::File::FILE_OK, event_result); | 156 EXPECT_EQ(base::File::FILE_OK, event_result); |
162 } | 157 } |
163 | 158 |
164 TEST_F(FileSystemProviderOperationsUnmountTest, OnError) { | 159 TEST_F(FileSystemProviderOperationsUnmountTest, OnError) { |
165 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 160 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
166 CallbackLogger callback_logger; | 161 CallbackLogger callback_logger; |
167 | 162 |
168 Unmount unmount( | 163 Unmount unmount(NULL, |
169 NULL, | 164 file_system_info_, |
170 file_system_info_, | 165 base::Bind(&CallbackLogger::OnUnmount, |
171 base::Bind(&CallbackLogger::OnUnmount, callback_logger.GetWeakPtr())); | 166 base::Unretained(&callback_logger))); |
172 unmount.SetDispatchEventImplForTesting( | 167 unmount.SetDispatchEventImplForTesting( |
173 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 168 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
174 base::Unretained(&dispatcher))); | 169 base::Unretained(&dispatcher))); |
175 | 170 |
176 EXPECT_TRUE(unmount.Execute(kRequestId)); | 171 EXPECT_TRUE(unmount.Execute(kRequestId)); |
177 | 172 |
178 unmount.OnError(kRequestId, | 173 unmount.OnError(kRequestId, |
179 scoped_ptr<RequestValue>(new RequestValue()), | 174 scoped_ptr<RequestValue>(new RequestValue()), |
180 base::File::FILE_ERROR_NOT_FOUND); | 175 base::File::FILE_ERROR_NOT_FOUND); |
181 ASSERT_EQ(1u, callback_logger.events().size()); | 176 ASSERT_EQ(1u, callback_logger.events().size()); |
182 base::File::Error event_result = callback_logger.events()[0]; | 177 base::File::Error event_result = callback_logger.events()[0]; |
183 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, event_result); | 178 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, event_result); |
184 } | 179 } |
185 | 180 |
186 } // namespace operations | 181 } // namespace operations |
187 } // namespace file_system_provider | 182 } // namespace file_system_provider |
188 } // namespace chromeos | 183 } // namespace chromeos |
OLD | NEW |