Skip to content

Commit

Permalink
Merge pull request crosswalk-project#3935 from chuan9/xwalk-7325-a
Browse files Browse the repository at this point in the history
Add XWalkViewAsynchronousApisTest referring to upstream's implementation.
  • Loading branch information
Raphael Kubo da Costa authored Oct 13, 2016
2 parents fb6e871 + 241ddf0 commit 6c66ad8
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 160 deletions.
5 changes: 2 additions & 3 deletions test/android/core/javatests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ android_library("xwalk_core_test_java") {
"src/org/xwalk/core/xwview/test/EvaluateJavascriptTest.java",
"src/org/xwalk/core/xwview/test/ExtensionEcho.java",
"src/org/xwalk/core/xwview/test/ExtensionEchoTest.java",
"src/org/xwalk/core/xwview/test/FindAsyncTest.java",
"src/org/xwalk/core/xwview/test/GetAPIVersionTest.java",
"src/org/xwalk/core/xwview/test/GetCompositingSurfaceTypeTest.java",
"src/org/xwalk/core/xwview/test/GetContentHeightTest.java",
Expand Down Expand Up @@ -98,6 +97,8 @@ android_library("xwalk_core_test_java") {
"src/org/xwalk/core/xwview/test/UseWideViewportTest.java",
"src/org/xwalk/core/xwview/test/UserAgentTest.java",
"src/org/xwalk/core/xwview/test/VideoWithBlobUrlTest.java",
"src/org/xwalk/core/xwview/test/XWalkViewAsynchronousFindApisTest.java",
"src/org/xwalk/core/xwview/test/XWalkViewFindApisTestBase.java",
"src/org/xwalk/core/xwview/test/XWalkViewTestBase.java",
"src/org/xwalk/core/xwview/test/ZoomTest.java",
]
Expand Down Expand Up @@ -127,7 +128,6 @@ android_assets("xwalk_core_test_apk_assets") {
"//xwalk/test/android/data/echo_sync_java.html",
"//xwalk/test/android/data/favicon.html",
"//xwalk/test/android/data/file_chooser.html",
"//xwalk/test/android/data/find.html",
"//xwalk/test/android/data/framesEcho.html",
"//xwalk/test/android/data/fullscreen_enter_exit.html",
"//xwalk/test/android/data/fullscreen_togged.html",
Expand All @@ -151,7 +151,6 @@ android_assets("xwalk_core_test_apk_assets") {
"echo_sync_java.html",
"favicon.html",
"file_chooser.html",
"find.html",
"framesEcho.html",
"fullscreen_enter_exit.html",
"fullscreen_togged.html",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -512,34 +512,6 @@ public void notifyCalled(String host) {
}
}

public class OnFindResultReceivedHelper extends CallbackHelper {
private int mIndex;
private int mMatches;
private boolean mIsDone;

public int getIndex() {
assert getCallCount() > 0;
return mIndex;
}

public int getMatches() {
assert getCallCount() > 0;
return mMatches;
}

public boolean isDone() {
assert getCallCount() > 0;
return mIsDone;
}

public void notifyCalled(int index, int matches, boolean isDone) {
mIndex = index;
mMatches = matches;
mIsDone = isDone;
notifyCalled();
}
}

private String mChangedTitle;
private LoadStatus mLoadStatus;
private final OnPageStartedHelper mOnPageStartedHelper;
Expand Down Expand Up @@ -573,7 +545,6 @@ public void notifyCalled(int index, int matches, boolean isDone) {
private final OnReceivedResponseHeadersHelper mOnReceivedResponseHeadersHelper;
private final OnReceivedHttpAuthRequestHelper mOnReceivedHttpAuthRequestHelper;
private final CallbackHelper mOnReceivedSslErrorHelper;
private final OnFindResultReceivedHelper mOnFindResultReceivedHelper;

public TestHelperBridge() {
mOnPageStartedHelper = new OnPageStartedHelper();
Expand Down Expand Up @@ -605,7 +576,6 @@ public TestHelperBridge() {
mOnReceivedResponseHeadersHelper = new OnReceivedResponseHeadersHelper();
mOnReceivedHttpAuthRequestHelper = new OnReceivedHttpAuthRequestHelper();
mOnReceivedSslErrorHelper = new CallbackHelper();
mOnFindResultReceivedHelper = new OnFindResultReceivedHelper();
}

public OnPageStartedHelper getOnPageStartedHelper() {
Expand Down Expand Up @@ -724,10 +694,6 @@ public CallbackHelper getOnReceivedSslErrorHelper() {
return mOnReceivedSslErrorHelper;
}

public OnFindResultReceivedHelper getOnFindResultReceivedHelper() {
return mOnFindResultReceivedHelper;
}

public void onTitleChanged(String title) {
mChangedTitle = title;
mOnTitleUpdatedHelper.notifyCalled(title);
Expand Down Expand Up @@ -840,12 +806,6 @@ public void onDownloadStart(String url, String userAgent,
mimetype, contentLength);
}

public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
boolean isDoneCounting) {
mOnFindResultReceivedHelper.notifyCalled(activeMatchOrdinal, numberOfMatches,
isDoneCounting);
}

public void onReceivedClientCertRequest(XWalkView view, ClientCertRequest handler) {
mOnReceivedClientCertRequestHelper.notifyCalled(handler);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Copyright 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2016 Intel Corporation. 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.xwalk.core.xwview.test;

import android.test.suitebuilder.annotation.SmallTest;

import org.chromium.base.test.util.Feature;
/**
* Test suite for asynchronous find APIs
*/
public class XWalkViewAsynchronousFindApisTest extends XWalkViewFindApisTestBase {
final String WOODCHUCK =
"How much WOOD would a woodchuck chuck if a woodchuck could chuck wOoD?";

final String data = "<html><head></head><body>" + WOODCHUCK + "</body></html>";

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindAllFinds() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(4, findAllAsyncOnUiThread("wood"));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindAllDouble() throws Throwable {
loadDataSync(null, data, "text/html", false);
findAllAsyncOnUiThread("wood");
assertEquals(4, findAllAsyncOnUiThread("chuck"));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindAllDoubleNext() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(4, findAllAsyncOnUiThread("wood"));
assertEquals(4, findAllAsyncOnUiThread("wood"));
assertEquals(2, findNextOnUiThread(true));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindAllDoesNotFind() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(0, findAllAsyncOnUiThread("foo"));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindAllEmptyPage() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(0, findAllAsyncOnUiThread("foo"));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindAllEmptyString() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(0, findAllAsyncOnUiThread(""));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindNextForward() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(4, findAllAsyncOnUiThread("wood"));

for (int i = 2; i <= 4; i++) {
assertEquals(i - 1, findNextOnUiThread(true));
}
assertEquals(0, findNextOnUiThread(true));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindNextBackward() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(4, findAllAsyncOnUiThread("wood"));

for (int i = 4; i >= 1; i--) {
assertEquals(i - 1, findNextOnUiThread(false));
}
assertEquals(3, findNextOnUiThread(false));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindNextBig() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(4, findAllAsyncOnUiThread("wood"));

assertEquals(1, findNextOnUiThread(true));
assertEquals(0, findNextOnUiThread(false));
assertEquals(3, findNextOnUiThread(false));
for (int i = 1; i <= 4; i++) {
assertEquals(i - 1, findNextOnUiThread(true));
}
assertEquals(0, findNextOnUiThread(true));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindAllEmptyNext() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(4, findAllAsyncOnUiThread("wood"));
assertEquals(1, findNextOnUiThread(true));
assertEquals(0, findAllAsyncOnUiThread(""));
assertEquals(0, findNextOnUiThread(true));
assertEquals(0, findAllAsyncOnUiThread(""));
assertEquals(4, findAllAsyncOnUiThread("wood"));
assertEquals(1, findNextOnUiThread(true));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testClearMatches() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(4, findAllAsyncOnUiThread("wood"));
clearMatchesOnUiThread();
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testClearFindNext() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(4, findAllAsyncOnUiThread("wood"));
clearMatchesOnUiThread();
assertEquals(4, findAllAsyncOnUiThread("wood"));
assertEquals(1, findNextOnUiThread(true));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindEmptyNext() throws Throwable {
loadDataSync(null, data, "text/html", false);
assertEquals(0, findAllAsyncOnUiThread(""));
assertEquals(0, findNextOnUiThread(true));
assertEquals(4, findAllAsyncOnUiThread("wood"));
}

@SmallTest
@Feature({"XWalkView", "FindInPage"})
public void testFindNextFirst() throws Throwable {
loadDataSync(null, data, "text/html", false);
runTestOnUiThread(new Runnable() {
@Override
public void run() {
getXWalkView().findNext(true);
}
});
assertEquals(4, findAllAsyncOnUiThread("wood"));
assertEquals(1, findNextOnUiThread(true));
assertEquals(0, findNextOnUiThread(false));
assertEquals(3, findNextOnUiThread(false));
}
}
Loading

0 comments on commit 6c66ad8

Please sign in to comment.