blob: 76b552501757211b1896e6d59371e675223684a1 [file] [log] [blame]
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros.enterprise import enterprise_policy_base
class policy_CookiesAllowedForUrls(enterprise_policy_base.EnterprisePolicyTest):
"""Test effect of the CookiesAllowedForUrls policy on Chrome OS behavior.
This test implicitly verifies one value of the DefaultCookiesSetting
policy as well. When the DefaultCookiesSetting policy value is set to 2,
cookies for all URLs shall not be stored (ie, shall be blocked), except
for the URL patterns specified by the CookiesAllowedForUrls policy.
The test verifies ChromeOS behaviour for different values of the
CookiesAllowedForUrls policy, i.e., for the policy value set to Not Set,
set to a single url/host pattern, or when the policy is set to multiple
url/host patterns. It also verifies that cookies are blocked for urls that
are not part of the policy value.
The corresponding three test cases are NotSet_CookiesBlocked,
SingleUrl_CookiesAllowed, MultipleUrls_CookiesAllowed, and
version = 1
def initialize(self, **kwargs):
"""Initialize this test."""
super(policy_CookiesAllowedForUrls, self).initialize(**kwargs)
def _initialize_test_constants(self):
"""Initialize test-specific constants, some from class constants."""
self.POLICY_NAME = 'CookiesAllowedForUrls'
self.COOKIE_NAME = 'cookie1'
self.TEST_FILE = 'cookie_status.html'
self.TEST_URL = '%s/%s' % (self.WEB_HOST, self.TEST_FILE)
self.COOKIE_BLOCKED_MULTIPLE_FILES = ['https://testingwebsite.html',
self.TEST_CASES = {
'NotSet_Block': None,
self.SUPPORTING_POLICIES = {'DefaultCookiesSetting': 2}
def _is_cookie_blocked(self, url):
"""Return True if cookie is blocked for the URL else return False.
@param url: Url of the page which is loaded to check whether it's
cookie is blocked or stored.
tab = self.navigate_to_url(url)
return tab.GetCookieByName(self.COOKIE_NAME) is None
def _test_cookies_allowed_for_urls(self, policy_value):
"""Verify CrOS enforces CookiesAllowedForUrls policy value.
When the CookiesAllowedForUrls policy is set to one or more urls/hosts,
check that cookies are not blocked for the urls/urlpatterns listed in
the policy value. When set to None, check that cookies are blocked for
all URLs.
@param policy_value: policy value for this case.
@raises: TestFail if cookies are blocked/not blocked based on the
corresponding policy values.
cookie_is_blocked = self._is_cookie_blocked(self.TEST_URL)
if policy_value and self.WEB_HOST in policy_value:
if cookie_is_blocked:
raise error.TestFail('Cookies should be allowed.')
if not cookie_is_blocked:
raise error.TestFail('Cookies should be blocked.')
def run_once(self, case):
"""Setup and run the test configured for the specified test case.
Set the expected |policy_value| and |policies_dict| data defined for
the specified test |case|, and run the test.
@param case: Name of the test case to run.
case_value = self.TEST_CASES[case]