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. |
| 14 |
| 15 Args: |
| 16 tab_index: The tab to request user media on. |
| 17 action: The action to take on the info bar. Can be 'allow', 'deny' or |
| 18 'dismiss'. |
| 19 |
| 20 Returns: |
| 21 A string as specified by the getUserMedia javascript function. |
| 22 """ |
| 23 self.assertEquals('ok-requested', self.ExecuteJavascript( |
| 24 'getUserMedia(true, true)', tab_index=tab_index)) |
| 25 |
| 26 self.WaitForInfobarCount(1, tab_index=tab_index) |
| 27 self.PerformActionOnInfobar(action, infobar_index=0, tab_index=tab_index) |
| 28 self.WaitForGetUserMediaResult(tab_index=0) |
| 29 |
| 30 result = self.GetUserMediaResult(tab_index=0) |
| 31 self.AssertNoFailures(tab_index) |
| 32 return result |
| 33 |
12 def WaitForGetUserMediaResult(self, tab_index): | 34 def WaitForGetUserMediaResult(self, tab_index): |
13 """Waits until WebRTC has responded to a getUserMedia query. | 35 """Waits until WebRTC has responded to a getUserMedia query. |
14 | 36 |
15 Fails an assert if WebRTC doesn't respond within the default timeout. | 37 Fails an assert if WebRTC doesn't respond within the default timeout. |
16 | 38 |
17 Args: | 39 Args: |
18 tab_index: the tab to query. | 40 tab_index: the tab to query. |
19 """ | 41 """ |
20 def HasResult(): | 42 def HasResult(): |
21 return self.GetUserMediaResult(tab_index) != 'not-called-yet' | 43 return self.GetUserMediaResult(tab_index) != 'not-called-yet' |
22 self.assertTrue(self.WaitUntil(HasResult), | 44 self.assertTrue(self.WaitUntil(HasResult), |
23 msg='Timed out while waiting for getUserMedia callback.') | 45 msg='Timed out while waiting for getUserMedia callback.') |
24 | 46 |
25 def GetUserMediaResult(self, tab_index): | 47 def GetUserMediaResult(self, tab_index): |
26 """Retrieves WebRTC's answer to a user media query. | 48 """Retrieves WebRTC's answer to a user media query. |
27 | 49 |
28 Args: | 50 Args: |
29 tab_index: the tab to query. | 51 tab_index: the tab to query. |
30 | 52 |
31 Returns: | 53 Returns: |
32 Specified in obtainGetUserMediaResult() in getusermedia.js. | 54 Specified in obtainGetUserMediaResult() in getusermedia.js. |
33 """ | 55 """ |
34 return self.ExecuteJavascript( | 56 return self.ExecuteJavascript( |
35 'obtainGetUserMediaResult()', tab_index=tab_index) | 57 'obtainGetUserMediaResult()', tab_index=tab_index) |
| 58 |
| 59 def AssertNoFailures(self, tab_index): |
| 60 """Ensures the javascript hasn't registered any asynchronous errors. |
| 61 |
| 62 Args: |
| 63 tab_index: The tab to check. |
| 64 """ |
| 65 self.assertEquals('ok-no-errors', self.ExecuteJavascript( |
| 66 'getAnyTestFailures()', tab_index=tab_index)) |
OLD | NEW |