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
3 // found in the LICENSE file.
5 package org.chromium.android_webview.test;
7 import android.test.suitebuilder.annotation.SmallTest;
9 import org.chromium.base.test.util.DisabledTest;
10 import org.chromium.base.test.util.Feature;
13 * Tests the asynchronous find-in-page APIs in WebView.
15 public class WebViewAsynchronousFindApisTest extends WebViewFindApisTestBase {
18 @Feature({"AndroidWebView", "FindInPage"})
19 public void testFindAllFinds() throws Throwable {
20 assertEquals(4, findAllAsyncOnUiThread("wood"));
24 @Feature({"AndroidWebView", "FindInPage"})
25 public void testFindAllDouble() throws Throwable {
26 findAllAsyncOnUiThread("wood");
27 assertEquals(4, findAllAsyncOnUiThread("chuck"));
32 @Feature({"AndroidWebView", "FindInPage"})
36 public void testFindAllDoubleNext() throws Throwable {
37 assertEquals(4, findAllAsyncOnUiThread("wood"));
38 assertEquals(4, findAllAsyncOnUiThread("wood"));
39 assertEquals(1, findNextOnUiThread(true));
43 @Feature({"AndroidWebView", "FindInPage"})
44 public void testFindAllDoesNotFind() throws Throwable {
45 assertEquals(0, findAllAsyncOnUiThread("foo"));
49 @Feature({"AndroidWebView", "FindInPage"})
50 public void testFindAllEmptyPage() throws Throwable {
51 assertEquals(0, findAllAsyncOnUiThread("foo"));
55 @Feature({"AndroidWebView", "FindInPage"})
56 public void testFindAllEmptyString() throws Throwable {
57 assertEquals(0, findAllAsyncOnUiThread(""));
61 @Feature({"AndroidWebView", "FindInPage"})
62 public void testFindNextForward() throws Throwable {
63 assertEquals(4, findAllAsyncOnUiThread("wood"));
65 for (int i = 2; i <= 4; i++) {
66 assertEquals(i - 1, findNextOnUiThread(true));
68 assertEquals(0, findNextOnUiThread(true));
72 @Feature({"AndroidWebView", "FindInPage"})
73 public void testFindNextBackward() throws Throwable {
74 assertEquals(4, findAllAsyncOnUiThread("wood"));
76 for (int i = 4; i >= 1; i--) {
77 assertEquals(i - 1, findNextOnUiThread(false));
79 assertEquals(3, findNextOnUiThread(false));
83 @Feature({"AndroidWebView", "FindInPage"})
84 public void testFindNextBig() throws Throwable {
85 assertEquals(4, findAllAsyncOnUiThread("wood"));
87 assertEquals(1, findNextOnUiThread(true));
88 assertEquals(0, findNextOnUiThread(false));
89 assertEquals(3, findNextOnUiThread(false));
90 for (int i = 1; i <= 4; i++) {
91 assertEquals(i - 1, findNextOnUiThread(true));
93 assertEquals(0, findNextOnUiThread(true));
97 @Feature({"AndroidWebView", "FindInPage"})
98 public void testFindAllEmptyNext() throws Throwable {
99 assertEquals(4, findAllAsyncOnUiThread("wood"));
100 assertEquals(1, findNextOnUiThread(true));
101 assertEquals(0, findAllAsyncOnUiThread(""));
102 assertEquals(0, findNextOnUiThread(true));
103 assertEquals(0, findAllAsyncOnUiThread(""));
104 assertEquals(4, findAllAsyncOnUiThread("wood"));
105 assertEquals(1, findNextOnUiThread(true));
109 @Feature({"AndroidWebView", "FindInPage"})
110 public void testClearMatches() throws Throwable {
111 assertEquals(4, findAllAsyncOnUiThread("wood"));
112 clearMatchesOnUiThread();
117 @Feature({"AndroidWebView", "FindInPage"})
121 public void testClearFindNext() throws Throwable {
122 assertEquals(4, findAllAsyncOnUiThread("wood"));
123 clearMatchesOnUiThread();
124 assertEquals(4, findAllAsyncOnUiThread("wood"));
125 assertEquals(1, findNextOnUiThread(true));
129 @Feature({"AndroidWebView", "FindInPage"})
130 public void testFindEmptyNext() throws Throwable {
131 assertEquals(0, findAllAsyncOnUiThread(""));
132 assertEquals(0, findNextOnUiThread(true));
133 assertEquals(4, findAllAsyncOnUiThread("wood"));
137 @Feature({"AndroidWebView", "FindInPage"})
138 public void testFindNextFirst() throws Throwable {
139 runTestOnUiThread(new Runnable() {
142 contents().findNext(true);
145 assertEquals(4, findAllAsyncOnUiThread("wood"));
146 assertEquals(1, findNextOnUiThread(true));
147 assertEquals(0, findNextOnUiThread(false));
148 assertEquals(3, findNextOnUiThread(false));