summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authoralyssad@google.com <alyssad@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-30 16:35:31 +0000
committeralyssad@google.com <alyssad@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-30 16:35:31 +0000
commitc48d8fada025ccfabd3e95e22b150d66fc98cb39 (patch)
treedd0d2ab4384c8b213147fcda476af7c724b0668c /chrome/test
parent359af188d36cc374076147f9808372a46a55baa7 (diff)
downloadchromium_src-c48d8fada025ccfabd3e95e22b150d66fc98cb39.zip
chromium_src-c48d8fada025ccfabd3e95e22b150d66fc98cb39.tar.gz
chromium_src-c48d8fada025ccfabd3e95e22b150d66fc98cb39.tar.bz2
Fix pyauto wait until hooks to use client-side WaitUntil BUG=53647
Some hooks have small chances of race conditions that can cause hangs and test failures. Fix this by using the client-side WaitUntil for now. Review URL: http://codereview.chromium.org/3222002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57865 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/functional/infobars.py13
-rw-r--r--chrome/test/functional/prefs.py4
-rw-r--r--chrome/test/functional/translate.py37
-rw-r--r--chrome/test/pyautolib/pyauto.py30
4 files changed, 40 insertions, 44 deletions
diff --git a/chrome/test/functional/infobars.py b/chrome/test/functional/infobars.py
index a2b1c1d..ebfaf18 100644
--- a/chrome/test/functional/infobars.py
+++ b/chrome/test/functional/infobars.py
@@ -50,7 +50,7 @@ class InfobarTest(pyauto.PyUITest):
self.assertTrue(flash)
logging.info('Killing flash plugin. pid %d' % flash['pid'])
self.Kill(flash['pid'])
- self.WaitForInfobarCount(1)
+ self.assertTrue(self.WaitForInfobarCount(1))
crash_infobar = self._GetTabInfo()['infobars']
self.assertTrue(crash_infobar)
self.assertEqual(1, len(crash_infobar))
@@ -83,7 +83,7 @@ class InfobarTest(pyauto.PyUITest):
self.DataDir(), 'geolocation', 'geolocation_on_load.html'))
match_text='file:/// wants to track your physical location'
self.NavigateToURL(url)
- self.WaitForInfobarCount(1)
+ self.assertTrue(self.WaitForInfobarCount(1))
self._VerifyGeolocationInfobar(windex=0, tab_index=0, match_text=match_text)
# Accept, and verify that the infobar went away
self.PerformActionOnInfobar('accept', infobar_index=0)
@@ -96,18 +96,19 @@ class InfobarTest(pyauto.PyUITest):
match_text='file:/// wants to track your physical location'
for tab_index in range(1, 2):
self.AppendTab(pyauto.GURL(url))
- self.WaitForInfobarCount(1, windex=0, tab_index=tab_index)
+ self.assertTrue(
+ self.WaitForInfobarCount(1, windex=0, tab_index=tab_index))
self._VerifyGeolocationInfobar(windex=0, tab_index=tab_index,
match_text=match_text)
# Try in a new window
self.OpenNewBrowserWindow(True)
self.NavigateToURL(url, 1, 0)
- self.WaitForInfobarCount(1, windex=1, tab_index=0)
+ self.assertTrue(self.WaitForInfobarCount(1, windex=1, tab_index=0))
self._VerifyGeolocationInfobar(windex=1, tab_index=0, match_text=match_text)
# Incognito window
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
self.NavigateToURL(url, 2, 0)
- self.WaitForInfobarCount(1, windex=2, tab_index=0)
+ self.assertTrue(self.WaitForInfobarCount(1, windex=2, tab_index=0))
self._VerifyGeolocationInfobar(windex=2, tab_index=0, match_text=match_text)
def testMultipleDownloadsInfobar(self):
@@ -125,7 +126,7 @@ class InfobarTest(pyauto.PyUITest):
self.DownloadAndWaitForStart(file_url)
# trigger page reload, which triggers the download infobar
self.GetBrowserWindow(0).GetTab(0).Reload()
- self.WaitForInfobarCount(1)
+ self.assertTrue(self.WaitForInfobarCount(1))
tab_info = self._GetTabInfo(0, 0)
infobars = tab_info['infobars']
self.assertTrue(infobars, 'Expected the multiple downloads infobar')
diff --git a/chrome/test/functional/prefs.py b/chrome/test/functional/prefs.py
index 700ebf8..3cb54da 100644
--- a/chrome/test/functional/prefs.py
+++ b/chrome/test/functional/prefs.py
@@ -150,14 +150,14 @@ class PrefsTest(pyauto.PyUITest):
self.assertEqual(3, # default state
self.GetPrefsInfo().Prefs(pyauto.kGeolocationDefaultContentSetting))
self.NavigateToURL(url)
- self.WaitForInfobarCount(1)
+ self.assertTrue(self.WaitForInfobarCount(1))
self.assertTrue(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'])
# Disable geolocation
self.SetPrefs(pyauto.kGeolocationDefaultContentSetting, 2)
self.assertEqual(2,
self.GetPrefsInfo().Prefs(pyauto.kGeolocationDefaultContentSetting))
self.GetBrowserWindow(0).GetTab(0).Reload()
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'])
diff --git a/chrome/test/functional/translate.py b/chrome/test/functional/translate.py
index 5fa0eca..abf6d90 100644
--- a/chrome/test/functional/translate.py
+++ b/chrome/test/functional/translate.py
@@ -43,7 +43,8 @@ class TranslateTest(pyauto.PyUITest):
def _NavigateAndWaitForBar(self, url, window_index=0, tab_index=0):
self.NavigateToURL(url, window_index, tab_index)
- self.WaitForInfobarCount(1, windex=window_index, tab_index=tab_index)
+ self.assertTrue(self.WaitForInfobarCount(
+ 1, windex=window_index, tab_index=tab_index))
def _ClickTranslateUntilSuccess(self, window_index=0, tab_index=0):
"""Since the translate can fail due to server error, continue trying until
@@ -172,7 +173,7 @@ class TranslateTest(pyauto.PyUITest):
self.assertTrue(translate_info['can_translate_page'])
# This page is an ssl error page.
self.NavigateToURL('https://www.sourceforge.net')
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
translate_info = self.GetTranslateInfo()
self.assertFalse('translate_bar' in translate_info)
@@ -184,7 +185,7 @@ class TranslateTest(pyauto.PyUITest):
self.assertTrue(translate_info['can_translate_page'])
# With the translate bar visible in same tab open an English page.
self.NavigateToURL(self._GetDefaultEnglishURL())
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
translate_info = self.GetTranslateInfo()
self.assertFalse('translate_bar' in translate_info)
@@ -201,7 +202,7 @@ class TranslateTest(pyauto.PyUITest):
self._NavigateAndWaitForBar(self._GetDefaultSpanishURL())
self.NavigateToURL(self._GetURLForDataDirFile(
os.path.join('translate', 'notranslate_meta_tag.html')))
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
translate_info = self.GetTranslateInfo()
self.assertFalse('translate_bar' in translate_info)
@@ -219,7 +220,7 @@ class TranslateTest(pyauto.PyUITest):
self.assertTrue(translate_info['page_translated'])
# Reload the tab and confirm the page was translated.
self.GetBrowserWindow(0).GetTab(0).Reload()
- self.WaitForInfobarCount(1)
+ self.assertTrue(self.WaitForInfobarCount(1))
success = self.WaitUntilTranslateComplete()
# Sometimes the translation fails. Continue clicking until it succeeds.
if not success:
@@ -243,15 +244,15 @@ class TranslateTest(pyauto.PyUITest):
# Due to crbug.com/51439, we must open two tabs here.
self.NavigateToURL("http://www.news.google.com")
self.AppendTab(pyauto.GURL("http://www.google.com/webhp?hl=es"))
- self.WaitForInfobarCount(1, tab_index=1)
+ self.assertTrue(self.WaitForInfobarCount(1, tab_index=1))
translate_info = self.GetTranslateInfo(tab_index=1)
self.assertTrue('translate_bar' in translate_info)
self.SelectTranslateOption('toggle_always_translate', tab_index=1)
self._ClickTranslateUntilSuccess(tab_index=1)
self.SetPrefs(pyauto.kRestoreOnStartup, 1)
self.RestartBrowser(clear_profile=False)
- self.WaitForInfobarCount(1, tab_index=1)
- self.WaitUntilTranslateComplete()
+ self.assertTrue(self.WaitForInfobarCount(1, tab_index=1))
+ self.WaitUntilTranslateComplete(tab_index=1)
translate_info = self.GetTranslateInfo(tab_index=1)
self.assertTrue('translate_bar' in translate_info)
# Sometimes translation fails. We don't really care whether it succeededs,
@@ -269,12 +270,12 @@ class TranslateTest(pyauto.PyUITest):
translate_info = self.GetTranslateInfo()
self.assertTrue('translate_bar' in translate_info)
self.NavigateToURL(no_trans_url)
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
self.assertFalse('translate_bar' in self.GetTranslateInfo())
# Go back to the page that should be translated and assert that the
# translate bar re-appears.
self.GetBrowserWindow(0).GetTab(0).GoBack()
- self.WaitForInfobarCount(1)
+ self.assertTrue(self.WaitForInfobarCount(1))
self.assertTrue('translate_bar' in self.GetTranslateInfo())
# Now test going forward.
@@ -283,11 +284,11 @@ class TranslateTest(pyauto.PyUITest):
self.assertFalse('translate_bar' in translate_info)
self._AssertTranslateWorks(trans_url, self.spanish)
self.GetBrowserWindow(0).GetTab(0).GoBack()
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
translate_info = self.GetTranslateInfo()
self.assertFalse('translate_bar' in translate_info)
self.GetBrowserWindow(0).GetTab(0).GoForward()
- self.WaitForInfobarCount(1)
+ self.assertTrue(self.WaitForInfobarCount(1))
translate_info = self.GetTranslateInfo()
self.assertTrue(translate_info['can_translate_page'])
self.assertTrue('translate_bar' in translate_info)
@@ -299,7 +300,7 @@ class TranslateTest(pyauto.PyUITest):
translate_info = self.GetTranslateInfo()
self.assertTrue('translate_bar' in translate_info)
self.NavigateToURL(crash_url)
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
self.assertFalse('translate_bar' in self.GetTranslateInfo())
def testTranslatePrefs(self):
@@ -359,7 +360,7 @@ class TranslateTest(pyauto.PyUITest):
# and wait for bar to go away.
self._NavigateAndWaitForBar('http://www.google.com/webhp?hl=fr')
self.NavigateToURL('http://www.google.com/webhp?hl=es')
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
self.assertFalse(self.GetTranslateInfo()['can_translate_page'])
def testChangeTargetLanguageAlwaysTranslate(self):
@@ -455,7 +456,7 @@ class TranslateTest(pyauto.PyUITest):
# it disappears on the history page.
self._NavigateAndWaitForBar(self._GetDefaultSpanishURL())
self.NavigateToURL('chrome://history/')
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
self.assertFalse('translate_bar' in self.GetTranslateInfo())
def testDownloadsNotTranslated(self):
@@ -466,7 +467,7 @@ class TranslateTest(pyauto.PyUITest):
# it disappears on the downloads page.
self._NavigateAndWaitForBar(self._GetDefaultSpanishURL())
self.NavigateToURL('chrome://downloads/')
- self.WaitForInfobarCount(0)
+ self.assertTrue(self.WaitForInfobarCount(0))
self.assertFalse('translate_bar' in self.GetTranslateInfo())
def testAlwaysTranslateInIncognito(self):
@@ -494,8 +495,8 @@ class TranslateTest(pyauto.PyUITest):
"""Navigate to a Spanish page in the given window/tab and verify that the
translate bar shows up.
"""
- self.NavigateToURL(url, window_index, tab_index)
- self.WaitForInfobarCount(1, windex=window_index, tab_index=tab_index)
+ self._NavigateAndWaitForBar(
+ url, window_index=window_index, tab_index=tab_index)
info_before_translate = self.GetTranslateInfo(window_index=window_index,
tab_index=tab_index)
self.assertTrue('translate_bar' in info_before_translate)
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 6aa64a2..0d4f667 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -560,21 +560,6 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
return self._GetResultFromJSONRequest(cmd_dict, windex=window_index)
- def WaitForAlwaysOpenDownloadTypeToOpen(self, id):
- """Wait for the given download to open.
-
- Note: This method should not be used after PerformActionOnDownload('open').
- It is used for files that are auto-downloaded based on the file type.
-
- Args:
- id: The id of the download.
- """
- cmd_dict = { # Prepare command for the json interface
- 'command': 'WaitForAlwaysOpenDownloadTypeToOpen',
- 'id': id
- }
- self._GetResultFromJSONRequest(cmd_dict)
-
def DownloadAndWaitForStart(self, file_url):
"""Trigger download for the given url and wait for downloads to start.
@@ -636,7 +621,12 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'count': count,
'tab_index': tab_index,
}
- self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+ # TODO(phajdan.jr): We need a solid automation infrastructure to handle
+ # these cases. See crbug.com/53647.
+ return self.WaitUntil(
+ lambda(count): len(self.GetBrowserInfo()\
+ ['windows'][windex]['tabs'][tab_index]['infobars']) == count,
+ args=[count])
def PerformActionOnInfobar(
self, action, infobar_index, windex=0, tab_index=0):
@@ -957,8 +947,12 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'command': 'WaitUntilTranslateComplete',
'tab_index': tab_index
}
- return self._GetResultFromJSONRequest(
- cmd_dict, windex=window_index)['translation_success']
+ # TODO(phajdan.jr): We need a solid automation infrastructure to handle
+ # these cases. See crbug.com/53647.
+ return self.WaitUntil(
+ lambda tab_index, window_index: self.GetTranslateInfo(
+ tab_index=tab_index, window_index=window_index)['page_translated'],
+ args=[tab_index, window_index])
def FillAutoFillProfile(self, profiles=None, credit_cards=None,
tab_index=0, window_index=0):