Commit dae22a04 authored by phoglund@chromium.org's avatar phoglund@chromium.org

Added a new test which aims to be really, really mean to WebRTC. Hopefully...

Added a new test which aims to be really, really mean to WebRTC. Hopefully this will cover some crashes we have fixed recently.


BUG=
NOTRY=True

Review URL: https://chromiumcodereview.appspot.com/10830159

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150312 0039d316-1c4b-4281-b951-d872f2087c98
parent 8ac33156
...@@ -831,7 +831,10 @@ ...@@ -831,7 +831,10 @@
'WEBRTC': { 'WEBRTC': {
'all': [ 'all': [
'media_stream_infobar', 'media_stream_infobar',
'webrtc_brutality_test',
'webrtc_call', 'webrtc_call',
# crbug.com/140465
'-webrtc_brutality_test.WebrtcBrutalityTest.testRepeatedGetUserMediaRequests'
], ],
}, },
......
#!/usr/bin/env python
# Copyright (c) 2012 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 pyauto_functional
import webrtc_test_base
class WebrtcBrutalityTest(webrtc_test_base.WebrtcTestBase):
"""Tests how WebRTC deals with inconvenient reloads, etc."""
def testReloadsAfterGetUserMedia(self):
"""Tests how we deal with reloads.
This test will quickly reload the page after running getUserMedia, which
will remove the pending request. This crashed the browser before the fix
for crbug.com/135043.
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_jsep_test.html')
self.NavigateToURL(url)
for i in range(1, 100):
if i % 10 == 0:
self.GetUserMedia(tab_index=0, action='allow')
else:
self._GetUserMediaWithoutTakingAction(tab_index=0)
self.ReloadTab(tab_index=0)
def testRepeatedGetUserMediaRequests(self):
"""Tests how we deal with lots of consecutive getUserMedia requests.
The test will alternate unanswered requests with requests that get answered.
"""
url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html')
self.NavigateToURL(url)
for i in range(1, 100):
if i % 10 == 0:
self.GetUserMedia(tab_index=0, action='allow')
else:
self._GetUserMediaWithoutTakingAction(tab_index=0)
def testSuccessfulGetUserMediaAndThenReload(self):
"""Waits for WebRTC to respond, and immediately reloads the tab."""
url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html')
self.NavigateToURL(url)
self.GetUserMedia(tab_index=0, action='allow')
self.ReloadTab(tab_index=0)
def testClosingTabAfterGetUserMedia(self):
"""Tests closing the tab right after a getUserMedia call."""
url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html')
self.NavigateToURL(url)
tab = self.GetBrowserWindow(0).GetTab(0)
self._GetUserMediaWithoutTakingAction(tab_index=0)
tab.Close()
def testSuccessfulGetUserMediaAndThenClose(self):
"""Waits for WebRTC to respond, and closes the tab."""
url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html')
self.NavigateToURL(url)
tab = self.GetBrowserWindow(0).GetTab(0)
self.GetUserMedia(tab_index=0, action='allow')
tab.Close()
def _GetUserMediaWithoutTakingAction(self, tab_index):
self.assertEquals('ok-requested', self.ExecuteJavascript(
'getUserMedia(true, true)', tab_index=0))
if __name__ == '__main__':
pyauto_functional.Main()
\ No newline at end of file
...@@ -10,11 +10,12 @@ import pyauto_functional ...@@ -10,11 +10,12 @@ import pyauto_functional
import pyauto import pyauto
import webrtc_test_base import webrtc_test_base
class MissingRequiredBinaryException(Exception): class MissingRequiredBinaryException(Exception):
pass pass
class WebRTCCallTest(webrtc_test_base.WebrtcTestBase): class WebrtcCallTest(webrtc_test_base.WebrtcTestBase):
"""Test we can set up a WebRTC call and disconnect it. """Test we can set up a WebRTC call and disconnect it.
Prerequisites: This test case must run on a machine with a webcam, either Prerequisites: This test case must run on a machine with a webcam, either
...@@ -81,8 +82,8 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase): ...@@ -81,8 +82,8 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase):
self.NavigateToURL(url) self.NavigateToURL(url)
self.AppendTab(pyauto.GURL(url)) self.AppendTab(pyauto.GURL(url))
self.assertEquals('ok-got-stream', self._GetUserMedia(tab_index=0)) self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=0))
self.assertEquals('ok-got-stream', self._GetUserMedia(tab_index=1)) self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=1))
self._Connect('user_1', tab_index=0) self._Connect('user_1', tab_index=0)
self._Connect('user_2', tab_index=1) self._Connect('user_2', tab_index=1)
...@@ -100,8 +101,8 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase): ...@@ -100,8 +101,8 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase):
self._Disconnect(tab_index=1) self._Disconnect(tab_index=1)
# Ensure we didn't miss any errors. # Ensure we didn't miss any errors.
self._AssertNoFailures(tab_index=0) self.AssertNoFailures(tab_index=0)
self._AssertNoFailures(tab_index=1) self.AssertNoFailures(tab_index=1)
def testSimpleWebRtcJsepCall(self): def testSimpleWebRtcJsepCall(self):
self._SimpleWebRtcCall('webrtc_jsep_test.html') self._SimpleWebRtcCall('webrtc_jsep_test.html')
...@@ -117,7 +118,7 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase): ...@@ -117,7 +118,7 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase):
""" """
url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html') url = self.GetFileURLForDataPath('webrtc', 'webrtc_jsep_test.html')
self.NavigateToURL(url) self.NavigateToURL(url)
self.assertEquals('ok-got-stream', self._GetUserMedia(tab_index=0)) self.assertEquals('ok-got-stream', self.GetUserMedia(tab_index=0))
self._StartDetectingVideo(tab_index=0, video_element='local_view') self._StartDetectingVideo(tab_index=0, video_element='local_view')
self._WaitForVideoToPlay() self._WaitForVideoToPlay()
...@@ -128,41 +129,28 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase): ...@@ -128,41 +129,28 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase):
self.NavigateToURL(url) self.NavigateToURL(url)
self.AppendTab(pyauto.GURL(url)) self.AppendTab(pyauto.GURL(url))
self._GetUserMedia(tab_index=0) self.GetUserMedia(tab_index=0)
self._GetUserMedia(tab_index=1) self.GetUserMedia(tab_index=1)
self._Connect("user_1", tab_index=0) self._Connect("user_1", tab_index=0)
self._Connect("user_2", tab_index=1) self._Connect("user_2", tab_index=1)
self._EstablishCall(from_tab_with_index=0) self._EstablishCall(from_tab_with_index=0)
self.assertEquals('failed-with-error-1', self.assertEquals('failed-with-error-1',
self._GetUserMedia(tab_index=0, action='deny')) self.GetUserMedia(tab_index=0, action='deny'))
self.assertEquals('failed-with-error-1', self.assertEquals('failed-with-error-1',
self._GetUserMedia(tab_index=0, action='dismiss')) self.GetUserMedia(tab_index=0, action='dismiss'))
def _GetUserMedia(self, tab_index, action='allow'):
"""Acquires webcam or mic for one tab and returns the result."""
self.assertEquals('ok-requested', self.ExecuteJavascript(
'getUserMedia(true, true)', tab_index=tab_index))
self.WaitForInfobarCount(1, tab_index=tab_index)
self.PerformActionOnInfobar(action, infobar_index=0, tab_index=tab_index)
self.WaitForGetUserMediaResult(tab_index=0)
result = self.GetUserMediaResult(tab_index=0)
self._AssertNoFailures(tab_index)
return result
def _Connect(self, user_name, tab_index): def _Connect(self, user_name, tab_index):
self.assertEquals('ok-connected', self.ExecuteJavascript( self.assertEquals('ok-connected', self.ExecuteJavascript(
'connect("http://localhost:8888", "%s")' % user_name, 'connect("http://localhost:8888", "%s")' % user_name,
tab_index=tab_index)) tab_index=tab_index))
self._AssertNoFailures(tab_index) self.AssertNoFailures(tab_index)
def _EstablishCall(self, from_tab_with_index): def _EstablishCall(self, from_tab_with_index):
self.assertEquals('ok-call-established', self.ExecuteJavascript( self.assertEquals('ok-call-established', self.ExecuteJavascript(
'call()', tab_index=from_tab_with_index)) 'call()', tab_index=from_tab_with_index))
self._AssertNoFailures(from_tab_with_index) self.AssertNoFailures(from_tab_with_index)
# Double-check the call reached the other side. # Double-check the call reached the other side.
self.assertEquals('yes', self.ExecuteJavascript( self.assertEquals('yes', self.ExecuteJavascript(
...@@ -172,7 +160,7 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase): ...@@ -172,7 +160,7 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase):
self.assertEquals('ok-call-hung-up', self.ExecuteJavascript( self.assertEquals('ok-call-hung-up', self.ExecuteJavascript(
'hangUp()', tab_index=from_tab_with_index)) 'hangUp()', tab_index=from_tab_with_index))
self._VerifyHungUp(from_tab_with_index) self._VerifyHungUp(from_tab_with_index)
self._AssertNoFailures(from_tab_with_index) self.AssertNoFailures(from_tab_with_index)
def _VerifyHungUp(self, tab_index): def _VerifyHungUp(self, tab_index):
self.assertEquals('no', self.ExecuteJavascript( self.assertEquals('no', self.ExecuteJavascript(
...@@ -194,10 +182,6 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase): ...@@ -194,10 +182,6 @@ class WebRTCCallTest(webrtc_test_base.WebrtcTestBase):
self.assertTrue(video_playing, self.assertTrue(video_playing,
msg='Timed out while trying to detect video.') msg='Timed out while trying to detect video.')
def _AssertNoFailures(self, tab_index):
self.assertEquals('ok-no-errors', self.ExecuteJavascript(
'getAnyTestFailures()', tab_index=tab_index))
if __name__ == '__main__': if __name__ == '__main__':
pyauto_functional.Main() pyauto_functional.Main()
...@@ -9,6 +9,28 @@ import pyauto ...@@ -9,6 +9,28 @@ import pyauto
class WebrtcTestBase(pyauto.PyUITest): class WebrtcTestBase(pyauto.PyUITest):
"""This base class provides helpers for getUserMedia calls.""" """This base class provides helpers for getUserMedia calls."""
def GetUserMedia(self, tab_index, action='allow'):
"""Acquires webcam or mic for one tab and returns the result.
Args:
tab_index: The tab to request user media on.
action: The action to take on the info bar. Can be 'allow', 'deny' or
'dismiss'.
Returns:
A string as specified by the getUserMedia javascript function.
"""
self.assertEquals('ok-requested', self.ExecuteJavascript(
'getUserMedia(true, true)', tab_index=tab_index))
self.WaitForInfobarCount(1, tab_index=tab_index)
self.PerformActionOnInfobar(action, infobar_index=0, tab_index=tab_index)
self.WaitForGetUserMediaResult(tab_index=0)
result = self.GetUserMediaResult(tab_index=0)
self.AssertNoFailures(tab_index)
return result
def WaitForGetUserMediaResult(self, tab_index): def WaitForGetUserMediaResult(self, tab_index):
"""Waits until WebRTC has responded to a getUserMedia query. """Waits until WebRTC has responded to a getUserMedia query.
...@@ -32,4 +54,13 @@ class WebrtcTestBase(pyauto.PyUITest): ...@@ -32,4 +54,13 @@ class WebrtcTestBase(pyauto.PyUITest):
Specified in obtainGetUserMediaResult() in getusermedia.js. Specified in obtainGetUserMediaResult() in getusermedia.js.
""" """
return self.ExecuteJavascript( return self.ExecuteJavascript(
'obtainGetUserMediaResult()', tab_index=tab_index) 'obtainGetUserMediaResult()', tab_index=tab_index)
\ No newline at end of file
def AssertNoFailures(self, tab_index):
"""Ensures the javascript hasn't registered any asynchronous errors.
Args:
tab_index: The tab to check.
"""
self.assertEquals('ok-no-errors', self.ExecuteJavascript(
'getAnyTestFailures()', tab_index=tab_index))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment