diff options
author | phoglund@chromium.org <phoglund@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-15 10:43:42 +0000 |
---|---|---|
committer | phoglund@chromium.org <phoglund@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-15 10:43:42 +0000 |
commit | 97ae21b8de5ee82c192033853061affdd60f2a4c (patch) | |
tree | a4bedf529e5d6454b5a56289f7f345921c261bdb | |
parent | 370013f04ebd7a960d807c743f15ca1450afd4d4 (diff) | |
download | chromium_src-97ae21b8de5ee82c192033853061affdd60f2a4c.zip chromium_src-97ae21b8de5ee82c192033853061affdd60f2a4c.tar.gz chromium_src-97ae21b8de5ee82c192033853061affdd60f2a4c.tar.bz2 |
Merge 185187 "Moved WebRTC audio test to its own file (since it ..."
> Moved WebRTC audio test to its own file (since it requires special configuration).
>
> The test was failing on unconfigured machines for devs, so now they can run the general webrtc call tests without having to configure their machines.
>
> I also tried to clean up test page names so they're not sprinkled throughout the code.
>
> NOTRY=True
> BUG=
>
>
> Review URL: https://chromiumcodereview.appspot.com/12321081
TBR=phoglund@chromium.org
Review URL: https://codereview.chromium.org/12668010
git-svn-id: svn://svn.chromium.org/chrome/branches/1410/src@188323 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 3 | ||||
-rwxr-xr-x | chrome/test/functional/webrtc_audio_call.py | 128 | ||||
-rwxr-xr-x | chrome/test/functional/webrtc_brutality_test.py | 20 | ||||
-rwxr-xr-x | chrome/test/functional/webrtc_call.py | 111 | ||||
-rwxr-xr-x | chrome/test/functional/webrtc_test_base.py | 11 | ||||
-rwxr-xr-x | chrome/test/functional/webrtc_video_quality.py | 3 |
6 files changed, 160 insertions, 116 deletions
diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index e580872..602195e 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -503,6 +503,9 @@ 'webrtc_brutality_test', 'webrtc_call', ], + 'linux': [ + 'webrtc_audio_call', + ], }, # WebRTC / AppRTC Integration tests. diff --git a/chrome/test/functional/webrtc_audio_call.py b/chrome/test/functional/webrtc_audio_call.py new file mode 100755 index 0000000..95e1c2c --- /dev/null +++ b/chrome/test/functional/webrtc_audio_call.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import tempfile +import time + +import media.audio_tools as audio_tools + +# Note: pyauto_functional must come before pyauto. +import pyauto_functional +import pyauto +import webrtc_test_base + +class WebrtcAudioCallTest(webrtc_test_base.WebrtcTestBase): + """Test we can set up a WebRTC call and play audio through it.""" + def setUp(self): + pyauto.PyUITest.setUp(self) + self.StartPeerConnectionServer() + + def tearDown(self): + self.StopPeerConnectionServer() + + pyauto.PyUITest.tearDown(self) + self.assertEquals('', self.CheckErrorsAndCrashes()) + + def testWebrtcAudioCallAndVerifyAudioIsPlaying(self): + """Test that WebRTC is capable of transmitting at least some audio. + + This test has some nontrivial prerequisites: + 1. The target system must have an active microphone, it must be selected + as default input for the user that runs the test, and it must record a + certain minimum level of ambient noise (for instance server fans). + Verify that you are getting ambient noise in the microphone by either + recording it directly or checking your OS' microphone settings. Amplify + the microphone if the background noise is too low. The microphone should + capture noise consistently above 5% of its total range. + 2. The target system must be configured to record its own input*. + + * On Linux: + 1. # sudo apt-get install pavucontrol + 2. For the user who will run the test: # pavucontrol + 3. In a separate terminal, # arecord dummy + 4. In pavucontrol, go to the recording tab. + 5. For the ALSA plug-in [aplay]: ALSA Capture from, change from <x> to + <Monitor of x>, where x is whatever your primary sound device is called. + 6. Try launching chrome as the target user on the target machine, try + playing, say, a YouTube video, and record with # arecord -f dat mine.dat. + Verify the recording with aplay (should have recorded what you played + from chrome). + """ + self.assertTrue(self.IsLinux(), msg='Only supported on Linux.') + + def CallWithAudio(): + self._RunWebrtcCall(duration_seconds=5) + + self._RecordAudioAndEnsureNotSilent(record_duration_seconds=10, + sound_producing_function=CallWithAudio) + + def _RunWebrtcCall(self, duration_seconds): + self.LoadTestPageInTwoTabs() + + # This sets up a audio-only call. + self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=0, + request_video=False)) + self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=1, + request_video=False)) + self.Connect('user_1', tab_index=0) + self.Connect('user_2', tab_index=1) + + self.EstablishCall(from_tab_with_index=0, to_tab_with_index=1) + + # Keep the call up while we detect audio. + time.sleep(duration_seconds) + + # The hang-up will automatically propagate to the second tab. + self.HangUp(from_tab_with_index=0) + self.WaitUntilHangUpVerified(tab_index=1) + + self.Disconnect(tab_index=0) + self.Disconnect(tab_index=1) + + # Ensure we didn't miss any errors. + self.AssertNoFailures(tab_index=0) + self.AssertNoFailures(tab_index=1) + + def _RecordAudioAndEnsureNotSilent(self, record_duration_seconds, + sound_producing_function): + _SIZE_OF_EMPTY_DAT_FILE_BYTES = 44 + + # The two temp files that will be potentially used in the test. + temp_file = None + file_no_silence = None + try: + temp_file = self._CreateTempFile() + record_thread = audio_tools.AudioRecorderThread(record_duration_seconds, + temp_file) + record_thread.start() + sound_producing_function() + record_thread.join() + + if record_thread.error: + self.fail(record_thread.error) + file_no_silence = self._CreateTempFile() + audio_tools.RemoveSilence(temp_file, file_no_silence) + + self.assertTrue(os.path.getsize(file_no_silence) > + _SIZE_OF_EMPTY_DAT_FILE_BYTES, + msg=('The test recorded only silence. Ensure your ' + 'machine is correctly configured for this test.')) + finally: + # Delete the temporary files used by the test. + if temp_file: + os.remove(temp_file) + if file_no_silence: + os.remove(file_no_silence) + + def _CreateTempFile(self): + """Returns an absolute path to an empty temp file.""" + file_handle, path = tempfile.mkstemp(suffix='_webrtc.dat') + os.close(file_handle) + return path + + +if __name__ == '__main__': + pyauto_functional.Main()
\ No newline at end of file diff --git a/chrome/test/functional/webrtc_brutality_test.py b/chrome/test/functional/webrtc_brutality_test.py index 849ed76..fc44205 100755 --- a/chrome/test/functional/webrtc_brutality_test.py +++ b/chrome/test/functional/webrtc_brutality_test.py @@ -20,9 +20,7 @@ class WebrtcBrutalityTest(webrtc_test_base.WebrtcTestBase): The test will make repeated getUserMedia requests with refreshes between them. Sometimes it will click past the bar and then refresh. """ - url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep01_test.html') - self.NavigateToURL(url) - + self.LoadTestPageInOneTab() for i in range(1, 100): if i % 10 == 0: self.GetUserMedia(tab_index=0, action='accept') @@ -35,9 +33,7 @@ class WebrtcBrutalityTest(webrtc_test_base.WebrtcTestBase): The test will alternate unanswered requests with requests that get answered. """ - url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep01_test.html') - self.NavigateToURL(url) - + self.LoadTestPageInOneTab() for i in range(1, 100): if i % 10 == 0: self.GetUserMedia(tab_index=0, action='accept') @@ -46,25 +42,19 @@ class WebrtcBrutalityTest(webrtc_test_base.WebrtcTestBase): def testSuccessfulGetUserMediaAndThenReload(self): """Waits for WebRTC to respond, and immediately reloads the tab.""" - url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep01_test.html') - self.NavigateToURL(url) - + self.LoadTestPageInOneTab() self.GetUserMedia(tab_index=0, action='accept') self.ReloadTab(tab_index=0) def testClosingTabAfterGetUserMedia(self): """Tests closing the tab right after a getUserMedia call.""" - url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep01_test.html') - self.NavigateToURL(url) - + self.LoadTestPageInOneTab() self._GetUserMediaWithoutTakingAction(tab_index=0) self.CloseTab(tab_index=0) def testSuccessfulGetUserMediaAndThenClose(self): """Waits for WebRTC to respond, and closes the tab.""" - url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep01_test.html') - self.NavigateToURL(url) - + self.LoadTestPageInOneTab() self.GetUserMedia(tab_index=0, action='accept') self.CloseTab(tab_index=0) diff --git a/chrome/test/functional/webrtc_call.py b/chrome/test/functional/webrtc_call.py index c372cde..bbfd490 100755 --- a/chrome/test/functional/webrtc_call.py +++ b/chrome/test/functional/webrtc_call.py @@ -3,13 +3,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import os -import subprocess -import tempfile import time -import media.audio_tools as audio_tools - # This little construct ensures we can run even if we have a bad version of # psutil installed. If so, we'll just skip the test that needs it. _HAS_CORRECT_PSUTIL_VERSION = False @@ -98,64 +93,26 @@ class WebrtcCallTest(webrtc_test_base.WebrtcTestBase): self.AssertNoFailures(tab_index=0) self.AssertNoFailures(tab_index=1) - def testWebrtcJsep01Call(self): - """Uses a draft of the PeerConnection API, using JSEP01.""" - self._LoadPageInTwoTabs('webrtc_jsep01_test.html') + def testWebrtcCall(self): + self.LoadTestPageInTwoTabs() self._SimpleWebrtcCall(request_video=True, request_audio=True) - def testWebrtcVideoOnlyJsep01Call(self): - self._LoadPageInTwoTabs('webrtc_jsep01_test.html') + def testWebrtcVideoOnlyCall(self): + self.LoadTestPageInTwoTabs() self._SimpleWebrtcCall(request_video=True, request_audio=False) - def testWebrtcAudioOnlyJsep01Call(self): - self._LoadPageInTwoTabs('webrtc_jsep01_test.html') + def testWebrtcAudioOnlyCall(self): + self.LoadTestPageInTwoTabs() self._SimpleWebrtcCall(request_video=False, request_audio=True) - def testWebrtcJsep01CallAndVerifyAudioIsPlaying(self): - """Test that WebRTC is capable of transmitting at least some audio. - - This test has some nontrivial prerequisites: - 1. The target system must have an active microphone, it must be selected - as default input for the user that runs the test, and it must record a - certain minimum level of ambient noise (for instance server fans). - Verify that you are getting ambient noise in the microphone by either - recording it directly or checking your OS' microphone settings. Amplify - the microphone if the background noise is too low. The microphone should - capture noise consistently above 5% of its total range. - 2. The target system must be configured to record its own input*. - - * On Linux: - 1. # sudo apt-get install pavucontrol - 2. For the user who will run the test: # pavucontrol - 3. In a separate terminal, # arecord dummy - 4. In pavucontrol, go to the recording tab. - 5. For the ALSA plug-in [aplay]: ALSA Capture from, change from <x> to - <Monitor of x>, where x is whatever your primary sound device is called. - 6. Try launching chrome as the target user on the target machine, try - playing, say, a YouTube video, and record with # arecord -f dat mine.dat. - Verify the recording with aplay (should have recorded what you played - from chrome). - """ - if not self.IsLinux(): - print 'This test is only available on Linux for now.' - return - - self._LoadPageInTwoTabs('webrtc_jsep01_test.html') - - def AudioCall(): - self._SimpleWebrtcCall(request_video=False, request_audio=True, - duration_seconds=5) - self._RecordAudioAndEnsureNotSilent(record_duration_seconds=10, - sound_producing_function=AudioCall) - - def testJsep01AndMeasureCpu20Seconds(self): + def testWebrtcJsep01CallAndMeasureCpu20Seconds(self): if not _HAS_CORRECT_PSUTIL_VERSION: print ('WARNING: Can not run cpu/mem measurements with this version of ' 'psutil. You must have at least psutil 0.4.1 installed for the ' 'version of python you are running this test with.') return - self._LoadPageInTwoTabs('webrtc_jsep01_test.html') + self.LoadTestPageInTwoTabs(test_page='webrtc_jsep01_test.html') # Prepare CPU measurements. renderer_process = self._GetChromeRendererProcess(tab_index=0) @@ -180,8 +137,7 @@ class WebrtcCallTest(webrtc_test_base.WebrtcTestBase): detect video in that tag using the video detector, and if we see video moving the test passes. """ - url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep01_test.html') - self.NavigateToURL(url) + self.LoadTestPageInOneTab() self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=0)) self._StartDetectingVideo(tab_index=0, video_element='local-view') @@ -189,9 +145,7 @@ class WebrtcCallTest(webrtc_test_base.WebrtcTestBase): def testHandlesNewGetUserMediaRequestSeparately(self): """Ensures WebRTC doesn't allow new requests to piggy-back on old ones.""" - url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep01_test.html') - self.NavigateToURL(url) - self.AppendTab(pyauto.GURL(url)) + self.LoadTestPageInTwoTabs() self.GetUserMedia(tab_index=0) self.GetUserMedia(tab_index=1) @@ -216,7 +170,7 @@ class WebrtcCallTest(webrtc_test_base.WebrtcTestBase): # feature is implemented. # TODO(perkj): Verify that audio is muted. - self._LoadPageInTwoTabs('webrtc_jsep01_test.html') + self.LoadTestPageInTwoTabs() self._SetupCall(request_video=True, request_audio=True) select_video_function = \ 'function(local) { return local.getVideoTracks()[0]; }' @@ -241,11 +195,6 @@ class WebrtcCallTest(webrtc_test_base.WebrtcTestBase): tab_index=1)) self._WaitForVideo(tab_index=1, expect_playing=True) - def _LoadPageInTwoTabs(self, test_page): - url = self.GetFileURLForDataPath('webrtc', test_page) - self.NavigateToURL(url) - self.AppendTab(pyauto.GURL(url)) - def _SetupCall(self, request_video, request_audio): """Gets user media and establishes a call. @@ -302,44 +251,6 @@ class WebrtcCallTest(webrtc_test_base.WebrtcTestBase): self.fail('Can not find the tab renderer process.') return psutil.Process(renderer_id) - def _RecordAudioAndEnsureNotSilent(self, record_duration_seconds, - sound_producing_function): - _RECORD_DURATION = 10 - _SIZE_OF_EMPTY_DAT_FILE_BYTES = 44 - - # The two temp files that will be potentially used in the test. - temp_file = None - file_no_silence = None - try: - temp_file = self._CreateTempFile() - record_thread = audio_tools.AudioRecorderThread(_RECORD_DURATION, - temp_file) - record_thread.start() - sound_producing_function() - record_thread.join() - - if record_thread.error: - self.fail(record_thread.error) - file_no_silence = self._CreateTempFile() - audio_tools.RemoveSilence(temp_file, file_no_silence) - - self.assertTrue(os.path.getsize(file_no_silence) > - _SIZE_OF_EMPTY_DAT_FILE_BYTES, - msg=('The test recorded only silence. Ensure your ' - 'machine is correctly configured for this test.')) - finally: - # Delete the temporary files used by the test. - if temp_file: - os.remove(temp_file) - if file_no_silence: - os.remove(file_no_silence) - - def _CreateTempFile(self): - """Returns an absolute path to an empty temp file.""" - file_handle, path = tempfile.mkstemp(suffix='_webrtc.dat') - os.close(file_handle) - return path - if __name__ == '__main__': pyauto_functional.Main() diff --git a/chrome/test/functional/webrtc_test_base.py b/chrome/test/functional/webrtc_test_base.py index 6840fab..4a3d598 100755 --- a/chrome/test/functional/webrtc_test_base.py +++ b/chrome/test/functional/webrtc_test_base.py @@ -16,11 +16,22 @@ class MissingRequiredBinaryException(Exception): class WebrtcTestBase(pyauto.PyUITest): """This base class provides helpers for WebRTC calls.""" + DEFAULT_TEST_PAGE = 'webrtc_jsep01_test.html' + def ExtraChromeFlags(self): """Adds flags to the Chrome command line.""" extra_flags = ['--enable-data-channels', '--enable-dcheck'] return pyauto.PyUITest.ExtraChromeFlags(self) + extra_flags + def LoadTestPageInTwoTabs(self, test_page=DEFAULT_TEST_PAGE): + url = self.GetFileURLForDataPath('webrtc', test_page) + self.NavigateToURL(url) + self.AppendTab(pyauto.GURL(url)) + + def LoadTestPageInOneTab(self, test_page=DEFAULT_TEST_PAGE): + url = self.GetFileURLForDataPath('webrtc', test_page) + self.NavigateToURL(url) + def GetUserMedia(self, tab_index, action='accept', request_video=True, request_audio=True): """Acquires webcam or mic for one tab and returns the result. diff --git a/chrome/test/functional/webrtc_video_quality.py b/chrome/test/functional/webrtc_video_quality.py index 82969b3..4f8f167 100755 --- a/chrome/test/functional/webrtc_video_quality.py +++ b/chrome/test/functional/webrtc_video_quality.py @@ -139,8 +139,9 @@ class WebrtcVideoQualityTest(webrtc_test_base.WebrtcTestBase): to use the original input video as a reference video. We take the name of this file from an environment variable that the bots set. """ + helper_page = webrtc_test_base.WebrtcTestBase.DEFAULT_TEST_PAGE self._StartVideoQualityTest(test_page='webrtc_video_quality_test.html', - helper_page='webrtc_jsep01_test.html', + helper_page=helper_page, reference_yuv=_REFERENCE_YUV_FILE, width=640, height=480, barcode_height=32) |