Chromium Code Reviews| Index: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java |
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java |
| index f052070ce0553963b3078d189695929630df26c7..d5989c4cb5329ef5d5df88c2fc830c6228c4d56d 100644 |
| --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java |
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java |
| @@ -7,22 +7,27 @@ package org.chromium.android_webview.test; |
| import android.content.Context; |
| import android.os.Handler; |
| import android.os.Looper; |
| +import android.os.Message; |
| import android.test.suitebuilder.annotation.SmallTest; |
| import android.widget.GridLayout; |
| import org.chromium.android_webview.AwContents; |
| -import org.chromium.android_webview.AwContentsClient; |
| import org.chromium.base.test.Feature; |
| import org.chromium.content.browser.ContentViewCore; |
| +import org.chromium.content.browser.test.CallbackHelper; |
| import java.util.concurrent.Semaphore; |
| import java.util.concurrent.TimeUnit; |
| +import java.util.concurrent.atomic.AtomicInteger; |
| +import java.util.concurrent.atomic.AtomicReference; |
| /** |
| * AwContents tests. |
| */ |
| public class AwContentsTest extends AndroidWebViewTestBase { |
| - private AwContentsClient mContentsClient = new NullContentsClient(); |
| + private static final long TEST_TIMEOUT = 20000L; |
|
mkosiba (inactive)
2012/08/30 09:43:13
maybe add this to the AndroidWebViewTestBase. I th
joth
2012/08/30 17:26:53
Done.
(actually switched to WAIT_TIMEOUT_SECONDS t
|
| + |
| + private TestAwContentsClient mContentsClient = new TestAwContentsClient(); |
| private AwContents createContents(Context context) { |
|
mkosiba (inactive)
2012/08/30 09:43:13
since you're already here.. :) please use createAw
joth
2012/08/30 17:26:53
Done.
|
| GridLayout viewGroup = new GridLayout(context); |
| @@ -62,4 +67,58 @@ public class AwContentsTest extends AndroidWebViewTestBase { |
| throw error[0]; |
| } |
| } |
| -} |
| + |
| + @SmallTest |
|
mkosiba (inactive)
2012/08/30 09:43:13
feature annotation
joth
2012/08/30 17:26:53
Done.
|
| + public void testDocumentHasImages() throws Throwable { |
| + final Context context = getActivity(); |
| + |
| + final AtomicReference<AwContents> awContentsRef = new AtomicReference<AwContents>(); |
| + runTestOnUiThread(new Runnable() { |
| + @Override |
| + public void run() { |
| + awContentsRef.set(createContents(context)); |
| + } |
| + }); |
| + AwContents awContents = awContentsRef.get(); |
|
mkosiba (inactive)
2012/08/30 09:43:13
remove lines 73-82, replace with a call to createA
joth
2012/08/30 17:26:53
Brill, thanks. I thought that must already exist s
|
| + |
| + final CallbackHelper loadHelper = mContentsClient.getOnPageFinishedHelper(); |
| + |
| + final String mime = "text/html"; |
| + final String emptyDoc = "<head/><body/>"; |
| + final String imageDoc = "<head/><body><img/><img/></body>"; |
| + |
| + // Make sure a document that does not have images returns 0 |
| + loadDataSync(awContents.getContentViewCore(), loadHelper, emptyDoc, mime, false); |
| + int result = callDocumentHasImagesSync(awContents); |
| + assertEquals(0, result); |
| + |
| + // Make sure a document that does have images returns 1 |
| + loadDataSync(awContents.getContentViewCore(), loadHelper, imageDoc, mime, false); |
| + result = callDocumentHasImagesSync(awContents); |
| + assertEquals(1, result); |
| + } |
| + |
| + private int callDocumentHasImagesSync(final AwContents awContents) |
| + throws Throwable, InterruptedException { |
| + // Set up a container to hold the result object and a semaphore to |
| + // make the test wait for the result. |
| + final AtomicInteger val = new AtomicInteger(); |
| + final Semaphore s = new Semaphore(0); |
| + final Message msg = Message.obtain(new Handler(Looper.getMainLooper()) { |
| + @Override |
| + public void handleMessage(Message msg) { |
| + val.set(msg.arg1); |
| + s.release(); |
| + } |
| + }); |
| + runTestOnUiThread(new Runnable() { |
| + @Override |
| + public void run() { |
| + awContents.documentHasImages(msg); |
| + } |
| + }); |
| + assertTrue(s.tryAcquire(TEST_TIMEOUT, TimeUnit.MILLISECONDS)); |
| + int result = val.get(); |
| + return result; |
| + } |
| +} |
|
joth
2012/08/30 17:26:53
test reduced to 81 lines :-)
|