Commit d4628ed8 authored by dyu@chromium.org's avatar dyu@chromium.org

Add prefs UI tests for Incognito exceptions for new Settings UI.

TEST=none
BUG=none
Review URL: https://chromiumcodereview.appspot.com/9467013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124962 0039d316-1c4b-4281-b951-d872f2087c98
parent fa0c3f29
...@@ -42,22 +42,26 @@ class PrefsUITest(pyauto.PyUITest): ...@@ -42,22 +42,26 @@ class PrefsUITest(pyauto.PyUITest):
behavior_key)) behavior_key))
return behaviors_dict[behavior_key] return behaviors_dict[behavior_key]
def _VerifyContentExceptionUI(self, content_type, hostname_pattern, behavior): def _VerifyContentExceptionUI(self, content_type, hostname_pattern, behavior,
incognito=False):
"""Find hostname pattern and behavior within UI on content exceptions page. """Find hostname pattern and behavior within UI on content exceptions page.
Args: Args:
content_type: The string content settings type to manage. content_type: The string content settings type to manage.
hostname_pattern: The URL or pattern associated with the behavior. hostname_pattern: The URL or pattern associated with the behavior.
behavior: The exception to allow or block the hostname. behavior: The exception to allow or block the hostname.
incognito: Incognito list displayed on exceptions settings page.
Default to False.
""" """
page = settings.ManageExceptionsPage.FromNavigation( page = settings.ManageExceptionsPage.FromNavigation(
self._driver, content_type) self._driver, content_type)
self.assertTrue(page.GetExceptions().has_key(hostname_pattern), self.assertTrue(page.GetExceptions(incognito).has_key(hostname_pattern),
msg=('No displayed host name matches pattern "%s"' msg=('No displayed host name matches pattern "%s"'
% hostname_pattern)) % hostname_pattern))
self.assertEqual(behavior, page.GetExceptions()[hostname_pattern], self.assertEqual(behavior, page.GetExceptions(incognito)[hostname_pattern],
msg=('Displayed behavior "%s" does not match behavior "%s"' msg=('Displayed behavior "%s" does not match behavior "%s"'
% (page.GetExceptions()[hostname_pattern], behavior))) % (page.GetExceptions(incognito)[hostname_pattern],
behavior)))
def testLocationSettingOptionsUI(self): def testLocationSettingOptionsUI(self):
"""Verify the location options setting UI. """Verify the location options setting UI.
...@@ -165,6 +169,32 @@ class PrefsUITest(pyauto.PyUITest): ...@@ -165,6 +169,32 @@ class PrefsUITest(pyauto.PyUITest):
self._driver, ContentTypes.GEOLOCATION) self._driver, ContentTypes.GEOLOCATION)
self.assertEqual(0, len(page.GetExceptions())) self.assertEqual(0, len(page.GetExceptions()))
def testCorrectCookiesSessionInUI(self):
"""Verify exceptions for cookies in UI list entry."""
# Block cookies for for a session for google.com.
self.SetPrefs(pyauto.kContentSettingsPatternPairs,
{'http://google.com:80': {'cookies': 2}})
self._VerifyContentExceptionUI(
ContentTypes.COOKIES, 'http://google.com:80', Behaviors.BLOCK)
def testInitialLineEntryInIncognitoUI(self):
"""Verify initial line entry is displayed in Incognito UI."""
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) # Display incognito list.
page = settings.ManageExceptionsPage.FromNavigation(
self._driver, ContentTypes.PLUGINS)
self.assertEqual(1, len(page.GetExceptions(incognito=True)))
def testIncognitoExceptionsEntryCorrectlyDisplayed(self):
"""Verify exceptions entry is correctly displayed in the incognito UI."""
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) # Display incognito list.
page = settings.ManageExceptionsPage.FromNavigation(
self._driver, ContentTypes.PLUGINS)
pattern, behavior = ('http://maps.google.com:80', Behaviors.BLOCK)
page.AddNewException(pattern, behavior, incognito=True)
self._VerifyContentExceptionUI(
ContentTypes.PLUGINS, 'http://maps.google.com:80',
Behaviors.BLOCK, incognito=True)
if __name__ == '__main__': if __name__ == '__main__':
pyauto_functional.Main() pyauto_functional.Main()
...@@ -323,35 +323,63 @@ class ManageExceptionsPage(object): ...@@ -323,35 +323,63 @@ class ManageExceptionsPage(object):
content_url = 'chrome://settings/contentExceptions#%s' % content_type content_url = 'chrome://settings/contentExceptions#%s' % content_type
assert content_url == driver.current_url assert content_url == driver.current_url
self._list_elem = driver.find_element_by_xpath( self._list_elem = driver.find_element_by_xpath(
'.//*[@id="content-settings-exceptions-area"]' \ './/*[@id="content-settings-exceptions-area"]'
'//*[@contenttype="%s"]//list[@role="listbox"]' \ '//*[@contenttype="%s"]//list[@role="listbox"]'
'[@class="settings-list"]' % content_type) '[@class="settings-list"]' % content_type)
self._driver = driver self._driver = driver
self._content_type = content_type self._content_type = content_type
try:
self._incognito_list_elem = driver.find_element_by_xpath(
'.//*[@id="content-settings-exceptions-area"]'
'//*[@contenttype="%s"]//div[not(@hidden)]'
'//list[@mode="otr"][@role="listbox"]'
'[@class="settings-list"]' % content_type)
except selenium.common.exceptions.NoSuchElementException:
self._incognito_list_elem = None
def _GetExceptionList(self): def _AssertIncognitoAvailable(self):
return DynamicList(self._driver, self._list_elem) if not self._incognito_list_elem:
raise AssertionError(
'Incognito settings in "%s" content page not available'
% self._content_type)
def _GetPatternList(self): def _GetExceptionList(self, incognito):
if not incognito:
list_elem = self._list_elem
else:
list_elem = self._incognito_list_elem
return DynamicList(self._driver, list_elem)
def _GetPatternList(self, incognito):
if not incognito:
list_elem = self._list_elem
else:
list_elem = self._incognito_list_elem
pattern_list = [p.text for p in pattern_list = [p.text for p in
self._list_elem.find_elements_by_xpath( list_elem.find_elements_by_xpath(
'.//*[contains(@class, "exception-pattern")]' './/*[contains(@class, "exception-pattern")]'
'//*[@class="static-text"]')] '//*[@class="static-text"]')]
return pattern_list return pattern_list
def AddNewException(self, pattern, behavior): def AddNewException(self, pattern, behavior, incognito=False):
"""Add a new pattern and behavior to the Exceptions page. """Add a new pattern and behavior to the Exceptions page.
Args: Args:
pattern: Hostname pattern string. pattern: Hostname pattern string.
behavior: Setting for the hostname pattern (Allow, Block, Session Only). behavior: Setting for the hostname pattern (Allow, Block, Session Only).
incognito: Incognito list box. Display to false.
Raises: Raises:
AssertionError when an exception cannot be added on the content page. AssertionError when an exception cannot be added on the content page.
""" """
if incognito:
self._AssertIncognitoAvailable()
list_elem = self._incognito_list_elem
else:
list_elem = self._list_elem
# Select behavior first. # Select behavior first.
try: try:
self._list_elem.find_element_by_xpath( list_elem.find_element_by_xpath(
'.//*[@class="exception-setting"]' './/*[@class="exception-setting"]'
'[not(@displaymode)]//option[@value="%s"]' '[not(@displaymode)]//option[@value="%s"]'
% behavior).click() % behavior).click()
...@@ -360,51 +388,71 @@ class ManageExceptionsPage(object): ...@@ -360,51 +388,71 @@ class ManageExceptionsPage(object):
'Adding new exception not allowed in "%s" content page' 'Adding new exception not allowed in "%s" content page'
% self._content_type) % self._content_type)
# Set pattern now. # Set pattern now.
self._GetExceptionList().Add(pattern) self._GetExceptionList(incognito).Add(pattern)
def DeleteException(self, pattern): def DeleteException(self, pattern, incognito=False):
"""Delete the exception for the selected hostname pattern. """Delete the exception for the selected hostname pattern.
Args: Args:
pattern: Hostname pattern string. pattern: Hostname pattern string.
incognito: Incognito list box. Default to false.
""" """
self._GetExceptionList().Remove(pattern) if incognito:
self._AssertIncognitoAvailable()
self._GetExceptionList(incognito).Remove(pattern)
def GetExceptions(self): def GetExceptions(self, incognito=False):
"""Returns a dictionary of {pattern: behavior}. """Returns a dictionary of {pattern: behavior}.
Example: {'file:///*': 'block'} Example: {'file:///*': 'block'}
Args:
incognito: Incognito list box. Default to false.
""" """
pattern_list = self._GetPatternList() if incognito:
behavior_list = self._list_elem.find_elements_by_xpath( self._AssertIncognitoAvailable()
'.//*[@role="listitem"][@class="deletable-item"]' \ list_elem = self._incognito_list_elem
else:
list_elem = self._list_elem
pattern_list = self._GetPatternList(incognito)
behavior_list = list_elem.find_elements_by_xpath(
'.//*[@role="listitem"][@class="deletable-item"]'
'//*[@class="exception-setting"][@displaymode="static"]') '//*[@class="exception-setting"][@displaymode="static"]')
assert len(pattern_list) == len(behavior_list), \ assert (len(pattern_list) == len(behavior_list),
'Number of patterns does not match the behaviors.' 'Number of patterns does not match the behaviors.')
return dict(zip(pattern_list, [b.text.lower() for b in behavior_list])) return dict(zip(pattern_list, [b.text.lower() for b in behavior_list]))
def GetBehaviorForPattern(self, pattern): def GetBehaviorForPattern(self, pattern, incognito=False):
"""Returns the behavior for a given pattern on the Exceptions page. """Returns the behavior for a given pattern on the Exceptions page.
Args: Args:
pattern: Hostname pattern string. pattern: Hostname pattern string.
""" incognito: Incognito list box. Default to false.
assert self.GetExceptions().has_key(pattern), \ """
'No displayed host name matches pattern "%s"' % pattern if incognito:
return self.GetExceptions()[pattern] self._AssertIncognitoAvailable()
assert (self.GetExceptions(incognito).has_key(pattern),
def SetBehaviorForPattern(self, pattern, behavior): 'No displayed host name matches pattern "%s"' % pattern)
return self.GetExceptions(incognito)[pattern]
def SetBehaviorForPattern(self, pattern, behavior, incognito=False):
"""Set the behavior for the selected pattern on the Exceptions page. """Set the behavior for the selected pattern on the Exceptions page.
Args: Args:
pattern: Hostname pattern string. pattern: Hostname pattern string.
behavior: Setting for the hostname pattern (Allow, Block, Session Only). behavior: Setting for the hostname pattern (Allow, Block, Session Only).
incognito: Incognito list box. Default to false.
Raises: Raises:
AssertionError when the behavior cannot be changed on the content page. AssertionError when the behavior cannot be changed on the content page.
""" """
pattern_list = self._GetPatternList() if incognito:
listitem_list = self._list_elem.find_elements_by_xpath( self._AssertIncognitoAvailable()
list_elem = self._incognito_list_elem
else:
list_elem = self._list_elem
pattern_list = self._GetPatternList(incognito)
listitem_list = list_elem.find_elements_by_xpath(
'.//*[@role="listitem"][@class="deletable-item"]') './/*[@role="listitem"][@class="deletable-item"]')
pattern_listitem_dict = dict(zip(pattern_list, listitem_list)) pattern_listitem_dict = dict(zip(pattern_list, listitem_list))
# Set focus to appropriate listitem. # Set focus to appropriate listitem.
......
...@@ -1294,7 +1294,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -1294,7 +1294,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
self._SendJSONRequest(-1, json.dumps(cmd_dict), self._SendJSONRequest(-1, json.dumps(cmd_dict),
self.action_max_timeout_ms())) self.action_max_timeout_ms()))
def SetPrefs(self, path, value): def SetPrefs(self, path, value, windex=0):
"""Set preference for the given path. """Set preference for the given path.
Preferences are stored by Chromium as a hierarchical dictionary. Preferences are stored by Chromium as a hierarchical dictionary.
...@@ -1315,10 +1315,11 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -1315,10 +1315,11 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
The user has to ensure that the right value is specified for the The user has to ensure that the right value is specified for the
right key. It's useful to dump the preferences first to determine right key. It's useful to dump the preferences first to determine
what type is expected for a particular preference path. what type is expected for a particular preference path.
windex: window index to work on. Defaults to 0 (first window).
""" """
cmd_dict = { cmd_dict = {
'command': 'SetPrefs', 'command': 'SetPrefs',
'windex': 0, 'windex': windex,
'path': path, 'path': path,
'value': value, 'value': value,
} }
...@@ -5037,6 +5038,7 @@ class Main(object): ...@@ -5037,6 +5038,7 @@ class Main(object):
sys.exit(0) sys.exit(0)
pyauto_suite = PyUITestSuite(suite_args) pyauto_suite = PyUITestSuite(suite_args)
loaded_tests = unittest.defaultTestLoader.loadTestsFromNames(test_names) loaded_tests = unittest.defaultTestLoader.loadTestsFromNames(test_names)
pyauto_suite = PyUITestSuite(suite_args)
pyauto_suite.addTests(loaded_tests) pyauto_suite.addTests(loaded_tests)
verbosity = 1 verbosity = 1
if self._options.verbose: if self._options.verbose:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment