OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/get_actions.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/get_actions.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <string> | 8 #include <string> |
8 #include <utility> | 9 #include <utility> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/files/file.h" | 12 #include "base/files/file.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" | 18 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" |
19 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" | 19 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" |
20 #include "chrome/common/extensions/api/file_system_provider.h" | 20 #include "chrome/common/extensions/api/file_system_provider.h" |
21 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy
stem_provider_capabilities_handler.h" | 21 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy
stem_provider_capabilities_handler.h" |
22 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 22 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
23 #include "extensions/browser/event_router.h" | 23 #include "extensions/browser/event_router.h" |
24 #include "storage/browser/fileapi/async_file_util.h" | 24 #include "storage/browser/fileapi/async_file_util.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const ScopedVector<Event>& events() const { return events_; } | 65 const ScopedVector<Event>& events() const { return events_; } |
66 | 66 |
67 private: | 67 private: |
68 ScopedVector<Event> events_; | 68 ScopedVector<Event> events_; |
69 | 69 |
70 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); | 70 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); |
71 }; | 71 }; |
72 | 72 |
73 // Returns the request value as |result| in case of successful parse. | 73 // Returns the request value as |result| in case of successful parse. |
74 void CreateRequestValueFromJSON(const std::string& json, | 74 void CreateRequestValueFromJSON(const std::string& json, |
75 scoped_ptr<RequestValue>* result) { | 75 std::unique_ptr<RequestValue>* result) { |
76 using extensions::api::file_system_provider_internal:: | 76 using extensions::api::file_system_provider_internal:: |
77 GetActionsRequestedSuccess::Params; | 77 GetActionsRequestedSuccess::Params; |
78 | 78 |
79 int json_error_code; | 79 int json_error_code; |
80 std::string json_error_msg; | 80 std::string json_error_msg; |
81 scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( | 81 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( |
82 json, base::JSON_PARSE_RFC, &json_error_code, &json_error_msg); | 82 json, base::JSON_PARSE_RFC, &json_error_code, &json_error_msg); |
83 ASSERT_TRUE(value.get()) << json_error_msg; | 83 ASSERT_TRUE(value.get()) << json_error_msg; |
84 | 84 |
85 base::ListValue* value_as_list; | 85 base::ListValue* value_as_list; |
86 ASSERT_TRUE(value->GetAsList(&value_as_list)); | 86 ASSERT_TRUE(value->GetAsList(&value_as_list)); |
87 scoped_ptr<Params> params(Params::Create(*value_as_list)); | 87 std::unique_ptr<Params> params(Params::Create(*value_as_list)); |
88 ASSERT_TRUE(params.get()); | 88 ASSERT_TRUE(params.get()); |
89 *result = RequestValue::CreateForGetActionsSuccess(std::move(params)); | 89 *result = RequestValue::CreateForGetActionsSuccess(std::move(params)); |
90 ASSERT_TRUE(result->get()); | 90 ASSERT_TRUE(result->get()); |
91 } | 91 } |
92 | 92 |
93 } // namespace | 93 } // namespace |
94 | 94 |
95 class FileSystemProviderOperationsGetActionsTest : public testing::Test { | 95 class FileSystemProviderOperationsGetActionsTest : public testing::Test { |
96 protected: | 96 protected: |
97 FileSystemProviderOperationsGetActionsTest() {} | 97 FileSystemProviderOperationsGetActionsTest() {} |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 " \"id\": \"OFFLINE_NOT_NECESSARY\",\n" | 189 " \"id\": \"OFFLINE_NOT_NECESSARY\",\n" |
190 " \"title\": \"Ignored title.\"\n" | 190 " \"title\": \"Ignored title.\"\n" |
191 " },\n" | 191 " },\n" |
192 " {\n" | 192 " {\n" |
193 " \"id\": \"SomeCustomActionId\",\n" | 193 " \"id\": \"SomeCustomActionId\",\n" |
194 " \"title\": \"Custom action.\"\n" | 194 " \"title\": \"Custom action.\"\n" |
195 " }\n" | 195 " }\n" |
196 " ],\n" | 196 " ],\n" |
197 " 0\n" // execution_time | 197 " 0\n" // execution_time |
198 "]\n"; | 198 "]\n"; |
199 scoped_ptr<RequestValue> request_value; | 199 std::unique_ptr<RequestValue> request_value; |
200 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); | 200 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); |
201 | 201 |
202 const bool has_more = false; | 202 const bool has_more = false; |
203 get_actions.OnSuccess(kRequestId, std::move(request_value), has_more); | 203 get_actions.OnSuccess(kRequestId, std::move(request_value), has_more); |
204 | 204 |
205 ASSERT_EQ(1u, callback_logger.events().size()); | 205 ASSERT_EQ(1u, callback_logger.events().size()); |
206 CallbackLogger::Event* event = callback_logger.events()[0]; | 206 CallbackLogger::Event* event = callback_logger.events()[0]; |
207 EXPECT_EQ(base::File::FILE_OK, event->result()); | 207 EXPECT_EQ(base::File::FILE_OK, event->result()); |
208 | 208 |
209 ASSERT_EQ(3u, event->actions().size()); | 209 ASSERT_EQ(3u, event->actions().size()); |
(...skipping 16 matching lines...) Expand all Loading... |
226 | 226 |
227 GetActions get_actions(NULL, file_system_info_, entry_paths_, | 227 GetActions get_actions(NULL, file_system_info_, entry_paths_, |
228 base::Bind(&CallbackLogger::OnGetActions, | 228 base::Bind(&CallbackLogger::OnGetActions, |
229 base::Unretained(&callback_logger))); | 229 base::Unretained(&callback_logger))); |
230 get_actions.SetDispatchEventImplForTesting( | 230 get_actions.SetDispatchEventImplForTesting( |
231 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 231 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
232 base::Unretained(&dispatcher))); | 232 base::Unretained(&dispatcher))); |
233 | 233 |
234 EXPECT_TRUE(get_actions.Execute(kRequestId)); | 234 EXPECT_TRUE(get_actions.Execute(kRequestId)); |
235 | 235 |
236 get_actions.OnError(kRequestId, scoped_ptr<RequestValue>(new RequestValue()), | 236 get_actions.OnError(kRequestId, |
| 237 std::unique_ptr<RequestValue>(new RequestValue()), |
237 base::File::FILE_ERROR_TOO_MANY_OPENED); | 238 base::File::FILE_ERROR_TOO_MANY_OPENED); |
238 | 239 |
239 ASSERT_EQ(1u, callback_logger.events().size()); | 240 ASSERT_EQ(1u, callback_logger.events().size()); |
240 CallbackLogger::Event* event = callback_logger.events()[0]; | 241 CallbackLogger::Event* event = callback_logger.events()[0]; |
241 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 242 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
242 ASSERT_EQ(0u, event->actions().size()); | 243 ASSERT_EQ(0u, event->actions().size()); |
243 } | 244 } |
244 | 245 |
245 } // namespace operations | 246 } // namespace operations |
246 } // namespace file_system_provider | 247 } // namespace file_system_provider |
247 } // namespace chromeos | 248 } // namespace chromeos |
OLD | NEW |