summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorfrankf@google.com <frankf@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-03 01:53:02 +0000
committerfrankf@google.com <frankf@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-03 01:53:02 +0000
commitaa47c403ff15893c404306008c92d6d5a3cfe071 (patch)
tree7b8187dc453aeed36ee3b03293f7b6008463ef3d /chrome/test
parentccfb098b3ec9f67f3ce1513506de75cc66f6848a (diff)
downloadchromium_src-aa47c403ff15893c404306008c92d6d5a3cfe071.zip
chromium_src-aa47c403ff15893c404306008c92d6d5a3cfe071.tar.gz
chromium_src-aa47c403ff15893c404306008c92d6d5a3cfe071.tar.bz2
Add PyAuto tests for triggering browser/page action.
BUG=chromium:104530 TEST=PyAuto tests Review URL: http://codereview.chromium.org/8772068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112844 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rwxr-xr-xchrome/test/functional/extensions.py81
-rwxr-xr-xchrome/test/pyautolib/pyauto.py37
2 files changed, 118 insertions, 0 deletions
diff --git a/chrome/test/functional/extensions.py b/chrome/test/functional/extensions.py
index e5a12a8..f158efd 100755
--- a/chrome/test/functional/extensions.py
+++ b/chrome/test/functional/extensions.py
@@ -181,6 +181,87 @@ class ExtensionsTest(pyauto.PyUITest):
extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id)
self.assertFalse(extension['allowed_in_incognito'])
+ def testTriggerBrowserAction(self):
+ """Test triggering browser action."""
+ dir_path = os.path.abspath(
+ os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
+ 'browser_action'))
+ ext_id = self.InstallExtension(dir_path)
+
+ self.NavigateToURL(self.GetFileURLForDataPath('simple.html'))
+
+ self.TriggerBrowserActionById(ext_id)
+
+ # Verify that the browser action turned the background red.
+ self.assertTrue(self.WaitUntil(
+ lambda: self.GetDOMValue('document.body.style.backgroundColor'),
+ expect_retval='red'),
+ msg='Browser action was not triggered.')
+
+ def testTriggerBrowserActionWithPopup(self):
+ """Test triggering browser action that shows a popup."""
+ dir_path = os.path.abspath(
+ os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
+ 'browser_action_popup'))
+ ext_id = self.InstallExtension(dir_path)
+
+ self.TriggerBrowserActionById(ext_id)
+
+ # Verify that the extension popup is displayed.
+ popup = self.WaitUntilExtensionViewLoaded(
+ view_type='EXTENSION_POPUP')
+ self.assertTrue(popup,
+ msg='Browser action failed to display the popup (views=%s).' %
+ self.GetBrowserInfo()['extension_views'])
+
+ def testTriggerPageAction(self):
+ """Test triggering page action."""
+ dir_path = os.path.abspath(
+ os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
+ 'page_action'))
+ ext_id = self.InstallExtension(dir_path)
+
+ # Page action icon is displayed when a tab is created.
+ self.NavigateToURL(self.GetFileURLForDataPath('simple.html'))
+ self.AppendTab(pyauto.GURL('chrome://newtab'))
+ self.ActivateTab(0)
+ self.assertTrue(self.WaitUntil(
+ lambda: ext_id in
+ self.GetBrowserInfo()['windows'][0]['visible_page_actions']),
+ msg='Page action icon is not visible.')
+
+ self.TriggerPageActionById(ext_id)
+
+ # Verify that page action turned the background red.
+ self.assertTrue(self.WaitUntil(
+ lambda: self.GetDOMValue('document.body.style.backgroundColor'),
+ expect_retval='red'),
+ msg='Page action was not triggered.')
+
+ def testTriggerPageActionWithPopup(self):
+ """Test triggering page action that shows a popup."""
+ dir_path = os.path.abspath(
+ os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
+ 'page_action_popup'))
+ ext_id = self.InstallExtension(dir_path)
+
+ # Page action icon is displayed when a tab is created.
+ self.AppendTab(pyauto.GURL('chrome://newtab'))
+ self.ActivateTab(0)
+ self.assertTrue(self.WaitUntil(
+ lambda: ext_id in
+ self.GetBrowserInfo()['windows'][0]['visible_page_actions']),
+ msg='Page action icon is not visible.')
+
+ self.TriggerPageActionById(ext_id)
+
+ # Verify that the extension popup is displayed.
+ popup = self.WaitUntilExtensionViewLoaded(
+ view_type='EXTENSION_POPUP')
+ self.assertTrue(popup,
+ msg='Page action failed to display the popup (views=%s).' %
+ self.GetBrowserInfo()['extension_views'])
+
def testAdblockExtensionCrash(self):
"""Test AdBlock extension successfully installed and enabled, and do not
cause browser crash.
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 033d4b9..3638e10 100755
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -1488,6 +1488,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
u'incognito': False,
u'profile_path': u'Default',
u'fullscreen': False,
+ u'visible_page_actions':
+ [u'dgcoklnmbeljaehamekjpeidmbicddfj',
+ u'osfcklnfasdofpcldmalwpicslasdfgd']
u'selected_tab': 0,
u'tabs': [ {
u'index': 0,
@@ -1837,6 +1840,38 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
self._GetResultFromJSONRequest(cmd_dict)
+ def TriggerPageActionById(self, id, windex=0):
+ """Trigger page action asynchronously in the active tab.
+
+ The page action icon must be displayed before invoking this function.
+
+ Args:
+ id: The string id of the extension.
+ windex: Integer index of the browser window to use; defaults to 0
+ (first window).
+ """
+ cmd_dict = { # Prepare command for the json interface
+ 'command': 'TriggerPageActionById',
+ 'id': id,
+ 'windex': windex,
+ }
+ self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+
+ def TriggerBrowserActionById(self, id, windex=0):
+ """Trigger browser action asynchronously in the active tab.
+
+ Args:
+ id: The string id of the extension.
+ windex: Integer index of the browser window to use; defaults to 0
+ (first window).
+ """
+ cmd_dict = { # Prepare command for the json interface
+ 'command': 'TriggerBrowserActionById',
+ 'id': id,
+ 'windex': windex,
+ }
+ self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+
def UpdateExtensionsNow(self):
"""Auto-updates installed extensions.
@@ -1867,6 +1902,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
extension_id: (optional) ID of the extension.
url: (optional) URL of the extension view.
view_type: (optional) Type of the extension view.
+ ['EXTENSION_BACKGROUND_PAGE'|'EXTENSION_POPUP'|'EXTENSION_INFOBAR'|
+ 'EXTENSION_DIALOG']
Returns:
The 'view' property of the extension view.