diff options
author | yolandyan <yolandyan@google.com> | 2015-10-08 11:42:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-08 18:43:14 +0000 |
commit | 2a9e4d1100e6b15d591f193c152bb705774c9c38 (patch) | |
tree | 0b491fdb2c928b3fa2906dd40ce00a3bbb2db3a4 /android_webview/tools/PageCycler | |
parent | 0526bc8dc2cd554c51bfe6ecfee0701297c70b21 (diff) | |
download | chromium_src-2a9e4d1100e6b15d591f193c152bb705774c9c38.zip chromium_src-2a9e4d1100e6b15d591f193c152bb705774c9c38.tar.gz chromium_src-2a9e4d1100e6b15d591f193c152bb705774c9c38.tar.bz2 |
refactor android_webview_shell and add page cycler
The previous android_webview/toos/WebViewShell directory is now separated into:
android_webview/tools/WebViewShell/
android_webview/tools/WebViewShellTest/
with android_webview/tools/PageCycler/ added
The target name are changed to system_webview_shell_apk, system_webview_shell_layout_test_apk, and system_webview_shell_page_cycler_apk.
BUG=
Review URL: https://codereview.chromium.org/1364593002
Cr-Commit-Position: refs/heads/master@{#353105}
Diffstat (limited to 'android_webview/tools/PageCycler')
3 files changed, 197 insertions, 0 deletions
diff --git a/android_webview/tools/PageCycler/AndroidManifest.xml b/android_webview/tools/PageCycler/AndroidManifest.xml new file mode 100644 index 0000000..241be5d --- /dev/null +++ b/android_webview/tools/PageCycler/AndroidManifest.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + * 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. +--> + +<manifest + xmlns:android="http://schemas.android.com/apk/res/android" + package="org.chromium.webview_shell.page_cycler" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23" /> + + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> + <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" /> + <uses-permission android:name="android.permission.WAKE_LOCK" /> + <uses-permission android:name="android.permission.READ_LOGS"/> + + <application android:hardwareAccelerated="false"> + <uses-library android:name="android.test.runner" /> + <activity android:name="org.chromium.test.broker.OnDeviceInstrumentationBroker" + android:exported="true"/> + </application> + + <instrumentation android:name="android.test.InstrumentationTestRunner" + android:targetPackage="org.chromium.webview_shell" + android:label="Page cycler for org.chromium.webview_shell" /> +</manifest> diff --git a/android_webview/tools/PageCycler/DEPS b/android_webview/tools/PageCycler/DEPS new file mode 100644 index 0000000..d8dc2b0 --- /dev/null +++ b/android_webview/tools/PageCycler/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content/public/test/android/javatests", +] diff --git a/android_webview/tools/PageCycler/src/org/chromium/webview_shell/page_cycler/PageCyclerTest.java b/android_webview/tools/PageCycler/src/org/chromium/webview_shell/page_cycler/PageCyclerTest.java new file mode 100644 index 0000000..bc29b7b --- /dev/null +++ b/android_webview/tools/PageCycler/src/org/chromium/webview_shell/page_cycler/PageCyclerTest.java @@ -0,0 +1,163 @@ +// 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.page_cycler; + +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.LargeTest; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import org.chromium.base.test.util.Restriction; +import org.chromium.content.browser.test.util.CallbackHelper; +import org.chromium.webview_shell.PageCyclerTestActivity; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * Tests running on bots with internet connection to load popular urls, + * making sure webview doesn't crash + */ +public class PageCyclerTest + extends ActivityInstrumentationTestCase2<PageCyclerTestActivity> { + + private static final long TIMEOUT_IN_SECS = 20; + + private PageCyclerTestActivity mTestActivity; + + public PageCyclerTest() { + super(PageCyclerTestActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mTestActivity = getActivity(); + } + + @LargeTest + @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) + public void testVisitGoogleCom() throws Throwable { + //TODO(yolandyan@): verify the page + visitUrlSync("http://google.com"); + } + + @LargeTest + @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) + public void testVisitFacebookCom() throws Throwable { + visitUrlSync("http://facebook.com"); + } + + @LargeTest + @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) + public void testVisitWikipediaOrg() throws Throwable { + visitUrlSync("http://wikipedia.org"); + } + + @LargeTest + @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) + public void testVisitAmazonCom() throws Throwable { + visitUrlSync("http://amazon.com"); + } + + @LargeTest + @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) + public void testVisitYoutubeCom() throws Throwable { + visitUrlSync("http://youtube.com"); + } + + @LargeTest + @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) + public void testVisitYahooCom() throws Throwable { + visitUrlSync("http://yahoo.com"); + } + + @LargeTest + @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) + public void testVisitEbayCom() throws Throwable { + visitUrlSync("http://ebay.com"); + } + + @LargeTest + @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) + public void testVisitRedditCom() throws Throwable { + visitUrlSync("http://reddit.com"); + } + + private static class PageCyclerWebViewClient extends WebViewClient { + private final CallbackHelper mPageFinishedCallback; + private final CallbackHelper mErrorCallback; + + public PageCyclerWebViewClient() { + super(); + mPageFinishedCallback = new CallbackHelper(); + mErrorCallback = new CallbackHelper(); + } + + public CallbackHelper getPageFinishedCallback() { + return mPageFinishedCallback; + } + + public CallbackHelper getErrorCallback() { + return mErrorCallback; + } + + @Override + public void onPageFinished(WebView view, String url) { + mPageFinishedCallback.notifyCalled(); + } + + // TODO(yolandyan@): create helper class to manage network error + @Override + public void onReceivedError(WebView webview, int code, String description, + String failingUrl) { + mErrorCallback.notifyCalled(); + } + } + + private void visitUrlSync(final String url) throws Throwable { + final PageCyclerWebViewClient pageCyclerWebViewClient = new PageCyclerWebViewClient(); + getInstrumentation().runOnMainSync(new Runnable() { + @Override + public void run() { + final WebView view = mTestActivity.getWebView(); + WebSettings settings = view.getSettings(); + settings.setJavaScriptEnabled(true); + view.setWebViewClient(pageCyclerWebViewClient); + } + }); + CallbackHelper pageFinishedCallback = pageCyclerWebViewClient.getPageFinishedCallback(); + CallbackHelper errorCallback = pageCyclerWebViewClient.getErrorCallback(); + loadUrlSync(url, pageFinishedCallback, errorCallback); + } + + private void loadUrlSync(final String url, final CallbackHelper pageFinishedCallback, + final CallbackHelper errorCallback) throws InterruptedException { + boolean timeout = false; + int pageFinishedCount = pageFinishedCallback.getCallCount(); + int errorCount = errorCallback.getCallCount(); + loadUrlAsync(url); + try { + pageFinishedCallback.waitForCallback(pageFinishedCount, pageFinishedCount + 1, + TIMEOUT_IN_SECS, TimeUnit.SECONDS); + } catch (TimeoutException ex) { + timeout = true; + } + assertEquals(String.format("Network error while accessing %s", url), errorCount, + errorCallback.getCallCount()); + assertFalse(String.format("Timeout error while accessing %s", url), timeout); + } + + private void loadUrlAsync(final String url) { + getInstrumentation().runOnMainSync(new Runnable() { + @Override + public void run() { + WebView view = mTestActivity.getWebView(); + view.loadUrl(url); + } + }); + } +} |