summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authormkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-29 19:39:20 +0000
committermkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-29 19:39:20 +0000
commit4422cc4ead145539b2dc36c7fbbeacb7c038ddd1 (patch)
tree00f1648a4489281c3c3716edccb90c25ea321d82 /android_webview
parentb04daa57e9dac39848bab18f1df7880eeae726de (diff)
downloadchromium_src-4422cc4ead145539b2dc36c7fbbeacb7c038ddd1.zip
chromium_src-4422cc4ead145539b2dc36c7fbbeacb7c038ddd1.tar.gz
chromium_src-4422cc4ead145539b2dc36c7fbbeacb7c038ddd1.tar.bz2
[Android] Remove ContentView usage from android_webview.
This changes the android_webview Java test code to use the new AwContentsView test class instead of ContentView. BUG= Review URL: https://chromiumcodereview.appspot.com/10873049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153953 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewLoadUrlTest.java51
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestBase.java41
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerActivity.java56
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java2
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java8
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwTestContainerView.java146
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java70
7 files changed, 287 insertions, 87 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewLoadUrlTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewLoadUrlTest.java
index a78d519..900c025 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewLoadUrlTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewLoadUrlTest.java
@@ -4,36 +4,22 @@
package org.chromium.android_webview.test;
-import android.test.suitebuilder.annotation.Smoke;
+import android.content.Context;
import android.test.suitebuilder.annotation.SmallTest;
+import android.test.suitebuilder.annotation.Smoke;
import org.chromium.base.test.Feature;
-import org.chromium.content.browser.ContentView;
+import org.chromium.android_webview.AwContents;
+import org.chromium.android_webview.AwWebContentsDelegate;
import org.chromium.content.browser.ContentViewCore;
-import org.chromium.content.browser.test.TestContentViewClient;
import java.util.concurrent.Callable;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.ArrayList;
/**
* Test suite for loadUrl().
*/
public class AndroidWebViewLoadUrlTest extends AndroidWebViewTestBase {
- private ContentViewCore createContentViewOnMainSync(final TestContentViewClient client)
- throws Exception {
- final AtomicReference<ContentView> contentView = new AtomicReference<ContentView>();
- getInstrumentation().runOnMainSync(new Runnable() {
- @Override
- public void run() {
- contentView.set(createContentView(false, client));
- getActivity().setContentViews(contentView.get());
- }
- });
- return contentView.get().getContentViewCore();
- }
-
private String getTitleOnUiThread(final ContentViewCore contentViewCore) throws Throwable {
return runTestOnUiThreadAndGetResult(new Callable<String>() {
@Override
@@ -47,12 +33,14 @@ public class AndroidWebViewLoadUrlTest extends AndroidWebViewTestBase {
@Feature({"Android-WebView"})
public void testDataUrl() throws Throwable {
final String expectedTitle = "dataUrlTest";
- final String dataUrl =
- "data:text/html,<html><head><title>" + expectedTitle + "</title></head></html>";
-
- final TestContentViewClient contentViewClient = new TestContentViewClient();
- final ContentViewCore contentViewCore = createContentViewOnMainSync(contentViewClient);
- loadUrlSync(contentViewCore, contentViewClient.getOnPageFinishedHelper(), dataUrl);
+ final String data =
+ "<html><head><title>" + expectedTitle + "</title></head><body>foo</body></html>";
+
+ final TestAwContentsClient contentsClient = new TestAwContentsClient();
+ final ContentViewCore contentViewCore =
+ createAwTestContainerViewOnMainSync(contentsClient).getContentViewCore();
+ loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), data,
+ "text/html", false);
assertEquals(expectedTitle, getTitleOnUiThread(contentViewCore));
}
@@ -60,13 +48,14 @@ public class AndroidWebViewLoadUrlTest extends AndroidWebViewTestBase {
@Feature({"Android-WebView"})
public void testDataUrlBase64() throws Throwable {
final String expectedTitle = "dataUrlTestBase64";
- final String dataUrl = "data:text/html;base64," +
- "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90aXRsZT48" +
- "L2hlYWQ+PC9odG1sPg==";
-
- final TestContentViewClient contentViewClient = new TestContentViewClient();
- final ContentViewCore contentViewCore = createContentViewOnMainSync(contentViewClient);
- loadUrlSync(contentViewCore, contentViewClient.getOnPageFinishedHelper(), dataUrl);
+ final String data = "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90aXRsZT48" +
+ "L2hlYWQ+PC9odG1sPg==";
+
+ final TestAwContentsClient contentsClient = new TestAwContentsClient();
+ final ContentViewCore contentViewCore =
+ createAwTestContainerViewOnMainSync(contentsClient).getContentViewCore();
+ loadDataSync(contentViewCore, contentsClient.getOnPageFinishedHelper(), data,
+ "text/html", true);
assertEquals(expectedTitle, getTitleOnUiThread(contentViewCore));
}
}
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 56b909a..d375b32 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
@@ -8,9 +8,11 @@ import android.app.Instrumentation;
import android.content.Context;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
+import android.view.ViewGroup;
import org.chromium.android_webview.AndroidWebViewUtil;
import org.chromium.android_webview.AwContents;
+import org.chromium.android_webview.AwContentsClient;
import org.chromium.content.browser.ContentSettings;
import org.chromium.content.browser.ContentView;
import org.chromium.content.browser.ContentViewClient;
@@ -20,6 +22,7 @@ import org.chromium.content.browser.test.CallbackHelper;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
@@ -123,12 +126,38 @@ public class AndroidWebViewTestBase
});
}
- protected ContentView createContentView(boolean incognito,
- ContentViewClient contentViewClient) {
+ protected AwTestContainerView createAwTestContainerView(final boolean incognito,
+ final AwContentsClient contentsClient) {
+ return createAwTestContainerView(incognito, new AwTestContainerView(getActivity()),
+ contentsClient);
+ }
+
+ protected AwTestContainerView createAwTestContainerView(final boolean incognito,
+ final AwTestContainerView testContainerView,
+ final AwContentsClient contentsClient) {
int nativeWebContents = AndroidWebViewUtil.createNativeWebContents(incognito);
- ContentView contentView = ContentView.newInstance(getActivity(), nativeWebContents,
- ContentView.PERSONALITY_VIEW);
- contentView.setContentViewClient(contentViewClient);
- return contentView;
+ ContentViewCore contentViewCore =
+ new ContentViewCore(getActivity(), testContainerView,
+ testContainerView.getInternalAccessDelegate(), nativeWebContents,
+ ContentViewCore.PERSONALITY_VIEW);
+ testContainerView.initialize(contentViewCore,
+ new AwContents(testContainerView, testContainerView.getInternalAccessDelegate(),
+ contentViewCore, contentsClient, incognito, false));
+ getActivity().addView(testContainerView);
+ return testContainerView;
+ }
+
+ protected AwTestContainerView createAwTestContainerViewOnMainSync(
+ final AwContentsClient client) throws Exception {
+ final AtomicReference<AwTestContainerView> testContainerView =
+ new AtomicReference<AwTestContainerView>();
+ final Context context = getActivity();
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ testContainerView.set(createAwTestContainerView(false, client));
+ }
+ });
+ return testContainerView.get();
}
}
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerActivity.java b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerActivity.java
index 4d78a6a..5abf524 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerActivity.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerActivity.java
@@ -5,30 +5,19 @@
package org.chromium.android_webview.test;
import android.app.Activity;
-import android.content.ContentUris;
-import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
+import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.LinearLayout;
-import org.chromium.content.browser.ContentView;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
/*
- * This is a lightweight activity for tests that only require ContentView functionality.
+ * This is a lightweight activity for tests that only require WebView functionality.
*/
public class AndroidWebViewTestRunnerActivity extends Activity {
private LinearLayout mLinearLayout;
- private List<ContentView> mContentViews = new ArrayList<ContentView>();
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -36,7 +25,6 @@ public class AndroidWebViewTestRunnerActivity extends Activity {
// TODO(joth): When SW-renderer is available, we'll want to enable this on a per-test
// basis.
- // BUG=http://b/5996811
boolean hardwareAccelerated = true;
Log.i("AndroidWebViewTestRunnerActivity", "Is " + (hardwareAccelerated ? "" : "NOT ")
+ "hardware accelerated");
@@ -57,38 +45,18 @@ public class AndroidWebViewTestRunnerActivity extends Activity {
}
/**
- * Set the ContentViews to be added to the current LinearLayout.
- *
- * This will destroy the ContentView instances that are being removed from the LinearLayout, so
- * care must be taken to not reference those instances.
+ * Adds a view to the main linear layout.
*/
- public void setContentViewList(Collection<ContentView> contentViews) {
- mLinearLayout.removeAllViews();
-
- Set<ContentView> toBeDeleted = new HashSet<ContentView>(mContentViews);
- toBeDeleted.removeAll(contentViews);
- for (ContentView c : toBeDeleted) {
- c.destroy();
- }
-
- for (ContentView c : contentViews) {
- c.setLayoutParams(new LinearLayout.LayoutParams(
- LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f));
- mLinearLayout.addView(c);
- }
- mContentViews.clear();
- mContentViews.addAll(contentViews);
+ public void addView(View view) {
+ view.setLayoutParams(new LinearLayout.LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f));
+ mLinearLayout.addView(view);
}
- public void setContentViews(ContentView... contentViews) {
- setContentViewList(Arrays.asList(contentViews));
- }
-
- public int getNumberOfContentViews() {
- return mContentViews.size();
- }
-
- public ContentView getContentView() {
- return mContentViews.get(0);
+ /**
+ * Clears the main linear layout.
+ */
+ public void removeAllViews() {
+ mLinearLayout.removeAllViews();
}
}
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java
index 7fb1d4c..fc42b175 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidWebViewTestRunnerApplication.java
@@ -11,8 +11,6 @@ import org.chromium.content.app.LibraryLoader;
import org.chromium.content.browser.ResourceExtractor;
import org.chromium.content.common.CommandLine;
-import android.util.Log;
-
public class AndroidWebViewTestRunnerApplication extends Application {
/**
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
index 8333804..f052070 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
@@ -8,12 +8,8 @@ import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.test.suitebuilder.annotation.SmallTest;
-import android.view.KeyEvent;
-import android.view.View;
-import android.webkit.ConsoleMessage;
import android.widget.GridLayout;
-import org.chromium.android_webview.AndroidWebViewUtil;
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwContentsClient;
import org.chromium.base.test.Feature;
@@ -31,6 +27,9 @@ public class AwContentsTest extends AndroidWebViewTestBase {
private AwContents createContents(Context context) {
GridLayout viewGroup = new GridLayout(context);
+ // TODO: Required ContentViewCore changes are not upstreamed yet.
+ // ContentViewCore contentViewCore = new ContentViewCore(
+ // context, ContentViewCore.PERSONALITY_VIEW);
ContentViewCore contentViewCore = new ContentViewCore(
context, viewGroup, null, 0, ContentViewCore.PERSONALITY_VIEW);
AwContents awContents = new AwContents(viewGroup, null, contentViewCore,
@@ -39,6 +38,7 @@ public class AwContentsTest extends AndroidWebViewTestBase {
}
@SmallTest
+ @Feature({"Android-WebView"})
public void testCreateDestroy() throws Throwable {
final Throwable[] error = new Throwable[1];
final Semaphore s = new Semaphore(0);
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
new file mode 100644
index 0000000..917b1ac
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestContainerView.java
@@ -0,0 +1,146 @@
+// 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.test;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.util.Log;
+
+import org.chromium.android_webview.AwContents;
+import org.chromium.content.browser.ContentViewCore;
+
+/**
+ * A View used for testing the AwContents internals.
+ *
+ * This class takes the place android.webkit.WebView would have in the production configuration.
+ */
+class AwTestContainerView extends FrameLayout {
+ private ContentViewCore mContentViewCore;
+ private AwContents mAwContents;
+ private ContentViewCore.InternalAccessDelegate mInternalAccessDelegate;
+
+ public AwTestContainerView(Context context) {
+ super(context);
+ mInternalAccessDelegate = new InternalAccessAdapter();
+ }
+
+ public void initialize(ContentViewCore contentViewCore, AwContents awContents) {
+ mContentViewCore = contentViewCore;
+ mAwContents = awContents;
+ }
+
+ public ContentViewCore getContentViewCore() {
+ return mContentViewCore;
+ }
+
+ public AwContents getAwContents() {
+ return mAwContents;
+ }
+
+ public ContentViewCore.InternalAccessDelegate getInternalAccessDelegate() {
+ return mInternalAccessDelegate;
+ }
+
+ public void destroy() {
+ mAwContents.destroy();
+ }
+
+ // TODO: Required ContentViewCore changes are not upstreamed yet.
+ /*
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ mContentViewCore.onConfigurationChanged(newConfig);
+ }
+
+ @Override
+ public void onAttachedToWindow() {
+ mContentViewCore.onAttachedToWindow();
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ mContentViewCore.onDetachedFromWindow();
+ }
+
+ @Override
+ public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
+ mContentViewCore.onFocusChanged(focused, direction, previouslyFocusedRect);
+ }
+
+ @Override
+ public void onSizeChanged(int w, int h, int ow, int oh) {
+ mContentViewCore.onSizeChanged(w, h, ow, oh);
+ }
+ */
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ return mContentViewCore.onTouchEvent(ev);
+ }
+
+ // TODO: ContentViewCore could define a generic class that holds an implementation similar to
+ // the one below.
+ private class InternalAccessAdapter implements ContentViewCore.InternalAccessDelegate {
+
+ @Override
+ public boolean drawChild(Canvas canvas, View child, long drawingTime) {
+ return AwTestContainerView.super.drawChild(canvas, child, drawingTime);
+ }
+
+ @Override
+ public boolean super_onKeyUp(int keyCode, KeyEvent event) {
+ return AwTestContainerView.super.onKeyUp(keyCode, event);
+ }
+
+ @Override
+ public boolean super_dispatchKeyEventPreIme(KeyEvent event) {
+ return AwTestContainerView.super.dispatchKeyEventPreIme(event);
+ }
+
+ @Override
+ public boolean super_dispatchKeyEvent(KeyEvent event) {
+ return AwTestContainerView.super.dispatchKeyEvent(event);
+ }
+
+ @Override
+ public boolean super_onGenericMotionEvent(MotionEvent event) {
+ return AwTestContainerView.super.onGenericMotionEvent(event);
+ }
+
+ @Override
+ public void super_onConfigurationChanged(Configuration newConfig) {
+ AwTestContainerView.super.onConfigurationChanged(newConfig);
+ }
+
+ @Override
+ public void onScrollChanged(int l, int t, int oldl, int oldt) {
+ AwTestContainerView.super.onScrollChanged(l, t, oldl, oldt);
+ }
+
+ @Override
+ public boolean awakenScrollBars() {
+ return AwTestContainerView.super.awakenScrollBars();
+ }
+
+ @Override
+ public boolean super_awakenScrollBars(int startDelay, boolean invalidate) {
+ return AwTestContainerView.super.awakenScrollBars(startDelay, invalidate);
+ }
+
+ // TODO: Required ContentViewCore changes are not upstreamed yet.
+ /*
+ @Override
+ public void onSurfaceTextureUpdated() {
+ }
+ */
+ }
+}
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java b/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java
new file mode 100644
index 0000000..89a09d7
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java
@@ -0,0 +1,70 @@
+// 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.test;
+
+import org.chromium.content.browser.test.TestContentViewClient.OnPageStartedHelper;
+import org.chromium.content.browser.test.TestContentViewClient.OnPageFinishedHelper;
+import org.chromium.content.browser.test.TestContentViewClient.OnReceivedErrorHelper;
+import org.chromium.content.browser.test.TestContentViewClient.OnEvaluateJavaScriptResultHelper;
+
+class TestAwContentsClient extends NullContentsClient {
+ private OnPageStartedHelper mOnPageStartedHelper;
+ private OnPageFinishedHelper mOnPageFinishedHelper;
+ private OnReceivedErrorHelper mOnReceivedErrorHelper;
+ private OnEvaluateJavaScriptResultHelper mOnEvaluateJavaScriptResultHelper;
+
+ public TestAwContentsClient() {
+ 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.notifyCalled(url);
+ }
+
+ @Override
+ public void onPageFinished(String url) {
+ super.onPageFinished(url);
+ mOnPageFinishedHelper.notifyCalled(url);
+ }
+
+ @Override
+ public void onReceivedError(int errorCode, String description, String failingUrl) {
+ super.onReceivedError(errorCode, description, failingUrl);
+ mOnReceivedErrorHelper.notifyCalled(errorCode, description, failingUrl);
+ }
+
+ @Override
+ public void onEvaluateJavaScriptResult(int id, String jsonResult) {
+ super.onEvaluateJavaScriptResult(id, jsonResult);
+ mOnEvaluateJavaScriptResultHelper.notifyCalled(id, jsonResult);
+ }
+}