| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/base/elements_upload_data_stream.h" | 5 #include "net/base/elements_upload_data_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // A mock class of UploadElementReader. | 57 // A mock class of UploadElementReader. |
| 58 class MockUploadElementReader : public UploadElementReader { | 58 class MockUploadElementReader : public UploadElementReader { |
| 59 public: | 59 public: |
| 60 MockUploadElementReader(int content_length, bool is_in_memory) | 60 MockUploadElementReader(int content_length, bool is_in_memory) |
| 61 : content_length_(content_length), | 61 : content_length_(content_length), |
| 62 bytes_remaining_(content_length), | 62 bytes_remaining_(content_length), |
| 63 is_in_memory_(is_in_memory), | 63 is_in_memory_(is_in_memory), |
| 64 init_result_(OK), | 64 init_result_(OK), |
| 65 read_result_(OK) {} | 65 read_result_(OK) {} |
| 66 | 66 |
| 67 virtual ~MockUploadElementReader() {} | 67 ~MockUploadElementReader() override {} |
| 68 | 68 |
| 69 // UploadElementReader overrides. | 69 // UploadElementReader overrides. |
| 70 MOCK_METHOD1(Init, int(const CompletionCallback& callback)); | 70 MOCK_METHOD1(Init, int(const CompletionCallback& callback)); |
| 71 virtual uint64 GetContentLength() const override { return content_length_; } | 71 uint64 GetContentLength() const override { return content_length_; } |
| 72 virtual uint64 BytesRemaining() const override { return bytes_remaining_; } | 72 uint64 BytesRemaining() const override { return bytes_remaining_; } |
| 73 virtual bool IsInMemory() const override { return is_in_memory_; } | 73 bool IsInMemory() const override { return is_in_memory_; } |
| 74 MOCK_METHOD3(Read, int(IOBuffer* buf, | 74 MOCK_METHOD3(Read, int(IOBuffer* buf, |
| 75 int buf_length, | 75 int buf_length, |
| 76 const CompletionCallback& callback)); | 76 const CompletionCallback& callback)); |
| 77 | 77 |
| 78 // Sets expectation to return the specified result from Init() asynchronously. | 78 // Sets expectation to return the specified result from Init() asynchronously. |
| 79 void SetAsyncInitExpectation(int result) { | 79 void SetAsyncInitExpectation(int result) { |
| 80 init_result_ = result; | 80 init_result_ = result; |
| 81 EXPECT_CALL(*this, Init(_)) | 81 EXPECT_CALL(*this, Init(_)) |
| 82 .WillOnce(DoAll(Invoke(this, &MockUploadElementReader::OnInit), | 82 .WillOnce(DoAll(Invoke(this, &MockUploadElementReader::OnInit), |
| 83 Return(ERR_IO_PENDING))); | 83 Return(ERR_IO_PENDING))); |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); | 812 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); |
| 813 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); | 813 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); |
| 814 EXPECT_EQ(expected_data, buf2); | 814 EXPECT_EQ(expected_data, buf2); |
| 815 EXPECT_TRUE(stream->IsEOF()); | 815 EXPECT_TRUE(stream->IsEOF()); |
| 816 | 816 |
| 817 // Make sure callbacks are not called for cancelled operations. | 817 // Make sure callbacks are not called for cancelled operations. |
| 818 EXPECT_FALSE(read_callback1.have_result()); | 818 EXPECT_FALSE(read_callback1.have_result()); |
| 819 } | 819 } |
| 820 | 820 |
| 821 } // namespace net | 821 } // namespace net |
| OLD | NEW |