summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authormkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 12:06:53 +0000
committermkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 12:06:53 +0000
commit13485fa0a0cbfb97b66cb52a298ddd278d247ec8 (patch)
treea8dfbfee2d81cb3ec82b15edd9919c904d6dbf91 /android_webview
parent67fcbafb309eece99f37c65851cc9fa7f6fbfcc3 (diff)
downloadchromium_src-13485fa0a0cbfb97b66cb52a298ddd278d247ec8.zip
chromium_src-13485fa0a0cbfb97b66cb52a298ddd278d247ec8.tar.gz
chromium_src-13485fa0a0cbfb97b66cb52a298ddd278d247ec8.tar.bz2
[android_webview] Add test shell for webview.
This adds a simple test shell (most code stolen from chrome testshell) for android_webview testing. The only currently supported rendering mode is s/w rendering. BUG=None Android_webview-only change, ran through trybots. NOTRY=true Review URL: https://chromiumcodereview.appspot.com/12317015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/android_webview_tests.gypi42
-rw-r--r--android_webview/javatests/assets/asset_icon.pngbin12887 -> 0 bytes
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestBase.java1
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwTestContainerView.java2
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwTestResourceProvider.java2
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/NullContentsClient.java2
-rw-r--r--android_webview/shell_apk/AndroidManifest.xml27
-rw-r--r--android_webview/shell_apk/res/layout/testshell_activity.xml47
-rw-r--r--android_webview/shell_apk/src/org/chromium/android_webview/shell/AndroidWebViewTestShellActivity.java162
-rw-r--r--android_webview/shell_apk/src/org/chromium/android_webview/shell/AndroidWebViewTestShellApplication.java35
-rw-r--r--android_webview/test_apk/AndroidManifest.xml (renamed from android_webview/javatests/AndroidManifest.xml)0
-rw-r--r--android_webview/test_apk/assets/asset_file.html (renamed from android_webview/javatests/assets/asset_file.html)0
-rw-r--r--android_webview/test_apk/assets/full_screen_video_test.html (renamed from android_webview/javatests/assets/full_screen_video_test.html)0
-rw-r--r--android_webview/test_apk/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java (renamed from android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java)2
14 files changed, 313 insertions, 9 deletions
diff --git a/android_webview/android_webview_tests.gypi b/android_webview/android_webview_tests.gypi
index 151e291..998aba3 100644
--- a/android_webview/android_webview_tests.gypi
+++ b/android_webview/android_webview_tests.gypi
@@ -4,20 +4,33 @@
{
'targets': [
{
- 'target_name': 'android_webview_test_apk',
+ 'target_name': 'android_webview_test_java',
'type': 'none',
'dependencies': [
'../base/base.gyp:base_java_test_support',
'../content/content.gyp:content_java_test_support',
'../net/net.gyp:net_java_test_support',
- 'android_webview_java',
+ 'android_webview_java',
'libwebviewchromium',
],
'variables': {
- 'apk_name': 'AndroidWebViewTest',
'java_in_dir': '../android_webview/javatests',
- 'resource_dir': 'res',
- 'is_test_apk': 1,
+ 'has_java_resources': 1,
+ 'R_package': 'org.chromium.android_webview.test',
+ 'R_package_relpath': 'org/chromium/android_webview/test',
+ },
+ 'includes': [ '../build/java.gypi' ],
+ },
+ {
+ 'target_name': 'android_webview_test_apk',
+ 'type': 'none',
+ 'dependencies': [
+ 'android_webview_test_java',
+ ],
+ 'variables': {
+ 'apk_name': 'AndroidWebViewTest',
+ 'java_in_dir': '../android_webview/test_apk',
+ 'is_test_apk': 0, # We want resources from android_webview_test_java.
'additional_input_paths': [
'<(PRODUCT_DIR)/android_webview_test_apk/assets/asset_file.html',
'<(PRODUCT_DIR)/android_webview_test_apk/assets/asset_icon.png',
@@ -37,6 +50,25 @@
'includes': [ '../build/java_apk.gypi' ],
},
{
+ 'target_name': 'android_webview_shell_apk',
+ 'type': 'none',
+ 'dependencies': [
+ 'android_webview_test_java',
+ 'android_webview_pak',
+ ],
+ 'variables': {
+ 'apk_name': 'AndroidWebViewShell',
+ 'java_in_dir': '../android_webview/shell_apk',
+ 'native_libs_paths': ['<(SHARED_LIB_DIR)/libwebviewchromium.so'],
+ 'resource_dir': 'res',
+ 'asset_location': '<(ant_build_out)/android_webview_apk/assets',
+ 'additional_input_paths': [
+ '<(PRODUCT_DIR)/android_webview_apk/assets/webviewchromium.pak',
+ ],
+ },
+ 'includes': [ '../build/java_apk.gypi' ],
+ },
+ {
'target_name': 'android_webview_unittests',
'type': '<(gtest_target_type)',
'dependencies': [
diff --git a/android_webview/javatests/assets/asset_icon.png b/android_webview/javatests/assets/asset_icon.png
deleted file mode 100644
index f381f86..0000000
--- a/android_webview/javatests/assets/asset_icon.png
+++ /dev/null
Binary files differ
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestBase.java b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestBase.java
index 03f8d20..e90344e 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestBase.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestBase.java
@@ -45,7 +45,6 @@ public class AndroidWebViewTestBase
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
- AwTestResourceProvider.registerResources(context);
AwBrowserProcess.start(context);
}
});
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestContainerView.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestContainerView.java
index dbb2851..bf36c9a 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestContainerView.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestContainerView.java
@@ -23,7 +23,7 @@ import org.chromium.content.browser.ContentViewCore;
*
* This class takes the place android.webkit.WebView would have in the production configuration.
*/
-class AwTestContainerView extends FrameLayout {
+public class AwTestContainerView extends FrameLayout {
private AwContents mAwContents;
private AwContents.InternalAccessDelegate mInternalAccessDelegate;
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestResourceProvider.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestResourceProvider.java
index 5aaab7b..0f515e5 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestResourceProvider.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestResourceProvider.java
@@ -11,7 +11,7 @@ import org.chromium.android_webview.AwResource;
public class AwTestResourceProvider {
private static boolean sInitialized;
- static void registerResources(Context context) {
+ public static void registerResources(Context context) {
if (sInitialized) {
return;
}
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/NullContentsClient.java b/android_webview/javatests/src/org/chromium/android_webview/test/NullContentsClient.java
index 0356710..c340073 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/NullContentsClient.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/NullContentsClient.java
@@ -26,7 +26,7 @@ import org.chromium.android_webview.JsResultReceiver;
* As a convience for tests that only care about specefic callbacks, this class provides
* empty implementations of all abstract methods.
*/
-class NullContentsClient extends AwContentsClient {
+public class NullContentsClient extends AwContentsClient {
@Override
public boolean shouldIgnoreNavigation(String url) {
return false;
diff --git a/android_webview/shell_apk/AndroidManifest.xml b/android_webview/shell_apk/AndroidManifest.xml
new file mode 100644
index 0000000..61a3308
--- /dev/null
+++ b/android_webview/shell_apk/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Copyright 2013 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.android_webview.shell">
+
+ <application android:name="org.chromium.android_webview.shell.AndroidWebViewTestShellApplication"
+ android:label="AndroidWebViewTestShellApplication" android:hardwareAccelerated="false">
+ <activity android:name="org.chromium.android_webview.shell.AndroidWebViewTestShellActivity"
+ android:label="Android WebView Test Shell">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+ <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="17" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.WAKE_LOCK"/>
+</manifest>
diff --git a/android_webview/shell_apk/res/layout/testshell_activity.xml b/android_webview/shell_apk/res/layout/testshell_activity.xml
new file mode 100644
index 0000000..0a997fa
--- /dev/null
+++ b/android_webview/shell_apk/res/layout/testshell_activity.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Copyright (c) 2013 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.
+ -->
+
+<LinearLayout android:id="@+id/testshell_activity"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <LinearLayout android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <EditText android:id="@+id/url"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:gravity="bottom"
+ android:textSize="18sp"
+ android:autoText="true"
+ android:capitalize="sentences"
+ android:singleLine="true"
+ android:selectAllOnFocus="true"
+ android:inputType="textUri"
+ android:imeOptions="actionGo" />
+ <ImageButton android:id="@+id/prev"
+ android:layout_width="38dp"
+ android:layout_height="38dp"
+ android:src="@android:drawable/ic_media_previous"
+ android:scaleType="center" />
+ <ImageButton android:id="@+id/next"
+ android:layout_width="38dp"
+ android:layout_height="38dp"
+ android:src="@android:drawable/ic_media_next"
+ android:scaleType="center" />
+ </LinearLayout>
+ <LinearLayout android:id="@+id/content_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ </LinearLayout>
+
+</LinearLayout>
+
diff --git a/android_webview/shell_apk/src/org/chromium/android_webview/shell/AndroidWebViewTestShellActivity.java b/android_webview/shell_apk/src/org/chromium/android_webview/shell/AndroidWebViewTestShellActivity.java
new file mode 100644
index 0000000..e1408e8
--- /dev/null
+++ b/android_webview/shell_apk/src/org/chromium/android_webview/shell/AndroidWebViewTestShellActivity.java
@@ -0,0 +1,162 @@
+// Copyright (c) 2013 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.android_webview.shell;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.View.OnFocusChangeListener;
+import android.view.ViewGroup.LayoutParams;
+import android.view.WindowManager;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.ImageButton;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.TextView.OnEditorActionListener;
+
+import org.chromium.android_webview.AwBrowserProcess;
+import org.chromium.android_webview.AwBrowserContext;
+import org.chromium.android_webview.AwContents;
+import org.chromium.android_webview.AwContentsClient;
+import org.chromium.android_webview.test.AwTestContainerView;
+import org.chromium.android_webview.test.NullContentsClient;
+import org.chromium.content.browser.LoadUrlParams;
+
+/*
+ * This is a lightweight activity for tests that only require WebView functionality.
+ */
+public class AndroidWebViewTestShellActivity extends Activity {
+ private final static String PREFERENCES_NAME = "AndroidWebViewTestShellPrefs";
+ private final static String INITIAL_URL = "about:blank";
+ private AwTestContainerView mAwTestContainerView;
+ private EditText mUrlTextView;
+ private ImageButton mPrevButton;
+ private ImageButton mNextButton;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.testshell_activity);
+
+ mAwTestContainerView = createAwTestContainerView();
+
+ LinearLayout contentContainer = (LinearLayout) findViewById(R.id.content_container);
+ mAwTestContainerView.setLayoutParams(new LinearLayout.LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f));
+ contentContainer.addView(mAwTestContainerView);
+ mAwTestContainerView.requestFocus();
+
+ initializeUrlField();
+ initializeNavigationButtons();
+
+ String startupUrl = getUrlFromIntent(getIntent());
+ if (TextUtils.isEmpty(startupUrl)) {
+ startupUrl = INITIAL_URL;
+ }
+
+ mAwTestContainerView.getAwContents().loadUrl(new LoadUrlParams(startupUrl));
+ mUrlTextView.setText(startupUrl);
+ }
+
+ private AwTestContainerView createAwTestContainerView() {
+ AwTestContainerView testContainerView = new AwTestContainerView(this);
+ AwContentsClient awContentsClient = new NullContentsClient() {
+ @Override
+ public void onPageStarted(String url) {
+ if (mUrlTextView != null) {
+ mUrlTextView.setText(url);
+ }
+ }
+ };
+
+ SharedPreferences sharedPreferences =
+ getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
+ AwBrowserContext browserContext = new AwBrowserContext(sharedPreferences);
+
+ testContainerView.initialize(new AwContents(browserContext, testContainerView,
+ testContainerView.getInternalAccessDelegate(),
+ awContentsClient, false));
+ testContainerView.getContentViewCore().getContentSettings().setJavaScriptEnabled(true);
+ return testContainerView;
+ }
+
+ private static String getUrlFromIntent(Intent intent) {
+ return intent != null ? intent.getDataString() : null;
+ }
+
+ private void setKeyboardVisibilityForUrl(boolean visible) {
+ InputMethodManager imm = (InputMethodManager) getSystemService(
+ Context.INPUT_METHOD_SERVICE);
+ if (visible) {
+ imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT);
+ } else {
+ imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0);
+ }
+ }
+
+ private void initializeUrlField() {
+ mUrlTextView = (EditText) findViewById(R.id.url);
+ mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() {
+ @Override
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+ if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null ||
+ event.getKeyCode() != KeyEvent.KEYCODE_ENTER ||
+ event.getKeyCode() != KeyEvent.ACTION_DOWN)) {
+ return false;
+ }
+
+ mAwTestContainerView.getAwContents().loadUrl(
+ new LoadUrlParams(mUrlTextView.getText().toString()));
+ mUrlTextView.clearFocus();
+ setKeyboardVisibilityForUrl(false);
+ mAwTestContainerView.requestFocus();
+ return true;
+ }
+ });
+ mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ setKeyboardVisibilityForUrl(hasFocus);
+ mNextButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
+ mPrevButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
+ if (!hasFocus) {
+ mUrlTextView.setText(mAwTestContainerView.getContentViewCore().getUrl());
+ }
+ }
+ });
+ }
+
+ private void initializeNavigationButtons() {
+ mPrevButton = (ImageButton) findViewById(R.id.prev);
+ mPrevButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mAwTestContainerView.getContentViewCore().canGoBack()) {
+ mAwTestContainerView.getContentViewCore().goBack();
+ }
+ }
+ });
+
+ mNextButton = (ImageButton) findViewById(R.id.next);
+ mNextButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mAwTestContainerView.getContentViewCore().canGoForward()) {
+ mAwTestContainerView.getContentViewCore().goForward();
+ }
+ }
+ });
+ }
+}
diff --git a/android_webview/shell_apk/src/org/chromium/android_webview/shell/AndroidWebViewTestShellApplication.java b/android_webview/shell_apk/src/org/chromium/android_webview/shell/AndroidWebViewTestShellApplication.java
new file mode 100644
index 0000000..44e64c2
--- /dev/null
+++ b/android_webview/shell_apk/src/org/chromium/android_webview/shell/AndroidWebViewTestShellApplication.java
@@ -0,0 +1,35 @@
+// 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.android_webview.shell;
+
+import android.app.Application;
+import android.content.Context;
+
+import org.chromium.android_webview.AwBrowserProcess;
+import org.chromium.android_webview.test.AwTestResourceProvider;
+import org.chromium.content.browser.ResourceExtractor;
+import org.chromium.content.common.CommandLine;
+
+public class AndroidWebViewTestShellApplication extends Application {
+
+ /** The minimum set of .pak files the test runner needs. */
+ private static final String[] MANDATORY_PAKS = {
+ "webviewchromium.pak", "en-US.pak"
+ };
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+
+ AwTestResourceProvider.registerResources(this);
+
+ CommandLine.initFromFile("/data/local/chrome-command-line");
+
+ ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAKS);
+ ResourceExtractor.setExtractImplicitLocaleForTesting(false);
+ AwBrowserProcess.loadLibrary();
+ AwBrowserProcess.start(this);
+ }
+}
diff --git a/android_webview/javatests/AndroidManifest.xml b/android_webview/test_apk/AndroidManifest.xml
index 3062283..3062283 100644
--- a/android_webview/javatests/AndroidManifest.xml
+++ b/android_webview/test_apk/AndroidManifest.xml
diff --git a/android_webview/javatests/assets/asset_file.html b/android_webview/test_apk/assets/asset_file.html
index 5008860..5008860 100644
--- a/android_webview/javatests/assets/asset_file.html
+++ b/android_webview/test_apk/assets/asset_file.html
diff --git a/android_webview/javatests/assets/full_screen_video_test.html b/android_webview/test_apk/assets/full_screen_video_test.html
index 466a8d4..466a8d4 100644
--- a/android_webview/javatests/assets/full_screen_video_test.html
+++ b/android_webview/test_apk/assets/full_screen_video_test.html
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java b/android_webview/test_apk/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java
index 55ca4cc..e12feef 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java
+++ b/android_webview/test_apk/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java
@@ -21,6 +21,8 @@ public class AndroidWebViewTestRunnerApplication extends Application {
public void onCreate() {
super.onCreate();
+ AwTestResourceProvider.registerResources(this);
+
CommandLine.initFromFile("/data/local/chrome-command-line");
ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAKS);