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

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

Issue 8587004: Add PyAuto tests for triggering browser/page action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added extension data files Created 9 years, 1 month 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 # Allow extension in incognito mode and verify. 175 # Allow extension in incognito mode and verify.
176 self.SetExtensionStateById(ext_id, enable=True, allow_in_incognito=True) 176 self.SetExtensionStateById(ext_id, enable=True, allow_in_incognito=True)
177 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id) 177 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id)
178 self.assertTrue(extension['allowed_in_incognito']) 178 self.assertTrue(extension['allowed_in_incognito'])
179 179
180 # Disallow extension in incognito mode and verify. 180 # Disallow extension in incognito mode and verify.
181 self.SetExtensionStateById(ext_id, enable=True, allow_in_incognito=False) 181 self.SetExtensionStateById(ext_id, enable=True, allow_in_incognito=False)
182 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id) 182 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id)
183 self.assertFalse(extension['allowed_in_incognito']) 183 self.assertFalse(extension['allowed_in_incognito'])
184 184
185 def testTriggerBrowserAction(self):
186 """Test triggering browser action."""
187 dir_path = os.path.abspath(
188 os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
189 'browser_action'))
190 ext_id = self.InstallExtension(dir_path, False)
191 self.assertTrue(ext_id, msg='Failed to install extension: %s.' % dir_path)
192
193 self.NavigateToURL(self.GetFileURLForDataPath('simple.html'))
194
195 self.TriggerBrowserActionById(ext_id)
196
197 # Verify that the browser action turned the background red.
198 self.assertTrue(self.WaitUntil(
199 lambda: self.GetDOMValue('document.body.style.backgroundColor'),
200 expect_retval='red'),
201 msg='Browser action was not triggered.')
202
203 def testTriggerBrowserActionWithPopup(self):
204 """Test triggering browser action that shows a popup."""
205 dir_path = os.path.abspath(
206 os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
207 'browser_action_popup'))
208 ext_id = self.InstallExtension(dir_path, False)
209 self.assertTrue(ext_id, msg='Failed to install extension: %s.' % dir_path)
210
211 self.TriggerBrowserActionById(ext_id)
212
213 # Verify that the extension popup is displayed.
214 popup = self.WaitUntilExtensionViewLoaded(
215 view_type='EXTENSION_POPUP')
216 self.assertTrue(popup,
217 msg='Browser action failed to display the popup (views=%s).' %
218 self.GetBrowserInfo()['extension_views'])
219
220 def testTriggerPageAction(self):
221 """Test triggering page action."""
222 dir_path = os.path.abspath(
223 os.path.join(self.DataDir(), 'extensions', 'trigger_actions',
224 'page_action'))
225 ext_id = self.InstallExtension(dir_path, False)
226 self.assertTrue(ext_id, msg='Failed to install extension: %s.' % dir_path)
227
228 # Page action icon is displayed when a tab is created.
kkania 2011/11/21 18:53:58 I think we need another function for GetVisiblePag
frankf 2011/11/22 22:26:10 I've added this to GetBrowserInfo, same thing shou
229 self.NavigateToURL(self.GetFileURLForDataPath('simple.html'))
230 self.AppendTab(pyauto.GURL('chrome://newtab'))
231 self.ActivateTab(0)
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, False)
247 self.assertTrue(ext_id, msg='Failed to install extension: %s.' % dir_path)
248
249 # Page action icon is displayed when a tab is created.
250 self.AppendTab(pyauto.GURL('chrome://newtab'))
251 self.ActivateTab(0)
252
253 self.TriggerPageActionById(ext_id)
254
255 # Verify that the extension popup is displayed.
256 popup = self.WaitUntilExtensionViewLoaded(
257 view_type='EXTENSION_POPUP')
258 self.assertTrue(popup,
259 msg='Page action failed to display the popup (views=%s).' %
260 self.GetBrowserInfo()['extension_views'])
261
185 def testAdblockExtensionCrash(self): 262 def testAdblockExtensionCrash(self):
186 """Test AdBlock extension successfully installed and enabled, and do not 263 """Test AdBlock extension successfully installed and enabled, and do not
187 cause browser crash. 264 cause browser crash.
188 """ 265 """
189 crx_file_path = os.path.abspath( 266 crx_file_path = os.path.abspath(
190 os.path.join(self.DataDir(), 'extensions', 'adblock.crx')) 267 os.path.join(self.DataDir(), 'extensions', 'adblock.crx'))
191 ext_id = self.InstallExtension(crx_file_path, False) 268 ext_id = self.InstallExtension(crx_file_path, False)
192 self.assertTrue(ext_id, msg='Failed to install extension.') 269 self.assertTrue(ext_id, msg='Failed to install extension.')
193 270
194 self.RestartBrowser(clear_profile=False) 271 self.RestartBrowser(clear_profile=False)
195 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id) 272 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id)
196 self.assertTrue(extension['is_enabled']) 273 self.assertTrue(extension['is_enabled'])
197 self.assertFalse(extension['allowed_in_incognito']) 274 self.assertFalse(extension['allowed_in_incognito'])
198 275
199 276
200 if __name__ == '__main__': 277 if __name__ == '__main__':
201 pyauto_functional.Main() 278 pyauto_functional.Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698