2 * Copyright 2013 The Chromium Authors. All rights reserved. Use of this
3 * source code is governed by a BSD-style license that can be found in the
8 <script type=
"text/javascript">
9 // A guest that requests media access.
10 // Notifies the embedder about the result of the request (success/fail)
11 // via post message. Note that the embedder has to initiate a postMessage
12 // first so that guest has a reference to the embedder's window.
14 // The window reference of the embedder to send post message reply.
15 var embedderWindowChannel
= null;
17 var notifyEmbedder = function(msg
) {
18 embedderWindowChannel
.postMessage(msg
, '*');
21 var onUserMediaSuccess = function(stream
, testCase
) {
22 notifyEmbedder(JSON
.stringify(['access-granted', testCase
]));
24 var onUserMediaFailure = function(err
, testCase
) {
25 notifyEmbedder(JSON
.stringify(['access-denied', testCase
]));
27 var startTest = function(testCase
) {
28 navigator
.webkitGetUserMedia(
30 function(stream
) { onUserMediaSuccess(stream
, testCase
); },
31 function(err
) { onUserMediaFailure(err
, testCase
); });
33 var onPostMessageReceived = function(e
) {
34 var data
= JSON
.parse(e
.data
);
35 var testName
= data
[0];
36 var testCase
= data
[1];
37 if (testName
== 'check-media-permission') {
38 embedderWindowChannel
= e
.source
;
40 // Start the test once we have |embedderWindowChannel|.
44 window
.addEventListener('message', onPostMessageReceived
, false);
48 <div>This is a guest that requests audio media.
</div>