diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 04:55:28 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 04:55:28 +0000 |
commit | e004a2d0d8d5f3e67483f52a48db29998882d7ff (patch) | |
tree | 1c5d4eeaa1734a026c0a1a5070dc3af6dfb85d7e /chrome/test | |
parent | 8e8efbd197406eaf4b4e458c32b158f360ba9307 (diff) | |
download | chromium_src-e004a2d0d8d5f3e67483f52a48db29998882d7ff.zip chromium_src-e004a2d0d8d5f3e67483f52a48db29998882d7ff.tar.gz chromium_src-e004a2d0d8d5f3e67483f52a48db29998882d7ff.tar.bz2 |
Add PyAuto automation hooks to perform actions on infobars
Actions include: dismissing an infobar, accept/close-ing it
Also, enable infobars tests.
Review URL: http://codereview.chromium.org/3042012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53304 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 1 | ||||
-rw-r--r-- | chrome/test/functional/infobars.py | 56 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 28 |
3 files changed, 84 insertions, 1 deletions
diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index 952eb98..1e16df7 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -31,6 +31,7 @@ 'cookies', 'downloads', 'history', + 'infobars', 'navigation', 'omnibox', 'passwords', diff --git a/chrome/test/functional/infobars.py b/chrome/test/functional/infobars.py index f5d48e3..b4f080b 100644 --- a/chrome/test/functional/infobars.py +++ b/chrome/test/functional/infobars.py @@ -31,6 +31,13 @@ class InfobarTest(pyauto.PyUITest): print 'Window', window['index'], 'tab', tab['index'] pp.pprint(tab['infobars']) + def _GetTabInfo(self, windex=0, tab_index=0): + """Helper to return info for the given tab in the given window. + + Defaults to first tab in first window. + """ + return self.GetBrowserInfo()['windows'][windex]['tabs'][tab_index] + def testPluginCrashInfobar(self): """Verify the "plugin crashed" infobar.""" flash_url = self.GetFileURLForPath(os.path.join(self.DataDir(), @@ -44,11 +51,58 @@ class InfobarTest(pyauto.PyUITest): logging.info('Killing flash plugin. pid %d' % flash['pid']) self.Kill(flash['pid']) self.WaitForInfobarCount(1) - crash_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] + crash_infobar = self._GetTabInfo()['infobars'] self.assertTrue(crash_infobar) self.assertEqual(1, len(crash_infobar)) self.assertTrue(re.match('The following plug-in has crashed:', crash_infobar[0]['text'])) + self.assertEqual('alert_infobar', crash_infobar[0]['type']) + # Dismiss the infobar + self.PerformActionOnInfobar('dismiss', infobar_index=0) + self.assertFalse(self._GetTabInfo()['infobars']) + + def _VerifyGeolocationInfobar(self, match_text, windex, tab_index): + """Verify geolocation infobar and match given text. + + Assumes that geolocation infobar is showing up in the given tab in the + given window. + """ + tab_info = self._GetTabInfo(windex, tab_index) + geolocation_infobar = tab_info['infobars'] + self.assertTrue(geolocation_infobar) + self.assertEqual(1, len(geolocation_infobar)) + self.assertEqual(match_text, geolocation_infobar[0]['text']) + self.assertEqual('Learn more', geolocation_infobar[0]['link_text']) + self.assertEqual(2, len(geolocation_infobar[0]['buttons'])) + self.assertEqual('Allow', geolocation_infobar[0]['buttons'][0]) + self.assertEqual('Deny', geolocation_infobar[0]['buttons'][1]) + + def testGeolocationInfobar(self): + """Verify geoLocation infobar.""" + url = 'http://m.flickr.com/#/nearby/' # automatically triggers geolocation + match_text='m.flickr.com wants to track your physical location' + self.NavigateToURL(url) + 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) + self.assertFalse(self._GetTabInfo()['infobars']) + + def testGeolocationInfobarInMultipleTabsAndWindows(self): + """Verify GeoLocation inforbar in multiple tabs.""" + url = 'http://m.flickr.com/#/nearby/' # automatically triggers geolocation + match_text='m.flickr.com wants to track your physical location' + for tab_index in range(1, 2): + self.AppendTab(pyauto.GURL(url)) + 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._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._VerifyGeolocationInfobar(windex=2, tab_index=0, match_text=match_text) if __name__ == '__main__': diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index fbd7ee3..5394752 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -510,6 +510,34 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): } self._GetResultFromJSONRequest(cmd_dict, windex=windex) + def PerformActionOnInfobar( + self, action, infobar_index, windex=0, tab_index=0): + """Perform actions on an infobar. + + Args: + action: the action to be performed. + Actions depend on the type of the infobar. The user needs to + call the right action for the right infobar. + Valid inputs are: + - "dismiss": closes the infobar (for all infobars) + - "accept", "cancel": click accept / cancel (for confirm infobars) + infobar_index: 0-based index of the infobar on which to perform the action + windex: 0-based window index Defaults to 0 (first window) + tab_index: 0-based tab index. Defaults to 0 (first tab) + + Raises: + pyauto_errors.JSONInterfaceError if the automation call returns an error. + """ + cmd_dict = { + 'command': 'PerformActionOnInfobar', + 'action': action, + 'infobar_index': infobar_index, + 'tab_index': tab_index, + } + if action not in ('dismiss', 'accept', 'cancel'): + raise JSONInterfaceError('Invalid action %s' % action) + self._GetResultFromJSONRequest(cmd_dict, windex=windex) + def GetBrowserInfo(self): """Return info about the browser. |