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

Unified Diff: android_webview/tools/WebViewShell/src/org/chromium/webview_shell/shell/PageCyclerTestActivity.java

Issue 1364593002: Refactor android_webview_shell and its tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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: android_webview/tools/WebViewShell/src/org/chromium/webview_shell/shell/PageCyclerTestActivity.java
diff --git a/android_webview/tools/WebViewShell/src/org/chromium/webview_shell/shell/PageCyclerTestActivity.java b/android_webview/tools/WebViewShell/src/org/chromium/webview_shell/shell/PageCyclerTestActivity.java
new file mode 100644
index 0000000000000000000000000000000000000000..4f29eab18aad4effce0b52b3e158f5e8d68dbeb7
--- /dev/null
+++ b/android_webview/tools/WebViewShell/src/org/chromium/webview_shell/shell/PageCyclerTestActivity.java
@@ -0,0 +1,93 @@
+// Copyright 2015 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.webview_shell.shell;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * This activity is used for loading urls using webview on Appurify bots to make sure the
+ * webview doesn't crash.
+ */
+public class PageCyclerTestActivity extends Activity {
+
+ private final Object mLock = new Object();
+
+ private WebView mWebView;
+ private boolean mPageFinished = false;
+
+ private boolean mReceivedError = false;
+ private int mErrorCode;
+ private String mErrorMessage;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_webview);
+ mWebView = (WebView) findViewById(R.id.webview);
+ WebSettings settings = mWebView.getSettings();
+ initializeSettings(settings);
+
+ mWebView.setWebViewClient(new WebViewClient() {
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ mPageFinished = true;
boliu 2015/09/23 16:59:07 this needs to be inside synchronized
Yoland Yan(Google) 2015/09/24 02:04:22 Done
+ synchronized (mLock) {
+ mLock.notifyAll();
+ }
+ }
+
+ // TODO(yolandyan@): create helper class to manage network error
+ @Override
+ public void onReceivedError(WebView webview, int code, String description,
+ String failingUrl) {
+ mErrorCode = code;
+ mErrorMessage = description;
+ mReceivedError = true;
boliu 2015/09/23 16:59:07 ditto
Yoland Yan(Google) 2015/09/24 02:04:22 Done
+ synchronized (mLock) {
+ mLock.notifyAll();
+ }
+ }
+ });
+ }
+
+ public void loadUrl(String url) {
+ mWebView.loadUrl(url);
+ mWebView.requestFocus();
+ }
+
+ // This function waits for url to be loaded or throws exception if an error occurs
+ public void waitForPageLoad(long timeout, TimeUnit unit) throws InterruptedException,
+ TimeoutException, Exception {
+ synchronized (mLock) {
boliu 2015/09/23 16:59:07 this belongs in the test apk, the activity can exp
Yoland Yan(Google) 2015/09/24 02:04:22 Done
+ long deadline = System.currentTimeMillis() + unit.toMillis(timeout);
+ while (!mPageFinished && !mReceivedError && System.currentTimeMillis() < deadline) {
+ mLock.wait(deadline - System.currentTimeMillis());
+ }
+ if (mReceivedError) {
+ throw new Exception(String.format("Error code: %d, error message: %s", mErrorCode,
+ mErrorMessage));
+ } else if (!mPageFinished) {
+ throw new TimeoutException("timeout");
+ }
+ }
+ }
+
+ public String getError() {
+ return String.format("Error code: %d, error description: %s", mErrorCode, mErrorMessage);
+ }
+
+ private void initializeSettings(WebSettings settings) {
+ settings.setJavaScriptEnabled(true);
+ settings.setGeolocationEnabled(true);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698