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 os | 6 import os |
7 import subprocess | 7 import subprocess |
8 | 8 |
9 import pyauto_functional | 9 import pyauto_functional |
10 import pyauto | 10 import pyauto |
11 import webrtc_test_base | 11 import webrtc_test_base |
12 | 12 |
13 | |
13 class MissingRequiredBinaryException(Exception): | 14 class MissingRequiredBinaryException(Exception): |
14 pass | 15 pass |
15 | 16 |
16 | 17 |
17 class WebRTCCallTest(webrtc_test_base.WebrtcTestBase): | 18 class WebrtcCallTest(webrtc_test_base.WebrtcTestBase): |
18 """Test we can set up a WebRTC call and disconnect it. | 19 """Test we can set up a WebRTC call and disconnect it. |
19 | 20 |
20 Prerequisites: This test case must run on a machine with a webcam, either | 21 Prerequisites: This test case must run on a machine with a webcam, either |
21 fake or real, and with some kind of audio device. You must make the | 22 fake or real, and with some kind of audio device. You must make the |
22 peerconnection_server target before you run. | 23 peerconnection_server target before you run. |
23 | 24 |
24 The test case will launch a custom binary | 25 The test case will launch a custom binary |
25 (peerconnection_server) which will allow two WebRTC clients to find each | 26 (peerconnection_server) which will allow two WebRTC clients to find each |
26 other. For more details, see the source code which is available at the site | 27 other. For more details, see the source code which is available at the site |
27 http://code.google.com/p/libjingle/source/browse/ (make sure to browse to | 28 http://code.google.com/p/libjingle/source/browse/ (make sure to browse to |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 one tab to call the other. | 75 one tab to call the other. |
75 | 76 |
76 We make sure that the javascript tells us that the call succeeded, lets it | 77 We make sure that the javascript tells us that the call succeeded, lets it |
77 run for a while and try to hang up the call after that. We verify video is | 78 run for a while and try to hang up the call after that. We verify video is |
78 playing by using the video detector. | 79 playing by using the video detector. |
79 """ | 80 """ |
80 url = self.GetFileURLForDataPath('webrtc', test_page) | 81 url = self.GetFileURLForDataPath('webrtc', test_page) |
81 self.NavigateToURL(url) | 82 self.NavigateToURL(url) |
82 self.AppendTab(pyauto.GURL(url)) | 83 self.AppendTab(pyauto.GURL(url)) |
83 | 84 |
84 self.assertEquals('ok-got-stream', self._GetUserMedia(tab_index=0)) | 85 self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=0)) |
85 self.assertEquals('ok-got-stream', self._GetUserMedia(tab_index=1)) | 86 self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=1)) |
86 self._Connect('user_1', tab_index=0) | 87 self._Connect('user_1', tab_index=0) |
87 self._Connect('user_2', tab_index=1) | 88 self._Connect('user_2', tab_index=1) |
88 | 89 |
89 self._EstablishCall(from_tab_with_index=0) | 90 self._EstablishCall(from_tab_with_index=0) |
90 | 91 |
91 self._StartDetectingVideo(tab_index=0, video_element='remote_view') | 92 self._StartDetectingVideo(tab_index=0, video_element='remote_view') |
92 | 93 |
93 self._WaitForVideoToPlay() | 94 self._WaitForVideoToPlay() |
94 | 95 |
95 # The hang-up will automatically propagate to the second tab. | 96 # The hang-up will automatically propagate to the second tab. |
96 self._HangUp(from_tab_with_index=0) | 97 self._HangUp(from_tab_with_index=0) |
97 self._VerifyHungUp(tab_index=1) | 98 self._VerifyHungUp(tab_index=1) |
98 | 99 |
99 self._Disconnect(tab_index=0) | 100 self._Disconnect(tab_index=0) |
100 self._Disconnect(tab_index=1) | 101 self._Disconnect(tab_index=1) |
101 | 102 |
102 # Ensure we didn't miss any errors. | 103 # Ensure we didn't miss any errors. |
103 self._AssertNoFailures(tab_index=0) | 104 self.AssertNoFailures(tab_index=0) |
104 self._AssertNoFailures(tab_index=1) | 105 self.AssertNoFailures(tab_index=1) |
105 | 106 |
106 def testSimpleWebRtcJsepCall(self): | 107 def testSimpleWebRtcJsepCall(self): |
107 self._SimpleWebRtcCall('webrtc_jsep_test.html') | 108 self._SimpleWebRtcCall('webrtc_jsep_test.html') |
108 | 109 |
109 def testLocalPreview(self): | 110 def testLocalPreview(self): |
110 """Brings up a local preview and ensures video is playing. | 111 """Brings up a local preview and ensures video is playing. |
111 | 112 |
112 This test will launch a window with a single tab and run a getUserMedia call | 113 This test will launch a window with a single tab and run a getUserMedia call |
113 which will give us access to the webcam and microphone. Then the javascript | 114 which will give us access to the webcam and microphone. Then the javascript |
114 code will hook up the webcam data to the local_view video tag. We will | 115 code will hook up the webcam data to the local_view video tag. We will |
115 detect video in that tag using the video detector, and if we see video | 116 detect video in that tag using the video detector, and if we see video |
116 moving the test passes. | 117 moving the test passes. |
117 """ | 118 """ |
118 url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html') | 119 url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html') |
119 self.NavigateToURL(url) | 120 self.NavigateToURL(url) |
120 self.assertEquals('ok-got-stream', self._GetUserMedia(tab_index=0)) | 121 self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=0)) |
121 self._StartDetectingVideo(tab_index=0, video_element='local_view') | 122 self._StartDetectingVideo(tab_index=0, video_element='local_view') |
122 | 123 |
123 self._WaitForVideoToPlay() | 124 self._WaitForVideoToPlay() |
124 | 125 |
125 def testHandlesNewGetUserMediaRequestSeparately(self): | 126 def testHandlesNewGetUserMediaRequestSeparately(self): |
126 """Ensures WebRTC doesn't allow new requests to piggy-back on old ones.""" | 127 """Ensures WebRTC doesn't allow new requests to piggy-back on old ones.""" |
127 url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html') | 128 url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html') |
128 self.NavigateToURL(url) | 129 self.NavigateToURL(url) |
129 self.AppendTab(pyauto.GURL(url)) | 130 self.AppendTab(pyauto.GURL(url)) |
130 | 131 |
131 self._GetUserMedia(tab_index=0) | 132 self.GetUserMedia(tab_index=0) |
132 self._GetUserMedia(tab_index=1) | 133 self.GetUserMedia(tab_index=1) |
133 self._Connect("user_1", tab_index=0) | 134 self._Connect("user_1", tab_index=0) |
134 self._Connect("user_2", tab_index=1) | 135 self._Connect("user_2", tab_index=1) |
135 | 136 |
136 self._EstablishCall(from_tab_with_index=0) | 137 self._EstablishCall(from_tab_with_index=0) |
137 | 138 |
138 self.assertEquals('failed-with-error-1', | 139 self.assertEquals('failed-with-error-1', |
139 self._GetUserMedia(tab_index=0, action='deny')) | 140 self.GetUserMedia(tab_index=0, action='deny')) |
140 self.assertEquals('failed-with-error-1', | 141 self.assertEquals('failed-with-error-1', |
141 self._GetUserMedia(tab_index=0, action='dismiss')) | 142 self.GetUserMedia(tab_index=0, action='dismiss')) |
phoglund_chromium
2012/08/03 12:36:29
I pulled GetUserMedia up into the base class since
| |
142 | |
143 def _GetUserMedia(self, tab_index, action='allow'): | |
144 """Acquires webcam or mic for one tab and returns the result.""" | |
145 self.assertEquals('ok-requested', self.ExecuteJavascript( | |
146 'getUserMedia(true, true)', tab_index=tab_index)) | |
147 | |
148 self.WaitForInfobarCount(1, tab_index=tab_index) | |
149 self.PerformActionOnInfobar(action, infobar_index=0, tab_index=tab_index) | |
150 self.WaitForGetUserMediaResult(tab_index=0) | |
151 | |
152 result = self.GetUserMediaResult(tab_index=0) | |
153 self._AssertNoFailures(tab_index) | |
154 return result | |
155 | 143 |
156 def _Connect(self, user_name, tab_index): | 144 def _Connect(self, user_name, tab_index): |
157 self.assertEquals('ok-connected', self.ExecuteJavascript( | 145 self.assertEquals('ok-connected', self.ExecuteJavascript( |
158 'connect("http://localhost:8888", "%s")' % user_name, | 146 'connect("http://localhost:8888", "%s")' % user_name, |
159 tab_index=tab_index)) | 147 tab_index=tab_index)) |
160 self._AssertNoFailures(tab_index) | 148 self.AssertNoFailures(tab_index) |
161 | 149 |
162 def _EstablishCall(self, from_tab_with_index): | 150 def _EstablishCall(self, from_tab_with_index): |
163 self.assertEquals('ok-call-established', self.ExecuteJavascript( | 151 self.assertEquals('ok-call-established', self.ExecuteJavascript( |
164 'call()', tab_index=from_tab_with_index)) | 152 'call()', tab_index=from_tab_with_index)) |
165 self._AssertNoFailures(from_tab_with_index) | 153 self.AssertNoFailures(from_tab_with_index) |
166 | 154 |
167 # Double-check the call reached the other side. | 155 # Double-check the call reached the other side. |
168 self.assertEquals('yes', self.ExecuteJavascript( | 156 self.assertEquals('yes', self.ExecuteJavascript( |
169 'is_call_active()', tab_index=from_tab_with_index)) | 157 'is_call_active()', tab_index=from_tab_with_index)) |
170 | 158 |
171 def _HangUp(self, from_tab_with_index): | 159 def _HangUp(self, from_tab_with_index): |
172 self.assertEquals('ok-call-hung-up', self.ExecuteJavascript( | 160 self.assertEquals('ok-call-hung-up', self.ExecuteJavascript( |
173 'hangUp()', tab_index=from_tab_with_index)) | 161 'hangUp()', tab_index=from_tab_with_index)) |
174 self._VerifyHungUp(from_tab_with_index) | 162 self._VerifyHungUp(from_tab_with_index) |
175 self._AssertNoFailures(from_tab_with_index) | 163 self.AssertNoFailures(from_tab_with_index) |
176 | 164 |
177 def _VerifyHungUp(self, tab_index): | 165 def _VerifyHungUp(self, tab_index): |
178 self.assertEquals('no', self.ExecuteJavascript( | 166 self.assertEquals('no', self.ExecuteJavascript( |
179 'is_call_active()', tab_index=tab_index)) | 167 'is_call_active()', tab_index=tab_index)) |
180 | 168 |
181 def _Disconnect(self, tab_index): | 169 def _Disconnect(self, tab_index): |
182 self.assertEquals('ok-disconnected', self.ExecuteJavascript( | 170 self.assertEquals('ok-disconnected', self.ExecuteJavascript( |
183 'disconnect()', tab_index=tab_index)) | 171 'disconnect()', tab_index=tab_index)) |
184 | 172 |
185 def _StartDetectingVideo(self, tab_index, video_element): | 173 def _StartDetectingVideo(self, tab_index, video_element): |
186 self.assertEquals('ok-started', self.ExecuteJavascript( | 174 self.assertEquals('ok-started', self.ExecuteJavascript( |
187 'startDetection("%s", "frame_buffer", 320, 240)' % video_element, | 175 'startDetection("%s", "frame_buffer", 320, 240)' % video_element, |
188 tab_index=tab_index)); | 176 tab_index=tab_index)); |
189 | 177 |
190 def _WaitForVideoToPlay(self): | 178 def _WaitForVideoToPlay(self): |
191 video_playing = self.WaitUntil( | 179 video_playing = self.WaitUntil( |
192 function=lambda: self.ExecuteJavascript('isVideoPlaying()'), | 180 function=lambda: self.ExecuteJavascript('isVideoPlaying()'), |
193 expect_retval='video-playing') | 181 expect_retval='video-playing') |
194 self.assertTrue(video_playing, | 182 self.assertTrue(video_playing, |
195 msg='Timed out while trying to detect video.') | 183 msg='Timed out while trying to detect video.') |
196 | 184 |
197 def _AssertNoFailures(self, tab_index): | |
198 self.assertEquals('ok-no-errors', self.ExecuteJavascript( | |
199 'getAnyTestFailures()', tab_index=tab_index)) | |
200 | |
201 | 185 |
202 if __name__ == '__main__': | 186 if __name__ == '__main__': |
203 pyauto_functional.Main() | 187 pyauto_functional.Main() |
OLD | NEW |