Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 import os | |
|
kkania
2012/01/20 17:16:28
rename this file to about_plugins_ui.py
vivianz
2012/01/27 23:24:36
Done.
| |
| 2 import re | |
| 3 | |
| 4 import pyauto_functional # Must be imported before pyauto | |
| 5 import pyauto | |
| 6 import test_utils | |
|
kkania
2012/01/20 17:16:28
you don't use this; remove?
vivianz
2012/01/27 23:24:36
Done.
| |
| 7 | |
| 8 | |
| 9 class AboutPluginsTest(pyauto.PyUITest): | |
| 10 """TestCase for chrome://plugins.""" | |
| 11 | |
| 12 def Debug(self): | |
| 13 """Test method for experimentation. | |
| 14 | |
| 15 This method will not run automatically. | |
| 16 """ | |
| 17 while True: | |
| 18 raw_input('Interact with the browser and hit <enter> to list plugins...') | |
|
kkania
2012/01/20 17:16:28
this method is more useful for the plugins test; h
vivianz
2012/01/27 23:24:36
Done.
| |
| 19 self.pprint(self.GetPluginsInfo().Plugins()) | |
| 20 | |
| 21 def _ClearLocalDownloadState(self, path): | |
| 22 """Prepare for downloading the given path. | |
| 23 | |
| 24 Clears the given path and the corresponding .crdownload, to prepare it to | |
| 25 be downloaded. | |
| 26 """ | |
| 27 if os.path.exists(path): os.remove(path) | |
| 28 crdownload = path + '.crdownload' | |
| 29 if os.path.exists(crdownload): os.remove(crdownload) | |
| 30 | |
| 31 def _IsEnabled(self, plugin_name): | |
| 32 """Checks if plugin is enabled.""" | |
| 33 for plugin in self.GetPluginsInfo().Plugins(): | |
| 34 if re.search(plugin_name, plugin['name']): | |
| 35 return plugin['enabled'] | |
| 36 | |
| 37 def _GoPDFSiteAndVerify(self, pdf_name, tab_index=0, windex=0, | |
| 38 is_pdf_enabled=True): | |
| 39 """Navigate to PDF file site and verify PDF viewer plugin. | |
| 40 | |
| 41 When PDF Viewer plugin is enabled, navigate the site should not trigger | |
|
kkania
2012/01/20 17:16:28
navigating to the site
vivianz
2012/01/27 23:24:36
Done.
| |
| 42 PDF file downloade and if PDF viewer plugin is disabled, PDF file should | |
|
kkania
2012/01/20 17:16:28
downloade?
vivianz
2012/01/27 23:24:36
fixed
| |
| 43 be viewable in browser. | |
|
kkania
2012/01/20 17:16:28
if plugin is disable, the pdf should be viewable i
vivianz
2012/01/27 23:24:36
my bad :) fixed
| |
| 44 | |
| 45 Args: | |
| 46 pdf_name: the name of the PDF file. | |
| 47 This should exist in the 'dangerous' directory. | |
| 48 tab_index: tab index. Default 0. | |
| 49 windex: window index. Default 0. | |
| 50 is_pdf_enabled: the boolean flag check if PDF viewer plugin is enabled. | |
| 51 Default True. | |
| 52 """ | |
| 53 file_url = self.GetHttpURLForDataPath('downloads', 'dangerous', | |
| 54 'download-dangerous.html' + '?' + pdf_name) | |
| 55 num_downloads = len(self.GetDownloadsInfo().Downloads()) | |
| 56 self.NavigateToURL(file_url, windex, tab_index) | |
| 57 # It might take a while for the download to kick in, hold on until then. | |
| 58 if is_pdf_enabled == False: | |
| 59 self.assertTrue(self.WaitUntil(lambda: | |
| 60 len(self.GetDownloadsInfo().Downloads()) == num_downloads + 1)) | |
| 61 else: | |
| 62 driver = self.NewWebDriver() | |
|
kkania
2012/01/20 17:16:28
don't create a new webdriver here; pass it in as a
vivianz
2012/01/27 23:24:36
Done.
| |
| 63 self.assertTrue(self.WaitUntil(lambda: len( | |
| 64 driver.find_elements_by_name('plugin')) == 1)) | |
| 65 | |
| 66 def testAboutPluginDetailInfo(self): | |
| 67 """Verify about:plugin page shows plugin details.""" | |
| 68 self.NavigateToURL('chrome://plugins/') | |
| 69 driver = self.NewWebDriver() | |
| 70 detail_link = driver.find_element_by_id('details-link') | |
| 71 while not detail_link.is_displayed(): | |
| 72 pass | |
| 73 detail_link.click() | |
| 74 # Verify the detail info for Remote Viewer plugin show up. | |
| 75 self.assertTrue(self.WaitUntil(lambda: len(driver.find_elements_by_xpath( | |
| 76 '//*[@jscontent="name"][text()="Remoting Viewer"]' + | |
|
kkania
2012/01/20 17:16:28
don't use jscontent, use class instead
vivianz
2012/01/27 23:24:36
have to use jscontent, that is the only unique lab
| |
| 77 '//ancestor::*[@class="plugin-text"]//a[text()="Disable"]')) == 1)) | |
|
kkania
2012/01/20 17:16:28
this isn't sufficient to determine if the details
vivianz
2012/01/27 23:24:36
change to locate the detail plugin path for Remote
| |
| 78 | |
| 79 def testAboutPluginEnableAndDisablePDFPlugin(self): | |
| 80 """Verify enable and disable plugins from about:plugins page.""" | |
| 81 self.NavigateToURL('chrome://plugins/') | |
| 82 driver = self.NewWebDriver() | |
| 83 # Override the animation for expanding detail info to make sure element | |
| 84 # remain at the same location where web driver found it. | |
| 85 override_animation_style_js = """ | |
| 86 style = document.createElement('style'); | |
| 87 style.innerHTML = "* { -webkit-transition: all 0s ease-in !important}"; | |
| 88 document.head.appendChild(style); | |
| 89 """ | |
| 90 driver.execute_script(override_animation_style_js) | |
| 91 | |
| 92 # Click Details link to expand details. | |
| 93 detail_link = driver.find_element_by_id('details-link') | |
| 94 while not detail_link.is_displayed(): | |
| 95 pass | |
| 96 detail_link.click() | |
| 97 pdf_disable_path = '//*[@class="plugin-name"][text()="Chrome PDF Viewer"' \ | |
| 98 ']//ancestor::*[@class="plugin-text"]//a[text()="Disable"]' | |
| 99 # Confirm Chrome PDF Viewer plugin is found. | |
| 100 self.assertTrue(self.WaitUntil(lambda: len(driver.find_elements_by_xpath( | |
| 101 pdf_disable_path)) == 1), | |
| 102 msg='Failed to find Chrome PDF Viewer plugin') | |
| 103 | |
| 104 # Disable PDF viewer plugin in about:plugins. | |
| 105 pdf_disable_link = driver.find_element_by_xpath(pdf_disable_path) | |
| 106 | |
| 107 # Need to sleep off 100ms for the detail-info expansion webkit transition. | |
|
kkania
2012/01/20 17:16:28
?
vivianz
2012/01/27 23:24:36
legacy comment deleted.
| |
| 108 pdf_disable_link.click() | |
| 109 self.assertFalse(self.WaitUntil(lambda: | |
| 110 self._IsEnabled('Chrome PDF Viewer'))) | |
|
kkania
2012/01/20 17:16:28
i don't think this is correct
vivianz
2012/01/27 23:24:36
change to assertTrue wait until chrome PDF viewer
| |
| 111 | |
| 112 # Navigate to a PDF file and verify the pdf file is downloaded. | |
| 113 self.OpenNewBrowserWindow(True) | |
| 114 self._GoPDFSiteAndVerify('fw4.pdf', tab_index=0, windex=1, | |
| 115 is_pdf_enabled=False) | |
| 116 id = self.GetDownloadsInfo().Downloads()[0]['id'] | |
| 117 self.PerformActionOnDownload(id, | |
| 118 'save_dangerous_download', | |
| 119 window_index=1) | |
| 120 self.WaitForAllDownloadsToComplete(windex=1) | |
| 121 | |
| 122 pdf_download = self.GetDownloadsInfo(1).Downloads() | |
| 123 # Verify that download info exists in the correct profile. | |
| 124 self.assertEqual(len(pdf_download), 1) | |
| 125 download_pkg = os.path.join(self.GetDownloadDirectory().value(), | |
| 126 'fw4.pdf') | |
| 127 self._ClearLocalDownloadState(download_pkg) | |
| 128 | |
| 129 # Navigate to plugins settings again and re-enable PDF viewer plugin. | |
| 130 self.NavigateToURL('chrome://plugins/') | |
| 131 driver = self.NewWebDriver() | |
|
kkania
2012/01/20 17:16:28
don't make a new driver
vivianz
2012/01/27 23:24:36
Done. removed.
| |
| 132 pdf_enable_path = '//*[@class="plugin-name"][text()="Chrome PDF Viewer"]' \ | |
| 133 '//ancestor::*[@class="plugin-text"]//a[text()="Enable"]' | |
| 134 self.assertTrue(self.WaitUntil(lambda: len(driver.find_elements_by_xpath( | |
| 135 pdf_enable_path)) == 1)) | |
| 136 pdf_enable_link = driver.find_element_by_xpath(pdf_enable_path) | |
| 137 pdf_enable_link.click() | |
| 138 self.CloseBrowserWindow(0) | |
| 139 self.OpenNewBrowserWindow(True) | |
| 140 self._GoPDFSiteAndVerify('fw4.pdf', tab_index=0, windex=0, | |
| 141 is_pdf_enabled=True) | |
| 142 | |
| 143 | |
| 144 if __name__ == '__main__': | |
| 145 pyauto_functional.Main() | |
| OLD | NEW |