summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authormichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-15 11:39:27 +0000
committermichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-15 11:39:27 +0000
commitc4f3aa249dfe938e9407bdd5a57ebfb4c5ad9c26 (patch)
tree53aa6639beff08e3b8f3ef58f7cdd1d5fbe2b46c /android_webview
parent7a3768e33c4aa19d3c7834b13ff18146281ec079 (diff)
downloadchromium_src-c4f3aa249dfe938e9407bdd5a57ebfb4c5ad9c26.zip
chromium_src-c4f3aa249dfe938e9407bdd5a57ebfb4c5ad9c26.tar.gz
chromium_src-c4f3aa249dfe938e9407bdd5a57ebfb4c5ad9c26.tar.bz2
[android_webview] Implementation of WebChromeClient.onHideCustomView.
Also refactorying VideoTestServer and AwContentsClientGetVideoLoadingProcessViewTest to make the test code resuable. BUG=http://b/6295468 Review URL: https://chromiumcodereview.appspot.com/12652003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188340 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/android_webview_tests.gypi4
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContentVideoViewDelegate.java1
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContentsClient.java24
-rw-r--r--android_webview/javatests/assets/full_screen_video_test.html (renamed from android_webview/javatests/assets/get_video_loading_progress_view_test.html)0
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenVideoTest.java47
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientGetVideoLoadingProgressViewTest.java83
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java2
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/FullScreenVideoTestAwContentsClient.java62
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/NullContentsClient.java4
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/util/VideoTestWebServer.java39
10 files changed, 185 insertions, 81 deletions
diff --git a/android_webview/android_webview_tests.gypi b/android_webview/android_webview_tests.gypi
index 95b51dc..151e291 100644
--- a/android_webview/android_webview_tests.gypi
+++ b/android_webview/android_webview_tests.gypi
@@ -21,7 +21,7 @@
'additional_input_paths': [
'<(PRODUCT_DIR)/android_webview_test_apk/assets/asset_file.html',
'<(PRODUCT_DIR)/android_webview_test_apk/assets/asset_icon.png',
- '<(PRODUCT_DIR)/android_webview_test_apk/assets/get_video_loading_progress_view_test.html',
+ '<(PRODUCT_DIR)/android_webview_test_apk/assets/full_screen_video_test.html',
],
},
'copies': [
@@ -30,7 +30,7 @@
'files': [
'<(java_in_dir)/assets/asset_file.html',
'<(java_in_dir)/assets/asset_icon.png',
- '<(java_in_dir)/assets/get_video_loading_progress_view_test.html',
+ '<(java_in_dir)/assets/full_screen_video_test.html',
],
},
],
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentVideoViewDelegate.java b/android_webview/java/src/org/chromium/android_webview/AwContentVideoViewDelegate.java
index 919348c..c2520c8 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentVideoViewDelegate.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentVideoViewDelegate.java
@@ -39,6 +39,7 @@ public class AwContentVideoViewDelegate implements ContentVideoViewContextDelega
@Override
public void onDestroyContentVideoView() {
+ mAwContentsClient.onHideCustomView();
}
@Override
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java b/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java
index 943cf1c..f72a659 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java
@@ -278,17 +278,26 @@ public abstract class AwContentsClient extends ContentViewClient {
protected abstract void onRequestFocus();
+ protected abstract View getVideoLoadingProgressView();
+
+ public abstract void onPageStarted(String url);
+
+ public abstract void onPageFinished(String url);
+
+ public abstract void onReceivedError(int errorCode, String description, String failingUrl);
+
+ public abstract void onShowCustomView(View view,
+ int requestedOrientation, WebChromeClient.CustomViewCallback callback);
+
// TODO (michaelbai): This method should be abstract, having empty body here
// makes the merge to the Android easy.
- protected View getVideoLoadingProgressView() {
- return null;
+ public void onHideCustomView() {
}
//--------------------------------------------------------------------------------------------
// Other WebView-specific methods
//--------------------------------------------------------------------------------------------
//
-
public abstract void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
boolean isDoneCounting);
@@ -298,15 +307,6 @@ public abstract class AwContentsClient extends ContentViewClient {
*/
public abstract void onNewPicture(Picture picture);
- public abstract void onPageStarted(String url);
-
- public abstract void onPageFinished(String url);
-
- public abstract void onReceivedError(int errorCode, String description, String failingUrl);
-
- public abstract void onShowCustomView(View view,
- int requestedOrientation, WebChromeClient.CustomViewCallback callback);
-
//--------------------------------------------------------------------------------------------
// Stuff that we ignore since it only makes sense for Chrome browser
//--------------------------------------------------------------------------------------------
diff --git a/android_webview/javatests/assets/get_video_loading_progress_view_test.html b/android_webview/javatests/assets/full_screen_video_test.html
index 466a8d4..466a8d4 100644
--- a/android_webview/javatests/assets/get_video_loading_progress_view_test.html
+++ b/android_webview/javatests/assets/full_screen_video_test.html
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenVideoTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenVideoTest.java
new file mode 100644
index 0000000..3e5d629
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenVideoTest.java
@@ -0,0 +1,47 @@
+// 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.test;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import android.test.TouchUtils;
+import android.view.KeyEvent;
+
+import org.chromium.android_webview.test.util.VideoTestWebServer;
+import org.chromium.base.test.util.DisabledTest;
+import org.chromium.base.test.util.Feature;
+
+/**
+ * Test WebChromeClient::onShow/HideCustomView.
+ */
+public class AwContentsClientFullScreenVideoTest extends AndroidWebViewTestBase {
+
+ /*
+ * @Feature({"AndroidWebView"})
+ * @SmallTest
+ * http://crbug.com/180575
+ */
+ @DisabledTest
+ public void testOnShowAndHideCustomView() throws Throwable {
+ FullScreenVideoTestAwContentsClient contentsClient =
+ new FullScreenVideoTestAwContentsClient(getActivity());
+ AwTestContainerView testContainerView =
+ createAwTestContainerViewOnMainSync(contentsClient);
+ enableJavaScriptOnUiThread(testContainerView.getAwContents());
+ VideoTestWebServer webServer = new VideoTestWebServer(getInstrumentation().getContext());
+ try {
+ loadUrlSync(testContainerView.getAwContents(),
+ contentsClient.getOnPageFinishedHelper(),
+ webServer.getFullScreenVideoTestURL());
+ Thread.sleep(5 * 1000);
+ TouchUtils.clickView(AwContentsClientFullScreenVideoTest.this, testContainerView);
+ contentsClient.waitForCustomViewShown();
+ getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
+ contentsClient.waitForCustomViewHidden();
+ }
+ finally {
+ if (webServer != null) webServer.getTestWebServer().shutdown();
+ }
+ }
+}
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientGetVideoLoadingProgressViewTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientGetVideoLoadingProgressViewTest.java
index 1774e44..35d5ddd 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientGetVideoLoadingProgressViewTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientGetVideoLoadingProgressViewTest.java
@@ -6,21 +6,16 @@ package org.chromium.android_webview.test;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.TouchUtils;
-import android.view.Gravity;
import android.view.View;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.webkit.WebChromeClient;
-import android.widget.FrameLayout;
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.test.util.VideoTestWebServer;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
+import org.chromium.content.browser.test.util.CallbackHelper;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ByteArrayOutputStream;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
/**
* Test for AwContentClient.GetVideoLoadingProgressView.
@@ -34,38 +29,31 @@ import java.io.ByteArrayOutputStream;
*/
public class AwContentsClientGetVideoLoadingProgressViewTest extends AndroidWebViewTestBase
implements View.OnAttachStateChangeListener {
- private Object mViewAttachedEvent = new Object();
- private boolean mViewAttached = false;
+ private CallbackHelper mViewAttachedCallbackHelper = new CallbackHelper();
@Override
public void onViewAttachedToWindow(View view) {
- synchronized(mViewAttachedEvent) {
- mViewAttachedEvent.notify();
- mViewAttached = true;
- view.removeOnAttachStateChangeListener(this);
- }
+ mViewAttachedCallbackHelper.notifyCalled();
+ view.removeOnAttachStateChangeListener(this);
}
@Override
public void onViewDetachedFromWindow(View arg0) {
}
- private void waitForViewAttached() throws InterruptedException {
- synchronized(mViewAttachedEvent) {
- while (!mViewAttached) {
- mViewAttachedEvent.wait();
- }
- }
+ private void waitForViewAttached() throws InterruptedException, TimeoutException {
+ mViewAttachedCallbackHelper.waitForCallback(0, 1, 20, TimeUnit.SECONDS);
}
/*
- * @Feature({"AndroidWebView"})
- * @SmallTest
- * http://crbug.com/180575
- */
+ * @Feature({"AndroidWebView"})
+ * @SmallTest
+ * http://crbug.com/180575
+ */
@DisabledTest
public void testGetVideoLoadingProgressView() throws Throwable {
- TestAwContentsClient contentsClient = new TestAwContentsClient() {
+ TestAwContentsClient contentsClient =
+ new FullScreenVideoTestAwContentsClient(getActivity()) {
@Override
protected View getVideoLoadingProgressView() {
View view = new View(getInstrumentation().getContext());
@@ -73,34 +61,16 @@ public class AwContentsClientGetVideoLoadingProgressViewTest extends AndroidWebV
AwContentsClientGetVideoLoadingProgressViewTest.this);
return view;
}
-
- @Override
- public void onShowCustomView(View view, int requestedOrientation,
- WebChromeClient.CustomViewCallback callback) {
- getActivity().getWindow().setFlags(
- WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
-
- getActivity().getWindow().addContentView(view,
- new FrameLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT,
- Gravity.CENTER));
- }
};
final AwTestContainerView testContainerView =
createAwTestContainerViewOnMainSync(contentsClient);
final AwContents awContents = testContainerView.getAwContents();
- getInstrumentation().runOnMainSync(new Runnable() {
- @Override
- public void run() {
- awContents.getContentViewCore().getContentSettings().setJavaScriptEnabled(true);
- }
- });
- VideoTestWebServer webServer = new VideoTestWebServer();
+ enableJavaScriptOnUiThread(awContents);
+ VideoTestWebServer webServer = new VideoTestWebServer(getInstrumentation().getContext());
try {
- loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(),
- getData(webServer.getOnePixelOneFrameWebmURL()), "text/html", false);
+ loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(),
+ webServer.getFullScreenVideoTestURL());
+ Thread.sleep(5 * 1000);
TouchUtils.clickView(AwContentsClientGetVideoLoadingProgressViewTest.this,
testContainerView);
waitForViewAttached();
@@ -108,19 +78,4 @@ public class AwContentsClientGetVideoLoadingProgressViewTest extends AndroidWebV
if (webServer != null) webServer.getTestWebServer().shutdown();
}
}
-
- private String getData(String url) throws IOException {
- InputStream in = getInstrumentation().getContext().getAssets().open(
- "get_video_loading_progress_view_test.html");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- int buflen = 128;
- byte[] buffer = new byte[buflen];
- int len = in.read(buffer, 0, buflen);
- while (len != -1) {
- os.write(buffer, 0, len);
- if (len < buflen) break;
- len = in.read(buffer, 0, buflen);
- }
- return os.toString().replace("VIDEO_FILE_URL", url);
- }
}
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
index 747d2bf..95c29f5 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
@@ -2540,7 +2540,7 @@ public class AwSettingsTest extends AndroidWebViewTestBase {
observer.register(awContents.getContentViewCore(), "javaObserver");
}
});
- VideoTestWebServer webServer = new VideoTestWebServer();
+ VideoTestWebServer webServer = new VideoTestWebServer(getInstrumentation().getContext());
try {
String data = "<html><head><script>" +
"addEventListener('DOMContentLoaded', function() { " +
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/FullScreenVideoTestAwContentsClient.java b/android_webview/javatests/src/org/chromium/android_webview/test/FullScreenVideoTestAwContentsClient.java
new file mode 100644
index 0000000..31d6639
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/FullScreenVideoTestAwContentsClient.java
@@ -0,0 +1,62 @@
+// 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.test;
+
+import android.app.Activity;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.webkit.WebChromeClient;
+import android.widget.FrameLayout;
+
+import org.chromium.content.browser.test.util.CallbackHelper;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * This class is a AwContentsClient for full screen video test.
+ */
+public class FullScreenVideoTestAwContentsClient extends TestAwContentsClient {
+ public final static int WAITING_SECONDS = 20;
+ private CallbackHelper mOnShowCustomViewCallbackHelper = new CallbackHelper();
+ private CallbackHelper mOnHideCustomViewCallbackHelper = new CallbackHelper();
+
+ private Activity mActivity;
+
+ public FullScreenVideoTestAwContentsClient(Activity activity) {
+ mActivity = activity;
+ }
+
+ @Override
+ public void onShowCustomView(View view, int requestedOrientation,
+ WebChromeClient.CustomViewCallback callback) {
+ mActivity.getWindow().setFlags(
+ WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
+
+ mActivity.getWindow().addContentView(view,
+ new FrameLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ Gravity.CENTER));
+ mOnShowCustomViewCallbackHelper.notifyCalled();
+ }
+
+ @Override
+ public void onHideCustomView() {
+ mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ mOnHideCustomViewCallbackHelper.notifyCalled();
+ }
+
+ public void waitForCustomViewShown() throws TimeoutException, InterruptedException {
+ mOnShowCustomViewCallbackHelper.waitForCallback(0, 1, WAITING_SECONDS, TimeUnit.SECONDS);
+ }
+
+ public void waitForCustomViewHidden() throws InterruptedException, TimeoutException {
+ mOnHideCustomViewCallbackHelper.waitForCallback(0, 1, WAITING_SECONDS, TimeUnit.SECONDS);
+ }
+} \ No newline at end of file
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 a5cb156..0356710 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
@@ -163,6 +163,10 @@ class NullContentsClient extends AwContentsClient {
}
@Override
+ public void onHideCustomView() {
+ }
+
+ @Override
public void onScaleChangedScaled(float oldScale, float newScale) {
}
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/util/VideoTestWebServer.java b/android_webview/javatests/src/org/chromium/android_webview/test/util/VideoTestWebServer.java
index 37ca84b..954508b 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/util/VideoTestWebServer.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/util/VideoTestWebServer.java
@@ -4,10 +4,14 @@
package org.chromium.android_webview.test.util;
+import android.content.Context;
import android.util.Pair;
import org.chromium.net.test.util.TestWebServer;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.List;
/**
@@ -24,14 +28,16 @@ public class VideoTestWebServer {
"0aNGjRo0aNGjRo0VAAD+/729RWRzH4mOZ9/O8Dl319afX4gsgAAA";
private String mOnePixelOneFrameWebmURL;
+ private String mFullScreenVideoTestURL;
private TestWebServer mTestWebServer;
- public VideoTestWebServer() throws Exception {
+ public VideoTestWebServer(Context context) throws Exception {
mTestWebServer = new TestWebServer(false);
List<Pair<String, String>> headers = getWebmHeaders(true);
mOnePixelOneFrameWebmURL = mTestWebServer.setResponseBase64("/" +
ONE_PIXEL_ONE_FRAME_WEBM_FILENAME,
ONE_PIXEL_ONE_FRAME_WEBM_BASE64, headers);
+ initFullScreenVideoTest(context);
}
/**
@@ -41,12 +47,41 @@ public class VideoTestWebServer {
return mOnePixelOneFrameWebmURL;
}
+ public String getFullScreenVideoTestURL() {
+ return mFullScreenVideoTestURL;
+ }
+
public TestWebServer getTestWebServer() {
return mTestWebServer;
}
- // Content-type headers used for javascript code.
private static List<Pair<String, String>> getWebmHeaders(boolean disableCache) {
return CommonResources.getContentTypeAndCacheHeaders("video/webm", disableCache);
}
+
+ private static List<Pair<String, String>> getHTMLHeaders(boolean disableCache) {
+ return CommonResources.getContentTypeAndCacheHeaders("text/html", disableCache);
+ }
+
+ private void initFullScreenVideoTest(Context context) throws IOException {
+ final String FULL_SCREEN_VIDEO_PATH = "full_screen_video_test.html";
+ String data = loadAssetData(context, FULL_SCREEN_VIDEO_PATH);
+ mFullScreenVideoTestURL = mTestWebServer.setResponse("/" + FULL_SCREEN_VIDEO_PATH,
+ data.replace("VIDEO_FILE_URL", getOnePixelOneFrameWebmURL()),
+ getHTMLHeaders(false));
+ }
+
+ private String loadAssetData(Context context, String asset) throws IOException {
+ InputStream in = context.getAssets().open(asset);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ int buflen = 128;
+ byte[] buffer = new byte[buflen];
+ int len = in.read(buffer, 0, buflen);
+ while (len != -1) {
+ os.write(buffer, 0, len);
+ if (len < buflen) break;
+ len = in.read(buffer, 0, buflen);
+ }
+ return os.toString();
+ }
}