Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: chrome/test/functional/webrtc_call.py

Issue 11155015: Implemented basic WebRTC Mem/CPU measurements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 psutil
7 import subprocess 8 import subprocess
8 9
10 # Note: pyauto_functional must come before pyauto.
9 import pyauto_functional 11 import pyauto_functional
10 import pyauto 12 import pyauto
13 import pyauto_utils
11 import webrtc_test_base 14 import webrtc_test_base
12 15
13 16
14 class WebrtcCallTest(webrtc_test_base.WebrtcTestBase): 17 class WebrtcCallTest(webrtc_test_base.WebrtcTestBase):
15 """Test we can set up a WebRTC call and disconnect it. 18 """Test we can set up a WebRTC call and disconnect it.
16 19
17 Prerequisites: This test case must run on a machine with a webcam, either 20 Prerequisites: This test case must run on a machine with a webcam, either
18 fake or real, and with some kind of audio device. You must make the 21 fake or real, and with some kind of audio device. You must make the
19 peerconnection_server target before you run. 22 peerconnection_server target before you run.
20 23
21 The test case will launch a custom binary 24 The test case will launch a custom binary
22 (peerconnection_server) which will allow two WebRTC clients to find each 25 (peerconnection_server) which will allow two WebRTC clients to find each
23 other. For more details, see the source code which is available at the site 26 other. For more details, see the source code which is available at the site
24 http://code.google.com/p/libjingle/source/browse/ (make sure to browse to 27 http://code.google.com/p/libjingle/source/browse/ (make sure to browse to
25 trunk/talk/examples/peerconnection/server). 28 trunk/talk/examples/peerconnection/server).
26 """ 29 """
27 30
28 def setUp(self): 31 def setUp(self):
29 pyauto.PyUITest.setUp(self) 32 pyauto.PyUITest.setUp(self)
30 self.StartPeerConnectionServer() 33 self.StartPeerConnectionServer()
31 34
32 def tearDown(self): 35 def tearDown(self):
33 self.StopPeerConnectionServer() 36 self.StopPeerConnectionServer()
34 37
35 pyauto.PyUITest.tearDown(self) 38 pyauto.PyUITest.tearDown(self)
36 self.assertEquals('', self.CheckErrorsAndCrashes()) 39 self.assertEquals('', self.CheckErrorsAndCrashes())
37 40
38 def _SimpleWebrtcCall(self, test_page): 41 def _SimpleWebrtcCall(self):
39 """Tests we can call and hang up with WebRTC. 42 """Tests we can call and hang up with WebRTC.
40 43
41 This test exercises pretty much the whole happy-case for the WebRTC 44 This test exercises pretty much the whole happy-case for the WebRTC
42 JavaScript API. Currently, it exercises a normal call setup using the API 45 JavaScript API. Currently, it exercises a normal call setup using the API
43 defined at http://dev.w3.org/2011/webrtc/editor/webrtc.html. The API is 46 defined at http://dev.w3.org/2011/webrtc/editor/webrtc.html. The API is
44 still evolving. 47 still evolving.
45 48
46 The test will load the supplied HTML file, which in turn will load different 49 Assuming two tabs are loaded using self._LoadPageInTwoTabs, the test will
47 javascript files depending on which version of the signaling protocol 50 acquire video and audio devices on the system. This will launch a dialog in
48 we are running. 51 Chrome which we click past using the automation controller. Then, we will
49 The supplied HTML file will be loaded in two tabs and tell the web 52 order both tabs to connect the peerconnection server, which will make the
50 pages to start up WebRTC, which will acquire video and audio devices on the 53 two tabs aware of each other. Once that is done we order one tab to call
51 system. This will launch a dialog in Chrome which we click past using the 54 the other.
52 automation controller. Then, we will order both tabs to connect the server,
53 which will make the two tabs aware of each other. Once that is done we order
54 one tab to call the other.
55 55
56 We make sure that the javascript tells us that the call succeeded, lets it 56 We make sure that the javascript tells us that the call succeeded, lets it
57 run for a while and try to hang up the call after that. We verify video is 57 run for a while and try to hang up the call after that. We verify video is
58 playing by using the video detector. 58 playing by using the video detector.
59 """ 59 """
60 self._SetupCall(test_page) 60 self._SetupCall()
61 61
62 # The hang-up will automatically propagate to the second tab. 62 # The hang-up will automatically propagate to the second tab.
63 self.HangUp(from_tab_with_index=0) 63 self.HangUp(from_tab_with_index=0)
64 self.WaitUntilHangUpVerified(tab_index=1) 64 self.WaitUntilHangUpVerified(tab_index=1)
65 65
66 self.Disconnect(tab_index=0)
67 self.Disconnect(tab_index=1)
68
69 # Ensure we didn't miss any errors. 66 # Ensure we didn't miss any errors.
70 self.AssertNoFailures(tab_index=0) 67 self.AssertNoFailures(tab_index=0)
71 self.AssertNoFailures(tab_index=1) 68 self.AssertNoFailures(tab_index=1)
72 69
70 self.Disconnect(tab_index=0)
71 self.Disconnect(tab_index=1)
72
73 def testSimpleWebrtcJsep00Call(self): 73 def testSimpleWebrtcJsep00Call(self):
74 """Uses a draft of the PeerConnection API, using JSEP00.""" 74 """Uses a draft of the PeerConnection API, using JSEP00."""
75 self._SimpleWebrtcCall('webrtc_jsep00_test.html') 75 self._LoadPageInTwoTabs('webrtc_jsep00_test.html')
76 self._SimpleWebrtcCall()
76 77
77 def testSimpleWebrtcJsep01Call(self): 78 def testSimpleWebrtcJsep01Call(self):
78 """Uses a draft of the PeerConnection API, using JSEP01.""" 79 """Uses a draft of the PeerConnection API, using JSEP01."""
79 self._SimpleWebrtcCall('webrtc_jsep01_test.html') 80 self._LoadPageInTwoTabs('webrtc_jsep01_test.html')
81
82 # Prepare CPU measurements.
83 renderer_process = self._GetChromeRendererProcess(tab_index=0)
84 renderer_process.get_cpu_percent()
85
86 self._SimpleWebrtcCall()
87
88 cpu_usage = renderer_process.get_cpu_percent(interval=0)
89 mem_usage_mb = renderer_process.get_memory_info()[0] / 1024 / 1024
90 pyauto_utils.PrintPerfResult('cpu', 'jsep01_call', cpu_usage, '%')
91 pyauto_utils.PrintPerfResult('memory', 'jsep01_call', mem_usage_mb, 'MB')
80 92
81 def testLocalPreview(self): 93 def testLocalPreview(self):
82 """Brings up a local preview and ensures video is playing. 94 """Brings up a local preview and ensures video is playing.
83 95
84 This test will launch a window with a single tab and run a getUserMedia call 96 This test will launch a window with a single tab and run a getUserMedia call
85 which will give us access to the webcam and microphone. Then the javascript 97 which will give us access to the webcam and microphone. Then the javascript
86 code will hook up the webcam data to the local-view video tag. We will 98 code will hook up the webcam data to the local-view video tag. We will
87 detect video in that tag using the video detector, and if we see video 99 detect video in that tag using the video detector, and if we see video
88 moving the test passes. 100 moving the test passes.
89 """ 101 """
(...skipping 26 matching lines...) Expand all
116 """Tests MediaStreamTrack.enable on tracks connected to a PeerConnection. 128 """Tests MediaStreamTrack.enable on tracks connected to a PeerConnection.
117 129
118 This test will check that if a local track is muted, the remote end don't 130 This test will check that if a local track is muted, the remote end don't
119 get video. Also test that if a remote track is disabled, the video is not 131 get video. Also test that if a remote track is disabled, the video is not
120 updated in the video tag.""" 132 updated in the video tag."""
121 133
122 # TODO(perkj): Also verify that the local preview is muted when the 134 # TODO(perkj): Also verify that the local preview is muted when the
123 # feature is implemented. 135 # feature is implemented.
124 # TODO(perkj): Verify that audio is muted. 136 # TODO(perkj): Verify that audio is muted.
125 137
126 self._SetupCall('webrtc_jsep01_test.html') 138 self._LoadPageInTwoTabs('webrtc_jsep01_test.html')
139 self._SetupCall()
127 select_video_function = 'function(local) { return local.videoTracks[0]; }' 140 select_video_function = 'function(local) { return local.videoTracks[0]; }'
128 self.assertEquals('ok-video-toggled-to-false', self.ExecuteJavascript( 141 self.assertEquals('ok-video-toggled-to-false', self.ExecuteJavascript(
129 'toggleLocalStream(' + select_video_function + ', "video")', 142 'toggleLocalStream(' + select_video_function + ', "video")',
130 tab_index=0)) 143 tab_index=0))
131 self._WaitForVideo(tab_index=1, expect_playing=False) 144 self._WaitForVideo(tab_index=1, expect_playing=False)
132 145
133 self.assertEquals('ok-video-toggled-to-true', self.ExecuteJavascript( 146 self.assertEquals('ok-video-toggled-to-true', self.ExecuteJavascript(
134 'toggleLocalStream(' + select_video_function + ', "video")', 147 'toggleLocalStream(' + select_video_function + ', "video")',
135 tab_index=0)) 148 tab_index=0))
136 self._WaitForVideo(tab_index=1, expect_playing=True) 149 self._WaitForVideo(tab_index=1, expect_playing=True)
137 150
138 # Test disabling a remote stream. The remote video is not played.""" 151 # Test disabling a remote stream. The remote video is not played."""
139 self.assertEquals('ok-video-toggled-to-false', self.ExecuteJavascript( 152 self.assertEquals('ok-video-toggled-to-false', self.ExecuteJavascript(
140 'toggleRemoteStream(' + select_video_function + ', "video")', 153 'toggleRemoteStream(' + select_video_function + ', "video")',
141 tab_index=1)) 154 tab_index=1))
142 self._WaitForVideo(tab_index=1, expect_playing=False) 155 self._WaitForVideo(tab_index=1, expect_playing=False)
143 156
144 self.assertEquals('ok-video-toggled-to-true', self.ExecuteJavascript( 157 self.assertEquals('ok-video-toggled-to-true', self.ExecuteJavascript(
145 'toggleRemoteStream(' + select_video_function + ', "video")', 158 'toggleRemoteStream(' + select_video_function + ', "video")',
146 tab_index=1)) 159 tab_index=1))
147 self._WaitForVideo(tab_index=1, expect_playing=True) 160 self._WaitForVideo(tab_index=1, expect_playing=True)
148 161
149 def _SetupCall(self, test_page): 162 def _LoadPageInTwoTabs(self, test_page):
150 url = self.GetFileURLForDataPath('webrtc', test_page) 163 url = self.GetFileURLForDataPath('webrtc', test_page)
151 self.NavigateToURL(url) 164 self.NavigateToURL(url)
152 self.AppendTab(pyauto.GURL(url)) 165 self.AppendTab(pyauto.GURL(url))
153 166
167 def _SetupCall(self):
168 """Gets user media and establishes a call.
169
170 Assumes that two tabs are already opened with a suitable test page.
171 """
154 self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=0)) 172 self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=0))
155 self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=1)) 173 self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=1))
156 self.Connect('user_1', tab_index=0) 174 self.Connect('user_1', tab_index=0)
157 self.Connect('user_2', tab_index=1) 175 self.Connect('user_2', tab_index=1)
158 176
159 self.EstablishCall(from_tab_with_index=0) 177 self.EstablishCall(from_tab_with_index=0)
160 178
161 self._StartDetectingVideo(tab_index=0, video_element='remote-view') 179 self._StartDetectingVideo(tab_index=0, video_element='remote-view')
162 self._StartDetectingVideo(tab_index=1, video_element='remote-view') 180 self._StartDetectingVideo(tab_index=1, video_element='remote-view')
163 181
164 self._WaitForVideo(tab_index=0, expect_playing=True) 182 self._WaitForVideo(tab_index=0, expect_playing=True)
165 self._WaitForVideo(tab_index=1, expect_playing=True) 183 self._WaitForVideo(tab_index=1, expect_playing=True)
166 184
167 def _StartDetectingVideo(self, tab_index, video_element): 185 def _StartDetectingVideo(self, tab_index, video_element):
168 self.assertEquals('ok-started', self.ExecuteJavascript( 186 self.assertEquals('ok-started', self.ExecuteJavascript(
169 'startDetection("%s", "frame-buffer", 320, 240)' % video_element, 187 'startDetection("%s", "frame-buffer", 320, 240)' % video_element,
170 tab_index=tab_index)); 188 tab_index=tab_index));
171 189
172 def _WaitForVideo(self, tab_index, expect_playing): 190 def _WaitForVideo(self, tab_index, expect_playing):
173 expect_retval='video-playing' if expect_playing else 'video-not-playing' 191 expect_retval='video-playing' if expect_playing else 'video-not-playing'
174 192
175 video_playing = self.WaitUntil( 193 video_playing = self.WaitUntil(
176 function=lambda: self.ExecuteJavascript('isVideoPlaying()', 194 function=lambda: self.ExecuteJavascript('isVideoPlaying()',
177 tab_index=tab_index), 195 tab_index=tab_index),
178 expect_retval=expect_retval) 196 expect_retval=expect_retval)
179 self.assertTrue(video_playing, 197 self.assertTrue(video_playing,
180 msg= 'Timed out while waiting for isVideoPlaying to ' + 198 msg= 'Timed out while waiting for isVideoPlaying to ' +
181 'return ' + expect_retval + '.') 199 'return ' + expect_retval + '.')
182 200
201 def _GetChromeRendererProcess(self, tab_index):
202 """Returns the Chrome renderer process as a psutil process wrapper."""
203 tab_info = self.GetBrowserInfo()['windows'][0]['tabs'][tab_index]
204 renderer_id = tab_info['renderer_pid']
205 if not renderer_id:
206 self.fail('Can not find the tab renderer process.')
207 return psutil.Process(renderer_id)
208
183 209
184 if __name__ == '__main__': 210 if __name__ == '__main__':
185 pyauto_functional.Main() 211 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698