1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import pyauto_functional # Must come before pyauto (and thus, policy_base).
import policy_base
class ChromeosDevicePolicy(policy_base.PolicyTestBase):
"""Tests various ChromeOS device policies."""
# Cache user credentials for easy lookup.
private_info = policy_base.PolicyTestBase.GetPrivateInfo()
credentials = (private_info['prod_enterprise_test_user'],
private_info['prod_enterprise_executive_user'],
private_info['prod_enterprise_sales_user'])
_usernames = [credential['username'] for credential in credentials]
_passwords = [credential['password'] for credential in credentials]
def LoginAsGuest(self):
self.assertFalse(self.GetLoginInfo()['is_logged_in'],
msg='Expected to be logged out.')
policy_base.PolicyTestBase.LoginAsGuest(self)
self.assertTrue(self.GetLoginInfo()['is_logged_in'],
msg='Expected to be logged in.')
def _Login(self, user_index, expect_success):
self.assertFalse(self.GetLoginInfo()['is_logged_in'],
msg='Expected to be logged out.')
policy_base.PolicyTestBase.Login(self,
self._usernames[user_index],
self._passwords[user_index])
if expect_success:
self.assertTrue(self.GetLoginInfo()['is_logged_in'],
msg='Expected to be logged in.')
else:
self.assertFalse(self.GetLoginInfo()['is_logged_in'],
msg='Expected to not be logged in.')
def _CheckGuestModeAvailableInLoginWindow(self):
return self.ExecuteJavascriptInOOBEWebUI(
"""window.domAutomationController.send(
!document.getElementById('guestSignin').hidden);
""")
def _CheckGuestModeAvailableInAccountPicker(self):
return self.ExecuteJavascriptInOOBEWebUI(
"""window.domAutomationController.send(
!!document.getElementById('pod-row').getPodWithUsername_(''));
""")
def _CheckPodVisible(self, username):
javascript = """
var pod = document.getElementById('pod-row').getPodWithUsername_('%s');
window.domAutomationController.send(!!pod && !pod.hidden);
"""
return self.ExecuteJavascriptInOOBEWebUI(javascript % username)
def _WaitForPodVisibility(self, username, visible):
self.assertTrue(
self.WaitUntil(function=lambda: self._CheckPodVisible(username),
expect_retval=visible),
msg='Expected pod for user %s to %s be visible.' %
(username, '' if visible else 'not'))
def testGuestModeEnabled(self):
"""Checks that guest mode login can be enabled/disabled."""
self.SetDevicePolicy({'guest_mode_enabled': True})
self.assertTrue(self._CheckGuestModeAvailableInLoginWindow(),
msg='Expected guest mode to be available.')
self.LoginAsGuest()
self.Logout()
self.SetDevicePolicy({'guest_mode_enabled': False})
self.assertFalse(self._CheckGuestModeAvailableInLoginWindow(),
msg='Expected guest mode to not be available.')
# Log in as a regular so that the pod row contains at least one pod and the
# account picker is shown.
self._Login(user_index=0, expect_success=True)
self.Logout()
self.SetDevicePolicy({'guest_mode_enabled': True})
self.assertTrue(self._CheckGuestModeAvailableInAccountPicker(),
msg='Expected guest mode to be available.')
self.LoginAsGuest()
self.Logout()
self.SetDevicePolicy({'guest_mode_enabled': False})
self.assertFalse(self._CheckGuestModeAvailableInAccountPicker(),
msg='Expected guest mode to not be available.')
def testShowUserNamesOnSignin(self):
"""Checks that the account picker can be enabled/disabled."""
# Log in as a regular user so that the pod row contains at least one pod and
# the account picker can be shown.
self._Login(user_index=0, expect_success=True)
self.Logout()
self.SetDevicePolicy({'show_user_names': False})
self._WaitForLoginScreenId('gaia-signin')
self.SetDevicePolicy({'show_user_names': True})
self._WaitForLoginScreenId('account-picker')
def testUserWhitelistAndAllowNewUsers(self):
"""Checks that login can be (dis)allowed by whitelist and allow-new-users.
The test verifies that these two interrelated policies behave as documented
in the chrome/browser/policy/proto/chrome_device_policy.proto file. Cases
for which the current behavior is marked as "broken" are intentionally
ommitted since the broken behavior should be fixed rather than protected by
tests.
"""
# No whitelist
self.SetDevicePolicy({'allow_new_users': True})
self._Login(user_index=0, expect_success=True)
self.Logout()
# Empty whitelist
self.SetDevicePolicy({'user_whitelist': []})
self._Login(user_index=0, expect_success=True)
self.Logout()
self.SetDevicePolicy({'allow_new_users': True,
'user_whitelist': []})
self._Login(user_index=0, expect_success=True)
self.Logout()
# Populated whitelist
self.SetDevicePolicy({'user_whitelist': [self._usernames[0]]})
self._Login(user_index=0, expect_success=True)
self.Logout()
self._Login(user_index=1, expect_success=False)
self.SetDevicePolicy({'allow_new_users': True,
'user_whitelist': [self._usernames[0]]})
self._Login(user_index=0, expect_success=True)
self.Logout()
self._Login(user_index=1, expect_success=True)
self.Logout()
# New users not allowed, populated whitelist
self.SetDevicePolicy({'allow_new_users': False,
'user_whitelist': [self._usernames[0]]})
self._Login(user_index=0, expect_success=True)
self.Logout()
self._Login(user_index=1, expect_success=False)
def testUserWhitelistInAccountPicker(self):
"""Checks that setting a whitelist removes non-whitelisted user pods."""
# Disable the account picker so that the login form is shown and the Login()
# automation call can be used.
self.PrepareToWaitForLoginFormReload()
self.SetDevicePolicy({'show_user_names': False})
self.WaitForLoginFormReload()
# Log in to populate the list of existing users.
self._Login(user_index=0, expect_success=True)
self.Logout()
self._Login(user_index=1, expect_success=True)
self.Logout()
# Enable the account picker.
self.SetDevicePolicy({'show_user_names': True})
self._WaitForLoginScreenId('account-picker')
# Check pod visibility with and without a whitelist.
self._WaitForPodVisibility(username=self._usernames[0], visible=True)
self._WaitForPodVisibility(username=self._usernames[1], visible=True)
self.SetDevicePolicy({'show_user_names': True,
'user_whitelist': [self._usernames[1]]})
self._WaitForPodVisibility(username=self._usernames[0], visible=False)
self._WaitForPodVisibility(username=self._usernames[1], visible=True)
self.SetDevicePolicy({'show_user_names': True})
self._WaitForPodVisibility(username=self._usernames[0], visible=True)
self._WaitForPodVisibility(username=self._usernames[1], visible=True)
_timezones = ['America/Barbados', 'Europe/Helsinki']
def testTimezoneSettingWithoutPolicy(self):
"""Without timezone policy, timezone changes by user are persistent."""
self.SetDevicePolicy(refresh=False)
for timezone in self._timezones:
self._Login(user_index=1, expect_success=True)
self.SetTimezone(timezone)
self.assertEqual(timezone, self.GetTimeInfo()['timezone'])
self.Logout()
self.assertEqual(timezone, self.GetTimeInfo()['timezone'])
def testTimezoneSettingWithPolicy(self):
"""With timezone policy, timezone changes by user are reset on logout."""
self.SetDevicePolicy({'timezone': self._timezones[0]}, refresh=True)
# Timezones are set on startup, i.e. everytime when loading the login
# screen. Something like a browser restart may work, too.
self._Login(user_index=1, expect_success=True)
self.Logout()
self.assertEqual(self._timezones[0], self.GetTimeInfo()['timezone'])
self._Login(user_index=1, expect_success=True)
self.SetTimezone(self._timezones[1])
self.assertEqual(self._timezones[1], self.GetTimeInfo()['timezone'])
self.Logout()
self.assertEqual(self._timezones[0], self.GetTimeInfo()['timezone'])
if __name__ == '__main__':
pyauto_functional.Main()
|