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/native/input_stream_impl.h" | 5 #include "android_webview/native/input_stream_impl.h" |
6 #include "base/android/jni_android.h" | 6 #include "base/android/jni_android.h" |
7 #include "base/android/scoped_java_ref.h" | 7 #include "base/android/scoped_java_ref.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "jni/InputStreamUnittest_jni.h" | 9 #include "jni/InputStreamUnittest_jni.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 DoReadCountedStreamTest(bytes_requested + 32, bytes_requested, &bytes_read); | 112 DoReadCountedStreamTest(bytes_requested + 32, bytes_requested, &bytes_read); |
113 EXPECT_EQ(bytes_requested, bytes_read); | 113 EXPECT_EQ(bytes_requested, bytes_read); |
114 } | 114 } |
115 | 115 |
116 TEST_F(InputStreamTest, ReadLargeStreamCompletely) { | 116 TEST_F(InputStreamTest, ReadLargeStreamCompletely) { |
117 const int bytes_requested = 3 * InputStreamImpl::kBufferSize; | 117 const int bytes_requested = 3 * InputStreamImpl::kBufferSize; |
118 int bytes_read = 0; | 118 int bytes_read = 0; |
119 DoReadCountedStreamTest(bytes_requested, bytes_requested, &bytes_read); | 119 DoReadCountedStreamTest(bytes_requested, bytes_requested, &bytes_read); |
120 EXPECT_EQ(bytes_requested, bytes_read); | 120 EXPECT_EQ(bytes_requested, bytes_read); |
121 } | 121 } |
| 122 |
| 123 TEST_F(InputStreamTest, DoesNotCrashWhenExceptionThrown) { |
| 124 ScopedJavaLocalRef<jobject> throw_jstream = |
| 125 Java_InputStreamUnittest_getThrowingStream(env_); |
| 126 EXPECT_FALSE(throw_jstream.is_null()); |
| 127 |
| 128 scoped_ptr<InputStream> input_stream(new InputStreamImpl(throw_jstream)); |
| 129 |
| 130 int64_t bytes_skipped; |
| 131 EXPECT_FALSE(input_stream->Skip(10, &bytes_skipped)); |
| 132 |
| 133 int bytes_available; |
| 134 EXPECT_FALSE(input_stream->BytesAvailable(&bytes_available)); |
| 135 |
| 136 |
| 137 const int bytes_requested = 10; |
| 138 int bytes_read = 0; |
| 139 scoped_refptr<IOBuffer> buffer = new IOBuffer(bytes_requested); |
| 140 EXPECT_FALSE(input_stream->Read(buffer.get(), bytes_requested, &bytes_read)); |
| 141 EXPECT_EQ(0, bytes_read); |
| 142 |
| 143 // This closes the stream. |
| 144 input_stream.reset(NULL); |
| 145 } |
OLD | NEW |