| 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 "android_webview/browser/input_stream.h" | 5 #include "android_webview/browser/input_stream.h" |
| 6 #include "android_webview/browser/net/input_stream_reader.h" | 6 #include "android_webview/browser/net/input_stream_reader.h" |
| 7 #include "base/android/scoped_java_ref.h" | 7 #include "base/android/scoped_java_ref.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.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 22 matching lines...) Expand all Loading... |
| 33 virtual ~MockInputStream() {} | 33 virtual ~MockInputStream() {} |
| 34 | 34 |
| 35 MOCK_CONST_METHOD1(BytesAvailable, bool(int* bytes_available)); | 35 MOCK_CONST_METHOD1(BytesAvailable, bool(int* bytes_available)); |
| 36 MOCK_METHOD2(Skip, bool(int64_t n, int64_t* bytes_skipped)); | 36 MOCK_METHOD2(Skip, bool(int64_t n, int64_t* bytes_skipped)); |
| 37 MOCK_METHOD3(Read, bool(net::IOBuffer* dest, int length, int* bytes_read)); | 37 MOCK_METHOD3(Read, bool(net::IOBuffer* dest, int length, int* bytes_read)); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 class InputStreamReaderTest : public Test { | 40 class InputStreamReaderTest : public Test { |
| 41 public: | 41 public: |
| 42 InputStreamReaderTest() | 42 InputStreamReaderTest() |
| 43 : input_stream_reader_(new InputStreamReader(&input_stream_)) { | 43 : input_stream_reader_(&input_stream_) { |
| 44 } | 44 } |
| 45 protected: | 45 protected: |
| 46 int SeekRange(int first_byte, int last_byte) { | 46 int SeekRange(int first_byte, int last_byte) { |
| 47 net::HttpByteRange byte_range; | 47 net::HttpByteRange byte_range; |
| 48 byte_range.set_first_byte_position(first_byte); | 48 byte_range.set_first_byte_position(first_byte); |
| 49 byte_range.set_last_byte_position(last_byte); | 49 byte_range.set_last_byte_position(last_byte); |
| 50 return input_stream_reader_->Seek(byte_range); | 50 return input_stream_reader_.Seek(byte_range); |
| 51 } | 51 } |
| 52 | 52 |
| 53 int ReadRawData(scoped_refptr<net::IOBuffer> buffer, int bytesToRead) { | 53 int ReadRawData(scoped_refptr<net::IOBuffer> buffer, int bytesToRead) { |
| 54 return input_stream_reader_->ReadRawData(buffer.get(), bytesToRead); | 54 return input_stream_reader_.ReadRawData(buffer.get(), bytesToRead); |
| 55 } | 55 } |
| 56 | 56 |
| 57 MockInputStream input_stream_; | 57 MockInputStream input_stream_; |
| 58 scoped_refptr<InputStreamReader> input_stream_reader_; | 58 InputStreamReader input_stream_reader_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 TEST_F(InputStreamReaderTest, BytesAvailableFailurePropagationOnSeek) { | 61 TEST_F(InputStreamReaderTest, BytesAvailableFailurePropagationOnSeek) { |
| 62 EXPECT_CALL(input_stream_, BytesAvailable(NotNull())) | 62 EXPECT_CALL(input_stream_, BytesAvailable(NotNull())) |
| 63 .WillOnce(Return(false)); | 63 .WillOnce(Return(false)); |
| 64 | 64 |
| 65 ASSERT_GT(0, SeekRange(0, 0)); | 65 ASSERT_GT(0, SeekRange(0, 0)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 TEST_F(InputStreamReaderTest, SkipFailurePropagationOnSeek) { | 68 TEST_F(InputStreamReaderTest, SkipFailurePropagationOnSeek) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 TEST_F(InputStreamReaderTest, ReadSuccess) { | 163 TEST_F(InputStreamReaderTest, ReadSuccess) { |
| 164 const int bytesToRead = 128; | 164 const int bytesToRead = 128; |
| 165 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(bytesToRead); | 165 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(bytesToRead); |
| 166 | 166 |
| 167 EXPECT_CALL(input_stream_, Read(buffer.get(), bytesToRead, NotNull())) | 167 EXPECT_CALL(input_stream_, Read(buffer.get(), bytesToRead, NotNull())) |
| 168 .WillOnce(DoAll(SetArgPointee<2>(bytesToRead), | 168 .WillOnce(DoAll(SetArgPointee<2>(bytesToRead), |
| 169 Return(true))); | 169 Return(true))); |
| 170 | 170 |
| 171 ASSERT_EQ(bytesToRead, ReadRawData(buffer, bytesToRead)); | 171 ASSERT_EQ(bytesToRead, ReadRawData(buffer, bytesToRead)); |
| 172 } | 172 } |
| OLD | NEW |