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) |
| 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 pattern, behavior = ('http://maps.google.com:80', Behaviors.BLOCK) |
| 193 page.AddNewException(pattern, behavior, incognito=True) |
| 194 self._VerifyContentExceptionUI( |
| 195 ContentTypes.PLUGINS, 'http://maps.google.com:80', |
| 196 Behaviors.BLOCK, incognito=True) |
| 197 |
168 | 198 |
169 if __name__ == '__main__': | 199 if __name__ == '__main__': |
170 pyauto_functional.Main() | 200 pyauto_functional.Main() |
OLD | NEW |