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

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

Issue 10830053: [chromeos] Simplify chromeos device policy tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: relogin hack Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging 5 import logging
bartfab (slow) 2012/07/30 08:59:45 Nit: "logging" is no longer needed by this file
6 6
7 import pyauto_functional # Must come before pyauto (and thus, policy_base). 7 import pyauto_functional # Must come before pyauto (and thus, policy_base).
8 import policy_base 8 import policy_base
9 9
10 10
11 class ChromeosDevicePolicy(policy_base.PolicyTestBase): 11 class ChromeosDevicePolicy(policy_base.PolicyTestBase):
12 """Tests various ChromeOS device policies.""" 12 """Tests various ChromeOS device policies."""
13 13
14 # Cache user credentials for easy lookup. The first user will become the
15 # owner.
bartfab (slow) 2012/07/30 08:59:45 Nit: This comment is actually no longer true. Now
16 private_info = policy_base.PolicyTestBase.GetPrivateInfo()
17 credentials = (private_info['prod_enterprise_test_user'],
18 private_info['prod_enterprise_executive_user'],
19 private_info['prod_enterprise_sales_user'])
20 _usernames = [credential['username'] for credential in credentials]
21 _passwords = [credential['password'] for credential in credentials]
22
14 def LoginAsGuest(self): 23 def LoginAsGuest(self):
15 self.assertFalse(self.GetLoginInfo()['is_logged_in'], 24 self.assertFalse(self.GetLoginInfo()['is_logged_in'],
16 msg='Expected to be logged out.') 25 msg='Expected to be logged out.')
17 policy_base.PolicyTestBase.LoginAsGuest(self) 26 policy_base.PolicyTestBase.LoginAsGuest(self)
18 self.assertTrue(self.GetLoginInfo()['is_logged_in'], 27 self.assertTrue(self.GetLoginInfo()['is_logged_in'],
19 msg='Expected to be logged in.') 28 msg='Expected to be logged in.')
20 29
21 def Login(self, user_index, expect_success): 30 def Login(self, user_index, expect_success):
22 self.assertFalse(self.GetLoginInfo()['is_logged_in'], 31 self.assertFalse(self.GetLoginInfo()['is_logged_in'],
23 msg='Expected to be logged out.') 32 msg='Expected to be logged out.')
24 policy_base.PolicyTestBase.Login(self, 33 policy_base.PolicyTestBase.Login(self,
25 self._usernames[user_index], 34 self._usernames[user_index],
26 self._passwords[user_index]) 35 self._passwords[user_index])
27 if expect_success: 36 if expect_success:
28 self.assertTrue(self.GetLoginInfo()['is_logged_in'], 37 self.assertTrue(self.GetLoginInfo()['is_logged_in'],
29 msg='Expected to be logged in.') 38 msg='Expected to be logged in.')
30 else: 39 else:
31 self.assertFalse(self.GetLoginInfo()['is_logged_in'], 40 self.assertFalse(self.GetLoginInfo()['is_logged_in'],
32 msg='Expected to not be logged in.') 41 msg='Expected to not be logged in.')
33 42
34 # TODO(bartfab): Remove this after crosbug.com/20709 is fixed.
35 def TryToDisableLocalStateAutoClearing(self):
36 # Try to disable automatic clearing of the local state.
37 self.TryToDisableLocalStateAutoClearingOnChromeOS()
38 self._local_state_auto_clearing = \
39 self.IsLocalStateAutoClearingEnabledOnChromeOS()
40 if not self._local_state_auto_clearing:
41 # Prevent the inherited Logout() method from cleaning up /home/chronos
42 # as this also clears the local state.
43 self.set_clear_profile(False)
44
45 def ExtraChromeFlags(self):
46 """Sets up Chrome to skip OOBE.
47
48 TODO(bartfab): Ensure OOBE is still skipped when crosbug.com/20709 is fixed.
49 Disabling automatic clearing of the local state has the curious side effect
50 of removing a flag that disables OOBE. This method adds back the flag.
51 """
52 flags = policy_base.PolicyTestBase.ExtraChromeFlags(self)
53 flags.append('--login-screen=login')
54 return flags
55
56 def setUp(self):
57 policy_base.PolicyTestBase.setUp(self)
58 # TODO(bartfab): Remove this after crosbug.com/20709 is fixed.
59 self._local_state_auto_clearing = \
60 self.IsLocalStateAutoClearingEnabledOnChromeOS()
61
62 # Cache user credentials for easy lookup. The first user will become the
63 # owner.
64 credentials = (self.GetPrivateInfo()['prod_enterprise_test_user'],
65 self.GetPrivateInfo()['prod_enterprise_executive_user'],
66 self.GetPrivateInfo()['prod_enterprise_sales_user'])
67 self._usernames = [credential['username'] for credential in credentials]
68 self._passwords = [credential['password'] for credential in credentials]
69
70 def tearDown(self):
71 # TODO(bartfab): Remove this after crosbug.com/20709 is fixed.
72 # Try to re-enable automatic clearing of the local state and /home/chronos.
73 if not self._local_state_auto_clearing:
74 self.TryToEnableLocalStateAutoClearingOnChromeOS()
75 self.set_clear_profile(True)
76 policy_base.PolicyTestBase.tearDown(self)
77
78 def _CheckGuestModeAvailableInLoginWindow(self): 43 def _CheckGuestModeAvailableInLoginWindow(self):
79 return self.ExecuteJavascriptInOOBEWebUI( 44 return self.ExecuteJavascriptInOOBEWebUI(
80 """window.domAutomationController.send( 45 """window.domAutomationController.send(
81 !document.getElementById('guestSignin').hidden); 46 !document.getElementById('guestSignin').hidden);
82 """) 47 """)
83 48
84 def _CheckGuestModeAvailableInAccountPicker(self): 49 def _CheckGuestModeAvailableInAccountPicker(self):
85 return self.ExecuteJavascriptInOOBEWebUI( 50 return self.ExecuteJavascriptInOOBEWebUI(
86 """window.domAutomationController.send( 51 """window.domAutomationController.send(
87 !!document.getElementById('pod-row').getPodWithUsername_('')); 52 !!document.getElementById('pod-row').getPodWithUsername_(''));
(...skipping 18 matching lines...) Expand all
106 self.SetDevicePolicy({'guest_mode_enabled': True}) 71 self.SetDevicePolicy({'guest_mode_enabled': True})
107 self.assertTrue(self._CheckGuestModeAvailableInLoginWindow(), 72 self.assertTrue(self._CheckGuestModeAvailableInLoginWindow(),
108 msg='Expected guest mode to be available.') 73 msg='Expected guest mode to be available.')
109 self.LoginAsGuest() 74 self.LoginAsGuest()
110 self.Logout() 75 self.Logout()
111 76
112 self.SetDevicePolicy({'guest_mode_enabled': False}) 77 self.SetDevicePolicy({'guest_mode_enabled': False})
113 self.assertFalse(self._CheckGuestModeAvailableInLoginWindow(), 78 self.assertFalse(self._CheckGuestModeAvailableInLoginWindow(),
114 msg='Expected guest mode to not be available.') 79 msg='Expected guest mode to not be available.')
115 80
116 # TODO(bartfab): Remove this after crosbug.com/20709 is fixed.
117 self.TryToDisableLocalStateAutoClearing()
118 if self._local_state_auto_clearing:
119 logging.warn("""Unable to disable local state clearing. Skipping remainder
120 of test.""")
121 return
122
123 # Log in as a regular so that the pod row contains at least one pod and the 81 # Log in as a regular so that the pod row contains at least one pod and the
124 # account picker is shown. 82 # account picker is shown.
125 self.Login(user_index=0, expect_success=True) 83 self.Login(user_index=0, expect_success=True)
126 self.Logout() 84 self.Logout()
127 85
128 self.SetDevicePolicy({'guest_mode_enabled': True}) 86 self.SetDevicePolicy({'guest_mode_enabled': True})
129 self.assertTrue(self._CheckGuestModeAvailableInAccountPicker(), 87 self.assertTrue(self._CheckGuestModeAvailableInAccountPicker(),
130 msg='Expected guest mode to be available.') 88 msg='Expected guest mode to be available.')
131 self.LoginAsGuest() 89 self.LoginAsGuest()
132 self.Logout() 90 self.Logout()
133 91
134 self.SetDevicePolicy({'guest_mode_enabled': False}) 92 self.SetDevicePolicy({'guest_mode_enabled': False})
135 self.assertFalse(self._CheckGuestModeAvailableInAccountPicker(), 93 self.assertFalse(self._CheckGuestModeAvailableInAccountPicker(),
136 msg='Expected guest mode to not be available.') 94 msg='Expected guest mode to not be available.')
137 95
138 def testShowUserNamesOnSignin(self): 96 def testShowUserNamesOnSignin(self):
139 """Checks that the account picker can be enabled/disabled.""" 97 """Checks that the account picker can be enabled/disabled."""
140 # TODO(bartfab): Remove this after crosbug.com/20709 is fixed.
141 self.TryToDisableLocalStateAutoClearing()
142 if self._local_state_auto_clearing:
143 logging.warn('Unable to disable local state clearing. Skipping test.')
144 return
145
146 # Log in as a regular user so that the pod row contains at least one pod and 98 # Log in as a regular user so that the pod row contains at least one pod and
147 # the account picker can be shown. 99 # the account picker can be shown.
148 self.Login(user_index=0, expect_success=True) 100 self.Login(user_index=0, expect_success=True)
149 self.Logout() 101 self.Logout()
150 102
151 self.SetDevicePolicy({'show_user_names': False}) 103 self.SetDevicePolicy({'show_user_names': False})
152 self._WaitForLoginScreenId('gaia-signin') 104 self._WaitForLoginScreenId('gaia-signin')
153 105
154 self.SetDevicePolicy({'show_user_names': True}) 106 self.SetDevicePolicy({'show_user_names': True})
155 self._WaitForLoginScreenId('account-picker') 107 self._WaitForLoginScreenId('account-picker')
156 108
157 def testUserWhitelistAndAllowNewUsers(self): 109 def testUserWhitelistAndAllowNewUsers(self):
158 """Checks that login can be (dis)allowed by whitelist and allow-new-users. 110 """Checks that login can be (dis)allowed by whitelist and allow-new-users.
159 111
160 The test verifies that these two interrelated policies behave as documented 112 The test verifies that these two interrelated policies behave as documented
161 in the chrome/browser/policy/proto/chrome_device_policy.proto file. Cases 113 in the chrome/browser/policy/proto/chrome_device_policy.proto file. Cases
162 for which the current behavior is marked as "broken" are intentionally 114 for which the current behavior is marked as "broken" are intentionally
163 ommitted since the broken behavior should be fixed rather than protected by 115 ommitted since the broken behavior should be fixed rather than protected by
164 tests. 116 tests.
165 """ 117 """
118 # TODO(nirnimesh): Remove show_user_names policy below when
119 # Login() automation can reliably handle relogin scenario.
120 # crbug.com/139166
121
166 # No whitelist 122 # No whitelist
167 self.SetDevicePolicy({'allow_new_users': True}) 123 self.SetDevicePolicy({'allow_new_users': True,
124 'show_user_names': False})
168 self.Login(user_index=0, expect_success=True) 125 self.Login(user_index=0, expect_success=True)
169 self.Logout() 126 self.Logout()
170 127
171 # Empty whitelist 128 # Empty whitelist
172 self.SetDevicePolicy({'user_whitelist': []}) 129 self.SetDevicePolicy({'user_whitelist': []})
173 self.Login(user_index=0, expect_success=True) 130 self.Login(user_index=0, expect_success=True)
174 self.Logout() 131 self.Logout()
175 132
176 self.SetDevicePolicy({'allow_new_users': True, 133 self.SetDevicePolicy({'allow_new_users': True,
177 'user_whitelist': []}) 134 'user_whitelist': [],
135 'show_user_names': False})
178 self.Login(user_index=0, expect_success=True) 136 self.Login(user_index=0, expect_success=True)
179 self.Logout() 137 self.Logout()
180 138
181 # Populated whitelist 139 # Populated whitelist
182 self.SetDevicePolicy({'user_whitelist': [self._usernames[0]]}) 140 self.SetDevicePolicy({'user_whitelist': [self._usernames[0]],
141 'show_user_names': False})
183 self.Login(user_index=0, expect_success=True) 142 self.Login(user_index=0, expect_success=True)
184 self.Logout() 143 self.Logout()
185 self.Login(user_index=1, expect_success=False) 144 self.Login(user_index=1, expect_success=False)
186 145
187 self.SetDevicePolicy({'allow_new_users': True, 146 self.SetDevicePolicy({'allow_new_users': True,
188 'user_whitelist': [self._usernames[0]]}) 147 'user_whitelist': [self._usernames[0]],
148 'show_user_names': False})
189 self.Login(user_index=0, expect_success=True) 149 self.Login(user_index=0, expect_success=True)
190 self.Logout() 150 self.Logout()
191 self.Login(user_index=1, expect_success=True) 151 self.Login(user_index=1, expect_success=True)
192 self.Logout() 152 self.Logout()
193 153
194 # New users not allowed, populated whitelist 154 # New users not allowed, populated whitelist
195 self.SetDevicePolicy({'allow_new_users': False, 155 self.SetDevicePolicy({'allow_new_users': False,
196 'user_whitelist': [self._usernames[0]]}) 156 'user_whitelist': [self._usernames[0]],
157 'show_user_names': False})
197 self.Login(user_index=0, expect_success=True) 158 self.Login(user_index=0, expect_success=True)
198 self.Logout() 159 self.Logout()
199 self.Login(user_index=1, expect_success=False) 160 self.Login(user_index=1, expect_success=False)
200 161
201 def testUserWhitelistInAccountPicker(self): 162 def testUserWhitelistInAccountPicker(self):
202 """Checks that setting a whitelist removes non-whitelisted user pods.""" 163 """Checks that setting a whitelist removes non-whitelisted user pods."""
203 # TODO(bartfab): Remove this after crosbug.com/20709 is fixed.
204 self.TryToDisableLocalStateAutoClearing()
205 if self._local_state_auto_clearing:
206 logging.warn('Unable to disable local state clearing. Skipping test.')
207 return
208
209 # Disable the account picker so that the login form is shown and the Login() 164 # Disable the account picker so that the login form is shown and the Login()
210 # automation call can be used. 165 # automation call can be used.
211 self.PrepareToWaitForLoginFormReload() 166 self.PrepareToWaitForLoginFormReload()
212 self.SetDevicePolicy({'show_user_names': False}) 167 self.SetDevicePolicy({'show_user_names': False})
213 self.WaitForLoginFormReload() 168 self.WaitForLoginFormReload()
214 169
215 # Log in to populate the list of existing users. 170 # Log in to populate the list of existing users.
216 self.Login(user_index=0, expect_success=True) 171 self.Login(user_index=0, expect_success=True)
217 self.Logout() 172 self.Logout()
218 self.Login(user_index=1, expect_success=True) 173 self.Login(user_index=1, expect_success=True)
(...skipping 12 matching lines...) Expand all
231 self._WaitForPodVisibility(username=self._usernames[0], visible=False) 186 self._WaitForPodVisibility(username=self._usernames[0], visible=False)
232 self._WaitForPodVisibility(username=self._usernames[1], visible=True) 187 self._WaitForPodVisibility(username=self._usernames[1], visible=True)
233 188
234 self.SetDevicePolicy({'show_user_names': True}) 189 self.SetDevicePolicy({'show_user_names': True})
235 self._WaitForPodVisibility(username=self._usernames[0], visible=True) 190 self._WaitForPodVisibility(username=self._usernames[0], visible=True)
236 self._WaitForPodVisibility(username=self._usernames[1], visible=True) 191 self._WaitForPodVisibility(username=self._usernames[1], visible=True)
237 192
238 193
239 if __name__ == '__main__': 194 if __name__ == '__main__':
240 pyauto_functional.Main() 195 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « no previous file | chrome/test/pyautolib/chromeos/suid_actions.py » ('j') | chrome/test/pyautolib/chromeos/suid_actions.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698