chromium/chrome/test/data/extensions/platform_apps/web_view/media_access/media_check_guest.html

<!--
Copyright 2014 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<html>
  <head>
    <script type="text/javascript">
      // A guest that requests media devices, which in turn checks for media
      // access permission.
      // Notifies the embedder when done via post message. Note that the
      // embedder has to initiate a postMessage first so that guest has a
      // reference to the embedder's window.

      // The window reference of the embedder to send post message reply.
      var embedderWindowChannel = null;

      var notifyEmbedder = function(msg) {
        embedderWindowChannel.postMessage(msg, '*');
      };

      var onSourceInfo = function(sources) {
        notifyEmbedder(JSON.stringify(['got-sources']));
      };
      var startTest = function() {
        navigator.mediaDevices.enumerateDevices().then(onSourceInfo);
      };
      var onPostMessageReceived = function(e) {
        var data = JSON.parse(e.data);
        var testName = data[0];
        if (testName == 'get-sources-permission') {
          embedderWindowChannel = e.source;

          // Start the test once we have |embedderWindowChannel|.
          startTest();
        }
      };
      window.addEventListener('message', onPostMessageReceived, false);
    </script>
  </head>
  <body>
    <div>
      This is a guest requests media sources, which will check for media
      access permission.
    </div>
  </body>
</html>