Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: chrome/test/data/extensions/platform_apps/web_view/media_access/check/embedder.js

Issue 573183002: Add WebView browser test for MediaStreamTrack.getSources and CheckMediaAccessPermisson. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@render_frame_get_sources_rfhd
Patch Set: Code review. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/platform_apps/web_view/media_access/check/embedder.js
diff --git a/chrome/test/data/extensions/platform_apps/web_view/media_access/check/embedder.js b/chrome/test/data/extensions/platform_apps/web_view/media_access/check/embedder.js
new file mode 100644
index 0000000000000000000000000000000000000000..aea1c2157122bb80ab1760682cf5fdf5c95b76c4
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/web_view/media_access/check/embedder.js
@@ -0,0 +1,93 @@
+// 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.
+
+var embedder = {};
+embedder.tests = {};
+embedder.baseGuestURL = '';
+embedder.guestURL = '';
+
+// Sends a message to WebViewTest denoting it is done and test
+// has failed.
+embedder.failTest = function(msg) {
+ window.console.log('test failure, reason: ' + msg);
+ chrome.test.sendMessage('TEST_FAILED');
+};
+
+// Sends a message to WebViewTest denoting it is done and test
+// has succeeded.
+embedder.maybePassTest = function() {
+ window.console.log('test passed');
+ chrome.test.sendMessage('TEST_PASSED');
+};
+
+/** @private */
+embedder.setUpGuest_ = function() {
+ document.querySelector('#webview-tag-container').innerHTML =
+ '<webview style="width: 100px; height: 100px;"' +
+ ' src="' + embedder.guestURL + '"' +
+ '></webview>';
+ var webview = document.querySelector('webview');
+ if (!webview) {
+ embedder.failTest('No <webview> element created');
+ return null;
+ }
+ return webview;
+};
+
+/** @private */
+embedder.setUpLoadStop_ = function(webview) {
+ var onWebViewLoadStop = function(e) {
+ window.console.log('onWebViewLoadStop');
+
+ // Send post message to <webview> when it's ready to receive them.
+ // This will make the guest start issueing media request. We do not
+ // worry about the Javascript outcome. MockWebContestsDelegate in
+ // WebViewTest will take care of that.
+ webview.contentWindow.postMessage(
+ JSON.stringify(['get-sources-permission']), '*');
+ };
+ webview.addEventListener('loadstop', onWebViewLoadStop);
+};
+
+// The test loads a guest which requests media sources, which will in turn check
+// for media access permission.
+//
+// Note that this is a manually run test, not using chrome.test.runTests.
+// This is because we want to wait for MockWebContestsDelegate to catch the
+// media access check and not actually do a check.
+
+// Entry point for test, called by WebViewTest.
+function startCheckTest(testName) {
+ chrome.test.getConfig(function(config) {
+ embedder.baseGuestURL = 'http://localhost:' + config.testServer.port;
+ embedder.guestURL = embedder.baseGuestURL +
+ '/extensions/platform_apps/web_view/media_access' +
+ '/media_check_guest.html';
+ chrome.test.log('Guest url is: ' + embedder.guestURL);
+
+ var webview = embedder.setUpGuest_();
+ if (!webview) {
+ return;
+ }
+
+ embedder.setUpLoadStop_(webview);
+
+ webview.addEventListener('consolemessage', function(e) {
+ window.console.log(e.message);
+ });
+
+ window.addEventListener('message', function(e) {
+ var data = JSON.parse(e.data);
+ if (data[0] == 'got-sources') {
+ embedder.maybePassTest();
+ } else {
+ window.console.log('Unexpected message: ' + e.message);
+ }
+ });
+ });
+}
+
+onload = function() {
+ chrome.test.sendMessage('Launched');
+};

Powered by Google App Engine
This is Rietveld 408576698