OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 import os | 6 import os |
7 import re | 7 import re |
8 | 8 |
9 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
10 import pyauto | 10 import pyauto |
(...skipping 23 matching lines...) Expand all Loading... |
34 def Debug(self): | 34 def Debug(self): |
35 """chrome://plugins test debug method. | 35 """chrome://plugins test debug method. |
36 | 36 |
37 This method will not run automatically. | 37 This method will not run automatically. |
38 """ | 38 """ |
39 self.NavigateToURL('chrome://plugins/') | 39 self.NavigateToURL('chrome://plugins/') |
40 driver = self.NewWebDriver() | 40 driver = self.NewWebDriver() |
41 import pdb | 41 import pdb |
42 pdb.set_trace() | 42 pdb.set_trace() |
43 | 43 |
44 def _IsEnabled(self, plugin_name): | 44 def _IsEnabled(self, driver, plugin_name): |
45 """Checks if plugin is enabled. | 45 """Checks if plugin is enabled. |
46 | 46 |
47 Args: | 47 Args: |
| 48 driver: A Chrome driver object. |
48 plugin_name: Plugin name to verify. | 49 plugin_name: Plugin name to verify. |
49 | 50 |
50 Returns: | 51 Returns: |
51 True, if plugin is enabled, or False otherwise. | 52 True, if plugin is enabled, or False otherwise. |
52 """ | 53 """ |
53 for plugin in self.GetPluginsInfo().Plugins(): | 54 check_plugin_enabled_js = 'return navigator.plugins["%s"] != undefined' % \ |
54 if re.search(plugin_name, plugin['name']): | 55 plugin_name |
55 return plugin['enabled'] | 56 return driver.execute_script(check_plugin_enabled_js) |
56 | 57 |
57 def _ExpandDetailInfoLink(self, driver): | 58 def _ExpandDetailInfoLink(self, driver): |
58 """Expand detail info link. | 59 """Expand detail info link. |
59 | 60 |
60 Args: | 61 Args: |
61 driver: A Chrome driver object. | 62 driver: A Chrome driver object. |
62 """ | 63 """ |
63 detail_link = driver.find_element_by_id('details-link') | 64 detail_link = driver.find_element_by_id('details-link') |
64 self.assertTrue(self.WaitUntil(lambda: detail_link.is_displayed()), | 65 self.assertTrue(self.WaitUntil(lambda: detail_link.is_displayed()), |
65 msg='Details link could not be found.') | 66 msg='Details link could not be found.') |
(...skipping 26 matching lines...) Expand all Loading... |
92 pdf_enable_path = '//*[@class="plugin-name"][text()="Chrome PDF Viewer"' \ | 93 pdf_enable_path = '//*[@class="plugin-name"][text()="Chrome PDF Viewer"' \ |
93 ']//ancestor::*[@class="plugin-text"]//a[text()="Enable"]' | 94 ']//ancestor::*[@class="plugin-text"]//a[text()="Enable"]' |
94 | 95 |
95 # Confirm Chrome PDF Viewer plugin is found and find disable PDF link. | 96 # Confirm Chrome PDF Viewer plugin is found and find disable PDF link. |
96 pdf_disable_link = pyauto_utils.WaitForDomElement(self, driver, | 97 pdf_disable_link = pyauto_utils.WaitForDomElement(self, driver, |
97 pdf_disable_path) | 98 pdf_disable_path) |
98 | 99 |
99 # Disable PDF viewer plugin in about:plugins. | 100 # Disable PDF viewer plugin in about:plugins. |
100 pdf_disable_link.click() | 101 pdf_disable_link.click() |
101 self.assertTrue(self.WaitUntil(lambda: not | 102 self.assertTrue(self.WaitUntil(lambda: not |
102 self._IsEnabled('Chrome PDF Viewer'))) | 103 self._IsEnabled(driver, 'Chrome PDF Viewer'))) |
103 | 104 |
104 # Re-enable PDF viewer plugin. | 105 # Re-enable PDF viewer plugin. |
105 pdf_enable_link = driver.find_element_by_xpath(pdf_enable_path) | 106 pdf_enable_link = driver.find_element_by_xpath(pdf_enable_path) |
106 pdf_enable_link.click() | 107 pdf_enable_link.click() |
107 self.assertTrue(self.WaitUntil(lambda: | 108 self.assertTrue(self.WaitUntil(lambda: |
108 self._IsEnabled('Chrome PDF Viewer'))) | 109 self._IsEnabled(driver, 'Chrome PDF Viewer'))) |
109 | 110 |
110 def testEnableAndDisableFlashPlugin(self): | 111 def testEnableAndDisableFlashPlugin(self): |
111 """Verify enable and disable flash plugins from about:plugins page.""" | 112 """Verify enable and disable flash plugins from about:plugins page.""" |
112 self.NavigateToURL('chrome://plugins/') | 113 self.NavigateToURL('chrome://plugins/') |
113 driver = self.NewWebDriver() | 114 driver = self.NewWebDriver() |
114 | 115 |
115 self._OverridePluginPageAnimation(driver) | 116 self._OverridePluginPageAnimation(driver) |
116 self._ExpandDetailInfoLink(driver) | 117 self._ExpandDetailInfoLink(driver) |
117 flash_plugins_elem = driver.find_element_by_xpath( | 118 flash_plugins_elem = driver.find_element_by_xpath( |
118 '//*[@jscontent="name"][text()="Flash"]//ancestor' \ | 119 '//*[@jscontent="name"][text()="Flash"]//ancestor' \ |
119 '::*[@class="plugin-text"]') | 120 '::*[@class="plugin-text"]') |
120 | 121 |
121 # Disable flash plugin from flash detail info. | 122 # Disable flash plugin from flash detail info. |
122 flash_disable_link = flash_plugins_elem.find_element_by_xpath( | 123 flash_disable_link = flash_plugins_elem.find_element_by_xpath( |
123 './/a[text()="Disable"]') | 124 './/a[text()="Disable"]') |
124 flash_disable_link.click() | 125 flash_disable_link.click() |
125 self.assertTrue(self.WaitUntil(lambda: not | 126 self.assertTrue(self.WaitUntil(lambda: not |
126 self._IsEnabled('Shockwave Flash'))) | 127 self._IsEnabled(driver, 'Shockwave Flash'))) |
127 | 128 |
128 # Re-enable Flash plugin from flash detail info. | 129 # Re-enable Flash plugin from flash detail info. |
129 flash_enable_link = flash_plugins_elem.find_element_by_xpath( | 130 flash_enable_link = flash_plugins_elem.find_element_by_xpath( |
130 './/a[text()="Enable"]') | 131 './/a[text()="Enable"]') |
131 flash_enable_link.click() | 132 flash_enable_link.click() |
132 self.assertTrue(self.WaitUntil(lambda: | 133 self.assertTrue(self.WaitUntil(lambda: |
133 self._IsEnabled('Shockwave Flash'))) | 134 self._IsEnabled(driver, 'Shockwave Flash'))) |
134 | 135 |
135 | 136 |
136 if __name__ == '__main__': | 137 if __name__ == '__main__': |
137 pyauto_functional.Main() | 138 pyauto_functional.Main() |
OLD | NEW |