Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import pyauto | 6 import pyauto |
| 7 | 7 |
| 8 | 8 |
| 9 class WebrtcTestBase(pyauto.PyUITest): | 9 class WebrtcTestBase(pyauto.PyUITest): |
| 10 """This base class provides helpers for getUserMedia calls.""" | 10 """This base class provides helpers for getUserMedia calls.""" |
| 11 | 11 |
| 12 def GetUserMedia(self, tab_index, action='allow'): | |
| 13 """Acquires webcam or mic for one tab and returns the result.""" | |
|
Nirnimesh
2012/08/03 18:32:13
Add Args & Returns: section. Describe what the r
phoglund_chromium
2012/08/06 15:02:18
Done.
| |
| 14 self.assertEquals('ok-requested', self.ExecuteJavascript( | |
| 15 'getUserMedia(true, true)', tab_index=tab_index)) | |
| 16 | |
| 17 self.WaitForInfobarCount(1, tab_index=tab_index) | |
| 18 self.PerformActionOnInfobar(action, infobar_index=0, tab_index=tab_index) | |
| 19 self.WaitForGetUserMediaResult(tab_index=0) | |
| 20 | |
| 21 result = self.GetUserMediaResult(tab_index=0) | |
| 22 self.AssertNoFailures(tab_index) | |
| 23 return result | |
| 24 | |
| 12 def WaitForGetUserMediaResult(self, tab_index): | 25 def WaitForGetUserMediaResult(self, tab_index): |
| 13 """Waits until WebRTC has responded to a getUserMedia query. | 26 """Waits until WebRTC has responded to a getUserMedia query. |
| 14 | 27 |
| 15 Fails an assert if WebRTC doesn't respond within the default timeout. | 28 Fails an assert if WebRTC doesn't respond within the default timeout. |
| 16 | 29 |
| 17 Args: | 30 Args: |
| 18 tab_index: the tab to query. | 31 tab_index: the tab to query. |
| 19 """ | 32 """ |
| 20 def HasResult(): | 33 def HasResult(): |
| 21 return self.GetUserMediaResult(tab_index) != 'not-called-yet' | 34 return self.GetUserMediaResult(tab_index) != 'not-called-yet' |
| 22 self.assertTrue(self.WaitUntil(HasResult), | 35 self.assertTrue(self.WaitUntil(HasResult), |
| 23 msg='Timed out while waiting for getUserMedia callback.') | 36 msg='Timed out while waiting for getUserMedia callback.') |
| 24 | 37 |
| 25 def GetUserMediaResult(self, tab_index): | 38 def GetUserMediaResult(self, tab_index): |
| 26 """Retrieves WebRTC's answer to a user media query. | 39 """Retrieves WebRTC's answer to a user media query. |
| 27 | 40 |
| 28 Args: | 41 Args: |
| 29 tab_index: the tab to query. | 42 tab_index: the tab to query. |
| 30 | 43 |
| 31 Returns: | 44 Returns: |
| 32 Specified in obtainGetUserMediaResult() in getusermedia.js. | 45 Specified in obtainGetUserMediaResult() in getusermedia.js. |
| 33 """ | 46 """ |
| 34 return self.ExecuteJavascript( | 47 return self.ExecuteJavascript( |
| 35 'obtainGetUserMediaResult()', tab_index=tab_index) | 48 'obtainGetUserMediaResult()', tab_index=tab_index) |
| 49 | |
| 50 def AssertNoFailures(self, tab_index): | |
| 51 self.assertEquals('ok-no-errors', self.ExecuteJavascript( | |
| 52 'getAnyTestFailures()', tab_index=tab_index)) | |
| OLD | NEW |