Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: chrome/test/functional/policy_prefs_ui.py

Issue 9791023: Allow setting of user and device policies in functional tests (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Comments addressed. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/functional/policy.py ('k') | chrome/test/functional/policy_test_cases.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 # If this test is failing, please check these steps. 6 # If this test is failing, please check these steps.
7 # 7 #
8 # - You introduced a new policy: 8 # - You introduced a new policy:
9 # Cool! Edit |policies| in policy_test_cases.py and add an entry for it. 9 # Cool! Edit |policies| in policy_test_cases.py and add an entry for it.
10 # See the comment above it for the format. 10 # See the comment above it for the format.
(...skipping 10 matching lines...) Expand all
21 import logging 21 import logging
22 22
23 import pyauto_functional # must come before pyauto. 23 import pyauto_functional # must come before pyauto.
24 import policy_base 24 import policy_base
25 import pyauto 25 import pyauto
26 26
27 from policy_test_cases import PolicyPrefsTestCases 27 from policy_test_cases import PolicyPrefsTestCases
28 28
29 29
30 class PolicyPrefsUITest(policy_base.PolicyTestBase): 30 class PolicyPrefsUITest(policy_base.PolicyTestBase):
31 """Tests policies and their impact on the prefs UI.""" 31 """Tests user policies and their impact on the prefs UI."""
32 32
33 settings_pages = [ 33 settings_pages = [
34 'chrome://settings-frame', 34 'chrome://settings-frame',
35 'chrome://settings-frame/searchEngines', 35 'chrome://settings-frame/searchEngines',
36 'chrome://settings-frame/passwords', 36 'chrome://settings-frame/passwords',
37 'chrome://settings-frame/autofill', 37 'chrome://settings-frame/autofill',
38 'chrome://settings-frame/content', 38 'chrome://settings-frame/content',
39 'chrome://settings-frame/homePageOverlay', 39 'chrome://settings-frame/homePageOverlay',
40 'chrome://settings-frame/languages', 40 'chrome://settings-frame/languages',
41 ] 41 ]
42 if pyauto.PyUITest.IsChromeOS(): 42 if pyauto.PyUITest.IsChromeOS():
43 settings_pages += [ 43 settings_pages += [
44 'chrome://settings-frame/accounts', 44 'chrome://settings-frame/accounts',
45 ] 45 ]
46 46
47 def setUp(self):
48 policy_base.PolicyTestBase.setUp(self)
49 if self.IsChromeOS():
50 self.LoginWithTestAccount()
47 51
48 def IsAnyBannerVisible(self): 52 def IsAnyBannerVisible(self):
49 """Returns true if any managed prefs banner is visible in the current page. 53 """Returns true if any managed prefs banner is visible in the current page.
50 """ 54 """
51 ret = self.ExecuteJavascript(""" 55 ret = self.ExecuteJavascript("""
52 var visible = false; 56 var visible = false;
53 var banners = document.querySelectorAll('.managed-prefs-banner'); 57 var banners = document.querySelectorAll('.managed-prefs-banner');
54 for (var i=0; i<banners.length; i++) { 58 for (var i=0; i<banners.length; i++) {
55 if (banners[i].parentElement.id == 'templates') 59 if (banners[i].parentElement.id == 'templates')
56 continue; 60 continue;
57 61
58 if (window.getComputedStyle(banners[i]).display != 'none') 62 if (window.getComputedStyle(banners[i]).display != 'none')
59 visible = true; 63 visible = true;
60 } 64 }
61 domAutomationController.send(visible.toString()); 65 domAutomationController.send(visible.toString());
62 """) 66 """)
63 return ret == 'true' 67 return ret == 'true'
64 68
65 def testNoPoliciesNoBanner(self): 69 def testNoUserPoliciesNoBanner(self):
66 """Verifies that the banner isn't present when no policies are in place.""" 70 """Verifies the banner isn't present when no user policies are in place."""
67 71
68 self.SetPolicies({}) 72 self.SetUserPolicy({})
69 for page in PolicyPrefsUITest.settings_pages: 73 for page in PolicyPrefsUITest.settings_pages:
70 self.NavigateToURL(page) 74 self.NavigateToURL(page)
71 self.assertFalse(self.IsAnyBannerVisible(), msg= 75 self.assertFalse(self.IsAnyBannerVisible(), msg=
72 'Unexpected banner in %s.\n' 76 'Unexpected banner in %s.\n'
73 'Please check that chrome/test/functional/policy_prefs_ui.py has an ' 77 'Please check that chrome/test/functional/policy_prefs_ui.py has an '
74 'entry for any new policies introduced.' % page) 78 'entry for any new policies introduced.' % page)
75 79
76 def RunPoliciesShowBanner(self, include_expected, include_unexpected): 80 def RunUserPoliciesShowBanner(self, include_expected, include_unexpected):
77 """Tests all the policies on each settings page. 81 """Tests all the user policies on each settings page.
78 82
79 If |include_expected|, pages where the banner is expected will be verified. 83 If |include_expected|, pages where the banner is expected will be verified.
80 If |include_unexpected|, pages where the banner should not appear will also 84 If |include_unexpected|, pages where the banner should not appear will also
81 be verified. This can take some time. 85 be verified. This can take some time.
82 """ 86 """
83 87
84 os = self.GetPlatform() 88 os = self.GetPlatform()
89 all_policies = self.GetPolicyDefinitionList()
85 90
86 for policy, policy_test in PolicyPrefsTestCases.policies.iteritems(): 91 for policy, policy_test in PolicyPrefsTestCases.policies.iteritems():
92 # Skip device policies
93 if policy in all_policies and all_policies[policy][1]:
94 continue
87 if os not in policy_test[PolicyPrefsTestCases.INDEX_OS]: 95 if os not in policy_test[PolicyPrefsTestCases.INDEX_OS]:
88 continue 96 continue
89 expected_pages = [PolicyPrefsUITest.settings_pages[n] 97 expected_pages = [PolicyPrefsUITest.settings_pages[n]
90 for n in policy_test[PolicyPrefsTestCases.INDEX_PAGES]] 98 for n in policy_test[PolicyPrefsTestCases.INDEX_PAGES]]
91 did_test = False 99 did_test = False
92 for page in PolicyPrefsUITest.settings_pages: 100 for page in PolicyPrefsUITest.settings_pages:
93 expected = page in expected_pages 101 expected = page in expected_pages
94 if expected and not include_expected: 102 if expected and not include_expected:
95 continue 103 continue
96 if not expected and not include_unexpected: 104 if not expected and not include_unexpected:
97 continue 105 continue
98 if not did_test: 106 if not did_test:
99 did_test = True 107 did_test = True
100 policy_dict = { 108 policy_dict = {
101 policy: policy_test[PolicyPrefsTestCases.INDEX_VALUE] 109 policy: policy_test[PolicyPrefsTestCases.INDEX_VALUE]
102 } 110 }
103 self.SetPolicies(policy_dict) 111 self.SetUserPolicy(policy_dict)
104 self.NavigateToURL(page) 112 self.NavigateToURL(page)
105 self.assertEqual(expected, self.IsAnyBannerVisible(), msg= 113 self.assertEqual(expected, self.IsAnyBannerVisible(), msg=
106 'Banner was%sexpected in %s, but it was%svisible.\n' 114 'Banner was%sexpected in %s, but it was%svisible.\n'
107 'The policy tested was "%s".\n' 115 'The policy tested was "%s".\n'
108 'Please check that chrome/test/functional/policy_prefs_ui.py has ' 116 'Please check that chrome/test/functional/policy_prefs_ui.py has '
109 'an entry for any new policies introduced.' % 117 'an entry for any new policies introduced.' %
110 (expected and ' ' or ' NOT ', page, expected and ' NOT ' or ' ', 118 (expected and ' ' or ' NOT ', page, expected and ' NOT ' or ' ',
111 policy)) 119 policy))
112 if did_test: 120 if did_test:
113 logging.debug('Policy passed: %s' % policy) 121 logging.debug('Policy passed: %s' % policy)
114 122
115 def testPoliciesShowBanner(self): 123 def testUserPoliciesShowBanner(self):
116 """Verifies that the banner is shown when a pref is managed by policy.""" 124 """Verifies the banner is shown when a user pref is managed by policy."""
117 self.RunPoliciesShowBanner(True, False) 125 self.RunUserPoliciesShowBanner(True, False)
118 126
119 # This test is disabled by default because it takes a very long time, 127 # This test is disabled by default because it takes a very long time,
120 # for little benefit. 128 # for little benefit.
121 def PoliciesDontShowBanner(self): 129 def UserPoliciesDontShowBanner(self):
122 """Verifies that the banner is NOT shown on unrelated pages.""" 130 """Verifies that the banner is NOT shown on unrelated pages."""
123 self.RunPoliciesShowBanner(False, True) 131 self.RunUserPoliciesShowBanner(False, True)
124 132
125 def testFailOnPoliciesNotTested(self): 133 def testFailOnUserPoliciesNotTested(self):
126 """Verifies that all existing policies are covered. 134 """Verifies that all existing user policies are covered.
127 135
128 Fails for all policies listed in GetPolicyDefinitionList() that aren't 136 Fails for all user policies listed in GetPolicyDefinitionList() that aren't
129 listed in |PolicyPrefsUITest.policies|, and thus are not tested by 137 listed in |PolicyPrefsUITest.policies|, and thus are not tested by
130 |testPoliciesShowBanner|. 138 |testUserPoliciesShowBanner|.
131 """ 139 """
132 140
133 all_policies = self.GetPolicyDefinitionList() 141 all_policies = self.GetPolicyDefinitionList()
134 for policy in all_policies: 142 for policy in all_policies:
143 # Skip device policies
144 if all_policies[policy][1]:
145 continue
135 self.assertTrue(policy in PolicyPrefsTestCases.policies, msg= 146 self.assertTrue(policy in PolicyPrefsTestCases.policies, msg=
136 'Policy "%s" does not have a test in ' 147 'Policy "%s" does not have a test in '
137 'chrome/test/functional/policy_prefs_ui.py.\n' 148 'chrome/test/functional/policy_prefs_ui.py.\n'
138 'Please edit the file and add an entry for this policy.' % policy) 149 'Please edit the file and add an entry for this policy.' % policy)
139 test_type = type(PolicyPrefsTestCases.policies[policy] 150 test_type = type(PolicyPrefsTestCases.policies[policy]
140 [PolicyPrefsTestCases.INDEX_VALUE]).__name__ 151 [PolicyPrefsTestCases.INDEX_VALUE]).__name__
141 expected_type = all_policies[policy][0] 152 expected_type = all_policies[policy][0]
142 self.assertEqual(expected_type, test_type, msg= 153 self.assertEqual(expected_type, test_type, msg=
143 'Policy "%s" has type "%s" but the test value has type "%s".' % 154 'Policy "%s" has type "%s" but the test value has type "%s".' %
144 (policy, expected_type, test_type)) 155 (policy, expected_type, test_type))
145 156
146 def testTogglePolicyTogglesBanner(self): 157 def testToggleUserPolicyTogglesBanner(self):
147 """Verifies that toggling a policy also toggles the banner's visibility.""" 158 """Verifies that toggling a user policy toggles the banner's visibility."""
148 # |policy| just has to be any policy that has at least a settings page that 159 # |policy| just has to be any user policy that has at least a settings page
149 # displays the banner when the policy is set. 160 # that displays the banner when the policy is set.
150 policy = 'ShowHomeButton' 161 policy = 'ShowHomeButton'
151 162
152 policy_test = PolicyPrefsTestCases.policies[policy] 163 policy_test = PolicyPrefsTestCases.policies[policy]
153 page = PolicyPrefsUITest.settings_pages[ 164 page = PolicyPrefsUITest.settings_pages[
154 policy_test[PolicyPrefsTestCases.INDEX_PAGES][0]] 165 policy_test[PolicyPrefsTestCases.INDEX_PAGES][0]]
155 policy_dict = { 166 policy_dict = {
156 policy: policy_test[PolicyPrefsTestCases.INDEX_VALUE] 167 policy: policy_test[PolicyPrefsTestCases.INDEX_VALUE]
157 } 168 }
158 169
159 self.SetPolicies({}) 170 self.SetUserPolicy({})
160 self.NavigateToURL(page) 171 self.NavigateToURL(page)
161 self.assertFalse(self.IsAnyBannerVisible()) 172 self.assertFalse(self.IsAnyBannerVisible())
162 173
163 self.SetPolicies(policy_dict) 174 self.SetUserPolicy(policy_dict)
164 self.assertTrue(self.IsAnyBannerVisible()) 175 self.assertTrue(self.IsAnyBannerVisible())
165 176
166 self.SetPolicies({}) 177 self.SetUserPolicy({})
167 self.assertFalse(self.IsAnyBannerVisible()) 178 self.assertFalse(self.IsAnyBannerVisible())
168 179
169 180
170 if __name__ == '__main__': 181 if __name__ == '__main__':
171 pyauto_functional.Main() 182 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/policy.py ('k') | chrome/test/functional/policy_test_cases.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698