Chromium Code Reviews| Index: android_webview/javatests/src/org/chromium/android_webview/test/MediaAccessPermissionRequestTest.java |
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/MediaAccessPermissionRequestTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/MediaAccessPermissionRequestTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9613456c19a33357d573b97807e4ab2445836550 |
| --- /dev/null |
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/MediaAccessPermissionRequestTest.java |
| @@ -0,0 +1,121 @@ |
| +// Copyright 2014 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.net.Uri; |
| +import android.test.suitebuilder.annotation.SmallTest; |
| + |
| +import org.chromium.android_webview.AwContents; |
| +import org.chromium.android_webview.permission.AwPermissionRequest; |
| +import org.chromium.base.test.util.DisabledTest; |
| +import org.chromium.base.test.util.Feature; |
| +import org.chromium.content.browser.test.util.CallbackHelper; |
| + |
| +import java.util.concurrent.Callable; |
| + |
| +/** |
| + * Test MediaAccessPermissionRequest. |
| + */ |
| +public class MediaAccessPermissionRequestTest extends AwTestBase { |
| + private static class OnPermissionRequestHelper extends CallbackHelper { |
| + private Uri mOrigin; |
| + private long mResources; |
| + public void notifyCalled(Uri origin, long resources) { |
| + mOrigin = origin; |
| + mResources = resources; |
| + notifyCalled(); |
| + } |
| + public Uri getOrigin() { |
| + assert getCallCount() > 0; |
| + return mOrigin; |
| + } |
| + public long getResources() { |
| + assert getCallCount() > 0; |
| + return mResources; |
| + } |
| + } |
| + |
| + private final String data = "<html> <script> " + |
| + "var constraints = {audio: true, video: true};" + |
| + "var video = document.querySelector('video');" + |
| + "function successCallback(stream) {" + |
| + "window.document.title = 'grant';" + |
| + "if (window.URL) {" + |
| + "video.src = window.URL.createObjectURL(stream);" + |
| + "} else {" + |
| + "video.src = stream;" + |
| + "}" + |
| + "}" + |
| + "function errorCallback(error){" + |
| + "window.document.title = 'deny';" + |
| + "console.log('navigator.getUserMedia error: ', error);" + |
| + "}" + |
| + "navigator.webkitGetUserMedia(constraints, successCallback, errorCallback)" + |
| + " </script><body>" + |
| + "<video autoplay></video>" + |
| + "</body></html>"; |
| + |
| + // The test isn't passed due to WebRTC requests security origin. |
|
mkosiba (inactive)
2014/04/29 17:29:53
if the only problem is the data: URL could we host
michaelbai
2014/04/29 19:28:05
It also need to be https:// if use TestWebServer.
|
| + @Feature({"AndroidWebView"}) |
| + @SmallTest |
| + @DisabledTest |
| + public void testGrantAccess() throws Throwable { |
| + final OnPermissionRequestHelper helper = new OnPermissionRequestHelper(); |
| + TestAwContentsClient contentsClient = |
| + new TestAwContentsClient() { |
| + @Override |
| + public void onPermissionRequest(AwPermissionRequest awPermissionRequest) { |
| + awPermissionRequest.grant(); |
| + helper.notifyCalled(awPermissionRequest.getOrigin(), |
| + awPermissionRequest.getResources()); |
| + } |
| + }; |
| + final AwTestContainerView testContainerView = |
| + createAwTestContainerViewOnMainSync(contentsClient); |
| + final AwContents awContents = testContainerView.getAwContents(); |
| + enableJavaScriptOnUiThread(awContents); |
| + int callCount = helper.getCallCount(); |
| + loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), data, |
| + "text/html", false); |
| + helper.waitForCallback(callCount); |
| + pollTitleAs("grant", awContents); |
| + } |
| + |
| + // The test isn't passed due to WebRTC requests security origin. |
| + @Feature({"AndroidWebView"}) |
| + @SmallTest |
| + @DisabledTest |
| + public void testDenyAccess() throws Throwable { |
| + final OnPermissionRequestHelper helper = new OnPermissionRequestHelper(); |
| + TestAwContentsClient contentsClient = |
| + new TestAwContentsClient() { |
| + @Override |
| + public void onPermissionRequest(AwPermissionRequest awPermissionRequest) { |
| + awPermissionRequest.deny(); |
| + helper.notifyCalled(awPermissionRequest.getOrigin(), |
| + awPermissionRequest.getResources()); |
| + } |
| + }; |
| + final AwTestContainerView testContainerView = |
| + createAwTestContainerViewOnMainSync(contentsClient); |
| + final AwContents awContents = testContainerView.getAwContents(); |
| + enableJavaScriptOnUiThread(awContents); |
| + int callCount = helper.getCallCount(); |
| + loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), data, |
| + "text/html", false); |
| + helper.waitForCallback(callCount); |
| + pollTitleAs("deny", awContents); |
| + } |
| + |
| + private void pollTitleAs(final String title, final AwContents awContents) |
| + throws Exception { |
| + poll(new Callable<Boolean>() { |
| + @Override |
| + public Boolean call() throws Exception { |
| + return title.equals(getTitleOnUiThread(awContents)); |
| + } |
| + }); |
| + } |
| +} |