1 #!/usr/bin/env python 2 # Copyright (c) 2012 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 import random 7 import time 8 9 # Note: pyauto_functional must come before pyauto. 10 import pyauto_functional 11 import pyauto 12 import webrtc_test_base 13 14 15 class WebrtcApprtcCallTest(webrtc_test_base.WebrtcTestBase): 16 """Tests calling apprtc.appspot.com and setting up a call. 17 18 Prerequisites: This test case must run on a machine with a webcam, either 19 fake or real, and with some kind of audio device. The machine must have access 20 to the public Internet. 21 22 This should be considered an integration test: test failures could mean 23 that the AppRTC reference is broken, that WebRTC is broken, or both. 24 """ 25 26 def tearDown(self): 27 pyauto.PyUITest.tearDown(self) 28 self.assertEquals('', self.CheckErrorsAndCrashes(), 29 'Chrome crashed or hit a critical error during test.') 30 31 def testApprtcLoopbackCall(self): 32 self.NavigateToURL('http://apprtc.appspot.com/?debug=loopback') 33 self.WaitForInfobarCount(1, tab_index=0) 34 self.PerformActionOnInfobar('accept', infobar_index=0, tab_index=0) 35 36 self._WaitForCallEstablishment(tab_index=0) 37 38 def testApprtcTabToTabCall(self): 39 # Randomize the call session id. If we would use the same id we would risk 40 # getting problems with hung calls and lingering state in AppRTC. 41 random_call_id = 'pyauto%d' % random.randint(0, 65536) 42 apprtc_url = 'http://apprtc.appspot.com/?r=%s' % random_call_id 43 44 self.NavigateToURL(apprtc_url) 45 self.AppendTab(pyauto.GURL(apprtc_url)) 46 47 self.WaitForInfobarCount(1, tab_index=0) 48 self.WaitForInfobarCount(1, tab_index=1) 49 50 self.PerformActionOnInfobar('accept', infobar_index=0, tab_index=0) 51 # TODO(phoglund): workaround for 52 # https://code.google.com/p/webrtc/issues/detail?id=1742 53 time.sleep(1) 54 self.PerformActionOnInfobar('accept', infobar_index=0, tab_index=1) 55 56 self._WaitForCallEstablishment(tab_index=0) 57 self._WaitForCallEstablishment(tab_index=1) 58 59 def _WaitForCallEstablishment(self, tab_index): 60 # AppRTC will set opacity to 1 for remote video when the call is up. 61 video_playing = self.WaitUntil( 62 function=lambda: self.GetDOMValue('remoteVideo.style.opacity', 63 tab_index=tab_index), 64 expect_retval='1') 65 self.assertTrue(video_playing, 66 msg=('Timed out while waiting for ' 67 'remoteVideo.style.opacity to return 1.')) 68 69 70 if __name__ == '__main__': 71 pyauto_functional.Main() 72