Update early policy_* tests to use class methods.
Many of the early policy_* tests had their own internal methods for
cleanup, run_once, run_test_case, and _get_policy_data_for_case.
These methods are now available in the class. Update the tests to
use the class methods.
policy_CookiesAllowedForUrls
policy_CookiesBlockedForUrls
policy_EditBookmarksEnabled
policy_ImagesAllowedForUrls
policy_ImagesBlockedForUrls
policy_JavaScriptAllowedForUrls
policy_JavaScriptBlockedForUrls
policy_ManagedBookmarks
policy_PopupsAllowedForUrls
policy_PopupsBlockedForUrls
policy_ProxySettings
policy_RestoreOnStartupURLs
policy_URLBlacklist
policy_URLWhitelist
BUG=chromium:616960
TEST=Run test_that <IP> <test> for each policy_* test.
Change-Id: I98aa0727a6594891def20444dfae694974e8df64
Reviewed-on: https://chromium-review.googlesource.com/349671
Commit-Ready: Scott Cunningham <scunningham@chromium.org>
Tested-by: Scott Cunningham <scunningham@chromium.org>
Reviewed-by: Scott Cunningham <scunningham@chromium.org>
Reviewed-by: Krishna Gavini <krishnargv@chromium.org>
diff --git a/client/site_tests/policy_CookiesAllowedForUrls/policy_CookiesAllowedForUrls.py b/client/site_tests/policy_CookiesAllowedForUrls/policy_CookiesAllowedForUrls.py
index 70f650a..f053834 100644
--- a/client/site_tests/policy_CookiesAllowedForUrls/policy_CookiesAllowedForUrls.py
+++ b/client/site_tests/policy_CookiesAllowedForUrls/policy_CookiesAllowedForUrls.py
@@ -11,22 +11,6 @@
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
-POLICY_NAME = 'CookiesAllowedForUrls'
-URL_BASE = 'http://localhost'
-URL_PORT = 8080
-URL_HOST = '%s:%d'%(URL_BASE, URL_PORT)
-URL_RESOURCE = '/test_data/testWebsite1.html'
-TEST_URL = URL_HOST + URL_RESOURCE
-COOKIE_NAME = 'cookie1'
-COOKIE_ALLOWED_SINGLE_FILE_DATA = [URL_HOST]
-COOKIE_ALLOWED_MULTIPLE_FILES_DATA = ['http://google.com', URL_HOST,
- 'http://doesnotmatter.com']
-COOKIE_BLOCKED_MULTIPLE_FILES_DATA = ['https://testingwebsite.html',
- 'https://somewebsite.com',
- 'http://doesnotmatter.com']
-# Setting DefaultCookiesSetting=2 blocks cookies on all sites.
-SUPPORTING_POLICIES = {'DefaultCookiesSetting': 2}
-
class policy_CookiesAllowedForUrls(enterprise_policy_base.EnterprisePolicyTest):
"""Test effect of the CookiesAllowedForUrls policy on Chrome OS behavior.
@@ -37,18 +21,32 @@
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 excercises an additional scenario i.e., it
- tests that cookies are blocked for urls that are not part of the policy
- value.
+ 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
- and MultipleUrls_CookiesBlocked.
+ MultipleUrls_CookiesBlocked.
"""
version = 1
+
+ POLICY_NAME = 'CookiesAllowedForUrls'
+ URL_BASE = 'http://localhost'
+ URL_PORT = 8080
+ URL_HOST = '%s:%d'%(URL_BASE, URL_PORT)
+ URL_RESOURCE = '/test_data/testWebsite1.html'
+ TEST_URL = URL_HOST + URL_RESOURCE
+ COOKIE_NAME = 'cookie1'
+ COOKIE_ALLOWED_SINGLE_FILE_DATA = [URL_HOST]
+ COOKIE_ALLOWED_MULTIPLE_FILES_DATA = ['http://google.com', URL_HOST,
+ 'http://doesnotmatter.com']
+ COOKIE_BLOCKED_MULTIPLE_FILES_DATA = ['https://testingwebsite.html',
+ 'https://somewebsite.com',
+ 'http://doesnotmatter.com']
+
TEST_CASES = {
'NotSet_CookiesBlocked': '',
'SingleUrl_CookiesAllowed': COOKIE_ALLOWED_SINGLE_FILE_DATA,
@@ -56,9 +54,11 @@
'MultipleUrls_CookiesBlocked': COOKIE_BLOCKED_MULTIPLE_FILES_DATA
}
+ SUPPORTING_POLICIES = {'DefaultCookiesSetting': 2}
+
def initialize(self, args=()):
super(policy_CookiesAllowedForUrls, self).initialize(args)
- self.start_webserver(URL_PORT)
+ self.start_webserver(self.URL_PORT)
def _is_cookie_blocked(self, url):
"""Return True if cookie is blocked for the URL else return False.
@@ -68,9 +68,9 @@
"""
tab = self.navigate_to_url(url)
- return tab.GetCookieByName(COOKIE_NAME) is None
+ return tab.GetCookieByName(self.COOKIE_NAME) is None
- def _test_CookiesAllowedForUrls(self, policy_value, policies_json):
+ def _test_cookies_allowed_for_urls(self, policy_value, policies_dict):
"""Verify CrOS enforces CookiesAllowedForUrls policy value.
When the CookiesAllowedForUrls policy is set to one or more urls/hosts,
@@ -79,19 +79,18 @@
When set to None, check that cookies are blocked for all URLs.
@param policy_value: policy value expected on chrome://policy page.
- @param policies_json: policy JSON data to send to the fake DM server.
+ @param policies_dict: policy dict data to send to the fake DM server.
@raises: TestFail if cookies are blocked/not blocked based on the
corresponding policy values.
"""
- logging.info('Running _test_CookiesAllowedForUrls(%s, %s)',
- policy_value, policies_json)
- self.setup_case(POLICY_NAME, policy_value, policies_json)
+ logging.info('Running _test_cookies_allowed_for_urls(%s, %s)',
+ policy_value, policies_dict)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
- cookie_is_blocked = self._is_cookie_blocked(TEST_URL)
- logging.info('cookie_is_blocked = %s', cookie_is_blocked)
+ cookie_is_blocked = self._is_cookie_blocked(self.TEST_URL)
- if policy_value and URL_HOST in policy_value:
+ if policy_value and self.URL_HOST in policy_value:
if cookie_is_blocked:
raise error.TestFail('Cookies should be allowed.')
else:
@@ -101,29 +100,15 @@
def run_test_case(self, case):
"""Setup and run the test configured for the specified test case.
- Set the expected |policy_value| and |policies_json| data based on the
- test |case|. If the user specified an expected |value| in the command
- line args, then use it to set the |policy_value| and blank out the
- |policies_json|.
+ Set the expected |policy_value| and |policies_dict| data defined for
+ the specified test |case|, and run the test. If the user specified an
+ expected |value| in the command line args, then it will be used to set
+ the |policy_value|.
@param case: Name of the test case to run.
"""
- policy_value = None
- policies_json = None
-
- if self.is_value_given:
- # If |value| was given in the command line args, then set expected
- # |policy_value| to the given value, and |policies_json| to None.
- policy_value = self.value
- policies_json = None
- else:
- # Otherwise, set expected |policy_value| and setup |policies_json|
- # data to the values required by the specified test |case|.
- policy_value = ','.join(self.TEST_CASES[case])
- policy_json = {POLICY_NAME: self.TEST_CASES[case]}
- policies_json = SUPPORTING_POLICIES.copy()
- policies_json.update(policy_json)
+ policy_value, policies_dict = self._get_policy_data_for_case(case)
# Run test using the values configured for the test case.
- self._test_CookiesAllowedForUrls(policy_value, policies_json)
+ self._test_cookies_allowed_for_urls(policy_value, policies_dict)
diff --git a/client/site_tests/policy_CookiesBlockedForUrls/policy_CookiesBlockedForUrls.py b/client/site_tests/policy_CookiesBlockedForUrls/policy_CookiesBlockedForUrls.py
index 30b9f84..034bed5 100644
--- a/client/site_tests/policy_CookiesBlockedForUrls/policy_CookiesBlockedForUrls.py
+++ b/client/site_tests/policy_CookiesBlockedForUrls/policy_CookiesBlockedForUrls.py
@@ -11,67 +11,67 @@
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
-POLICY_NAME = 'CookiesBlockedForUrls'
-URL_BASE = 'http://localhost'
-URL_PORT = 8080
-URL_HOST = '%s:%d'%(URL_BASE, URL_PORT)
-URL_RESOURCE = '/test_data/testWebsite1.html'
-TEST_URL = URL_HOST + URL_RESOURCE
-COOKIE_NAME = 'cookie1'
-COOKIE_BLOCKED_SINGLE_FILE_DATA = [URL_HOST]
-COOKIE_BLOCKED_MULTIPLE_FILES_DATA = ['http://google.com', URL_HOST,
- 'http://doesnotmatter.com']
-COOKIE_ALLOWED_MULTIPLE_FILES_DATA = ['https://testingwebsite.html'
- 'https://somewebsite.com',
- 'http://doesnotmatter.com']
-#Setting the DefaultCookiesSetting to the value 1, allows cookies on all sites.
-SUPPORTING_POLICIES = {'DefaultCookiesSetting': 1}
-
class policy_CookiesBlockedForUrls(enterprise_policy_base.EnterprisePolicyTest):
- """
- Test effect of the CookiesBlockedForUrls policy on Chrome OS behavior.
+ """Test effect of the CookiesBlockedForUrls policy on Chrome OS behavior.
- This test implicitly verifies one of the settings of the
- DefaultCookiesSetting policy as well. When DefaultCookiesSetting is set to
- 1, cookies for all URLs shall be stored (i.e., shall be not blocked), except
- for the URL patterns specified by the CookiesBlockedForUrls policy value.
+ This test implicitly verifies one value of the DefaultCookiesSetting
+ policy as well. When DefaultCookiesSetting is set to 1, cookies for all
+ URLs shall be stored (i.e., shall be not blocked), except for the URL
+ patterns specified by the CookiesBlockedForUrls policy value.
+
The test verifies ChromeOS behaviour for different values of the
- CookiesBlockedForUrls policy eg, 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 excercises an additional scenario i.e., it tests that
- cookies are allowed for urls that are not part of the policy value. The
- corresponding three test cases are NotSet_CookiesAllowed,
+ CookiesBlockedForUrls 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 allowed for urls that
+ are not part of the policy value.
+
+ The corresponding three test cases are NotSet_CookiesAllowed,
SingleUrl_CookiesBlocked, MultipleUrls_CookiesBlocked and
- and MultipleUrls_CookiesAllowed.
+ MultipleUrls_CookiesAllowed.
"""
version = 1
+
+ POLICY_NAME = 'CookiesBlockedForUrls'
+ URL_BASE = 'http://localhost'
+ URL_PORT = 8080
+ URL_HOST = '%s:%d'%(URL_BASE, URL_PORT)
+ URL_RESOURCE = '/test_data/testWebsite1.html'
+ TEST_URL = URL_HOST + URL_RESOURCE
+ COOKIE_NAME = 'cookie1'
+ COOKIE_BLOCKED_SINGLE_FILE_DATA = [URL_HOST]
+ COOKIE_BLOCKED_MULTIPLE_FILES_DATA = ['http://google.com', URL_HOST,
+ 'http://doesnotmatter.com']
+ COOKIE_ALLOWED_MULTIPLE_FILES_DATA = ['https://testingwebsite.html'
+ 'https://somewebsite.com',
+ 'http://doesnotmatter.com']
+
TEST_CASES = {
- 'NotSet_CookiesAllowed': '',
- 'SingleUrl_CookiesBlocked': COOKIE_BLOCKED_SINGLE_FILE_DATA,
- 'MultipleUrls_CookiesBlocked': COOKIE_BLOCKED_MULTIPLE_FILES_DATA,
- 'MultipleUrls_CookiesAllowed' : COOKIE_ALLOWED_MULTIPLE_FILES_DATA
- }
+ 'NotSet_CookiesAllowed': '',
+ 'SingleUrl_CookiesBlocked': COOKIE_BLOCKED_SINGLE_FILE_DATA,
+ 'MultipleUrls_CookiesBlocked': COOKIE_BLOCKED_MULTIPLE_FILES_DATA,
+ 'MultipleUrls_CookiesAllowed' : COOKIE_ALLOWED_MULTIPLE_FILES_DATA
+ }
+
+ SUPPORTING_POLICIES = {'DefaultCookiesSetting': 1}
def initialize(self, args=()):
super(policy_CookiesBlockedForUrls, self).initialize(args)
- self.start_webserver(URL_PORT)
+ self.start_webserver(self.URL_PORT)
def _is_cookie_blocked(self, url):
- """
- Returns True if the cookie is blocked for the URL else returns False.
+ """Return True if the cookie is blocked for the URL else returns 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(COOKIE_NAME) is None
+ return tab.GetCookieByName(self.COOKIE_NAME) is None
- def _test_CookiesBlockedForUrls(self, policy_value, policies_json):
- """
- Verify CrOS enforces CookiesBlockedForUrls policy value.
+ def _test_cookies_blocked_for_urls(self, policy_value, policies_dict):
+ """Verify CrOS enforces CookiesBlockedForUrls policy value.
When the CookiesBlockedForUrls policy is set to one or more urls/hosts,
check that cookies are blocked for the urls/urlpatterns listed in
@@ -79,57 +79,36 @@
all URLs.
@param policy_value: policy value expected on chrome://policy page.
- @param policies_json: policy JSON data to send to the fake DM server.
+ @param policies_dict: policy dict data to send to the fake DM server.
@raises: TestFail if cookies are blocked/not blocked based on the
corresponding policy values.
"""
- logging.info('Running _test_CookiesBlockedForUrls(%s, %s)',
- policy_value, policies_json)
- self.setup_case(POLICY_NAME, policy_value, policies_json)
+ logging.info('Running _test_cookies_blocked_for_urls(%s, %s)',
+ policy_value, policies_dict)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
- cookie_is_blocked = self._is_cookie_blocked(TEST_URL)
+ cookie_is_blocked = self._is_cookie_blocked(self.TEST_URL)
- if policy_value and URL_HOST in policy_value:
+ if policy_value and self.URL_HOST in policy_value:
if not cookie_is_blocked:
raise error.TestFail('Cookies should be blocked.')
else:
if cookie_is_blocked:
raise error.TestFail('Cookies should be allowed.')
- def _run_test_case(self, case):
- """
- Setup and run the test configured for the specified test case.
+ def run_test_case(self, case):
+ """Setup and run the test configured for the specified test case.
- Set the expected |policy_value| and |policies_json| data based on the
- test |case|. If the user specified an expected |value| in the command
- line args, then use it to set the |policy_value| and blank out the
- |policies_json|.
+ Set the expected |policy_value| and |policies_dict| data defined for
+ the specified test |case|, and run the test. If the user specified an
+ expected |value| in the command line args, then it will be used to set
+ the |policy_value|.
@param case: Name of the test case to run.
"""
- policy_value = None
- policies_json = None
-
- if self.is_value_given:
- # If |value| was given in the command line args, then set expected
- # |policy_value| to the given value, and |policies_json| to None.
- policy_value = self.value
- policies_json = None
- else:
- # Otherwise, set expected |policy_value| and setup |policies_json|
- # data to the values required by the specified test |case|.
- policy_value = ','.join(self.TEST_CASES[case])
- policy_json = {'CookiesBlockedForUrls': self.TEST_CASES[case]}
- policies_json = SUPPORTING_POLICIES.copy()
- policies_json.update(policy_json)
+ policy_value, policies_dict = self._get_policy_data_for_case(case)
# Run test using the values configured for the test case.
- self._test_CookiesBlockedForUrls(policy_value, policies_json)
-
- def run_once(self):
- # The run_once() method is required by autotest. We call the base
- # class run_once_impl() method, which handles command-line run modes,
- # and pass in the standard _run_test_case() method of this test.
- self.run_once_impl(self._run_test_case)
+ self._test_cookies_blocked_for_urls(policy_value, policies_dict)
diff --git a/client/site_tests/policy_EditBookmarksEnabled/policy_EditBookmarksEnabled.py b/client/site_tests/policy_EditBookmarksEnabled/policy_EditBookmarksEnabled.py
index 3a61c0b..bf1e08b 100644
--- a/client/site_tests/policy_EditBookmarksEnabled/policy_EditBookmarksEnabled.py
+++ b/client/site_tests/policy_EditBookmarksEnabled/policy_EditBookmarksEnabled.py
@@ -2,8 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging
-import time
+import logging, time
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
@@ -87,14 +86,12 @@
@returns: True if add-new-bookmarks-command is disabled.
"""
- tab = self.cr.browser.tabs.New()
- tab.Navigate('chrome://bookmarks/#1')
- tab.WaitForDocumentReadyStateToBeComplete()
+ tab = self.navigate_to_url('chrome://bookmarks/#1')
# Wait until list.reload() is defined on bmm page.
tab.WaitForJavaScriptExpression(
"typeof bmm.list.reload == 'function'", 60)
- time.sleep(1) # Allow JS to run after function is defined.
+ time.sleep(1) # Allow JS to run after reload function is defined.
# Check if add-new-bookmark menu command has disabled property.
is_disabled = tab.EvaluateJavaScript(
diff --git a/client/site_tests/policy_ImagesAllowedForUrls/policy_ImagesAllowedForUrls.py b/client/site_tests/policy_ImagesAllowedForUrls/policy_ImagesAllowedForUrls.py
index ae5d1af..66e0637 100644
--- a/client/site_tests/policy_ImagesAllowedForUrls/policy_ImagesAllowedForUrls.py
+++ b/client/site_tests/policy_ImagesAllowedForUrls/policy_ImagesAllowedForUrls.py
@@ -2,8 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging
-import utils
+import logging, utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
@@ -85,9 +84,9 @@
"""Verify CrOS enforces the ImagesAllowedForUrls policy.
When ImagesAllowedForUrls is undefined, images shall be blocked on
- all pages. When ImagesAllowedForUrls contains one or more domains,
- images shall be shown only on the pages whose domain matches any of
- the listed domains.
+ all pages. When ImagesAllowedForUrls contains one or more URLs, images
+ shall be shown only on the pages whose domain matches any of the
+ listed domains.
@param policy_value: policy value expected on chrome://policy page.
@param policies_dict: policy dict data to send to the fake DM server.
@@ -116,7 +115,9 @@
"""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.
+ the specified test |case|, and run the test. If the user specified an
+ expected |value| in the command line args, then it will be used to set
+ the |policy_value|.
@param case: Name of the test case to run.
diff --git a/client/site_tests/policy_ImagesBlockedForUrls/policy_ImagesBlockedForUrls.py b/client/site_tests/policy_ImagesBlockedForUrls/policy_ImagesBlockedForUrls.py
index d78f562..1ab2583 100644
--- a/client/site_tests/policy_ImagesBlockedForUrls/policy_ImagesBlockedForUrls.py
+++ b/client/site_tests/policy_ImagesBlockedForUrls/policy_ImagesBlockedForUrls.py
@@ -2,8 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging
-import utils
+import logging, utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
@@ -84,9 +83,9 @@
def _test_images_blocked_for_urls(self, policy_value, policies_dict):
"""Verify CrOS enforces the ImagesBlockedForUrls policy.
- When ImagesBlockedForUrls is undefined, images shall not be blocked on
- any page. When ImagesBlockedForUrls contains one or more URLs, images
- are blocked on any page whose domain matches any of the listed
+ When ImagesBlockedForUrls is undefined, images shall be allowed on
+ all pages. When ImagesBlockedForUrls contains one or more URLs, images
+ shall be blocked on any page whose domain matches any of the listed
domains.
@param policy_value: policy value expected on chrome://policy page.
@@ -116,7 +115,9 @@
"""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.
+ the specified test |case|, and run the test. If the user specified an
+ expected |value| in the command line args, then it will be used to set
+ the |policy_value|.
@param case: Name of the test case to run.
diff --git a/client/site_tests/policy_JavaScriptAllowedForUrls/control b/client/site_tests/policy_JavaScriptAllowedForUrls/control
index bd0a09d..5b465a9 100644
--- a/client/site_tests/policy_JavaScriptAllowedForUrls/control
+++ b/client/site_tests/policy_JavaScriptAllowedForUrls/control
@@ -15,10 +15,9 @@
This test verifies the effect of the JavaScriptAllowedForUrls user policy on
Chrome OS client behavior when the DefaultJavaScriptSetting user policy is set
-to 2. It exercises a range of policy values using four unique test cases,
-named: NotSet_BlockJS, SingleUrl_AllowJS, MultipleUrls_BlockJS, and
-MultipleUrls_AllowJS. See the test file for a full description of what each
-test case does.
+to 2. It exercises a range of policy values using four unique test cases:
+NotSet_Block, SingleUrl_Allow, MultipleUrls_Block, and MultipleUrls_Allow.
+See the test file for a full description of what each test case does.
In general, a test shall pass if the browser allows JavaScript to execute only
on a test page with a URL that matches one or more of the URL patterns listed
@@ -26,15 +25,6 @@
on a page where it should be allowed, or allows execution on a page where it
should be blocked.
-Usage example:
-$ test_that <IPAddress> JavaScriptAllowedForUrls --args="mode=single
-case=SingleUrl_AllowJS env=dm-test dms_name=xot-dmst
-username=test@crosprqa4.com password=test0000"
-
-Runs a single test case (e.g., SingleUrl_AllowJS) against a device with the
-specified IP address, using the DM Test environment with the given DM Server
-name, and signing in to the device with the given username and password.
-
"""
job.run_test("policy_JavaScriptAllowedForUrls", args=args)
diff --git a/client/site_tests/policy_JavaScriptAllowedForUrls/policy_JavaScriptAllowedForUrls.py b/client/site_tests/policy_JavaScriptAllowedForUrls/policy_JavaScriptAllowedForUrls.py
index 0ae4deb..aeff529 100644
--- a/client/site_tests/policy_JavaScriptAllowedForUrls/policy_JavaScriptAllowedForUrls.py
+++ b/client/site_tests/policy_JavaScriptAllowedForUrls/policy_JavaScriptAllowedForUrls.py
@@ -2,9 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging
-import time
-import utils
+import logging, time, utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
@@ -16,19 +14,19 @@
This test verifies the behavior of Chrome OS with a range of valid values
for the JavaScriptAllowedForUrls user policies. These values are covered
- by four test cases, named: NotSet_BlockJS, SingleUrl_AllowJS,
- MultipleUrls_BlockJS, and MultipleUrls_AllowJS.
+ by four test cases, named: NotSet_Block, SingleUrl_Allow,
+ MultipleUrls_Block, and MultipleUrls_Allow.
- When the policy value is None (as in case=NotSet_BlockJS), then
+ When the policy value is None (as in case=NotSet_Block), then
JavaScript will be blocked on any page. When the value is set to a single
- URL pattern (as in case=SingleUrl_AllowJS), JavaScript will be allowed on
+ URL pattern (as in case=SingleUrl_Allow), JavaScript will be allowed on
any page that matches that pattern. When set to multiple URL patterns (as
- in case=MultipleUrls_BlockJS or MultipleUrls_AllowJS) then JavaScript will
+ in case=MultipleUrls_Block or MultipleUrls_Allow) then JavaScript will
be allowed on any page with a URL that matches any of the listed patterns.
- Two test cases (SingleUrl_AllowJS, MultipleUrls_AllowJS) are designed to
- allow JavaScript to run on the test page. The other two test cases
- (NotSet_BlockJS, MultipleUrls_BlockJS) are designed to block JavaScript
+ Two test cases (SingleUrl_Allow, MultipleUrls_Allow) are designed to allow
+ JavaScript to run on the test page. The other two test cases
+ (NotSet_Block, MultipleUrls_Block) are designed to block JavaScript
from running on the test page.
Note this test has a dependency on the DefaultJavaScriptSetting policy,
@@ -51,13 +49,13 @@
TEST_URL = URL_BASE + URL_PAGE
TEST_CASES = {
- 'NotSet_BlockJS': None,
- 'SingleUrl_AllowJS': [URL_BASE],
- 'MultipleUrls_BlockJS': ['http://www.bing.com',
- 'https://www.yahoo.com'],
- 'MultipleUrls_AllowJS': ['http://www.bing.com',
- TEST_URL,
- 'https://www.yahoo.com']
+ 'NotSet_Block': None,
+ 'SingleUrl_Allow': [URL_BASE],
+ 'MultipleUrls_Block': ['http://www.bing.com',
+ 'https://www.yahoo.com'],
+ 'MultipleUrls_Allow': ['http://www.bing.com',
+ TEST_URL,
+ 'https://www.yahoo.com']
}
STARTUP_URLS = ['chrome://policy', 'chrome://settings']
@@ -86,7 +84,7 @@
except:
return False
- def _test_javascript_allowed_for_urls(self, policy_value, policies_json):
+ def _test_javascript_allowed_for_urls(self, policy_value, policies_dict):
"""Verify CrOS enforces the JavaScriptAllowedForUrls policy.
When JavaScriptAllowedForUrls is undefined, JavaScript shall be blocked
@@ -95,12 +93,12 @@
URL matches any of the listed patterns.
@param policy_value: policy value expected on chrome://policy page.
- @param policies_json: policy JSON data to send to the fake DM server.
+ @param policies_dict: policy dict data to send to the fake DM server.
"""
- self.setup_case(self.POLICY_NAME, policy_value, policies_json)
logging.info('Running _test_javascript_allowed_for_urls(%s, %s)',
- policy_value, policies_json)
+ policy_value, policies_dict)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
tab = self.cr.browser.tabs.New()
tab.Activate()
@@ -122,35 +120,18 @@
raise error.TestFail('JavaScript should be blocked.')
tab.Close()
- def _run_test_case(self, case):
+ def run_test_case(self, case):
"""Setup and run the test configured for the specified test case.
- Set the expected |policy_value| string and |policies_json| data based
+ Set the expected |policy_value| string and |policies_dict| data based
on the test |case|. If the user specified an expected |value| in the
command line args, then use it to set the |policy_value| and blank out
- the |policies_json|.
+ the |policies_dict|.
@param case: Name of the test case to run.
"""
- if self.is_value_given:
- # If |value| was given in the command line args, then set expected
- # |policy_value| to the given value, and |policies_json| to None.
- policy_value = self.value
- policies_json = None
- else:
- # Otherwise, set expected |policy_value| and setup |policies_json|
- # data to the values required by the specified test |case|.
- if not self.TEST_CASES[case]:
- policy_value = None
- else:
- policy_value = ','.join(self.TEST_CASES[case])
- policy_json = {'JavaScriptAllowedForUrls': self.TEST_CASES[case]}
- policies_json = self.SUPPORTING_POLICIES.copy()
- policies_json.update(policy_json)
+ policy_value, policies_dict = self._get_policy_data_for_case(case)
# Run test using the values configured for the test |case|.
- self._test_javascript_allowed_for_urls(policy_value, policies_json)
-
- def run_once(self):
- self.run_once_impl(self._run_test_case)
+ self._test_javascript_allowed_for_urls(policy_value, policies_dict)
diff --git a/client/site_tests/policy_JavaScriptBlockedForUrls/control b/client/site_tests/policy_JavaScriptBlockedForUrls/control
index 7b698e4..50dd717 100644
--- a/client/site_tests/policy_JavaScriptBlockedForUrls/control
+++ b/client/site_tests/policy_JavaScriptBlockedForUrls/control
@@ -17,9 +17,8 @@
Chrome OS client behavior when user policy DefaultJavaScriptSetting=1, meaning
allow JavaScript on all pages except for those in JavaScriptBlockedForUrls.
It exercises a range of policy values using four unique named test cases:
-NotSet_AllowJS, SingleUrl_BlockJS, MultipleUrls_AllowJS, and
-MultipleUrls_BlockJS. See the test file for a full description of what each
-test case does.
+NotSet_Allow, SingleUrl_Block, MultipleUrls_Allow, and MultipleUrls_Block.
+See the test file for a full description of what each test case does.
In general, a test shall pass if the browser blocks JavaScript execution only
on a test page with a URL that matches one or more of the URL patterns listed
@@ -27,14 +26,6 @@
on a page where it should be blocked, or blocks execution on a page where it
should be allowed.
-Usage example:
-$ test_that <IPAddress> JavaScriptBlockedForUrls --args="mode=single
-case=SingleUrl_BlockJS env=cr-dev username=test@crosqa4.com password=test0000"
-
-Runs a single test case (e.g., SingleUrl_BlockJS) against a device with the
-specified IP address, using the Staging environment on the cros-dev DM Server,
-and signing in to the device with the given username and password.
-
"""
job.run_test("policy_JavaScriptBlockedForUrls", args=args)
diff --git a/client/site_tests/policy_JavaScriptBlockedForUrls/policy_JavaScriptBlockedForUrls.py b/client/site_tests/policy_JavaScriptBlockedForUrls/policy_JavaScriptBlockedForUrls.py
index 2da5476..f5e947c 100644
--- a/client/site_tests/policy_JavaScriptBlockedForUrls/policy_JavaScriptBlockedForUrls.py
+++ b/client/site_tests/policy_JavaScriptBlockedForUrls/policy_JavaScriptBlockedForUrls.py
@@ -16,20 +16,20 @@
This test verifies the behavior of Chrome OS with a range of valid values
for the JavaScriptBlockedForUrls user policy, covered by four named test
- cases: NotSet_AllowJS, SingleUrl_BlockJS, MultipleUrls_AllowJS, and
- MultipleUrls_BlockJS.
+ cases: NotSet_Allow, SingleUrl_Block, MultipleUrls_Allow, and
+ MultipleUrls_Block.
- When the policy value is None (as in test case=NotSet_AllowJS), then
+ When the policy value is None (as in test case=NotSet_Allow), then
JavaScript execution be allowed on any page. When the policy value is set
- to a single URL pattern (as in test case=SingleUrl_BlockJS), then
+ to a single URL pattern (as in test case=SingleUrl_Block), then
JavaScript execution will be blocked on any page that matches that
- pattern. When set to multiple URL patterns (as case=MultipleUrls_AllowJS
- and MultipleUrls_BlockJS) then JavaScript execution will be blocked on any
+ pattern. When set to multiple URL patterns (as case=MultipleUrls_Allow
+ and MultipleUrls_Block) then JavaScript execution will be blocked on any
page with an URL that matches any of the listed patterns.
- Two test cases (NotSet_AllowJS, MultipleUrls_AllowJS) are designed to
- allow JavaScript execution the test page. The other two test cases
- (NotSet_AllowJS, MultipleUrls_BlockJS) are designed to block JavaScript
+ Two test cases (NotSet_Allow, MultipleUrls_Allow) are designed to allow
+ JavaScript execution the test page. The other two test cases
+ (NotSet_Allow, MultipleUrls_Block) are designed to block JavaScript
execution on the test page.
Note this test has a dependency on the DefaultJavaScriptSetting user
@@ -53,13 +53,13 @@
TEST_URL = URL_BASE + URL_PAGE
TEST_CASES = {
- 'NotSet_AllowJS': None,
- 'SingleUrl_BlockJS': [URL_BASE],
- 'MultipleUrls_AllowJS': ['http://www.bing.com',
- 'https://www.yahoo.com'],
- 'MultipleUrls_BlockJS': ['http://www.bing.com',
- TEST_URL,
- 'https://www.yahoo.com']
+ 'NotSet_Allow': None,
+ 'SingleUrl_Block': [URL_BASE],
+ 'MultipleUrls_Allow': ['http://www.bing.com',
+ 'https://www.yahoo.com'],
+ 'MultipleUrls_Block': ['http://www.bing.com',
+ TEST_URL,
+ 'https://www.yahoo.com']
}
STARTUP_URLS = ['chrome://policy', 'chrome://settings']
@@ -88,7 +88,7 @@
except:
return False
- def _test_javascript_blocked_for_urls(self, policy_value, policies_json):
+ def _test_javascript_blocked_for_urls(self, policy_value, policies_dict):
"""Verify CrOS enforces the JavaScriptBlockedForUrls policy.
When JavaScriptBlockedForUrls is undefined, JavaScript execution shall
@@ -97,22 +97,23 @@
pages whose URL matches any of the listed patterns.
@param policy_value: policy value expected on chrome://policy page.
- @param policies_json: policy JSON data to send to the fake DM server.
+ @param policies_dict: policy dict data to send to the fake DM server.
"""
- self.setup_case(self.POLICY_NAME, policy_value, policies_json)
logging.info('Running _test_javascript_blocked_for_urls(%s, %s)',
- policy_value, policies_json)
+ policy_value, policies_dict)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
tab = self.cr.browser.tabs.New()
tab.Activate()
tab.Navigate(self.TEST_URL)
+ time.sleep(1)
+
utils.poll_for_condition(
lambda: tab.url == self.TEST_URL,
exception=error.TestError('Test page is not ready.'))
- time.sleep(1)
-
javascript_is_allowed = self._can_execute_javascript(tab)
+
if policy_value is not None and self.URL_HOST in policy_value:
# If |URL_HOST| is in |policy_value|, then JavaScript execution
# should be blocked. If execution is allowed, raise an error.
@@ -123,35 +124,18 @@
raise error.TestFail('JavaScript should be allowed.')
tab.Close()
- def _run_test_case(self, case):
+ def run_test_case(self, case):
"""Setup and run the test configured for the specified test case.
- Set the expected |policy_value| string and |policies_json| data based
+ Set the expected |policy_value| string and |policies_dict| data based
on the test |case|. If the user specified an expected |value| in the
command line args, then use it to set the |policy_value| and blank out
- the |policies_json|.
+ the |policies_dict|.
@param case: Name of the test case to run.
"""
- if self.is_value_given:
- # If |value| was given in the command line args, then set expected
- # |policy_value| to the given value, and |policies_json| to None.
- policy_value = self.value
- policies_json = None
- else:
- # Otherwise, set expected |policy_value| and setup |policies_json|
- # data to the values required by the specified test |case|.
- if not self.TEST_CASES[case]:
- policy_value = None
- else:
- policy_value = ','.join(self.TEST_CASES[case])
- policy_json = {'JavaScriptBlockedForUrls': self.TEST_CASES[case]}
- policies_json = self.SUPPORTING_POLICIES.copy()
- policies_json.update(policy_json)
+ policy_value, policies_dict = self._get_policy_data_for_case(case)
# Run test using the values configured for the test |case|.
- self._test_javascript_blocked_for_urls(policy_value, policies_json)
-
- def run_once(self):
- self.run_once_impl(self._run_test_case)
+ self._test_javascript_blocked_for_urls(policy_value, policies_dict)
diff --git a/client/site_tests/policy_ManagedBookmarks/policy_ManagedBookmarks.py b/client/site_tests/policy_ManagedBookmarks/policy_ManagedBookmarks.py
index 7680349..fb2689d 100644
--- a/client/site_tests/policy_ManagedBookmarks/policy_ManagedBookmarks.py
+++ b/client/site_tests/policy_ManagedBookmarks/policy_ManagedBookmarks.py
@@ -2,9 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import json
-import logging
-import time
+import json, logging, time
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
@@ -94,7 +92,7 @@
tree_items = self.get_elements_from_page(tab, cmd)
# Scan bookmark tree for a folder with the domain-name in title.
- domain_name = self.USERNAME.split('@')[1]
+ domain_name = self.username.split('@')[1]
folder_title = domain_name + ' bookmarks'
for bookmark_element in tree_items.itervalues():
bookmark_node = bookmark_element['bookmarkNode']
diff --git a/client/site_tests/policy_PopupsAllowedForUrls/control b/client/site_tests/policy_PopupsAllowedForUrls/control
index 85d7c51..1a064a9 100644
--- a/client/site_tests/policy_PopupsAllowedForUrls/control
+++ b/client/site_tests/policy_PopupsAllowedForUrls/control
@@ -24,13 +24,6 @@
fail if the browser blocks popups on a page where they should be allowed, or
allows popups on a page where they should be blocked.
-Usage example:
-$ test_that <IPAddress> PopupsAllowedForUrls
-
-Runs all the test cases against a device with the specified IP address, using
-the DM Test environment with the given DM Server name, and signing in to the
-device with the given username and password.
-
"""
job.run_test("policy_PopupsAllowedForUrls", args=args)
diff --git a/client/site_tests/policy_PopupsAllowedForUrls/policy_PopupsAllowedForUrls.py b/client/site_tests/policy_PopupsAllowedForUrls/policy_PopupsAllowedForUrls.py
index 2c62cf4..f3bd1b8 100644
--- a/client/site_tests/policy_PopupsAllowedForUrls/policy_PopupsAllowedForUrls.py
+++ b/client/site_tests/policy_PopupsAllowedForUrls/policy_PopupsAllowedForUrls.py
@@ -2,8 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging
-import utils
+import logging, utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
@@ -61,17 +60,12 @@
super(policy_PopupsAllowedForUrls, self).initialize(args)
self.start_webserver(self.URL_PORT)
- def cleanup(self):
- if self._web_server:
- self._web_server.stop()
- super(policy_PopupsAllowedForUrls, self).cleanup()
-
def _wait_for_page_ready(self, tab):
utils.poll_for_condition(
lambda: tab.EvaluateJavaScript('pageReady'),
exception=error.TestError('Test page is not ready.'))
- def _test_popups_allowed_for_urls(self, policy_value, policies_json):
+ def _test_popups_allowed_for_urls(self, policy_value, policies_dict):
"""Verify CrOS enforces the PopupsAllowedForUrls policy.
When PopupsAllowedForUrls is undefined, popups shall be blocked on
@@ -80,12 +74,12 @@
the listed URLs.
@param policy_value: policy value expected on chrome://policy page.
- @param policies_json: policy JSON data to send to the fake DM server.
+ @param policies_dict: policy dict data to send to the fake DM server.
"""
- self.setup_case(self.POLICY_NAME, policy_value, policies_json)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
logging.info('Running _test_popups_allowed_for_urls(%s, %s)',
- policy_value, policies_json)
+ policy_value, policies_dict)
tab = self.navigate_to_url(self.TEST_URL)
self._wait_for_page_ready(tab)
@@ -102,33 +96,18 @@
raise error.TestFail('Popups should be blocked.')
tab.Close()
- def _run_test_case(self, case):
+ def run_test_case(self, case):
"""Setup and run the test configured for the specified test case.
- Set the expected |policy_value| and |policies_json| data based on the
- test |case|. If the user specified an expected |value| in the command
- line args, then use it to set the |policy_value| and blank out the
- |policies_json|.
+ Set the expected |policy_value| and |policies_dict| data defined for
+ the specified test |case|, and run the test. If the user specified an
+ expected |value| in the command line args, then it will be used to set
+ the |policy_value|.
@param case: Name of the test case to run.
"""
- if self.is_value_given:
- # If |value| was given in args, then set expected |policy_value|
- # to the given value, and setup |policies_json| data to None.
- policy_value = self.value
- policies_json = None
- else:
- # Otherwise, set expected |policy_value| and setup |policies_json|
- # data to the values specified by the test |case|.
- policy_value = ','.join(self.TEST_CASES[case])
- policy_json = {self.POLICY_NAME: self.TEST_CASES[case]}
- policies_json = self.SUPPORTING_POLICIES.copy()
- policies_json.update(policy_json)
+ policy_value, policies_dict = self._get_policy_data_for_case(case)
# Run test using the values configured for the test case.
- self._test_popups_allowed_for_urls(policy_value, policies_json)
-
- def run_once(self):
- self.run_once_impl(self._run_test_case)
-
+ self._test_popups_allowed_for_urls(policy_value, policies_dict)
diff --git a/client/site_tests/policy_PopupsBlockedForUrls/control b/client/site_tests/policy_PopupsBlockedForUrls/control
index e2c195b..60ecda2 100644
--- a/client/site_tests/policy_PopupsBlockedForUrls/control
+++ b/client/site_tests/policy_PopupsBlockedForUrls/control
@@ -24,13 +24,6 @@
fail if the browser blocks popups on a page where they should be allowed, or
allows popups on a page where they should be blocked.
-Usage example:
-$ test_that <IPAddress> PopupsBlockedForUrls
-
-Runs all the test cases against a device with the specified IP address, using
-the DM Test environment with the given DM Server name, and signing in to the
-device with the given username and password.
-
"""
job.run_test("policy_PopupsBlockedForUrls", args=args)
diff --git a/client/site_tests/policy_PopupsBlockedForUrls/policy_PopupsBlockedForUrls.py b/client/site_tests/policy_PopupsBlockedForUrls/policy_PopupsBlockedForUrls.py
index 6cd3087..69dcf01 100644
--- a/client/site_tests/policy_PopupsBlockedForUrls/policy_PopupsBlockedForUrls.py
+++ b/client/site_tests/policy_PopupsBlockedForUrls/policy_PopupsBlockedForUrls.py
@@ -2,8 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging
-import utils
+import logging, utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
@@ -61,17 +60,12 @@
super(policy_PopupsBlockedForUrls, self).initialize(args)
self.start_webserver(self.URL_PORT)
- def cleanup(self):
- if self._web_server:
- self._web_server.stop()
- super(policy_PopupsBlockedForUrls, self).cleanup()
-
def _wait_for_page_ready(self, tab):
utils.poll_for_condition(
lambda: tab.EvaluateJavaScript('pageReady'),
exception=error.TestError('Test page is not ready.'))
- def _test_popups_blocked_for_urls(self, policy_value, policies_json):
+ def _test_popups_blocked_for_urls(self, policy_value, policies_dict):
"""Verify CrOS enforces the PopupsBlockedForUrls policy.
When PopupsBlockedForUrls is undefined, popups shall be allowed on
@@ -80,12 +74,12 @@
listed URLs.
@param policy_value: policy value expected on chrome://policy page.
- @param policies_json: policy JSON data to send to the fake DM server.
+ @param policies_dict: policy dict data to send to the fake DM server.
"""
- self.setup_case(self.POLICY_NAME, policy_value, policies_json)
logging.info('Running _test_popups_blocked_for_urls(%s, %s)',
- policy_value, policies_json)
+ policy_value, policies_dict)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
tab = self.navigate_to_url(self.TEST_URL)
self._wait_for_page_ready(tab)
@@ -102,35 +96,30 @@
raise error.TestFail('Popups should not be blocked.')
tab.Close()
- def _run_test_case(self, case):
+ def run_test_case(self, case):
"""Setup and run the test configured for the specified test case.
- Set the expected |policy_value| and |policies_json| data based on the
- test |case|. If the user specified an expected |value| in the command
- line args, then use it to set the |policy_value| and blank out the
- |policies_json|.
+ Set the expected |policy_value| and |policies_dict| data defined for
+ the specified test |case|, and run the test. If the user specified an
+ expected |value| in the command line args, then it will be used to set
+ the |policy_value|.
@param case: Name of the test case to run.
"""
- if self.is_value_given:
+ """if self.is_value_given:
# If |value| was given in args, then set expected |policy_value|
- # to the given value, and setup |policies_json| data to None.
+ # to the given value, and setup |policies_dict| data to None.
policy_value = self.value
- policies_json = None
+ policies_dict = None
else:
- # Otherwise, set expected |policy_value| and setup |policies_json|
+ # Otherwise, set expected |policy_value| and setup |policies_dict|
# data to the values specified by the test |case|.
policy_value = ','.join(self.TEST_CASES[case])
- policy_json = {self.POLICY_NAME: self.TEST_CASES[case]}
- policies_json = self.SUPPORTING_POLICIES.copy()
- policies_json.update(policy_json)
+ policy_dict = {self.POLICY_NAME: self.TEST_CASES[case]}
+ policies_dict = self.SUPPORTING_POLICIES.copy()
+ policies_dict.update(policy_dict)"""
+ policy_value, policies_dict = self._get_policy_data_for_case(case)
# Run test using the values configured for the test case.
- self._test_popups_blocked_for_urls(policy_value, policies_json)
-
- def run_once(self):
- # The run_once() method is required by autotest. We call the base
- # class run_once_impl() method, which handles command-line run modes,
- # and pass in the standard _run_test_case() method of this test.
- self.run_once_impl(self._run_test_case)
+ self._test_popups_blocked_for_urls(policy_value, policies_dict)
diff --git a/client/site_tests/policy_ProxySettings/policy_ProxySettings.py b/client/site_tests/policy_ProxySettings/policy_ProxySettings.py
index 4ddded2..6e27366 100644
--- a/client/site_tests/policy_ProxySettings/policy_ProxySettings.py
+++ b/client/site_tests/policy_ProxySettings/policy_ProxySettings.py
@@ -2,32 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging
-import threading
+import logging, threading
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
from SocketServer import ThreadingTCPServer, StreamRequestHandler
-POLICY_NAME = 'ProxySettings'
-PROXY_HOST = 'localhost'
-PROXY_PORT = 3128
-WEB_PORT = 8080
-PAC_FILE_URL = 'http://localhost:%d/test_data/test_proxy.pac' % WEB_PORT
-FIXED_PROXY = '''{
- "ProxyBypassList": "www.google.com,www.googleapis.com",
- "ProxyMode": "fixed_servers",
- "ProxyServer": "localhost:%s"
-}''' % PROXY_PORT
-DIRECT_PROXY = '''{
- "ProxyMode": "direct"
-}'''
-PAC_PROXY = '''{
- "ProxyMode": "pac_script",
- "ProxyPacUrl": "%s"
-}''' % PAC_FILE_URL
-TEST_URL = 'http://www.wired.com/'
-
class ProxyHandler(StreamRequestHandler):
"""Provide request handler for the Threaded Proxy Listener."""
@@ -122,6 +102,26 @@
entry should be used.
"""
version = 1
+
+ POLICY_NAME = 'ProxySettings'
+ PROXY_HOST = 'localhost'
+ PROXY_PORT = 3128
+ WEB_PORT = 8080
+ PAC_FILE_URL = 'http://localhost:%d/test_data/test_proxy.pac' % WEB_PORT
+ FIXED_PROXY = '''{
+ "ProxyBypassList": "www.google.com,www.googleapis.com",
+ "ProxyMode": "fixed_servers",
+ "ProxyServer": "localhost:%s"
+ }''' % PROXY_PORT
+ DIRECT_PROXY = '''{
+ "ProxyMode": "direct"
+ }'''
+ PAC_PROXY = '''{
+ "ProxyMode": "pac_script",
+ "ProxyPacUrl": "%s"
+ }''' % PAC_FILE_URL
+ TEST_URL = 'http://www.wired.com/'
+
TEST_CASES = {
'FixedProxy_UseFixedProxy': FIXED_PROXY,
'PacProxy_UsePacFile': PAC_PROXY,
@@ -131,9 +131,9 @@
def initialize(self, args=()):
super(policy_ProxySettings, self).initialize(args)
- self._proxy_server = ProxyListener(('', PROXY_PORT))
+ self._proxy_server = ProxyListener(('', self.PROXY_PORT))
self._proxy_server.run()
- self.start_webserver(WEB_PORT)
+ self.start_webserver(self.WEB_PORT)
def cleanup(self):
self._proxy_server.stop()
@@ -147,10 +147,10 @@
"""
logging.info('Running _test_proxy_configuration(%s, %s)',
policy_value, policies_dict)
- self.setup_case(POLICY_NAME, policy_value, policies_dict)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
self._proxy_server.reset_requests_received()
- self.navigate_to_url(TEST_URL)
+ self.navigate_to_url(self.TEST_URL)
proxied_requests = self._proxy_server.get_requests_received()
# Determine whether TEST_URL is in |proxied_requests|. Comprehension
@@ -159,7 +159,7 @@
# elements inside |proxied_requests| are not necessarily equal, i.e.,
# TEST_URL is a substring of the received request.
matching_requests = [request for request in proxied_requests
- if TEST_URL in request]
+ if self.TEST_URL in request]
logging.info('matching_requests: %s', matching_requests)
if policy_value is None or 'direct' in policy_value:
@@ -192,6 +192,6 @@
# Otherwise, set expected |policy_value| and setup |policies_dict|
# data to the values required by the specified test |case|.
policy_value = self.TEST_CASES[case]
- policies_dict = {POLICY_NAME: self.TEST_CASES[case]}
+ policies_dict = {self.POLICY_NAME: self.TEST_CASES[case]}
self._test_proxy_configuration(policy_value, policies_dict)
diff --git a/client/site_tests/policy_RestoreOnStartupURLs/policy_RestoreOnStartupURLs.py b/client/site_tests/policy_RestoreOnStartupURLs/policy_RestoreOnStartupURLs.py
index cb019f4..618fec2 100644
--- a/client/site_tests/policy_RestoreOnStartupURLs/policy_RestoreOnStartupURLs.py
+++ b/client/site_tests/policy_RestoreOnStartupURLs/policy_RestoreOnStartupURLs.py
@@ -12,8 +12,12 @@
"""Test effect of RestoreOnStartupURLs policy on Chrome OS behavior.
This test verifies the behavior of Chrome OS for a range of valid values
- in the RestoreOnStartupURLs user policy. The values are covered by three
- test cases named: NotSet_NoTabs, SingleUrl_1Tab, and MultipleUrls_3Tabs.
+ in the RestoreOnStartupURLs user policy. It also exercises the dependent
+ user policy RestoreOnStartup, which must be set equal to 4 to utilize the
+ specified startup URLs, and to None to when no URLs are specified.
+
+ The combination of policy values are covered by three test cases named:
+ NotSet_NoTabs, SingleUrl_1Tab, and MultipleUrls_3Tabs.
- Case NotSet_NoTabs opens no tabs. This is the default behavior for
un-managed user and guest user sessions.
- Case SingleUrl_1Tab opens a single tab to chrome://settings.
@@ -30,14 +34,13 @@
NEWTAB_URLS = ['chrome://newtab',
'https://www.google.com/_/chrome/newtab?espv=2&ie=UTF-8']
- # Dictionary of named test cases and policy data.
TEST_CASES = {
'NotSet_NoTabs': None,
'SingleUrl_1Tab': URLS1_DATA,
'MultipleUrls_3Tabs': URLS3_DATA
}
- def _test_startup_urls(self, policy_value, policies_json):
+ def _test_startup_urls(self, policy_value, policies_dict):
"""Verify CrOS enforces RestoreOnStartupURLs policy value.
When RestoreOnStartupURLs policy is set to one or more URLs, check
@@ -45,12 +48,12 @@
is opened.
@param policy_value: policy value expected on chrome://policy page.
- @param policies_json: policy JSON data to send to the fake DM server.
+ @param policies_dict: policy dict data to send to the fake DM server.
"""
- self.setup_case(self.POLICY_NAME, policy_value, policies_json)
logging.info('Running _test_StartupURLs(%s, %s)',
- policy_value, policies_json)
+ policy_value, policies_dict)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
# Get list of open tab urls from browser; Convert unicode to text;
# Strip any trailing '/' character reported by devtools.
@@ -70,34 +73,31 @@
'(expected: %s)' %
(tab_urls_value, policy_value))
- def _run_test_case(self, case):
+ def run_test_case(self, case):
"""Setup and run the test configured for the specified test case.
- Set the expected |policy_value| string and |policies_json| data based
+ Set the expected |policy_value| string and |policies_dict| data based
on the test |case|. If the user specified an expected |value| in the
command line args, then use it to set the |policy_value| and blank out
- the |policies_json|.
+ the |policies_dict|.
@param case: Name of the test case to run.
"""
if self.is_value_given:
# If |value| was given by user, then set expected |policy_value|
- # to the given value, and setup |policies_json| to None.
+ # to the given value, and setup |policies_dict| to None.
policy_value = self.value
- policies_json = None
+ policies_dict = None
else:
if self.TEST_CASES[case] is None:
policy_value = None
- policies_json = {'RestoreOnStartup': None}
+ policies_dict = {'RestoreOnStartup': None}
else:
policy_value = ','.join(self.TEST_CASES[case])
- policies_json = {'RestoreOnStartup': 4}
- policy_json = {self.POLICY_NAME: self.TEST_CASES[case]}
- policies_json.update(policy_json)
+ policies_dict = {'RestoreOnStartup': 4}
+ policy_dict = {self.POLICY_NAME: self.TEST_CASES[case]}
+ policies_dict.update(policy_dict)
# Run test using values configured for the test case.
- self._test_startup_urls(policy_value, policies_json)
-
- def run_once(self):
- self.run_once_impl(self._run_test_case)
+ self._test_startup_urls(policy_value, policies_dict)
diff --git a/client/site_tests/policy_URLBlacklist/control b/client/site_tests/policy_URLBlacklist/control
index 3d07bdc..dfdc5dd 100644
--- a/client/site_tests/policy_URLBlacklist/control
+++ b/client/site_tests/policy_URLBlacklist/control
@@ -11,28 +11,18 @@
TEST_TYPE = "client"
DOC = """
-Verify effects of policy_URLBlacklist policy on client behavior & appearance.
+Verify effects of policy_URLBlacklist policy on client behavior.
-This test verifies the effect of the URLBlacklist user policy on
-Chrome OS client behavior and appearance. It exercises a range of policy values using three
-unique test cases, named: NotSet, SingleBlacklistedFile and MultipleBlacklistedFiles. See the test file for a
-full description of what each test case does.
+This test verifies the effect of the URLBlacklist user policy on Chrome OS
+client behavior. It exercises a range of policy values using three unique test
+cases, named: NotSet_Allowed, SinglePage_Blocked and MultiplePages_Blocked.
+See the test file for a full description of what each test case does.
-A test case shall pass if the URLs that are not part of the URLBlacklist policy value
-are not blocked.
-The test case shall also pass if the URLs that are part of the URLBlacklist policy value
-are blocked.
-A test case shall fail if the above behavior is not enforced.
-
-Usage example:
-$ test_that <IPAddress> policy_URLBlacklist --args="mode=single case=MultipleBlacklistedFiles
-env=dm-test dms_name=xot-dmst username=test@crosprqa1.com password=test1234"
-
-Runs a single test case (e.g., MultipleBlacklistedFiles) using the specified test DM Server
-environment, signing in with the specified username and password. Expectation
-is that the page will be blocked.
+A test case shall pass if the URLs that are not in the URLBlacklist policy
+value are allowed. The test case shall also pass if the URLs that are in
+the URLBlacklist policy value are blocked. A test case shall fail if the above
+behavior is not enforced.
"""
job.run_test("policy_URLBlacklist", args=args)
-
diff --git a/client/site_tests/policy_URLBlacklist/policy_URLBlacklist.py b/client/site_tests/policy_URLBlacklist/policy_URLBlacklist.py
index 419d004..e9d0450 100644
--- a/client/site_tests/policy_URLBlacklist/policy_URLBlacklist.py
+++ b/client/site_tests/policy_URLBlacklist/policy_URLBlacklist.py
@@ -4,81 +4,59 @@
import logging
-from autotest_lib.client.cros import httpd
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
-POLICY_NAME = 'URLBlacklist'
-URL_HOST = 'http://localhost'
-URL_PORT = 8080
-URL_BASE = '%s:%d/%s' % (URL_HOST, URL_PORT, 'test_data')
-ALL_URLS_LIST = [URL_BASE + website for website in
- ['/website1.html',
- '/website2.html',
- '/website3.html']]
-SINGLE_BLACKLISTED_FILE_DATA = ALL_URLS_LIST[:1]
-MULTIPLE_BLACKLISTED_FILES_DATA = ALL_URLS_LIST[:2]
-BLOCKED_USER_MESSAGE = 'Webpage Blocked'
-BLOCKED_ERROR_MESSAGE = 'ERR_BLOCKED_BY_ADMINISTRATOR'
-
class policy_URLBlacklist(enterprise_policy_base.EnterprisePolicyTest):
- """
- Test effect of URLBlacklist policy on Chrome OS behavior.
+ """Test effect of URLBlacklist policy on Chrome OS behavior.
- Navigate to each the URLs in the ALL_URLS_LIST and verify that the URLs
- specified by the URLBlackList policy are blocked.
- Throw a warning if the user message on the blocked page is incorrect.
+ Navigate to all the websites in the ALL_URLS_LIST. Verify that the
+ websites specified by the URLBlackList policy are blocked. Throw a warning
+ if the user message on the blocked page is incorrect.
- Two test cases (SingleBlacklistedFile, MultipleBlacklistedFiles) are
- designed to verify that URLs specified in the URLBlacklist policy are
- blocked.
- The third test case(NotSet) is designed to verify that none of the URLs
- are blocked since the URLBlacklist policy is set to None
+ Two test cases (SinglePage_Blocked, MultiplePages_Blocked) are designed
+ to verify that URLs specified in the URLBlacklist policy are blocked.
+ The third test case (NotSet_Allowed) is designed to verify that none of
+ the URLs are blocked since the URLBlacklist policy is set to None
The test case shall pass if the URLs that are part of the URLBlacklist
- policy value are blocked.
- The test case shall also pass if the URLs that are not part of the
- URLBlacklist policy value are not blocked.
- The test case shall fail if the above behavior is not enforced.
+ policy value are blocked. The test case shall also pass if the URLs that
+ are not part of the URLBlacklist policy value are allowed. The test case
+ shall fail if the above behavior is not enforced.
"""
version = 1
+
+ POLICY_NAME = 'URLBlacklist'
+ URL_HOST = 'http://localhost'
+ URL_PORT = 8080
+ URL_BASE = '%s:%d/%s' % (URL_HOST, URL_PORT, 'test_data')
+ ALL_URLS_LIST = [URL_BASE + website for website in
+ ['/website1.html',
+ '/website2.html',
+ '/website3.html']]
+ SINGLE_BLACKLISTED_FILE_DATA = ALL_URLS_LIST[:1]
+ MULTIPLE_BLACKLISTED_FILES_DATA = ALL_URLS_LIST[:2]
+ BLOCKED_USER_MESSAGE = 'Webpage Blocked'
+ BLOCKED_ERROR_MESSAGE = 'ERR_BLOCKED_BY_ADMINISTRATOR'
+
TEST_CASES = {
- 'NotSet': '',
- 'SingleBlacklistedFile': SINGLE_BLACKLISTED_FILE_DATA,
- 'MultipleBlacklistedFiles': MULTIPLE_BLACKLISTED_FILES_DATA,
+ 'NotSet_Allowed': '',
+ 'SinglePage_Blocked': SINGLE_BLACKLISTED_FILE_DATA,
+ 'MultiplePages_Blocked': MULTIPLE_BLACKLISTED_FILES_DATA,
}
+ SUPPORTING_POLICIES = {'URLWhitelist': None}
def initialize(self, args=()):
super(policy_URLBlacklist, self).initialize(args)
- self.start_webserver(URL_PORT)
+ self.start_webserver(self.URL_PORT)
- def navigate_to_website(self, url):
- """
- Open a new tab in the browser and navigate to the URL.
-
- @param url: the URL that the browser is navigated to.
- @returns: a chrome browser tab navigated to the URL.
-
- """
- tab = self.cr.browser.tabs.New()
- logging.info('Navigating to URL:%s', url)
- try:
- tab.Navigate(url, timeout=10)
- except Exception, err:
- logging.error('Timeout Exception in navigating URL: %s\n %s',
- url, err)
- tab.WaitForDocumentReadyStateToBeComplete()
- return tab
-
- def scrape_text_from_website(self, tab):
- """
- Returns a list of the text content matching the page_scrape_cmd filter.
+ def _scrape_text_from_webpage(self, tab):
+ """Return a list of filtered text on the web page.
@param tab: tab containing the website to be parsed.
- @raises: TestFail if the expected text content was not found on the
- page.
+ @raises: TestFail if the expected text was not found on the page.
"""
parsed_message_string = ''
@@ -88,109 +66,77 @@
parsed_message_string = tab.EvaluateJavaScript(page_scrape_cmd)
except Exception as err:
raise error.TestFail('Unable to find the expected '
- 'text content on the test page: %s\n %r'%(tab.url, err))
+ 'text content on the test '
+ 'page: %s\n %r'%(tab.url, err))
logging.info('Parsed message:%s', parsed_message_string)
parsed_message_list = [str(word) for word in
parsed_message_string.split('\n') if word]
return parsed_message_list
- def is_url_blocked(self, url):
- """
- Returns True if the URL is blocked else returns False.
+ def _is_url_blocked(self, url):
+ """Return True if the URL is blocked else returns False.
@param url: The URL to be checked whether it is blocked.
"""
parsed_message_list = []
- tab = self.navigate_to_website(url)
- parsed_message_list = self.scrape_text_from_website(tab)
+ tab = self.navigate_to_url(url)
+ parsed_message_list = self._scrape_text_from_webpage(tab)
if len(parsed_message_list) == 2 and \
parsed_message_list[0] == 'Website enabled' and \
parsed_message_list[1] == 'Website is enabled':
return False
- #Check if the accurate user error message displayed on the error page.
- if parsed_message_list[0] != BLOCKED_USER_MESSAGE or \
- parsed_message_list[1] != BLOCKED_ERROR_MESSAGE:
+ # Check if accurate user error message is shown on the error page.
+ if parsed_message_list[0] != self.BLOCKED_USER_MESSAGE or \
+ parsed_message_list[1] != self.BLOCKED_ERROR_MESSAGE:
logging.warning('The Blocked page user notification '
'messages, %s and %s are not displayed on '
'the blocked page. The messages may have '
'been modified. Please check and update the '
'messages in this file accordingly.',
- BLOCKED_USER_MESSAGE, BLOCKED_ERROR_MESSAGE)
+ self.BLOCKED_USER_MESSAGE,
+ self.BLOCKED_ERROR_MESSAGE)
return True
- def _test_URLBlacklist(self, policy_value, policies_json):
- """
- Verify CrOS enforces URLBlacklist policy value.
+ def _test_url_blacklist(self, policy_value, policies_dict):
+ """Verify CrOS enforces URLBlacklist policy value.
- When the URLBlacklist policy is set to one or more Domains,
- check that navigation to URLs in the Blocked list are blocked.
- When set to None, check that none of the websites are blocked.
+ Navigate to all the websites in the ALL_URLS_LIST. Verify that
+ the websites specified in the URLWhitelist policy value are allowed.
+ Also verify that the websites not in the URLWhitelist policy value
+ are blocked.
@param policy_value: policy value expected on chrome://policy page.
- @param policies_json: policy JSON data to send to the fake DM server.
+ @param policies_dict: policy dict data to send to the fake DM server.
@raises: TestFail if url is blocked/not blocked based on the
corresponding policy values.
"""
- url_is_blocked = None
- self.setup_case(POLICY_NAME, policy_value, policies_json)
- logging.info('Running _test_URLBlacklist(%s, %s)',
- policy_value, policies_json)
+ logging.info('Running _test_url_blacklist(%s, %s)',
+ policy_value, policies_dict)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
- for url in ALL_URLS_LIST:
- url_is_blocked = self.is_url_blocked(url)
+ for url in self.ALL_URLS_LIST:
+ url_is_blocked = self._is_url_blocked(url)
if policy_value:
if url in policy_value and not url_is_blocked:
raise error.TestFail('The URL %s should have been blocked'
- ' by policy, but it was allowed' % url)
+ ' by policy, but was allowed.' % url)
elif url_is_blocked:
raise error.TestFail('The URL %s should have been allowed'
- 'by policy, but it was blocked' % url)
+ 'by policy, but was blocked' % url)
- def _run_test_case(self, case):
- """
- Setup and run the test configured for the specified test case.
+ def run_test_case(self, case):
+ """Setup and run the test configured for the specified test case.
- Set the expected |policy_value| and |policies_json| data based on the
- test |case|. If the user specified an expected |value| in the command
- line args, then use it to set the |policy_value| and blank out the
- |policies_json|.
+ Set the expected |policy_value| and |policies_dict| data defined for
+ the specified test |case|, and run the test. If the user specified an
+ expected |value| in the command line args, then it will be used to set
+ the |policy_value|.
@param case: Name of the test case to run.
"""
- policy_value = None
- policies_json = None
-
- if case not in self.TEST_CASES:
- raise error.TestError('Test case %s is not valid.' % case)
- logging.info('Running test case: %s', case)
-
- if self.is_value_given:
- # If |value| was given in the command line args, then set expected
- # |policy_value| to the given value, and |policies_json| to None.
- policy_value = self.value
- policies_json = None
- else:
- # Otherwise, set expected |policy_value| and setup |policies_json|
- # data to the values required by the test |case|.
- if case == 'NotSet':
- policy_value = None
- policies_json = {'URLBlacklist': None}
- elif case == 'SingleBlacklistedFile':
- policy_value = ','.join(SINGLE_BLACKLISTED_FILE_DATA)
- policies_json = {'URLBlacklist': SINGLE_BLACKLISTED_FILE_DATA}
-
- elif case == 'MultipleBlacklistedFiles':
- policy_value = ','.join(MULTIPLE_BLACKLISTED_FILES_DATA)
- policies_json = {
- 'URLBlacklist': MULTIPLE_BLACKLISTED_FILES_DATA
- }
-
- # Run test using the values configured for the test case.
- self._test_URLBlacklist(policy_value, policies_json)
-
- def run_once(self):
- self.run_once_impl(self._run_test_case)
+ policy_value, policies_dict = self._get_policy_data_for_case(case)
+ self._test_url_blacklist(policy_value, policies_dict)
diff --git a/client/site_tests/policy_URLWhitelist/control b/client/site_tests/policy_URLWhitelist/control
index 2d78f42..53b0b7b 100644
--- a/client/site_tests/policy_URLWhitelist/control
+++ b/client/site_tests/policy_URLWhitelist/control
@@ -11,29 +11,18 @@
TEST_TYPE = "client"
DOC = """
-Verify effects of policy_URLWhitelist policy on client behavior & appearance.
+Verify effects of policy_URLWhitelist policy on client behavior.
This test verifies the effect of the URLWhitelist user policy on Chrome OS
-client behavior and appearance. It exercises a range of policy values using
-three unique test cases, named: NotSet, SingleWhitelistedFile and
-MultipleWhitelistedFiles.
+client behavior. It exercises a range of policy values using three unique test
+cases, named: NotSet_Blocked, SinglePage_Allowed and MultiplePages_Allowed.
See the test file for a full description of what each test case does.
The test case shall pass if:
- -only the URLs that are part of the URLWhitelist policy value are not blocked.
- -all other URLs are blocked.
+ - Only URLs that in the URLWhitelist policy value are allowed.
+ - All other URLs are blocked.
The test case shall fail if the above behavior is not enforced.
-Usage example:
-$ test_that <IPAddress> policy_URLWhitelist --args="mode=single
-case=MultipleWhitelistedFiles nv=dm-test dms_name=xot-dmst
-username=test@crosprqa1.com password=test1234"
-
-This command runs a single test case (e.g., MultipleWhitelistedFiles) using
-the specified test DM Server environment, signing in with the specified
-username and password.
-
"""
job.run_test("policy_URLWhitelist", args=args)
-
diff --git a/client/site_tests/policy_URLWhitelist/policy_URLWhitelist.py b/client/site_tests/policy_URLWhitelist/policy_URLWhitelist.py
index 7a76c89..b497e4d 100644
--- a/client/site_tests/policy_URLWhitelist/policy_URLWhitelist.py
+++ b/client/site_tests/policy_URLWhitelist/policy_URLWhitelist.py
@@ -4,85 +4,60 @@
import logging
-from autotest_lib.client.cros import httpd
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import enterprise_policy_base
-POLICY_NAME = 'URLWhitelist'
-URL_HOST = 'http://localhost'
-URL_PORT = 8080
-URL_BASE = '%s:%d/%s' % (URL_HOST, URL_PORT, 'test_data')
-BLOCKED_URLS_LIST = [URL_BASE + website for website in
- ['/website1.html',
- '/website2.html',
- '/website3.html']]
-SINGLE_WHITELISTED_FILE_DATA = BLOCKED_URLS_LIST[:1]
-MULTIPLE_WHITELISTED_FILES_DATA = BLOCKED_URLS_LIST[:2]
-BLOCKED_USER_MESSAGE = 'Webpage Blocked'
-BLOCKED_ERROR_MESSAGE = 'ERR_BLOCKED_BY_ADMINISTRATOR'
-SUPPORTING_POLICIES = {'URLBlacklist': BLOCKED_URLS_LIST}
-
class policy_URLWhitelist(enterprise_policy_base.EnterprisePolicyTest):
- """
- Test effect of URLWhitleist policy on Chrome OS behavior.
+ """Test effect of URLWhitleist policy on Chrome OS behavior.
Navigate to all the websites in the BLOCKED_URLS_LIST. Verify that the
- websites specified by the URLWhitelist policy value are not blocked.
- Also verify that the websites not in the URLWhitelist policy
- value are blocked.
+ websites specified by the URLWhitelist policy value are allowed. Also
+ verify that the websites not in the URLWhitelist policy value are blocked.
- Two TEST_CASES (SingleWhitelistedFile, MultipleWhitelistedFiles) are
- designed to verify that the functionality works regardless of whether a
- a SINGLE website is specified in the URLWhitelist policy or if MULTIPLE
- websites are specified.
- The third TEST_CASE (NotSet) is designed to verify that all of the websites
- are blocked since the URLWhitelistlist policy is set to None.
+ Two TEST_CASES (SinglePage_Allowed, MultiplePages_Allowed) are designed to
+ verify that a website is allowed regardless of whether a SINGLE webpage is
+ specified in the URLWhitelist policy, or if MULTIPLE webpages are
+ specified. The third TEST_CASE (NotSet_Blocked) is designed to verify that
+ all websites are blocked since the URLWhitelistlist policy is set to None.
The test case shall pass if the URLs that are part of the URLWhitelist
- policy value are not blocked.
- The test case shall also pass if the URLs that are not part of the
- URLWhitelist policy value are blocked.
- The test case shall fail if the above behavior is not enforced.
+ policy value are allowed. The test case shall also pass if the URLs that
+ are not part of the URLWhitelist policy value are blocked. The test case
+ shall fail if the above behavior is not enforced.
"""
version = 1
+
+ POLICY_NAME = 'URLWhitelist'
+ URL_HOST = 'http://localhost'
+ URL_PORT = 8080
+ URL_BASE = '%s:%d/%s' % (URL_HOST, URL_PORT, 'test_data')
+ BLOCKED_URLS_LIST = [URL_BASE + website for website in
+ ['/website1.html',
+ '/website2.html',
+ '/website3.html']]
+ SINGLE_WHITELISTED_FILE_DATA = BLOCKED_URLS_LIST[:1]
+ MULTIPLE_WHITELISTED_FILES_DATA = BLOCKED_URLS_LIST[:2]
+ BLOCKED_USER_MESSAGE = 'Webpage Blocked'
+ BLOCKED_ERROR_MESSAGE = 'ERR_BLOCKED_BY_ADMINISTRATOR'
+
TEST_CASES = {
- 'NotSet': '',
- 'SingleWhitelistedFile': SINGLE_WHITELISTED_FILE_DATA,
- 'MultipleWhitelistedFiles': MULTIPLE_WHITELISTED_FILES_DATA
- }
+ 'NotSet_Blocked': '',
+ 'SinglePage_Allowed': SINGLE_WHITELISTED_FILE_DATA,
+ 'MultiplePages_Allowed': MULTIPLE_WHITELISTED_FILES_DATA
+ }
+ SUPPORTING_POLICIES = {'URLBlacklist': BLOCKED_URLS_LIST}
def initialize(self, args=()):
super(policy_URLWhitelist, self).initialize(args)
- self.start_webserver(URL_PORT)
+ self.start_webserver(self.URL_PORT)
- def _navigate_to_website(self, url):
- """
- Open a new tab in the browser and navigate to the URL.
-
- @param url: the website that the browser is navigated to.
- @returns: a chrome browser tab navigated to the URL.
-
- """
- tab = self.cr.browser.tabs.New()
- logging.info('Navigating to URL:%s', url)
- try:
- tab.Navigate(url, timeout=10)
- except Exception, err:
- logging.error('Timeout Exception in navigating URL: %s\n %s',
- url, err)
- tab.WaitForDocumentReadyStateToBeComplete()
- return tab
-
- def _scrape_text_from_website(self, tab):
- """
- Returns a list of the the text content displayed on the page
- matching the page_scrape_cmd filter.
+ def _scrape_text_from_webpage(self, tab):
+ """Return a list of filtered text on the web page.
@param tab: tab containing the website to be parsed.
- @raises: TestFail if the expected text content was not found on the
- page.
+ @raises: TestFail if the expected text was not found on the page.
"""
parsed_message_string = ''
@@ -100,97 +75,75 @@
return parsed_message_list
def _is_url_blocked(self, url):
- """
- Returns True if the URL is blocked else returns False.
+ """Return True if the URL is blocked else returns False.
@param url: The URL to be checked whether it is blocked.
"""
parsed_message_list = []
- tab = self._navigate_to_website(url)
- parsed_message_list = self._scrape_text_from_website(tab)
+ tab = self.navigate_to_url(url)
+ parsed_message_list = self._scrape_text_from_webpage(tab)
if len(parsed_message_list) == 2 and \
parsed_message_list[0] == 'Website enabled' and \
parsed_message_list[1] == 'Website is enabled':
return False
- # Check if the accurate user error message displayed on the error page.
- if parsed_message_list[0] != BLOCKED_USER_MESSAGE or \
- parsed_message_list[1] != BLOCKED_ERROR_MESSAGE:
+ # Check if accurate user error message is shown on the error page.
+ if parsed_message_list[0] != self.BLOCKED_USER_MESSAGE or \
+ parsed_message_list[1] != self.BLOCKED_ERROR_MESSAGE:
logging.warning('The Blocked page user notification '
'messages, %s and %s are not displayed on '
'the blocked page. The messages may have '
'been modified. Please check and update the '
'messages in this file accordingly.',
- BLOCKED_USER_MESSAGE, BLOCKED_ERROR_MESSAGE)
+ self.BLOCKED_USER_MESSAGE,
+ self.BLOCKED_ERROR_MESSAGE)
return True
- def _test_URLWhitelist(self, policy_value, policies_json):
- """
- Verify CrOS enforces URLWhitelist policy value.
+ def _test_url_whitelist(self, policy_value, policies_dict):
+ """Verify CrOS enforces URLWhitelist policy value.
Navigate to all the websites in the BLOCKED_URLS_LIST. Verify that
- the websites specified by the URLWhitelist policy value are not
- blocked. Also verify that the websites not in the URLWhitelist policy
- value are blocked.
+ the websites specified by the URLWhitelist policy value allowed.
+ Also verify that the websites not in the URLWhitelist policy value
+ are blocked.
@param policy_value: policy value expected on chrome://policy page.
- @param policies_json: policy JSON data to send to the fake DM server.
+ @param policies_dict: policy dict data to send to the fake DM server.
@raises: TestFail if url is blocked/not blocked based on the
corresponding policy values.
"""
- url_is_blocked = None
- logging.info('Running _test_Whitelist(%s, %s)',
- policy_value, policies_json)
- self.setup_case(POLICY_NAME, policy_value, policies_json)
+ logging.info('Running _test_url_whitelist(%s, %s)',
+ policy_value, policies_dict)
+ self.setup_case(self.POLICY_NAME, policy_value, policies_dict)
- for url in BLOCKED_URLS_LIST:
+ for url in self.BLOCKED_URLS_LIST:
url_is_blocked = self._is_url_blocked(url)
if policy_value:
if url in policy_value and url_is_blocked:
- raise error.TestFail('The URL %s should have been allowed'
- ' by policy, but it was blocked' % url)
+ raise error.TestFail('The URL %s should have been '
+ 'allowed by policy, but it '
+ 'was blocked.' % url)
elif url not in policy_value and not url_is_blocked:
- raise error.TestFail('The URL %s should have been blocked'
- ' by policy, but it was allowed' % url)
+ raise error.TestFail('The URL %s should have been '
+ 'blocked by policy, but it '
+ 'was allowed' % url)
elif not url_is_blocked:
raise error.TestFail('The URL %s should have been blocked'
'by policy, but it was allowed' % url)
- def _run_test_case(self, case):
- """
- Setup and run the test configured for the specified test case.
+ def run_test_case(self, case):
+ """Setup and run the test configured for the specified test case.
- Set the expected |policy_value| and |policies_json| data based on the
- test |case|. If the user specified an expected |value| in the command
- line args, then use it to set the |policy_value| and blank out the
- |policies_json|.
+ Set the expected |policy_value| and |policies_dict| data defined for
+ the specified test |case|, and run the test. If the user specified an
+ expected |value| in the command line args, then it will be used to set
+ the |policy_value|.
@param case: Name of the test case to run.
"""
- policy_value = None
- policies_json = None
-
- if self.is_value_given:
- # If |value| was given in the command line args, then set expected
- # |policy_value| to the given value, and |policies_json| to None.
- policy_value = self.value
- policies_json = None
- else:
- # Otherwise, set expected |policy_value| and setup |policies_json|
- # data to the values required by the specified test |case|.
- policies_json = SUPPORTING_POLICIES.copy()
- if not self.TEST_CASES[case]:
- policy_value = None
- else:
- policy_value = ','.join(self.TEST_CASES[case])
- policies_json.update({'URLWhitelist': self.TEST_CASES[case]})
-
- # Run test using the values configured for the test case.
- self._test_URLWhitelist(policy_value, policies_json)
-
- def run_once(self):
- self.run_once_impl(self._run_test_case)
+ policy_value, policies_dict = self._get_policy_data_for_case(case)
+ self._test_url_whitelist(policy_value, policies_dict)