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 pyauto_functional # Must be imported before pyauto | 6 import pyauto_functional # Must be imported before pyauto |
7 import pyauto | 7 import pyauto |
8 from webdriver_pages import settings | 8 from webdriver_pages import settings |
9 from webdriver_pages.settings import Behaviors, ContentTypes | 9 from webdriver_pages.settings import Behaviors, ContentTypes |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 """ | 35 """ |
36 behavior_key = self.GetPrefsInfo().Prefs( | 36 behavior_key = self.GetPrefsInfo().Prefs( |
37 pyauto.kGeolocationDefaultContentSetting) | 37 pyauto.kGeolocationDefaultContentSetting) |
38 behaviors_dict = {1: 'ALLOW', 2: 'BLOCK', 3: 'ASK'} | 38 behaviors_dict = {1: 'ALLOW', 2: 'BLOCK', 3: 'ASK'} |
39 self.assertTrue( | 39 self.assertTrue( |
40 behavior_key in behaviors_dict, | 40 behavior_key in behaviors_dict, |
41 msg=('Invalid default behavior key "%s" for "geolocation" content' % | 41 msg=('Invalid default behavior key "%s" for "geolocation" content' % |
42 behavior_key)) | 42 behavior_key)) |
43 return behaviors_dict[behavior_key] | 43 return behaviors_dict[behavior_key] |
44 | 44 |
45 def _VerifyContentExceptionUI(self, content_type, hostname_pattern, behavior): | 45 def _VerifyContentExceptionUI(self, content_type, hostname_pattern, behavior, |
46 incognito=False): | |
46 """Find hostname pattern and behavior within UI on content exceptions page. | 47 """Find hostname pattern and behavior within UI on content exceptions page. |
47 | 48 |
48 Args: | 49 Args: |
49 content_type: The string content settings type to manage. | 50 content_type: The string content settings type to manage. |
50 hostname_pattern: The URL or pattern associated with the behavior. | 51 hostname_pattern: The URL or pattern associated with the behavior. |
51 behavior: The exception to allow or block the hostname. | 52 behavior: The exception to allow or block the hostname. |
53 incognito: Incognito list displayed on exceptions settings page. | |
54 Default to False. | |
52 """ | 55 """ |
53 page = settings.ManageExceptionsPage.FromNavigation( | 56 page = settings.ManageExceptionsPage.FromNavigation( |
54 self._driver, content_type) | 57 self._driver, content_type) |
55 self.assertTrue(page.GetExceptions().has_key(hostname_pattern), | 58 self.assertTrue(page.GetExceptions(incognito).has_key(hostname_pattern), |
56 msg=('No displayed host name matches pattern "%s"' | 59 msg=('No displayed host name matches pattern "%s"' |
57 % hostname_pattern)) | 60 % hostname_pattern)) |
58 self.assertEqual(behavior, page.GetExceptions()[hostname_pattern], | 61 self.assertEqual(behavior, page.GetExceptions(incognito)[hostname_pattern], |
59 msg=('Displayed behavior "%s" does not match behavior "%s"' | 62 msg=('Displayed behavior "%s" does not match behavior "%s"' |
60 % (page.GetExceptions()[hostname_pattern], behavior))) | 63 % (page.GetExceptions(incognito)[hostname_pattern], |
64 behavior))) | |
61 | 65 |
62 def testLocationSettingOptionsUI(self): | 66 def testLocationSettingOptionsUI(self): |
63 """Verify the location options setting UI. | 67 """Verify the location options setting UI. |
64 | 68 |
65 Set the options through the UI using webdriver and verify the settings in | 69 Set the options through the UI using webdriver and verify the settings in |
66 pyAuto. | 70 pyAuto. |
67 """ | 71 """ |
68 page = settings.ContentSettingsPage.FromNavigation(self._driver) | 72 page = settings.ContentSettingsPage.FromNavigation(self._driver) |
69 page.SetContentTypeOption(ContentTypes.GEOLOCATION, Behaviors.ALLOW) | 73 page.SetContentTypeOption(ContentTypes.GEOLOCATION, Behaviors.ALLOW) |
70 self.assertEqual( | 74 self.assertEqual( |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 def testNoInitialLineEntryInUI(self): | 162 def testNoInitialLineEntryInUI(self): |
159 """Verify no initial line entry is displayed in UI.""" | 163 """Verify no initial line entry is displayed in UI.""" |
160 # Ask for permission when site wants to track. | 164 # Ask for permission when site wants to track. |
161 self.SetPrefs(pyauto.kGeolocationDefaultContentSetting, 3) | 165 self.SetPrefs(pyauto.kGeolocationDefaultContentSetting, 3) |
162 self.assertEqual( | 166 self.assertEqual( |
163 3, self.GetPrefsInfo().Prefs(pyauto.kGeolocationDefaultContentSetting)) | 167 3, self.GetPrefsInfo().Prefs(pyauto.kGeolocationDefaultContentSetting)) |
164 page = settings.ManageExceptionsPage.FromNavigation( | 168 page = settings.ManageExceptionsPage.FromNavigation( |
165 self._driver, ContentTypes.GEOLOCATION) | 169 self._driver, ContentTypes.GEOLOCATION) |
166 self.assertEqual(0, len(page.GetExceptions())) | 170 self.assertEqual(0, len(page.GetExceptions())) |
167 | 171 |
172 def testCorrectCookiesSessionInUI(self): | |
173 """Verify exceptions for cookies in UI list entry.""" | |
174 # Block cookies for for a session for google.com. | |
175 self.SetPrefs(pyauto.kContentSettingsPatternPairs, | |
176 {'http://google.com:80': {'cookies': 2}}) | |
177 self._VerifyContentExceptionUI( | |
178 ContentTypes.COOKIES, 'http://google.com:80', Behaviors.BLOCK) | |
179 | |
180 def testInitialLineEntryInIncognitoUI(self): | |
181 """Verify initial line entry is displayed in Incognito UI.""" | |
182 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) # Display incognito list. | |
183 page = settings.ManageExceptionsPage.FromNavigation( | |
184 self._driver, ContentTypes.PLUGINS) | |
kkania
2012/03/03 02:02:27
bad indentation and several places below
dyu1
2012/03/03 02:16:45
Done.
| |
185 self.assertEqual(1, len(page.GetExceptions(incognito=True))) | |
186 | |
187 def testIncognitoExceptionsEntryCorrectlyDisplayed(self): | |
188 """Verify exceptions entry is correctly displayed in the incognito UI.""" | |
189 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) # Display incognito list. | |
190 page = settings.ManageExceptionsPage.FromNavigation( | |
191 self._driver, ContentTypes.PLUGINS) | |
192 plugins_exception = { | |
193 'pattern': 'http://maps.google.com:80', 'behavior': Behaviors.BLOCK, | |
194 'incognito': True} | |
195 page.AddNewException(**plugins_exception) | |
kkania
2012/03/03 02:02:27
this is pretty fancy, but can you just do it the n
dyu1
2012/03/03 02:16:45
Done.
| |
196 self._VerifyContentExceptionUI( | |
197 ContentTypes.PLUGINS, 'http://maps.google.com:80', | |
198 Behaviors.BLOCK, incognito=True) | |
199 | |
200 def testCorrectBehaviorSetInIncognitoUI(self): | |
kkania
2012/03/03 02:02:27
remove?
dyu1
2012/03/03 02:16:45
Removing since SetPrefs() function doesn't offer t
| |
201 """Verify behavior is correctly set for initial Incognito list entry.""" | |
202 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) # Display incognito list. | |
203 # Ask for permission when site wants to track (Click to play). | |
204 self.SetPrefs(pyauto.kDefaultContentSettings, {'plugins': 3}, windex=1) | |
205 self._VerifyContentExceptionUI( | |
206 ContentTypes.PLUGINS, '*', Behaviors.ASK, incognito=True) | |
207 # Block all sites. | |
208 self.SetPrefs(pyauto.kDefaultContentSettings, {'plugins': 2}, windex=1) | |
209 self._VerifyContentExceptionUI( | |
210 ContentTypes.PLUGINS, '*', Behaviors.BLOCK, incognito=True) | |
211 # Allow all sites. | |
212 self.SetPrefs(pyauto.kDefaultContentSettings, {'plugins': 1}, windex=1) | |
213 self._VerifyContentExceptionUI( | |
214 ContentTypes.PLUGINS, '*', Behaviors.ALLOW, incognito=True) | |
215 | |
168 | 216 |
169 if __name__ == '__main__': | 217 if __name__ == '__main__': |
170 pyauto_functional.Main() | 218 pyauto_functional.Main() |
OLD | NEW |