1// Copyright 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.
4
5package org.chromium.android_webview.test;
6
7import android.test.suitebuilder.annotation.SmallTest;
8
9import org.chromium.base.test.util.DisabledTest;
10import org.chromium.base.test.util.Feature;
11
12/**
13 * Tests the asynchronous find-in-page APIs in WebView.
14 */
15public class WebViewAsynchronousFindApisTest extends WebViewFindApisTestBase {
16
17    @SmallTest
18    @Feature({"AndroidWebView", "FindInPage"})
19    public void testFindAllFinds() throws Throwable {
20        assertEquals(4, findAllAsyncOnUiThread("wood"));
21    }
22
23    @SmallTest
24    @Feature({"AndroidWebView", "FindInPage"})
25    public void testFindAllDouble() throws Throwable {
26        findAllAsyncOnUiThread("wood");
27        assertEquals(4, findAllAsyncOnUiThread("chuck"));
28    }
29
30    /*
31    @SmallTest
32    @Feature({"AndroidWebView", "FindInPage"})
33    crbug.com/311495
34    */
35    @DisabledTest
36    public void testFindAllDoubleNext() throws Throwable {
37        assertEquals(4, findAllAsyncOnUiThread("wood"));
38        assertEquals(4, findAllAsyncOnUiThread("wood"));
39        assertEquals(1, findNextOnUiThread(true));
40    }
41
42    @SmallTest
43    @Feature({"AndroidWebView", "FindInPage"})
44    public void testFindAllDoesNotFind() throws Throwable {
45        assertEquals(0, findAllAsyncOnUiThread("foo"));
46    }
47
48    @SmallTest
49    @Feature({"AndroidWebView", "FindInPage"})
50    public void testFindAllEmptyPage() throws Throwable {
51        assertEquals(0, findAllAsyncOnUiThread("foo"));
52    }
53
54    @SmallTest
55    @Feature({"AndroidWebView", "FindInPage"})
56    public void testFindAllEmptyString() throws Throwable {
57        assertEquals(0, findAllAsyncOnUiThread(""));
58    }
59
60    @SmallTest
61    @Feature({"AndroidWebView", "FindInPage"})
62    public void testFindNextForward() throws Throwable {
63        assertEquals(4, findAllAsyncOnUiThread("wood"));
64
65        for (int i = 2; i <= 4; i++) {
66            assertEquals(i - 1, findNextOnUiThread(true));
67        }
68        assertEquals(0, findNextOnUiThread(true));
69    }
70
71    @SmallTest
72    @Feature({"AndroidWebView", "FindInPage"})
73    public void testFindNextBackward() throws Throwable {
74        assertEquals(4, findAllAsyncOnUiThread("wood"));
75
76        for (int i = 4; i >= 1; i--) {
77            assertEquals(i - 1, findNextOnUiThread(false));
78        }
79        assertEquals(3, findNextOnUiThread(false));
80    }
81
82    @SmallTest
83    @Feature({"AndroidWebView", "FindInPage"})
84    public void testFindNextBig() throws Throwable {
85        assertEquals(4, findAllAsyncOnUiThread("wood"));
86
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));
92        }
93        assertEquals(0, findNextOnUiThread(true));
94    }
95
96    @SmallTest
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));
106    }
107
108    @SmallTest
109    @Feature({"AndroidWebView", "FindInPage"})
110    public void testClearMatches() throws Throwable {
111        assertEquals(4, findAllAsyncOnUiThread("wood"));
112        clearMatchesOnUiThread();
113    }
114
115    /*
116    @SmallTest
117    @Feature({"AndroidWebView", "FindInPage"})
118    crbug.com/311495
119    */
120    @DisabledTest
121    public void testClearFindNext() throws Throwable {
122        assertEquals(4, findAllAsyncOnUiThread("wood"));
123        clearMatchesOnUiThread();
124        assertEquals(4, findAllAsyncOnUiThread("wood"));
125        assertEquals(1, findNextOnUiThread(true));
126    }
127
128    @SmallTest
129    @Feature({"AndroidWebView", "FindInPage"})
130    public void testFindEmptyNext() throws Throwable {
131        assertEquals(0, findAllAsyncOnUiThread(""));
132        assertEquals(0, findNextOnUiThread(true));
133        assertEquals(4, findAllAsyncOnUiThread("wood"));
134    }
135
136    @SmallTest
137    @Feature({"AndroidWebView", "FindInPage"})
138    public void testFindNextFirst() throws Throwable {
139        runTestOnUiThread(new Runnable() {
140            @Override
141            public void run() {
142                contents().findNext(true);
143            }
144        });
145        assertEquals(4, findAllAsyncOnUiThread("wood"));
146        assertEquals(1, findNextOnUiThread(true));
147        assertEquals(0, findNextOnUiThread(false));
148        assertEquals(3, findNextOnUiThread(false));
149    }
150}
151