| 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 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 bool dispatch_reply_; | 50 bool dispatch_reply_; |
| 51 | 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(LoggingDispatchEventImpl); | 52 DISALLOW_COPY_AND_ASSIGN(LoggingDispatchEventImpl); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 // Callback invocation logger. Acts as a fileapi end-point. | 55 // Callback invocation logger. Acts as a fileapi end-point. |
| 56 class CallbackLogger { | 56 class CallbackLogger { |
| 57 public: | 57 public: |
| 58 class Event { | 58 class Event { |
| 59 public: | 59 public: |
| 60 Event(int chunk_length, bool has_next, base::File::Error result) | 60 Event(int chunk_length, bool has_more, base::File::Error result) |
| 61 : chunk_length_(chunk_length), has_next_(has_next), result_(result) {} | 61 : chunk_length_(chunk_length), has_more_(has_more), result_(result) {} |
| 62 virtual ~Event() {} | 62 virtual ~Event() {} |
| 63 | 63 |
| 64 int chunk_length() const { return chunk_length_; } | 64 int chunk_length() const { return chunk_length_; } |
| 65 bool has_next() const { return has_next_; } | 65 bool has_more() const { return has_more_; } |
| 66 base::File::Error result() const { return result_; } | 66 base::File::Error result() const { return result_; } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 int chunk_length_; | 69 int chunk_length_; |
| 70 bool has_next_; | 70 bool has_more_; |
| 71 base::File::Error result_; | 71 base::File::Error result_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(Event); | 73 DISALLOW_COPY_AND_ASSIGN(Event); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 CallbackLogger() : weak_ptr_factory_(this) {} | 76 CallbackLogger() : weak_ptr_factory_(this) {} |
| 77 virtual ~CallbackLogger() {} | 77 virtual ~CallbackLogger() {} |
| 78 | 78 |
| 79 void OnReadFile(int chunk_length, bool has_next, base::File::Error result) { | 79 void OnReadFile(int chunk_length, bool has_more, base::File::Error result) { |
| 80 events_.push_back(new Event(chunk_length, has_next, result)); | 80 events_.push_back(new Event(chunk_length, has_more, result)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 ScopedVector<Event>& events() { return events_; } | 83 ScopedVector<Event>& events() { return events_; } |
| 84 | 84 |
| 85 base::WeakPtr<CallbackLogger> GetWeakPtr() { | 85 base::WeakPtr<CallbackLogger> GetWeakPtr() { |
| 86 return weak_ptr_factory_.GetWeakPtr(); | 86 return weak_ptr_factory_.GetWeakPtr(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 ScopedVector<Event> events_; | 90 ScopedVector<Event> events_; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 kOffset, | 195 kOffset, |
| 196 kLength, | 196 kLength, |
| 197 base::Bind(&CallbackLogger::OnReadFile, callback_logger.GetWeakPtr())); | 197 base::Bind(&CallbackLogger::OnReadFile, callback_logger.GetWeakPtr())); |
| 198 read_file.SetDispatchEventImplForTesting( | 198 read_file.SetDispatchEventImplForTesting( |
| 199 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 199 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 200 base::Unretained(&dispatcher))); | 200 base::Unretained(&dispatcher))); |
| 201 | 201 |
| 202 EXPECT_TRUE(read_file.Execute(kRequestId)); | 202 EXPECT_TRUE(read_file.Execute(kRequestId)); |
| 203 | 203 |
| 204 const std::string data = "ABCDE"; | 204 const std::string data = "ABCDE"; |
| 205 const bool has_next = false; | 205 const bool has_more = false; |
| 206 | 206 |
| 207 base::ListValue value_as_list; | 207 base::ListValue value_as_list; |
| 208 value_as_list.Set(0, new base::StringValue(kFileSystemId)); | 208 value_as_list.Set(0, new base::StringValue(kFileSystemId)); |
| 209 value_as_list.Set(1, new base::FundamentalValue(kRequestId)); | 209 value_as_list.Set(1, new base::FundamentalValue(kRequestId)); |
| 210 value_as_list.Set( | 210 value_as_list.Set( |
| 211 2, base::BinaryValue::CreateWithCopiedBuffer(data.c_str(), data.size())); | 211 2, base::BinaryValue::CreateWithCopiedBuffer(data.c_str(), data.size())); |
| 212 value_as_list.Set(3, new base::FundamentalValue(has_next)); | 212 value_as_list.Set(3, new base::FundamentalValue(has_more)); |
| 213 | 213 |
| 214 scoped_ptr<Params> params(Params::Create(value_as_list)); | 214 scoped_ptr<Params> params(Params::Create(value_as_list)); |
| 215 ASSERT_TRUE(params.get()); | 215 ASSERT_TRUE(params.get()); |
| 216 scoped_ptr<RequestValue> request_value( | 216 scoped_ptr<RequestValue> request_value( |
| 217 RequestValue::CreateForReadFileSuccess(params.Pass())); | 217 RequestValue::CreateForReadFileSuccess(params.Pass())); |
| 218 ASSERT_TRUE(request_value.get()); | 218 ASSERT_TRUE(request_value.get()); |
| 219 | 219 |
| 220 read_file.OnSuccess(kRequestId, request_value.Pass(), has_next); | 220 read_file.OnSuccess(kRequestId, request_value.Pass(), has_more); |
| 221 | 221 |
| 222 ASSERT_EQ(1u, callback_logger.events().size()); | 222 ASSERT_EQ(1u, callback_logger.events().size()); |
| 223 CallbackLogger::Event* event = callback_logger.events()[0]; | 223 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 224 EXPECT_EQ(kLength, event->chunk_length()); | 224 EXPECT_EQ(kLength, event->chunk_length()); |
| 225 EXPECT_FALSE(event->has_next()); | 225 EXPECT_FALSE(event->has_more()); |
| 226 EXPECT_EQ(data, std::string(io_buffer_->data(), kLength)); | 226 EXPECT_EQ(data, std::string(io_buffer_->data(), kLength)); |
| 227 EXPECT_EQ(base::File::FILE_OK, event->result()); | 227 EXPECT_EQ(base::File::FILE_OK, event->result()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 TEST_F(FileSystemProviderOperationsReadFileTest, OnError) { | 230 TEST_F(FileSystemProviderOperationsReadFileTest, OnError) { |
| 231 using extensions::api::file_system_provider_internal::ReadFileRequestedError:: | 231 using extensions::api::file_system_provider_internal::ReadFileRequestedError:: |
| 232 Params; | 232 Params; |
| 233 | 233 |
| 234 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 234 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 235 CallbackLogger callback_logger; | 235 CallbackLogger callback_logger; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 251 read_file.OnError(kRequestId, base::File::FILE_ERROR_TOO_MANY_OPENED); | 251 read_file.OnError(kRequestId, base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 252 | 252 |
| 253 ASSERT_EQ(1u, callback_logger.events().size()); | 253 ASSERT_EQ(1u, callback_logger.events().size()); |
| 254 CallbackLogger::Event* event = callback_logger.events()[0]; | 254 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 255 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 255 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
| 256 } | 256 } |
| 257 | 257 |
| 258 } // namespace operations | 258 } // namespace operations |
| 259 } // namespace file_system_provider | 259 } // namespace file_system_provider |
| 260 } // namespace chromeos | 260 } // namespace chromeos |
| OLD | NEW |