| <!-- |
| Copyright 2013 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. |
| --> |
| <!DOCTYPE html> |
| <html> |
| <body> |
| <script> |
| window.chrome = {}; |
| |
| window.setUp = function() { |
| var doNothing = function() {}; |
| var mockClientRenderer = { |
| playerUpdated: doNothing, |
| playerRemoved: doNothing, |
| playerAdded: doNothing, |
| audioComponentAdded: doNothing, |
| audioComponentRemoved: doNothing, |
| generalAudioInformationSet: doNothing |
| }; |
| |
| var manager = new Manager(mockClientRenderer); |
| media.initialize(manager); |
| |
| window.manager = manager; |
| }; |
| |
| // The renderer and player ids are completely arbitrarily. |
| var TEST_RENDERER = 12; |
| var TEST_PLAYER = 4; |
| var TEST_NAME = TEST_RENDERER + ':' + TEST_PLAYER; |
| |
| // Correctly use the information from a media event. |
| window.testOnMediaEvent = function() { |
| var event = { |
| ticksMillis: 132, |
| renderer: TEST_RENDERER, |
| player: TEST_PLAYER, |
| params: { |
| fps: 60, |
| other: 'hi' |
| } |
| }; |
| |
| window.media.onMediaEvent(event); |
| var info = window.manager.players_[TEST_NAME]; |
| |
| assertEquals(event.ticksMillis, info.firstTimestamp_); |
| assertEquals(TEST_NAME, info.id); |
| assertEquals(event.params.fps, info.properties.fps); |
| }; |
| |
| window.testAudioComponents = function() { |
| var event = { |
| component_id: 1, |
| component_type: 0, |
| owner_id: 3, |
| status: 'created' |
| }; |
| |
| // Ensure no components are currently present. |
| assertEquals(0, window.manager.audioComponents_.length); |
| |
| // Test adding an audio component. |
| window.media.updateAudioComponent(event); |
| assertEquals(1, window.manager.audioComponents_.length); |
| |
| // The key format is an implementation detail we don't care about, so |
| // just ensure there's only one key and then use it directly. |
| assertEquals(1, Object.keys( |
| window.manager.audioComponents_[event.component_type]).length); |
| for (key in window.manager.audioComponents_[event.component_type]) { |
| var component = |
| window.manager.audioComponents_[event.component_type][key]; |
| assertEquals(event.component_id, component['component_id']); |
| assertEquals(event.component_type, component['component_type']); |
| assertEquals(event.owner_id, component['owner_id']); |
| assertEquals(event.status, component['status']); |
| } |
| |
| // Test removing an audio component. |
| event.status = 'closed'; |
| window.media.updateAudioComponent(event); |
| assertEquals(1, window.manager.audioComponents_.length); |
| assertEquals(0, Object.keys( |
| window.manager.audioComponents_[event.component_type]).length); |
| }; |
| |
| window.testGeneralAudioInformation = function() { |
| var audioInfo = { |
| property: 'value' |
| }; |
| window.media.updateGeneralAudioInformation(audioInfo); |
| assertEquals(audioInfo.property, window.manager.audioInfo_.property); |
| }; |
| </script> |
| </body> |
| </html> |