This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Add test case for onShow/HideCustomView.
This patch is to add test for OnShowCustomView and onHideCustomView. Some code was ported from android webview.
- Loading branch information
Showing
6 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...nternal/javatests/src/org/xwalk/core/internal/xwview/test/OnShowOnHideCustomViewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (c) 2014 Intel Corporation. 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.xwalk.core.internal.xwview.test; | ||
|
||
import android.test.suitebuilder.annotation.MediumTest; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.chromium.base.test.util.Feature; | ||
import org.chromium.content.browser.ContentViewCore; | ||
import org.chromium.content.browser.test.util.DOMUtils; | ||
import org.chromium.content.browser.test.util.TouchCommon; | ||
import org.xwalk.core.internal.xwview.test.util.VideoTestWebServer; | ||
|
||
/** | ||
* Tests XWalkWebChromeClient::onShow/onHideCustomView. | ||
*/ | ||
public class OnShowOnHideCustomViewTest extends XWalkViewInternalTestBase { | ||
private VideoTestWebServer mWebServer; | ||
private TestXWalkWebChromeClientBase mWebChromeClient; | ||
private ContentViewCore mContentViewCore; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
mWebChromeClient = new TestXWalkWebChromeClientBase(); | ||
setXWalkWebChromeClient(mWebChromeClient); | ||
mContentViewCore = getContentViewCore(); | ||
mWebServer = new VideoTestWebServer(getInstrumentation().getContext()); | ||
} | ||
|
||
@Override | ||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
if (mWebServer != null) mWebServer.getTestWebServer().shutdown(); | ||
} | ||
|
||
@MediumTest | ||
@Feature({"onShow/onHideCustomView"}) | ||
public void testOnShowAndHideCustomViewWithCallback() throws Throwable { | ||
doOnShowAndHideCustomViewTest(new Runnable() { | ||
@Override | ||
public void run() { | ||
mWebChromeClient.getExitCallback().onCustomViewHidden(); | ||
} | ||
}); | ||
} | ||
|
||
@MediumTest | ||
@Feature({"onShow/onHideCustomView"}) | ||
public void testOnShowAndHideCustomViewWithJavascript() throws Throwable { | ||
doOnShowAndHideCustomViewTest(new Runnable() { | ||
@Override | ||
public void run() { | ||
DOMUtils.exitFullscreen(mContentViewCore); | ||
} | ||
}); | ||
} | ||
|
||
@MediumTest | ||
@Feature({"onShow/onHideCustomView"}) | ||
public void testOnShowCustomViewAndPlayWithHtmlControl() throws Throwable { | ||
doOnShowCustomViewTest(); | ||
Assert.assertFalse(DOMUtils.hasVideoEnded(mContentViewCore, VideoTestWebServer.VIDEO_ID)); | ||
|
||
// Click the html play button that is rendered above the video right in the middle | ||
// of the custom view. Note that we're not able to get the precise location of the | ||
// control since it is a shadow element, so this test might break if the location | ||
// ever moves. | ||
TouchCommon touchCommon = new TouchCommon(OnShowOnHideCustomViewTest.this); | ||
touchCommon.singleClickView(mWebChromeClient.getCustomView()); | ||
|
||
Assert.assertTrue(DOMUtils.waitForEndOfVideo( | ||
mContentViewCore, VideoTestWebServer.VIDEO_ID)); | ||
} | ||
|
||
private void doOnShowAndHideCustomViewTest(final Runnable existFullscreen) throws Throwable { | ||
doOnShowCustomViewTest(); | ||
getInstrumentation().runOnMainSync(existFullscreen); | ||
mWebChromeClient.waitForCustomViewHidden(); | ||
} | ||
|
||
private void doOnShowCustomViewTest() throws Exception { | ||
loadTestPageAndClickFullscreen(); | ||
mWebChromeClient.waitForCustomViewShown(); | ||
} | ||
|
||
private void loadTestPageAndClickFullscreen() throws Exception { | ||
loadUrlSync(mWebServer.getFullScreenVideoTestURL()); | ||
|
||
// Click the button in full_screen_video_test.html to enter fullscreen. | ||
TouchCommon touchCommon = new TouchCommon(this); | ||
touchCommon.singleClickView(getXWalkView()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...e_internal/javatests/src/org/xwalk/core/internal/xwview/test/util/VideoTestWebServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Copyright (c) 2014 Intel Corporation. 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.xwalk.core.internal.xwview.test.util; | ||
|
||
import android.content.Context; | ||
import android.util.Pair; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
import org.chromium.net.test.util.TestWebServer; | ||
|
||
/** | ||
* This class is a WebServer provide video data. | ||
*/ | ||
public class VideoTestWebServer { | ||
// VIDEO_ID must be kept in sync with the id in full_screen_video_test.html. | ||
public static final String VIDEO_ID = "video"; | ||
public static final String ONE_PIXEL_ONE_FRAME_WEBM_FILENAME = "one_pixel_one_frame.webm"; | ||
public static final String ONE_PIXEL_ONE_FRAME_WEBM_BASE64 = | ||
"GkXfo0AgQoaBAUL3gQFC8oEEQvOBCEKCQAR3ZWJtQoeBAkKFgQIYU4BnQN8VSalmQCgq17FAAw9C" + | ||
"QE2AQAZ3aGFtbXlXQUAGd2hhbW15RIlACECPQAAAAAAAFlSua0AxrkAu14EBY8WBAZyBACK1nEAD" + | ||
"dW5khkAFVl9WUDglhohAA1ZQOIOBAeBABrCBlrqBlh9DtnVAdOeBAKNAboEAAIDyCACdASqWAJYA" + | ||
"Pk0ci0WD+IBAAJiWlu4XdQTSq2H4MW0+sMO0gz8HMRe+0jRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo" + | ||
"0aNGjRo0aNGjRo0VAAD+/729RWRzH4mOZ9/O8Dl319afX4gsgAAA"; | ||
|
||
private String mOnePixelOneFrameWebmURL; | ||
private String mFullScreenVideoTestURL; | ||
private TestWebServer mTestWebServer; | ||
|
||
public VideoTestWebServer(Context context) throws Exception { | ||
mTestWebServer = TestWebServer.start(); | ||
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); | ||
} | ||
|
||
/** | ||
* @return the mOnePixelOneFrameWebmURL | ||
*/ | ||
public String getOnePixelOneFrameWebmURL() { | ||
return mOnePixelOneFrameWebmURL; | ||
} | ||
|
||
public String getFullScreenVideoTestURL() { | ||
return mFullScreenVideoTestURL; | ||
} | ||
|
||
public TestWebServer getTestWebServer() { | ||
return mTestWebServer; | ||
} | ||
|
||
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 fullScreenVideoPath = "full_screen_video_test.html"; | ||
String data = loadAssetData(context, fullScreenVideoPath); | ||
mFullScreenVideoTestURL = mTestWebServer.setResponse("/" + fullScreenVideoPath, | ||
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 bufferLength = 128; | ||
byte[] buffer = new byte[bufferLength]; | ||
int len = in.read(buffer, 0, bufferLength); | ||
while (len != -1) { | ||
os.write(buffer, 0, len); | ||
if (len < bufferLength) break; | ||
len = in.read(buffer, 0, bufferLength); | ||
} | ||
return os.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<html> | ||
<head> | ||
<script> | ||
function goFullscreen(id) { | ||
var element = document.getElementById(id); | ||
if (element.webkitRequestFullScreen) { | ||
element.webkitRequestFullScreen(); | ||
} | ||
} | ||
|
||
addEventListener('DOMContentLoaded', function() { | ||
document.getElementById('video').addEventListener('play', function() { | ||
console.log('Video Played'); | ||
}, false); | ||
document.addEventListener('webkitfullscreenerror', function() { | ||
javaFullScreenErrorObserver.notifyJava(); | ||
}, false); | ||
}, false); | ||
</script> | ||
</head> | ||
<body> | ||
</script></head><body> | ||
<button autofocus style ='padding:1024px 1024px;' onclick="goFullscreen('video'); return false">Big enough you can't miss it</button> | ||
<p></p> | ||
<!-- The video id must be kept in sync with VideoTestWebServer.VIDEO_ID --> | ||
<video style = 'width: 10px; height: 10px;' id='video' controls> | ||
<source id="webm" src="VIDEO_FILE_URL" type="video/webm"> | ||
</video> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters