summaryrefslogtreecommitdiffstats
path: root/android_webview/unittestjava/src/org
diff options
context:
space:
mode:
authormkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-22 16:21:26 +0000
committermkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-22 16:21:26 +0000
commit17373866b8912a64bba105e6387b3b7cbe48301a (patch)
tree59e2ae08a8a6cd07b75b3fd4f28f70ebc56c09e6 /android_webview/unittestjava/src/org
parent3fd370b5b2201628fe1b9c108b9917de93977257 (diff)
downloadchromium_src-17373866b8912a64bba105e6387b3b7cbe48301a.zip
chromium_src-17373866b8912a64bba105e6387b3b7cbe48301a.tar.gz
chromium_src-17373866b8912a64bba105e6387b3b7cbe48301a.tar.bz2
[android_webview] Don't block the IO thread when reading from an InputStream.
This breaks up the functionality in the AndroidStreamReader..Job into three separate classes, adds native unittests and makes the Job read the InputStream on a background thread. This change adds a separate unittestjava folder because the code under javatests can't be compiled to be a part of a native unittest APK due to resource dependencies. TEST=AndroidWebviewTests,android_webview_unittests BUG=None Review URL: https://codereview.chromium.org/11363123 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169274 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/unittestjava/src/org')
-rw-r--r--android_webview/unittestjava/src/org/chromium/android_webview/unittest/InputStreamUnittest.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/android_webview/unittestjava/src/org/chromium/android_webview/unittest/InputStreamUnittest.java b/android_webview/unittestjava/src/org/chromium/android_webview/unittest/InputStreamUnittest.java
new file mode 100644
index 0000000..3405017
--- /dev/null
+++ b/android_webview/unittestjava/src/org/chromium/android_webview/unittest/InputStreamUnittest.java
@@ -0,0 +1,40 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.android_webview.unittest;
+
+import org.chromium.base.CalledByNative;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+class InputStreamUnittest {
+ private InputStreamUnittest() {
+ }
+
+ @CalledByNative
+ static InputStream getEmptyStream() {
+ return new InputStream() {
+ @Override
+ public int read() {
+ return -1;
+ }
+ };
+ }
+
+ @CalledByNative
+ static InputStream getCountingStream(final int size) {
+ return new InputStream() {
+ private int count = 0;
+
+ @Override
+ public int read() {
+ if (count < size)
+ return count++ % 256;
+ else
+ return -1;
+ }
+ };
+ }
+}