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.
7 // These variables will be filled in chrome.test.getConfig() below.
8 embedder.baseGuestURL = '';
9 embedder.guestURL = '';
11 // Sends a message to WebViewTest denoting it is done and test
13 embedder.failTest = function(msg) {
14 window.console.log('test failure, reason: ' + msg);
15 chrome.test.sendMessage('TEST_FAILED');
18 // Sends a message to WebViewTest denoting it is done and test
20 embedder.maybePassTest = function() {
21 chrome.test.sendMessage('TEST_PASSED');
25 embedder.setUpGuest_ = function() {
26 document.querySelector('#webview-tag-container').innerHTML =
27 '<webview style="width: 100px; height: 100px;"' +
28 ' src="' + embedder.guestURL + '"' +
30 var webview = document.querySelector('webview');
32 embedder.failTest('No <webview> element created');
39 embedder.setUpLoadStop_ = function(webview) {
40 var onWebViewLoadStop = function(e) {
41 window.console.log('onWebViewLoadStop');
43 // Send post message to <webview> when it's ready to receive them.
44 // This will make the guest start issueing media request. We do not
45 // worry about the Javascript outcome. MockWebContestsDelegate in
46 // WebViewTest will take care of that.
47 webview.contentWindow.postMessage(
48 JSON.stringify(['get-sources-permission']), '*');
50 webview.addEventListener('loadstop', onWebViewLoadStop);
53 // The test loads a guest which requests media sources, which will in turn check
54 // for media access permission.
56 // Note that this is a manually run test, not using chrome.test.runTests.
57 // This is because we want to wait for MockWebContestsDelegate to catch the
58 // media access check and not actually do a check.
60 // Entry point for test, called by WebViewTest.
61 function runTest(testName) {
62 chrome.test.getConfig(function(config) {
63 embedder.baseGuestURL = 'http://localhost:' + config.testServer.port;
64 embedder.guestURL = embedder.baseGuestURL + '/media_check_guest.html';
65 chrome.test.log('Guest url is: ' + embedder.guestURL);
67 var webview = embedder.setUpGuest_();
72 embedder.setUpLoadStop_(webview);
74 webview.addEventListener('consolemessage', function(e) {
75 window.console.log(e.message);
78 window.addEventListener('message', function(e) {
79 var data = JSON.parse(e.data);
80 if (data[0] == 'got-sources') {
81 embedder.maybePassTest();
83 window.console.log('Unexpected message: ' + e.message);
90 chrome.test.sendMessage('LAUNCHED');