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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "android_webview/native/input_stream_impl.h" | 7 #include "android_webview/browser/input_stream_impl.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
10 #include "jni/InputStreamUnittest_jni.h" | 10 #include "jni/InputStreamUnittest_jni.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/http/http_byte_range.h" | 13 #include "net/http/http_byte_range.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using android_webview::InputStream; | 17 using android_webview::InputStream; |
18 using android_webview::InputStreamImpl; | 18 using android_webview::InputStreamImpl; |
19 using base::android::AttachCurrentThread; | 19 using base::android::AttachCurrentThread; |
20 using base::android::ScopedJavaLocalRef; | 20 using base::android::ScopedJavaLocalRef; |
21 using net::IOBuffer; | 21 using net::IOBuffer; |
22 using testing::DoAll; | 22 using testing::DoAll; |
23 using testing::Ge; | 23 using testing::Ge; |
24 using testing::InSequence; | 24 using testing::InSequence; |
25 using testing::Lt; | 25 using testing::Lt; |
26 using testing::Ne; | 26 using testing::Ne; |
27 using testing::NotNull; | 27 using testing::NotNull; |
28 using testing::Return; | 28 using testing::Return; |
29 using testing::SetArgPointee; | 29 using testing::SetArgPointee; |
30 using testing::Test; | 30 using testing::Test; |
31 using testing::_; | 31 using testing::_; |
32 | 32 |
33 class InputStreamTest : public Test { | 33 class InputStreamTest : public Test { |
34 public: | 34 public: |
35 InputStreamTest() { | 35 InputStreamTest() {} |
36 } | 36 |
37 protected: | 37 protected: |
38 void SetUp() override { | 38 void SetUp() override { |
39 env_ = AttachCurrentThread(); | 39 env_ = AttachCurrentThread(); |
40 ASSERT_THAT(env_, NotNull()); | 40 ASSERT_THAT(env_, NotNull()); |
41 } | 41 } |
42 | 42 |
43 scoped_refptr<IOBuffer> DoReadCountedStreamTest(int stream_size, | 43 scoped_refptr<IOBuffer> DoReadCountedStreamTest(int stream_size, |
44 int bytes_requested, | 44 int bytes_requested, |
45 int* bytes_read) { | 45 int* bytes_read) { |
46 ScopedJavaLocalRef<jobject> counting_jstream = | 46 ScopedJavaLocalRef<jobject> counting_jstream = |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 EXPECT_FALSE(throw_jstream.is_null()); | 124 EXPECT_FALSE(throw_jstream.is_null()); |
125 | 125 |
126 std::unique_ptr<InputStream> input_stream(new InputStreamImpl(throw_jstream)); | 126 std::unique_ptr<InputStream> input_stream(new InputStreamImpl(throw_jstream)); |
127 | 127 |
128 int64_t bytes_skipped; | 128 int64_t bytes_skipped; |
129 EXPECT_FALSE(input_stream->Skip(10, &bytes_skipped)); | 129 EXPECT_FALSE(input_stream->Skip(10, &bytes_skipped)); |
130 | 130 |
131 int bytes_available; | 131 int bytes_available; |
132 EXPECT_FALSE(input_stream->BytesAvailable(&bytes_available)); | 132 EXPECT_FALSE(input_stream->BytesAvailable(&bytes_available)); |
133 | 133 |
134 | |
135 const int bytes_requested = 10; | 134 const int bytes_requested = 10; |
136 int bytes_read = 0; | 135 int bytes_read = 0; |
137 scoped_refptr<IOBuffer> buffer = new IOBuffer(bytes_requested); | 136 scoped_refptr<IOBuffer> buffer = new IOBuffer(bytes_requested); |
138 EXPECT_FALSE(input_stream->Read(buffer.get(), bytes_requested, &bytes_read)); | 137 EXPECT_FALSE(input_stream->Read(buffer.get(), bytes_requested, &bytes_read)); |
139 EXPECT_EQ(0, bytes_read); | 138 EXPECT_EQ(0, bytes_read); |
140 | 139 |
141 // This closes the stream. | 140 // This closes the stream. |
142 input_stream.reset(NULL); | 141 input_stream.reset(NULL); |
143 } | 142 } |
OLD | NEW |