| Index: android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/shell/PageCyclerTestActivity.java
|
| diff --git a/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/shell/PageCyclerTestActivity.java b/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/shell/PageCyclerTestActivity.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..93cb800101fc05726763c92315414c81edfa53f3
|
| --- /dev/null
|
| +++ b/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/shell/PageCyclerTestActivity.java
|
| @@ -0,0 +1,89 @@
|
| +// 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;
|
| + 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;
|
| + 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) {
|
| + 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");
|
| + }
|
| + }
|
| + }
|
| +
|
| + private void initializeSettings(WebSettings settings) {
|
| + settings.setJavaScriptEnabled(true);
|
| + settings.setGeolocationEnabled(true);
|
| + }
|
| +}
|
|
|