Home | History | Annotate | Download | only in webui
      1 <!--
      2 Copyright 2013 The Chromium Authors. All rights reserved.
      3 Use of this source code is governed by a BSD-style license that can be
      4 found in the LICENSE file.
      5 -->
      6 <!DOCTYPE html>
      7 <html>
      8   <body>
      9     <script>
     10       window.chrome = {};
     11 
     12       window.setUp = function() {
     13         var doNothing = function() {};
     14         var mockClientRenderer = {
     15           playerUpdated: doNothing,
     16           playerRemoved: doNothing,
     17           playerAdded: doNothing,
     18           audioComponentAdded: doNothing,
     19           audioComponentRemoved: doNothing
     20         };
     21 
     22         var manager = new Manager(mockClientRenderer);
     23         media.initialize(manager);
     24 
     25         window.manager = manager;
     26       };
     27 
     28       // The renderer and player ids are completely arbitrarily.
     29       var TEST_RENDERER = 12;
     30       var TEST_PLAYER = 4;
     31       var TEST_NAME = TEST_RENDERER + ':' + TEST_PLAYER;
     32 
     33       // Correctly use the information from a media event.
     34       window.testOnMediaEvent = function() {
     35         var event = {
     36           ticksMillis: 132,
     37           renderer: TEST_RENDERER,
     38           player: TEST_PLAYER,
     39           params: {
     40             fps: 60,
     41             other: 'hi'
     42           }
     43         };
     44 
     45         window.media.onMediaEvent(event);
     46         var info = window.manager.players_[TEST_NAME];
     47 
     48         assertEquals(event.ticksMillis, info.firstTimestamp_);
     49         assertEquals(TEST_NAME, info.id);
     50         assertEquals(event.params.fps, info.properties.fps);
     51       };
     52 
     53       // Remove a player.
     54       window.testOnRenderTerminated = function() {
     55         window.testOnMediaEvent();
     56 
     57         window.media.onRendererTerminated(TEST_RENDERER);
     58         assertEquals(undefined, window.manager.players_[TEST_NAME]);
     59       };
     60 
     61       window.testAudioComponents = function() {
     62         var event = {
     63           component_id: 1,
     64           component_type: 0,
     65           owner_id: 3,
     66           status: 'created'
     67         };
     68 
     69         // Ensure no components are currently present.
     70         assertEquals(0, window.manager.audioComponents_.length);
     71 
     72         // Test adding an audio component.
     73         window.media.updateAudioComponent(event);
     74         assertEquals(1, window.manager.audioComponents_.length);
     75 
     76         // The key format is an implementation detail we don't care about, so
     77         // just ensure there's only one key and then use it directly.
     78         assertEquals(1, Object.keys(
     79             window.manager.audioComponents_[event.component_type]).length);
     80         for (key in window.manager.audioComponents_[event.component_type]) {
     81           var component =
     82               window.manager.audioComponents_[event.component_type][key];
     83           assertEquals(event.component_id, component['component_id']);
     84           assertEquals(event.component_type, component['component_type']);
     85           assertEquals(event.owner_id, component['owner_id']);
     86           assertEquals(event.status, component['status']);
     87         }
     88 
     89         // Test removing an audio component.
     90         event.status = 'closed';
     91         window.media.updateAudioComponent(event);
     92         assertEquals(1, window.manager.audioComponents_.length);
     93         assertEquals(0, Object.keys(
     94             window.manager.audioComponents_[event.component_type]).length);
     95       };
     96     </script>
     97   </body>
     98 </html>
     99