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 import time | 8 import time |
9 | 9 |
10 # This little construct ensures we can run even if we have a bad version of | 10 # This little construct ensures we can run even if we have a bad version of |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 def setUp(self): | 43 def setUp(self): |
44 pyauto.PyUITest.setUp(self) | 44 pyauto.PyUITest.setUp(self) |
45 self.StartPeerConnectionServer() | 45 self.StartPeerConnectionServer() |
46 | 46 |
47 def tearDown(self): | 47 def tearDown(self): |
48 self.StopPeerConnectionServer() | 48 self.StopPeerConnectionServer() |
49 | 49 |
50 pyauto.PyUITest.tearDown(self) | 50 pyauto.PyUITest.tearDown(self) |
51 self.assertEquals('', self.CheckErrorsAndCrashes()) | 51 self.assertEquals('', self.CheckErrorsAndCrashes()) |
52 | 52 |
53 def _SimpleWebrtcCall(self, duration_seconds=0): | 53 def _SimpleWebrtcCall(self, request_video, request_audio, duration_seconds=0): |
54 """Tests we can call and hang up with WebRTC. | 54 """Tests we can call and hang up with WebRTC. |
55 | 55 |
56 This test exercises pretty much the whole happy-case for the WebRTC | 56 This test exercises pretty much the whole happy-case for the WebRTC |
57 JavaScript API. Currently, it exercises a normal call setup using the API | 57 JavaScript API. Currently, it exercises a normal call setup using the API |
58 defined at http://dev.w3.org/2011/webrtc/editor/webrtc.html. The API is | 58 defined at http://dev.w3.org/2011/webrtc/editor/webrtc.html. The API is |
59 still evolving. | 59 still evolving. |
60 | 60 |
61 The test will load the supplied HTML file, which in turn will load different | 61 The test will load the supplied HTML file, which in turn will load different |
62 javascript files depending on which version of the signaling protocol | 62 javascript files depending on which version of the signaling protocol |
63 we are running. | 63 we are running. |
64 The supplied HTML file will be loaded in two tabs and tell the web | 64 The supplied HTML file will be loaded in two tabs and tell the web |
65 pages to start up WebRTC, which will acquire video and audio devices on the | 65 pages to start up WebRTC, which will acquire video and audio devices on the |
66 system. This will launch a dialog in Chrome which we click past using the | 66 system. This will launch a dialog in Chrome which we click past using the |
67 automation controller. Then, we will order both tabs to connect the server, | 67 automation controller. Then, we will order both tabs to connect the server, |
68 which will make the two tabs aware of each other. Once that is done we order | 68 which will make the two tabs aware of each other. Once that is done we order |
69 one tab to call the other. | 69 one tab to call the other. |
70 | 70 |
71 We make sure that the javascript tells us that the call succeeded, lets it | 71 We make sure that the javascript tells us that the call succeeded, lets it |
72 run for a while and try to hang up the call after that. We verify video is | 72 run for a while and try to hang up the call after that. We verify video is |
73 playing by using the video detector. | 73 playing by using the video detector. |
74 | 74 |
75 Args: | 75 Args: |
| 76 request_video: Whether to request video. |
| 77 request_audio: Whether to request audio. |
76 duration_seconds: The number of seconds to keep the call up before | 78 duration_seconds: The number of seconds to keep the call up before |
77 shutting it down. | 79 shutting it down. |
78 """ | 80 """ |
79 self._SetupCall() | 81 self._SetupCall(request_video=request_video, request_audio=request_audio) |
80 | 82 |
81 if duration_seconds: | 83 if duration_seconds: |
82 print 'Call up: sleeping %d seconds...' % duration_seconds | 84 print 'Call up: sleeping %d seconds...' % duration_seconds |
83 time.sleep(duration_seconds); | 85 time.sleep(duration_seconds); |
84 | 86 |
85 # The hang-up will automatically propagate to the second tab. | 87 # The hang-up will automatically propagate to the second tab. |
86 self.HangUp(from_tab_with_index=0) | 88 self.HangUp(from_tab_with_index=0) |
87 self.WaitUntilHangUpVerified(tab_index=1) | 89 self.WaitUntilHangUpVerified(tab_index=1) |
88 | 90 |
89 self.Disconnect(tab_index=0) | 91 self.Disconnect(tab_index=0) |
90 self.Disconnect(tab_index=1) | 92 self.Disconnect(tab_index=1) |
91 | 93 |
92 # Ensure we didn't miss any errors. | 94 # Ensure we didn't miss any errors. |
93 self.AssertNoFailures(tab_index=0) | 95 self.AssertNoFailures(tab_index=0) |
94 self.AssertNoFailures(tab_index=1) | 96 self.AssertNoFailures(tab_index=1) |
95 | 97 |
96 def testSimpleWebrtcJsep01Call(self): | 98 def testWebrtcJsep01Call(self): |
97 """Uses a draft of the PeerConnection API, using JSEP01.""" | 99 """Uses a draft of the PeerConnection API, using JSEP01.""" |
98 self._LoadPageInTwoTabs('webrtc_jsep01_test.html') | 100 self._LoadPageInTwoTabs('webrtc_jsep01_test.html') |
99 self._SimpleWebrtcCall() | 101 self._SimpleWebrtcCall(request_video=True, request_audio=True) |
| 102 |
| 103 def testWebrtcVideoOnlyJsep01Call(self): |
| 104 self._LoadPageInTwoTabs('webrtc_jsep01_test.html') |
| 105 self._SimpleWebrtcCall(request_video=True, request_audio=False) |
| 106 |
| 107 def testWebrtcAudioOnlyJsep01Call(self): |
| 108 self._LoadPageInTwoTabs('webrtc_jsep01_test.html') |
| 109 self._SimpleWebrtcCall(request_video=False, request_audio=True) |
100 | 110 |
101 def testJsep01AndMeasureCpu20Seconds(self): | 111 def testJsep01AndMeasureCpu20Seconds(self): |
102 if not _HAS_CORRECT_PSUTIL_VERSION: | 112 if not _HAS_CORRECT_PSUTIL_VERSION: |
103 print ('WARNING: Can not run cpu/mem measurements with this version of ' | 113 print ('WARNING: Can not run cpu/mem measurements with this version of ' |
104 'psutil. You must have at least psutil 0.4.1 installed for the ' | 114 'psutil. You must have at least psutil 0.4.1 installed for the ' |
105 'version of python you are running this test with.') | 115 'version of python you are running this test with.') |
106 return | 116 return |
107 | 117 |
108 self._LoadPageInTwoTabs('webrtc_jsep01_test.html') | 118 self._LoadPageInTwoTabs('webrtc_jsep01_test.html') |
109 | 119 |
110 # Prepare CPU measurements. | 120 # Prepare CPU measurements. |
111 renderer_process = self._GetChromeRendererProcess(tab_index=0) | 121 renderer_process = self._GetChromeRendererProcess(tab_index=0) |
112 renderer_process.get_cpu_percent() | 122 renderer_process.get_cpu_percent() |
113 | 123 |
114 self._SimpleWebrtcCall(duration_seconds=20) | 124 self._SimpleWebrtcCall(request_video=True, |
| 125 request_audio=True, |
| 126 duration_seconds=20) |
115 | 127 |
116 cpu_usage = renderer_process.get_cpu_percent(interval=0) | 128 cpu_usage = renderer_process.get_cpu_percent(interval=0) |
117 mem_usage_bytes = renderer_process.get_memory_info()[0] | 129 mem_usage_bytes = renderer_process.get_memory_info()[0] |
118 mem_usage_kb = float(mem_usage_bytes) / 1024 | 130 mem_usage_kb = float(mem_usage_bytes) / 1024 |
119 pyauto_utils.PrintPerfResult('cpu', 'jsep01_call', cpu_usage, '%') | 131 pyauto_utils.PrintPerfResult('cpu', 'jsep01_call', cpu_usage, '%') |
120 pyauto_utils.PrintPerfResult('memory', 'jsep01_call', mem_usage_kb, 'KiB') | 132 pyauto_utils.PrintPerfResult('memory', 'jsep01_call', mem_usage_kb, 'KiB') |
121 | 133 |
122 def testLocalPreview(self): | 134 def testLocalPreview(self): |
123 """Brings up a local preview and ensures video is playing. | 135 """Brings up a local preview and ensures video is playing. |
124 | 136 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 170 |
159 This test will check that if a local track is muted, the remote end don't | 171 This test will check that if a local track is muted, the remote end don't |
160 get video. Also test that if a remote track is disabled, the video is not | 172 get video. Also test that if a remote track is disabled, the video is not |
161 updated in the video tag.""" | 173 updated in the video tag.""" |
162 | 174 |
163 # TODO(perkj): Also verify that the local preview is muted when the | 175 # TODO(perkj): Also verify that the local preview is muted when the |
164 # feature is implemented. | 176 # feature is implemented. |
165 # TODO(perkj): Verify that audio is muted. | 177 # TODO(perkj): Verify that audio is muted. |
166 | 178 |
167 self._LoadPageInTwoTabs('webrtc_jsep01_test.html') | 179 self._LoadPageInTwoTabs('webrtc_jsep01_test.html') |
168 self._SetupCall() | 180 self._SetupCall(request_video=True, request_audio=True) |
169 select_video_function = 'function(local) { return local.videoTracks[0]; }' | 181 select_video_function = 'function(local) { return local.videoTracks[0]; }' |
170 self.assertEquals('ok-video-toggled-to-false', self.ExecuteJavascript( | 182 self.assertEquals('ok-video-toggled-to-false', self.ExecuteJavascript( |
171 'toggleLocalStream(' + select_video_function + ', "video")', | 183 'toggleLocalStream(' + select_video_function + ', "video")', |
172 tab_index=0)) | 184 tab_index=0)) |
173 self._WaitForVideo(tab_index=1, expect_playing=False) | 185 self._WaitForVideo(tab_index=1, expect_playing=False) |
174 | 186 |
175 self.assertEquals('ok-video-toggled-to-true', self.ExecuteJavascript( | 187 self.assertEquals('ok-video-toggled-to-true', self.ExecuteJavascript( |
176 'toggleLocalStream(' + select_video_function + ', "video")', | 188 'toggleLocalStream(' + select_video_function + ', "video")', |
177 tab_index=0)) | 189 tab_index=0)) |
178 self._WaitForVideo(tab_index=1, expect_playing=True) | 190 self._WaitForVideo(tab_index=1, expect_playing=True) |
179 | 191 |
180 # Test disabling a remote stream. The remote video is not played.""" | 192 # Test disabling a remote stream. The remote video is not played.""" |
181 self.assertEquals('ok-video-toggled-to-false', self.ExecuteJavascript( | 193 self.assertEquals('ok-video-toggled-to-false', self.ExecuteJavascript( |
182 'toggleRemoteStream(' + select_video_function + ', "video")', | 194 'toggleRemoteStream(' + select_video_function + ', "video")', |
183 tab_index=1)) | 195 tab_index=1)) |
184 self._WaitForVideo(tab_index=1, expect_playing=False) | 196 self._WaitForVideo(tab_index=1, expect_playing=False) |
185 | 197 |
186 self.assertEquals('ok-video-toggled-to-true', self.ExecuteJavascript( | 198 self.assertEquals('ok-video-toggled-to-true', self.ExecuteJavascript( |
187 'toggleRemoteStream(' + select_video_function + ', "video")', | 199 'toggleRemoteStream(' + select_video_function + ', "video")', |
188 tab_index=1)) | 200 tab_index=1)) |
189 self._WaitForVideo(tab_index=1, expect_playing=True) | 201 self._WaitForVideo(tab_index=1, expect_playing=True) |
190 | 202 |
191 def _LoadPageInTwoTabs(self, test_page): | 203 def _LoadPageInTwoTabs(self, test_page): |
192 url = self.GetFileURLForDataPath('webrtc', test_page) | 204 url = self.GetFileURLForDataPath('webrtc', test_page) |
193 self.NavigateToURL(url) | 205 self.NavigateToURL(url) |
194 self.AppendTab(pyauto.GURL(url)) | 206 self.AppendTab(pyauto.GURL(url)) |
195 | 207 |
196 def _SetupCall(self): | 208 def _SetupCall(self, request_video, request_audio): |
197 """Gets user media and establishes a call. | 209 """Gets user media and establishes a call. |
198 | 210 |
199 Assumes that two tabs are already opened with a suitable test page. | 211 Assumes that two tabs are already opened with a suitable test page. |
| 212 |
| 213 Args: |
| 214 request_video: Whether to request video. |
| 215 request_audio: Whether to request audio. |
200 """ | 216 """ |
201 self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=0)) | 217 self.assertEquals('ok-got-stream', self.GetUserMedia( |
202 self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=1)) | 218 tab_index=0, request_video=request_video, request_audio=request_audio)) |
| 219 self.assertEquals('ok-got-stream', self.GetUserMedia( |
| 220 tab_index=1, request_video=request_video, request_audio=request_audio)) |
203 self.Connect('user_1', tab_index=0) | 221 self.Connect('user_1', tab_index=0) |
204 self.Connect('user_2', tab_index=1) | 222 self.Connect('user_2', tab_index=1) |
205 | 223 |
206 self.EstablishCall(from_tab_with_index=0, to_tab_with_index=1) | 224 self.EstablishCall(from_tab_with_index=0, to_tab_with_index=1) |
207 | 225 |
208 self._StartDetectingVideo(tab_index=0, video_element='remote-view') | 226 if request_video: |
209 self._StartDetectingVideo(tab_index=1, video_element='remote-view') | 227 self._StartDetectingVideo(tab_index=0, video_element='remote-view') |
| 228 self._StartDetectingVideo(tab_index=1, video_element='remote-view') |
210 | 229 |
211 self._WaitForVideo(tab_index=0, expect_playing=True) | 230 self._WaitForVideo(tab_index=0, expect_playing=True) |
212 self._WaitForVideo(tab_index=1, expect_playing=True) | 231 self._WaitForVideo(tab_index=1, expect_playing=True) |
213 | 232 |
214 def _StartDetectingVideo(self, tab_index, video_element): | 233 def _StartDetectingVideo(self, tab_index, video_element): |
215 self.assertEquals('ok-started', self.ExecuteJavascript( | 234 self.assertEquals('ok-started', self.ExecuteJavascript( |
216 'startDetection("%s", "frame-buffer", 320, 240)' % video_element, | 235 'startDetection("%s", "frame-buffer", 320, 240)' % video_element, |
217 tab_index=tab_index)); | 236 tab_index=tab_index)); |
218 | 237 |
219 def _WaitForVideo(self, tab_index, expect_playing): | 238 def _WaitForVideo(self, tab_index, expect_playing): |
220 expect_retval='video-playing' if expect_playing else 'video-not-playing' | 239 expect_retval='video-playing' if expect_playing else 'video-not-playing' |
221 | 240 |
222 video_playing = self.WaitUntil( | 241 video_playing = self.WaitUntil( |
223 function=lambda: self.ExecuteJavascript('isVideoPlaying()', | 242 function=lambda: self.ExecuteJavascript('isVideoPlaying()', |
224 tab_index=tab_index), | 243 tab_index=tab_index), |
225 expect_retval=expect_retval) | 244 expect_retval=expect_retval) |
226 self.assertTrue(video_playing, | 245 self.assertTrue(video_playing, |
227 msg= 'Timed out while waiting for isVideoPlaying to ' + | 246 msg= 'Timed out while waiting for isVideoPlaying to ' + |
228 'return ' + expect_retval + '.') | 247 'return ' + expect_retval + '.') |
229 | 248 |
230 def _GetChromeRendererProcess(self, tab_index): | 249 def _GetChromeRendererProcess(self, tab_index): |
231 """Returns the Chrome renderer process as a psutil process wrapper.""" | 250 """Returns the Chrome renderer process as a psutil process wrapper.""" |
232 tab_info = self.GetBrowserInfo()['windows'][0]['tabs'][tab_index] | 251 tab_info = self.GetBrowserInfo()['windows'][0]['tabs'][tab_index] |
233 renderer_id = tab_info['renderer_pid'] | 252 renderer_id = tab_info['renderer_pid'] |
234 if not renderer_id: | 253 if not renderer_id: |
235 self.fail('Can not find the tab renderer process.') | 254 self.fail('Can not find the tab renderer process.') |
236 return psutil.Process(renderer_id) | 255 return psutil.Process(renderer_id) |
237 | 256 |
238 | 257 |
239 if __name__ == '__main__': | 258 if __name__ == '__main__': |
240 pyauto_functional.Main() | 259 pyauto_functional.Main() |
OLD | NEW |