Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1138)

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/test/TestContentViewClient.java

Issue 10855171: Add a test runner for android_webview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove infobars dep, add DEPS file to chrome/android/java Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/javatests/src/org/chromium/content/browser/test/TestContentViewClient.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/test/TestContentViewClient.java b/content/public/android/javatests/src/org/chromium/content/browser/test/TestContentViewClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..3abecf9b3fab4b8a07a17d8803abee4dcdd857bb
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/test/TestContentViewClient.java
@@ -0,0 +1,152 @@
+// 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.content.browser.test;
+
+
+import org.chromium.content.browser.ContentViewClient;
+
+/**
+ * The default ContentViewClient used by ContentView tests.
+ * <p>
+ * Tests that need to supply their own ContentViewClient should do that
+ * by extending this one.
+ */
+public class TestContentViewClient extends ContentViewClient {
+
+ protected static int WAIT_TIMEOUT_SECONDS = 5;
+
+ public static class OnPageFinishedHelper extends CallbackHelper {
+ private String mUrl;
+ void setUrl(String url) {
+ mUrl = url;
+ }
+ public String getUrl() {
+ assert getCallCount() > 0;
+ return mUrl;
+ }
+ }
+
+ public static class OnPageStartedHelper extends CallbackHelper {
+ private String mUrl;
+ void setUrl(String url) {
+ mUrl = url;
+ }
+ public String getUrl() {
+ assert getCallCount() > 0;
+ return mUrl;
+ }
+ }
+
+ public static class OnReceivedErrorHelper extends CallbackHelper {
+ private int mErrorCode;
+ private String mDescription;
+ private String mFailingUrl;
+ void setErrorCode(int errorCode) {
+ mErrorCode = errorCode;
+ }
+ void setDescription(String description) {
+ mDescription = description;
+ }
+ void setFailingUrl(String failingUrl) {
+ mFailingUrl = failingUrl;
+ }
+ public int getErrorCode() {
+ assert getCallCount() > 0;
+ return mErrorCode;
+ }
+ public String getDescription() {
+ assert getCallCount() > 0;
+ return mDescription;
+ }
+ public String getFailingUrl() {
+ assert getCallCount() > 0;
+ return mFailingUrl;
+ }
+ }
+
+ public static class OnEvaluateJavaScriptResultHelper extends CallbackHelper {
+ private int mId;
+ private String mJsonResult;
+ void setId(int id) {
+ mId = id;
+ }
+ void setJsonResult(String jsonResult) {
+ mJsonResult = jsonResult;
+ }
+ public int getId() {
+ assert getCallCount() > 0;
+ return mId;
+ }
+ public String getJsonResult() {
+ assert getCallCount() > 0;
+ return mJsonResult;
+ }
+ }
+
+ private OnPageStartedHelper mOnPageStartedHelper;
+ private OnPageFinishedHelper mOnPageFinishedHelper;
+ private OnReceivedErrorHelper mOnReceivedErrorHelper;
+ private OnEvaluateJavaScriptResultHelper mOnEvaluateJavaScriptResultHelper;
+
+ public TestContentViewClient() {
+ mOnPageStartedHelper = new OnPageStartedHelper();
+ mOnPageFinishedHelper = new OnPageFinishedHelper();
+ mOnReceivedErrorHelper = new OnReceivedErrorHelper();
+ mOnEvaluateJavaScriptResultHelper = new OnEvaluateJavaScriptResultHelper();
+ }
+
+ public OnPageStartedHelper getOnPageStartedHelper() {
+ return mOnPageStartedHelper;
+ }
+
+ public OnPageFinishedHelper getOnPageFinishedHelper() {
+ return mOnPageFinishedHelper;
+ }
+
+ public OnReceivedErrorHelper getOnReceivedErrorHelper() {
+ return mOnReceivedErrorHelper;
+ }
+
+ public OnEvaluateJavaScriptResultHelper getOnEvaluateJavaScriptResultHelper() {
+ return mOnEvaluateJavaScriptResultHelper;
+ }
+
+ /**
+ * ATTENTION!: When overriding the following methods, be sure to call
+ * the corresponding methods in the super class. Otherwise
+ * {@link CallbackHelper#waitForCallback()} methods will
+ * stop working!
+ */
+ @Override
+ public void onPageStarted(String url) {
+ super.onPageStarted(url);
+ mOnPageStartedHelper.setUrl(url);
+ mOnPageStartedHelper.notifyCalled();
+ }
+
+ @Override
+ public void onPageFinished(String url) {
+ super.onPageFinished(url);
+ mOnPageFinishedHelper.setUrl(url);
+ mOnPageFinishedHelper.notifyCalled();
+ }
+
+ @Override
+ public void onReceivedError(int errorCode, String description, String failingUrl) {
+ super.onReceivedError(errorCode, description, failingUrl);
+ mOnReceivedErrorHelper.setErrorCode(errorCode);
+ mOnReceivedErrorHelper.setDescription(description);
+ mOnReceivedErrorHelper.setFailingUrl(failingUrl);
+ mOnReceivedErrorHelper.notifyCalled();
+ }
+
+ @Override
+ public void onEvaluateJavaScriptResult(int id, String jsonResult) {
+ super.onEvaluateJavaScriptResult(id, jsonResult);
+ mOnEvaluateJavaScriptResultHelper.setId(id);
+ mOnEvaluateJavaScriptResultHelper.setJsonResult(jsonResult);
+ mOnEvaluateJavaScriptResultHelper.notifyCalled();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698