1# Copyright 2017 The Chromium OS 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. 4 5from autotest_lib.client.bin import test 6from autotest_lib.client.common_lib import error 7from autotest_lib.client.common_lib.cros import test_webrtc_peer_connection 8 9 10class webrtc_PausePlayPeerConnections(test.test): 11 """Tests many peerconnections randomly paused and played.""" 12 version = 1 13 14 def run_once(self, mode = 'functional', element_type='video'): 15 """ 16 Runs the test. 17 18 @param mode: 'functional' or 'performance' depending on desired mode. 19 @param element_type: the element type to use for feeds, video or audio. 20 """ 21 kwargs = { 22 'own_script': 'pause-play.js', 23 'common_script': 'loopback-peerconnection.js', 24 'bindir': self.bindir, 25 'tmpdir': self.tmpdir, 26 'debugdir': self.debugdir, 27 'num_peer_connections': 10, 28 'iteration_delay_millis': 20, 29 'before_start_hook': lambda tab: tab.EvaluateJavaScript( 30 "elementType = '{}'".format(element_type)) 31 } 32 33 if mode == 'functional': 34 test = test_webrtc_peer_connection.WebRtcPeerConnectionTest( 35 title = 'Pause Play Peerconnections', 36 **kwargs) 37 test.run_test() 38 elif mode == 'performance': 39 test = test_webrtc_peer_connection\ 40 .WebRtcPeerConnectionPerformanceTest( 41 title = 'Pause Play Peerconnections ' 42 + 'Performance test', 43 **kwargs) 44 test.run_test() 45 test.collector.write_metrics(self.output_perf_value) 46 else: 47 raise error.TestError('mode must be "functional" or "performance"') 48 49