OLD | NEW |
---|---|
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 Loading... | |
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) | |
dennis_jeffrey
2011/11/23 21:54:54
I think these calls to InstallExtension() will hav
| |
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. | |
229 self.NavigateToURL(self.GetFileURLForDataPath('simple.html')) | |
230 self.AppendTab(pyauto.GURL('chrome://newtab')) | |
231 self.ActivateTab(0) | |
232 self.assertTrue(self.WaitUntil( | |
233 lambda: ext_id in | |
234 self.GetBrowserInfo()['windows'][0]['visible_page_actions']), | |
235 msg='Page action icon is not visible.') | |
236 | |
237 self.TriggerPageActionById(ext_id) | |
238 | |
239 # Verify that page action turned the background red. | |
240 self.assertTrue(self.WaitUntil( | |
241 lambda: self.GetDOMValue('document.body.style.backgroundColor'), | |
242 expect_retval='red'), | |
243 msg='Page action was not triggered.') | |
244 | |
245 def testTriggerPageActionWithPopup(self): | |
246 """Test triggering page action that shows a popup.""" | |
247 dir_path = os.path.abspath( | |
248 os.path.join(self.DataDir(), 'extensions', 'trigger_actions', | |
249 'page_action_popup')) | |
250 ext_id = self.InstallExtension(dir_path, False) | |
251 self.assertTrue(ext_id, msg='Failed to install extension: %s.' % dir_path) | |
252 | |
253 # Page action icon is displayed when a tab is created. | |
254 self.AppendTab(pyauto.GURL('chrome://newtab')) | |
255 self.ActivateTab(0) | |
256 self.assertTrue(self.WaitUntil( | |
257 lambda: ext_id in | |
258 self.GetBrowserInfo()['windows'][0]['visible_page_actions']), | |
259 msg='Page action icon is not visible.') | |
260 | |
261 self.TriggerPageActionById(ext_id) | |
262 | |
263 # Verify that the extension popup is displayed. | |
264 popup = self.WaitUntilExtensionViewLoaded( | |
265 view_type='EXTENSION_POPUP') | |
266 self.assertTrue(popup, | |
267 msg='Page action failed to display the popup (views=%s).' % | |
268 self.GetBrowserInfo()['extension_views']) | |
269 | |
185 def testAdblockExtensionCrash(self): | 270 def testAdblockExtensionCrash(self): |
186 """Test AdBlock extension successfully installed and enabled, and do not | 271 """Test AdBlock extension successfully installed and enabled, and do not |
187 cause browser crash. | 272 cause browser crash. |
188 """ | 273 """ |
189 crx_file_path = os.path.abspath( | 274 crx_file_path = os.path.abspath( |
190 os.path.join(self.DataDir(), 'extensions', 'adblock.crx')) | 275 os.path.join(self.DataDir(), 'extensions', 'adblock.crx')) |
191 ext_id = self.InstallExtension(crx_file_path, False) | 276 ext_id = self.InstallExtension(crx_file_path, False) |
192 self.assertTrue(ext_id, msg='Failed to install extension.') | 277 self.assertTrue(ext_id, msg='Failed to install extension.') |
193 | 278 |
194 self.RestartBrowser(clear_profile=False) | 279 self.RestartBrowser(clear_profile=False) |
195 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id) | 280 extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id) |
196 self.assertTrue(extension['is_enabled']) | 281 self.assertTrue(extension['is_enabled']) |
197 self.assertFalse(extension['allowed_in_incognito']) | 282 self.assertFalse(extension['allowed_in_incognito']) |
198 | 283 |
199 | 284 |
200 if __name__ == '__main__': | 285 if __name__ == '__main__': |
201 pyauto_functional.Main() | 286 pyauto_functional.Main() |
OLD | NEW |