Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(583)

Side by Side Diff: chrome/test/functional/extensions.py

Issue 8772068: Add PyAuto tests for triggering browser/page action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_browser.gypi ('k') | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 This module is a simple qa tool that installs extensions and tests whether the 7 This module is a simple qa tool that installs extensions and tests whether the
8 browser crashes while visiting a list of urls. 8 browser crashes while visiting a list of urls.
9 9
10 Usage: python extensions.py -v 10 Usage: python extensions.py -v
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 # Allow extension in incognito mode and verify. 174 # Allow extension in incognito mode and verify.
175 self.SetExtensionStateById(ext_id, enable=True, allow_in_incognito=True) 175 self.SetExtensionStateById(ext_id, enable=True, allow_in_incognito=True)
176 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id) 176 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id)
177 self.assertTrue(extension['allowed_in_incognito']) 177 self.assertTrue(extension['allowed_in_incognito'])
178 178
179 # Disallow extension in incognito mode and verify. 179 # Disallow extension in incognito mode and verify.
180 self.SetExtensionStateById(ext_id, enable=True, allow_in_incognito=False) 180 self.SetExtensionStateById(ext_id, enable=True, allow_in_incognito=False)
181 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id) 181 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id)
182 self.assertFalse(extension['allowed_in_incognito']) 182 self.assertFalse(extension['allowed_in_incognito'])
183 183
184 def testTriggerBrowserAction(self):
185 """Test triggering browser action."""
186 dir_path = os.path.abspath(
187 os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
188 'browser_action'))
189 ext_id = self.InstallExtension(dir_path)
190
191 self.NavigateToURL(self.GetFileURLForDataPath('simple.html'))
192
193 self.TriggerBrowserActionById(ext_id)
194
195 # Verify that the browser action turned the background red.
196 self.assertTrue(self.WaitUntil(
197 lambda: self.GetDOMValue('document.body.style.backgroundColor'),
198 expect_retval='red'),
199 msg='Browser action was not triggered.')
200
201 def testTriggerBrowserActionWithPopup(self):
202 """Test triggering browser action that shows a popup."""
203 dir_path = os.path.abspath(
204 os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
205 'browser_action_popup'))
206 ext_id = self.InstallExtension(dir_path)
207
208 self.TriggerBrowserActionById(ext_id)
209
210 # Verify that the extension popup is displayed.
211 popup = self.WaitUntilExtensionViewLoaded(
212 view_type='EXTENSION_POPUP')
213 self.assertTrue(popup,
214 msg='Browser action failed to display the popup (views=%s).' %
215 self.GetBrowserInfo()['extension_views'])
216
217 def testTriggerPageAction(self):
218 """Test triggering page action."""
219 dir_path = os.path.abspath(
220 os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
221 'page_action'))
222 ext_id = self.InstallExtension(dir_path)
223
224 # Page action icon is displayed when a tab is created.
225 self.NavigateToURL(self.GetFileURLForDataPath('simple.html'))
226 self.AppendTab(pyauto.GURL('chrome://newtab'))
227 self.ActivateTab(0)
228 self.assertTrue(self.WaitUntil(
229 lambda: ext_id in
230 self.GetBrowserInfo()['windows'][0]['visible_page_actions']),
231 msg='Page action icon is not visible.')
232
233 self.TriggerPageActionById(ext_id)
234
235 # Verify that page action turned the background red.
236 self.assertTrue(self.WaitUntil(
237 lambda: self.GetDOMValue('document.body.style.backgroundColor'),
238 expect_retval='red'),
239 msg='Page action was not triggered.')
240
241 def testTriggerPageActionWithPopup(self):
242 """Test triggering page action that shows a popup."""
243 dir_path = os.path.abspath(
244 os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
245 'page_action_popup'))
246 ext_id = self.InstallExtension(dir_path)
247
248 # Page action icon is displayed when a tab is created.
249 self.AppendTab(pyauto.GURL('chrome://newtab'))
250 self.ActivateTab(0)
251 self.assertTrue(self.WaitUntil(
252 lambda: ext_id in
253 self.GetBrowserInfo()['windows'][0]['visible_page_actions']),
254 msg='Page action icon is not visible.')
255
256 self.TriggerPageActionById(ext_id)
257
258 # Verify that the extension popup is displayed.
259 popup = self.WaitUntilExtensionViewLoaded(
260 view_type='EXTENSION_POPUP')
261 self.assertTrue(popup,
262 msg='Page action failed to display the popup (views=%s).' %
263 self.GetBrowserInfo()['extension_views'])
264
184 def testAdblockExtensionCrash(self): 265 def testAdblockExtensionCrash(self):
185 """Test AdBlock extension successfully installed and enabled, and do not 266 """Test AdBlock extension successfully installed and enabled, and do not
186 cause browser crash. 267 cause browser crash.
187 """ 268 """
188 crx_file_path = os.path.abspath( 269 crx_file_path = os.path.abspath(
189 os.path.join(self.DataDir(), 'extensions', 'adblock.crx')) 270 os.path.join(self.DataDir(), 'extensions', 'adblock.crx'))
190 ext_id = self.InstallExtension(crx_file_path) 271 ext_id = self.InstallExtension(crx_file_path)
191 272
192 self.RestartBrowser(clear_profile=False) 273 self.RestartBrowser(clear_profile=False)
193 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id) 274 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id)
194 self.assertTrue(extension['is_enabled']) 275 self.assertTrue(extension['is_enabled'])
195 self.assertFalse(extension['allowed_in_incognito']) 276 self.assertFalse(extension['allowed_in_incognito'])
196 277
197 278
198 if __name__ == '__main__': 279 if __name__ == '__main__':
199 pyauto_functional.Main() 280 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/chrome_browser.gypi ('k') | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698