OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.android_webview.test; | |
6 | |
7 import android.net.Uri; | |
8 import android.test.suitebuilder.annotation.SmallTest; | |
9 | |
10 import org.chromium.android_webview.AwContents; | |
11 import org.chromium.android_webview.permission.AwPermissionRequest; | |
12 import org.chromium.base.test.util.DisabledTest; | |
13 import org.chromium.base.test.util.Feature; | |
14 import org.chromium.content.browser.test.util.CallbackHelper; | |
15 | |
16 /** | |
17 * Test MediaAccessPermissionRequest. | |
18 */ | |
19 public class MediaAccessPermissionRequestTest extends AwTestBase { | |
20 private static class OnPermissionRequestHelper extends CallbackHelper { | |
21 private Uri mOrigin; | |
22 private long mResources; | |
23 public void notifyCalled(Uri origin, long resources) { | |
24 mOrigin = origin; | |
25 mResources = resources; | |
26 notifyCalled(); | |
27 } | |
28 public Uri getOrigin() { | |
29 assert getCallCount() > 0; | |
30 return mOrigin; | |
31 } | |
32 public long getResources() { | |
33 assert getCallCount() > 0; | |
34 return mResources; | |
35 } | |
36 } | |
37 | |
38 private final String data = "<html> <script> " + | |
39 "var constraints = {audio: true, video: true};" + | |
40 "var video = document.querySelector('video');" + | |
41 "function successCallback(stream) {" + | |
42 "window.document.title = 'grant';" + | |
43 "if (window.URL) {" + | |
44 "video.src = window.URL.createObjectURL(stream);" + | |
45 "} else {" + | |
46 "video.src = stream;" + | |
47 "}" + | |
48 "}" + | |
49 "function errorCallback(error){" + | |
50 "window.document.title = 'deny';" + | |
51 "console.log('navigator.getUserMedia error: ', error);" + | |
52 "}" + | |
53 "navigator.webkitGetUserMedia(constraints, successCallback, errorCal lback)" + | |
54 " </script><body>" + | |
55 "<video autoplay></video>" + | |
56 "</body></html>"; | |
57 | |
58 // The test isn't passed due to WebRTC requests security origin. | |
59 @Feature({"AndroidWebView"}) | |
60 @SmallTest | |
61 @DisabledTest | |
62 public void testGrantAccess() throws Throwable { | |
63 final OnPermissionRequestHelper helper = new OnPermissionRequestHelper() ; | |
64 TestAwContentsClient contentsClient = | |
65 new TestAwContentsClient() { | |
66 @Override | |
67 public void onPermissionRequest(AwPermissionRequest awPermis sionRequest) { | |
68 awPermissionRequest.grant(); | |
69 helper.notifyCalled(awPermissionRequest.getOrigin(), | |
70 awPermissionRequest.getResources()); | |
71 } | |
72 }; | |
73 final AwTestContainerView testContainerView = | |
74 createAwTestContainerViewOnMainSync(contentsClient); | |
75 final AwContents awContents = testContainerView.getAwContents(); | |
76 enableJavaScriptOnUiThread(awContents); | |
77 int callCount = helper.getCallCount(); | |
78 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), data, | |
79 "text/html", false); | |
80 helper.waitForCallback(callCount); | |
81 Thread.sleep(5 * 1000); | |
mkosiba (inactive)
2014/04/23 18:04:40
instead you could use CriteriaHelper to poll for t
michaelbai
2014/04/24 00:56:43
Done.
| |
82 assertEquals("grant", getTitleOnUiThread(awContents)); | |
83 } | |
84 | |
85 // The test isn't passed due to WebRTC requests security origin. | |
86 @Feature({"AndroidWebView"}) | |
87 @SmallTest | |
88 @DisabledTest | |
89 public void testDenyAccess() throws Throwable { | |
90 final OnPermissionRequestHelper helper = new OnPermissionRequestHelper() ; | |
91 TestAwContentsClient contentsClient = | |
92 new TestAwContentsClient() { | |
93 @Override | |
94 public void onPermissionRequest(AwPermissionRequest awPermis sionRequest) { | |
95 awPermissionRequest.deny(); | |
96 helper.notifyCalled(awPermissionRequest.getOrigin(), | |
97 awPermissionRequest.getResources()); | |
98 } | |
99 }; | |
100 final AwTestContainerView testContainerView = | |
101 createAwTestContainerViewOnMainSync(contentsClient); | |
102 final AwContents awContents = testContainerView.getAwContents(); | |
103 enableJavaScriptOnUiThread(awContents); | |
104 int callCount = helper.getCallCount(); | |
105 loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), data, | |
106 "text/html", false); | |
107 helper.waitForCallback(callCount); | |
108 Thread.sleep(5 * 1000); | |
109 assertEquals("deny", getTitleOnUiThread(awContents)); | |
110 } | |
111 } | |
OLD | NEW |