| 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/read_directory
.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/read_directory
.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" | 17 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" |
| 18 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" | 18 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" |
| 19 #include "chrome/common/extensions/api/file_system_provider.h" | 19 #include "chrome/common/extensions/api/file_system_provider.h" |
| 20 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy
stem_provider_capabilities_handler.h" | 20 #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_internal.h" | 21 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
| 22 #include "extensions/browser/event_router.h" | 22 #include "extensions/browser/event_router.h" |
| 23 #include "storage/browser/fileapi/async_file_util.h" | 23 #include "storage/browser/fileapi/async_file_util.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 ScopedVector<Event>& events() { return events_; } | 71 ScopedVector<Event>& events() { return events_; } |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 ScopedVector<Event> events_; | 74 ScopedVector<Event> events_; |
| 75 | 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); | 76 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // Returns the request value as |result| in case of successful parse. | 79 // Returns the request value as |result| in case of successful parse. |
| 80 void CreateRequestValueFromJSON(const std::string& json, | 80 void CreateRequestValueFromJSON(const std::string& json, |
| 81 scoped_ptr<RequestValue>* result) { | 81 std::unique_ptr<RequestValue>* result) { |
| 82 using extensions::api::file_system_provider_internal:: | 82 using extensions::api::file_system_provider_internal:: |
| 83 ReadDirectoryRequestedSuccess::Params; | 83 ReadDirectoryRequestedSuccess::Params; |
| 84 | 84 |
| 85 int json_error_code; | 85 int json_error_code; |
| 86 std::string json_error_msg; | 86 std::string json_error_msg; |
| 87 scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( | 87 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( |
| 88 json, base::JSON_PARSE_RFC, &json_error_code, &json_error_msg); | 88 json, base::JSON_PARSE_RFC, &json_error_code, &json_error_msg); |
| 89 ASSERT_TRUE(value.get()) << json_error_msg; | 89 ASSERT_TRUE(value.get()) << json_error_msg; |
| 90 | 90 |
| 91 base::ListValue* value_as_list; | 91 base::ListValue* value_as_list; |
| 92 ASSERT_TRUE(value->GetAsList(&value_as_list)); | 92 ASSERT_TRUE(value->GetAsList(&value_as_list)); |
| 93 scoped_ptr<Params> params(Params::Create(*value_as_list)); | 93 std::unique_ptr<Params> params(Params::Create(*value_as_list)); |
| 94 ASSERT_TRUE(params.get()); | 94 ASSERT_TRUE(params.get()); |
| 95 *result = RequestValue::CreateForReadDirectorySuccess(std::move(params)); | 95 *result = RequestValue::CreateForReadDirectorySuccess(std::move(params)); |
| 96 ASSERT_TRUE(result->get()); | 96 ASSERT_TRUE(result->get()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace | 99 } // namespace |
| 100 | 100 |
| 101 class FileSystemProviderOperationsReadDirectoryTest : public testing::Test { | 101 class FileSystemProviderOperationsReadDirectoryTest : public testing::Test { |
| 102 protected: | 102 protected: |
| 103 FileSystemProviderOperationsReadDirectoryTest() {} | 103 FileSystemProviderOperationsReadDirectoryTest() {} |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 " 2,\n" // kRequestId | 186 " 2,\n" // kRequestId |
| 187 " [\n" | 187 " [\n" |
| 188 " {\n" | 188 " {\n" |
| 189 " \"isDirectory\": false,\n" | 189 " \"isDirectory\": false,\n" |
| 190 " \"name\": \"blueberries.txt\"\n" | 190 " \"name\": \"blueberries.txt\"\n" |
| 191 " }\n" | 191 " }\n" |
| 192 " ],\n" | 192 " ],\n" |
| 193 " false,\n" // has_more | 193 " false,\n" // has_more |
| 194 " 0\n" // execution_time | 194 " 0\n" // execution_time |
| 195 "]\n"; | 195 "]\n"; |
| 196 scoped_ptr<RequestValue> request_value; | 196 std::unique_ptr<RequestValue> request_value; |
| 197 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); | 197 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); |
| 198 | 198 |
| 199 const bool has_more = false; | 199 const bool has_more = false; |
| 200 read_directory.OnSuccess(kRequestId, std::move(request_value), has_more); | 200 read_directory.OnSuccess(kRequestId, std::move(request_value), has_more); |
| 201 | 201 |
| 202 ASSERT_EQ(1u, callback_logger.events().size()); | 202 ASSERT_EQ(1u, callback_logger.events().size()); |
| 203 CallbackLogger::Event* event = callback_logger.events()[0]; | 203 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 204 EXPECT_EQ(base::File::FILE_OK, event->result()); | 204 EXPECT_EQ(base::File::FILE_OK, event->result()); |
| 205 | 205 |
| 206 ASSERT_EQ(1u, event->entry_list().size()); | 206 ASSERT_EQ(1u, event->entry_list().size()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 233 " 2,\n" // kRequestId | 233 " 2,\n" // kRequestId |
| 234 " [\n" | 234 " [\n" |
| 235 " {\n" | 235 " {\n" |
| 236 " \"isDirectory\": false,\n" | 236 " \"isDirectory\": false,\n" |
| 237 " \"name\": \"blue/berries.txt\"\n" | 237 " \"name\": \"blue/berries.txt\"\n" |
| 238 " }\n" | 238 " }\n" |
| 239 " ],\n" | 239 " ],\n" |
| 240 " false,\n" // has_more | 240 " false,\n" // has_more |
| 241 " 0\n" // execution_time | 241 " 0\n" // execution_time |
| 242 "]\n"; | 242 "]\n"; |
| 243 scoped_ptr<RequestValue> request_value; | 243 std::unique_ptr<RequestValue> request_value; |
| 244 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); | 244 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); |
| 245 | 245 |
| 246 const bool has_more = false; | 246 const bool has_more = false; |
| 247 read_directory.OnSuccess(kRequestId, std::move(request_value), has_more); | 247 read_directory.OnSuccess(kRequestId, std::move(request_value), has_more); |
| 248 | 248 |
| 249 ASSERT_EQ(1u, callback_logger.events().size()); | 249 ASSERT_EQ(1u, callback_logger.events().size()); |
| 250 CallbackLogger::Event* event = callback_logger.events()[0]; | 250 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 251 EXPECT_EQ(base::File::FILE_ERROR_IO, event->result()); | 251 EXPECT_EQ(base::File::FILE_ERROR_IO, event->result()); |
| 252 | 252 |
| 253 EXPECT_EQ(0u, event->entry_list().size()); | 253 EXPECT_EQ(0u, event->entry_list().size()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnError) { | 256 TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnError) { |
| 257 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 257 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 258 CallbackLogger callback_logger; | 258 CallbackLogger callback_logger; |
| 259 | 259 |
| 260 ReadDirectory read_directory(NULL, file_system_info_, | 260 ReadDirectory read_directory(NULL, file_system_info_, |
| 261 base::FilePath(kDirectoryPath), | 261 base::FilePath(kDirectoryPath), |
| 262 base::Bind(&CallbackLogger::OnReadDirectory, | 262 base::Bind(&CallbackLogger::OnReadDirectory, |
| 263 base::Unretained(&callback_logger))); | 263 base::Unretained(&callback_logger))); |
| 264 read_directory.SetDispatchEventImplForTesting( | 264 read_directory.SetDispatchEventImplForTesting( |
| 265 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 265 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 266 base::Unretained(&dispatcher))); | 266 base::Unretained(&dispatcher))); |
| 267 | 267 |
| 268 EXPECT_TRUE(read_directory.Execute(kRequestId)); | 268 EXPECT_TRUE(read_directory.Execute(kRequestId)); |
| 269 | 269 |
| 270 read_directory.OnError(kRequestId, | 270 read_directory.OnError(kRequestId, |
| 271 scoped_ptr<RequestValue>(new RequestValue()), | 271 std::unique_ptr<RequestValue>(new RequestValue()), |
| 272 base::File::FILE_ERROR_TOO_MANY_OPENED); | 272 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 273 | 273 |
| 274 ASSERT_EQ(1u, callback_logger.events().size()); | 274 ASSERT_EQ(1u, callback_logger.events().size()); |
| 275 CallbackLogger::Event* event = callback_logger.events()[0]; | 275 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 276 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 276 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
| 277 ASSERT_EQ(0u, event->entry_list().size()); | 277 ASSERT_EQ(0u, event->entry_list().size()); |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace operations | 280 } // namespace operations |
| 281 } // namespace file_system_provider | 281 } // namespace file_system_provider |
| 282 } // namespace chromeos | 282 } // namespace chromeos |
| OLD | NEW |