| 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // Fake internal file stream reader. | 38 // Fake internal file stream reader. |
| 39 class FakeFileStreamReader : public storage::FileStreamReader { | 39 class FakeFileStreamReader : public storage::FileStreamReader { |
| 40 public: | 40 public: |
| 41 FakeFileStreamReader(std::vector<int>* log, net::Error return_error) | 41 FakeFileStreamReader(std::vector<int>* log, net::Error return_error) |
| 42 : log_(log), return_error_(return_error) {} | 42 : log_(log), return_error_(return_error) {} |
| 43 virtual ~FakeFileStreamReader() {} | 43 virtual ~FakeFileStreamReader() {} |
| 44 | 44 |
| 45 // storage::FileStreamReader overrides. | 45 // storage::FileStreamReader overrides. |
| 46 virtual int Read(net::IOBuffer* buf, | 46 virtual int Read(net::IOBuffer* buf, |
| 47 int buf_len, | 47 int buf_len, |
| 48 const net::CompletionCallback& callback) OVERRIDE { | 48 const net::CompletionCallback& callback) override { |
| 49 DCHECK(log_); | 49 DCHECK(log_); |
| 50 log_->push_back(buf_len); | 50 log_->push_back(buf_len); |
| 51 | 51 |
| 52 if (return_error_ != net::OK) { | 52 if (return_error_ != net::OK) { |
| 53 base::MessageLoopProxy::current()->PostTask( | 53 base::MessageLoopProxy::current()->PostTask( |
| 54 FROM_HERE, base::Bind(callback, return_error_)); | 54 FROM_HERE, base::Bind(callback, return_error_)); |
| 55 return net::ERR_IO_PENDING; | 55 return net::ERR_IO_PENDING; |
| 56 } | 56 } |
| 57 | 57 |
| 58 const std::string fake_data('X', buf_len); | 58 const std::string fake_data('X', buf_len); |
| 59 memcpy(buf->data(), fake_data.c_str(), buf_len); | 59 memcpy(buf->data(), fake_data.c_str(), buf_len); |
| 60 | 60 |
| 61 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 61 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 62 base::Bind(callback, buf_len)); | 62 base::Bind(callback, buf_len)); |
| 63 return net::ERR_IO_PENDING; | 63 return net::ERR_IO_PENDING; |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual int64 GetLength( | 66 virtual int64 GetLength( |
| 67 const net::Int64CompletionCallback& callback) OVERRIDE { | 67 const net::Int64CompletionCallback& callback) override { |
| 68 DCHECK_EQ(net::OK, return_error_); | 68 DCHECK_EQ(net::OK, return_error_); |
| 69 base::MessageLoopProxy::current()->PostTask( | 69 base::MessageLoopProxy::current()->PostTask( |
| 70 FROM_HERE, base::Bind(callback, kFileSize)); | 70 FROM_HERE, base::Bind(callback, kFileSize)); |
| 71 return net::ERR_IO_PENDING; | 71 return net::ERR_IO_PENDING; |
| 72 } | 72 } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 std::vector<int>* log_; // Not owned. | 75 std::vector<int>* log_; // Not owned. |
| 76 net::Error return_error_; | 76 net::Error return_error_; |
| 77 DISALLOW_COPY_AND_ASSIGN(FakeFileStreamReader); | 77 DISALLOW_COPY_AND_ASSIGN(FakeFileStreamReader); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 reader.GetLength(base::Bind(&LogValue<int64>, &get_length_log)); | 351 reader.GetLength(base::Bind(&LogValue<int64>, &get_length_log)); |
| 352 base::RunLoop().RunUntilIdle(); | 352 base::RunLoop().RunUntilIdle(); |
| 353 | 353 |
| 354 EXPECT_EQ(net::ERR_IO_PENDING, result); | 354 EXPECT_EQ(net::ERR_IO_PENDING, result); |
| 355 ASSERT_EQ(1u, get_length_log.size()); | 355 ASSERT_EQ(1u, get_length_log.size()); |
| 356 EXPECT_EQ(kFileSize, get_length_log[0]); | 356 EXPECT_EQ(kFileSize, get_length_log[0]); |
| 357 } | 357 } |
| 358 | 358 |
| 359 } // namespace file_system_provider | 359 } // namespace file_system_provider |
| 360 } // namespace chromeos | 360 } // namespace chromeos |
| OLD | NEW |