OLD | NEW |
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 pyauto_functional # Must come before pyauto (and thus, policy_base). | 5 import pyauto_functional # Must come before pyauto (and thus, policy_base). |
6 import policy_base | 6 import policy_base |
7 | 7 |
8 | 8 |
9 class ChromeosDevicePolicy(policy_base.PolicyTestBase): | 9 class ChromeosDevicePolicy(policy_base.PolicyTestBase): |
10 """Tests various ChromeOS device policies.""" | 10 """Tests various ChromeOS device policies.""" |
11 | 11 |
12 # Cache user credentials for easy lookup. | 12 # Cache user credentials for easy lookup. |
13 private_info = policy_base.PolicyTestBase.GetPrivateInfo() | 13 private_info = policy_base.PolicyTestBase.GetPrivateInfo() |
14 credentials = (private_info['prod_enterprise_test_user'], | 14 credentials = (private_info['prod_enterprise_test_user'], |
15 private_info['prod_enterprise_executive_user'], | 15 private_info['prod_enterprise_executive_user'], |
16 private_info['prod_enterprise_sales_user']) | 16 private_info['prod_enterprise_sales_user']) |
17 _usernames = [credential['username'] for credential in credentials] | 17 _usernames = [credential['username'] for credential in credentials] |
18 _passwords = [credential['password'] for credential in credentials] | 18 _passwords = [credential['password'] for credential in credentials] |
19 | 19 |
20 def LoginAsGuest(self): | 20 def LoginAsGuest(self): |
21 self.assertFalse(self.GetLoginInfo()['is_logged_in'], | 21 self.assertFalse(self.GetLoginInfo()['is_logged_in'], |
22 msg='Expected to be logged out.') | 22 msg='Expected to be logged out.') |
23 policy_base.PolicyTestBase.LoginAsGuest(self) | 23 policy_base.PolicyTestBase.LoginAsGuest(self) |
24 self.assertTrue(self.GetLoginInfo()['is_logged_in'], | 24 self.assertTrue(self.GetLoginInfo()['is_logged_in'], |
25 msg='Expected to be logged in.') | 25 msg='Expected to be logged in.') |
26 | 26 |
27 def Login(self, user_index, expect_success): | 27 def _Login(self, user_index, expect_success): |
28 self.assertFalse(self.GetLoginInfo()['is_logged_in'], | 28 self.assertFalse(self.GetLoginInfo()['is_logged_in'], |
29 msg='Expected to be logged out.') | 29 msg='Expected to be logged out.') |
30 policy_base.PolicyTestBase.Login(self, | 30 policy_base.PolicyTestBase.Login(self, |
31 self._usernames[user_index], | 31 self._usernames[user_index], |
32 self._passwords[user_index]) | 32 self._passwords[user_index]) |
33 if expect_success: | 33 if expect_success: |
34 self.assertTrue(self.GetLoginInfo()['is_logged_in'], | 34 self.assertTrue(self.GetLoginInfo()['is_logged_in'], |
35 msg='Expected to be logged in.') | 35 msg='Expected to be logged in.') |
36 else: | 36 else: |
37 self.assertFalse(self.GetLoginInfo()['is_logged_in'], | 37 self.assertFalse(self.GetLoginInfo()['is_logged_in'], |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 msg='Expected guest mode to be available.') | 70 msg='Expected guest mode to be available.') |
71 self.LoginAsGuest() | 71 self.LoginAsGuest() |
72 self.Logout() | 72 self.Logout() |
73 | 73 |
74 self.SetDevicePolicy({'guest_mode_enabled': False}) | 74 self.SetDevicePolicy({'guest_mode_enabled': False}) |
75 self.assertFalse(self._CheckGuestModeAvailableInLoginWindow(), | 75 self.assertFalse(self._CheckGuestModeAvailableInLoginWindow(), |
76 msg='Expected guest mode to not be available.') | 76 msg='Expected guest mode to not be available.') |
77 | 77 |
78 # Log in as a regular so that the pod row contains at least one pod and the | 78 # Log in as a regular so that the pod row contains at least one pod and the |
79 # account picker is shown. | 79 # account picker is shown. |
80 self.Login(user_index=0, expect_success=True) | 80 self._Login(user_index=0, expect_success=True) |
81 self.Logout() | 81 self.Logout() |
82 | 82 |
83 self.SetDevicePolicy({'guest_mode_enabled': True}) | 83 self.SetDevicePolicy({'guest_mode_enabled': True}) |
84 self.assertTrue(self._CheckGuestModeAvailableInAccountPicker(), | 84 self.assertTrue(self._CheckGuestModeAvailableInAccountPicker(), |
85 msg='Expected guest mode to be available.') | 85 msg='Expected guest mode to be available.') |
86 self.LoginAsGuest() | 86 self.LoginAsGuest() |
87 self.Logout() | 87 self.Logout() |
88 | 88 |
89 self.SetDevicePolicy({'guest_mode_enabled': False}) | 89 self.SetDevicePolicy({'guest_mode_enabled': False}) |
90 self.assertFalse(self._CheckGuestModeAvailableInAccountPicker(), | 90 self.assertFalse(self._CheckGuestModeAvailableInAccountPicker(), |
91 msg='Expected guest mode to not be available.') | 91 msg='Expected guest mode to not be available.') |
92 | 92 |
93 def testShowUserNamesOnSignin(self): | 93 def testShowUserNamesOnSignin(self): |
94 """Checks that the account picker can be enabled/disabled.""" | 94 """Checks that the account picker can be enabled/disabled.""" |
95 # Log in as a regular user so that the pod row contains at least one pod and | 95 # Log in as a regular user so that the pod row contains at least one pod and |
96 # the account picker can be shown. | 96 # the account picker can be shown. |
97 self.Login(user_index=0, expect_success=True) | 97 self._Login(user_index=0, expect_success=True) |
98 self.Logout() | 98 self.Logout() |
99 | 99 |
100 self.SetDevicePolicy({'show_user_names': False}) | 100 self.SetDevicePolicy({'show_user_names': False}) |
101 self._WaitForLoginScreenId('gaia-signin') | 101 self._WaitForLoginScreenId('gaia-signin') |
102 | 102 |
103 self.SetDevicePolicy({'show_user_names': True}) | 103 self.SetDevicePolicy({'show_user_names': True}) |
104 self._WaitForLoginScreenId('account-picker') | 104 self._WaitForLoginScreenId('account-picker') |
105 | 105 |
106 def testUserWhitelistAndAllowNewUsers(self): | 106 def testUserWhitelistAndAllowNewUsers(self): |
107 """Checks that login can be (dis)allowed by whitelist and allow-new-users. | 107 """Checks that login can be (dis)allowed by whitelist and allow-new-users. |
108 | 108 |
109 The test verifies that these two interrelated policies behave as documented | 109 The test verifies that these two interrelated policies behave as documented |
110 in the chrome/browser/policy/proto/chrome_device_policy.proto file. Cases | 110 in the chrome/browser/policy/proto/chrome_device_policy.proto file. Cases |
111 for which the current behavior is marked as "broken" are intentionally | 111 for which the current behavior is marked as "broken" are intentionally |
112 ommitted since the broken behavior should be fixed rather than protected by | 112 ommitted since the broken behavior should be fixed rather than protected by |
113 tests. | 113 tests. |
114 """ | 114 """ |
115 # TODO(nirnimesh): Remove show_user_names policy below when | 115 # TODO(nirnimesh): Remove show_user_names policy below when |
116 # Login() automation can reliably handle relogin scenario. | 116 # Login() automation can reliably handle relogin scenario. |
117 # crbug.com/139166 | 117 # crbug.com/139166 |
118 | 118 |
119 # No whitelist | 119 # No whitelist |
120 self.SetDevicePolicy({'allow_new_users': True, | 120 self.SetDevicePolicy({'allow_new_users': True, |
121 'show_user_names': False}) | 121 'show_user_names': False}) |
122 self.Login(user_index=0, expect_success=True) | 122 self._Login(user_index=0, expect_success=True) |
123 self.Logout() | 123 self.Logout() |
124 | 124 |
125 # Empty whitelist | 125 # Empty whitelist |
126 self.SetDevicePolicy({'user_whitelist': []}) | 126 self.SetDevicePolicy({'user_whitelist': []}) |
127 self.Login(user_index=0, expect_success=True) | 127 self._Login(user_index=0, expect_success=True) |
128 self.Logout() | 128 self.Logout() |
129 | 129 |
130 self.SetDevicePolicy({'allow_new_users': True, | 130 self.SetDevicePolicy({'allow_new_users': True, |
131 'user_whitelist': [], | 131 'user_whitelist': [], |
132 'show_user_names': False}) | 132 'show_user_names': False}) |
133 self.Login(user_index=0, expect_success=True) | 133 self._Login(user_index=0, expect_success=True) |
134 self.Logout() | 134 self.Logout() |
135 | 135 |
136 # Populated whitelist | 136 # Populated whitelist |
137 self.SetDevicePolicy({'user_whitelist': [self._usernames[0]], | 137 self.SetDevicePolicy({'user_whitelist': [self._usernames[0]], |
138 'show_user_names': False}) | 138 'show_user_names': False}) |
139 self.Login(user_index=0, expect_success=True) | 139 self._Login(user_index=0, expect_success=True) |
140 self.Logout() | 140 self.Logout() |
141 self.Login(user_index=1, expect_success=False) | 141 self._Login(user_index=1, expect_success=False) |
142 | 142 |
143 self.SetDevicePolicy({'allow_new_users': True, | 143 self.SetDevicePolicy({'allow_new_users': True, |
144 'user_whitelist': [self._usernames[0]], | 144 'user_whitelist': [self._usernames[0]], |
145 'show_user_names': False}) | 145 'show_user_names': False}) |
146 self.Login(user_index=0, expect_success=True) | 146 self._Login(user_index=0, expect_success=True) |
147 self.Logout() | 147 self.Logout() |
148 self.Login(user_index=1, expect_success=True) | 148 self._Login(user_index=1, expect_success=True) |
149 self.Logout() | 149 self.Logout() |
150 | 150 |
151 # New users not allowed, populated whitelist | 151 # New users not allowed, populated whitelist |
152 self.SetDevicePolicy({'allow_new_users': False, | 152 self.SetDevicePolicy({'allow_new_users': False, |
153 'user_whitelist': [self._usernames[0]], | 153 'user_whitelist': [self._usernames[0]], |
154 'show_user_names': False}) | 154 'show_user_names': False}) |
155 self.Login(user_index=0, expect_success=True) | 155 self._Login(user_index=0, expect_success=True) |
156 self.Logout() | 156 self.Logout() |
157 self.Login(user_index=1, expect_success=False) | 157 self._Login(user_index=1, expect_success=False) |
158 | 158 |
159 def testUserWhitelistInAccountPicker(self): | 159 def testUserWhitelistInAccountPicker(self): |
160 """Checks that setting a whitelist removes non-whitelisted user pods.""" | 160 """Checks that setting a whitelist removes non-whitelisted user pods.""" |
161 # Disable the account picker so that the login form is shown and the Login() | 161 # Disable the account picker so that the login form is shown and the Login() |
162 # automation call can be used. | 162 # automation call can be used. |
163 self.PrepareToWaitForLoginFormReload() | 163 self.PrepareToWaitForLoginFormReload() |
164 self.SetDevicePolicy({'show_user_names': False}) | 164 self.SetDevicePolicy({'show_user_names': False}) |
165 self.WaitForLoginFormReload() | 165 self.WaitForLoginFormReload() |
166 | 166 |
167 # Log in to populate the list of existing users. | 167 # Log in to populate the list of existing users. |
168 self.Login(user_index=0, expect_success=True) | 168 self._Login(user_index=0, expect_success=True) |
169 self.Logout() | 169 self.Logout() |
170 self.Login(user_index=1, expect_success=True) | 170 self._Login(user_index=1, expect_success=True) |
171 self.Logout() | 171 self.Logout() |
172 | 172 |
173 # Enable the account picker. | 173 # Enable the account picker. |
174 self.SetDevicePolicy({'show_user_names': True}) | 174 self.SetDevicePolicy({'show_user_names': True}) |
175 self._WaitForLoginScreenId('account-picker') | 175 self._WaitForLoginScreenId('account-picker') |
176 | 176 |
177 # Check pod visibility with and without a whitelist. | 177 # Check pod visibility with and without a whitelist. |
178 self._WaitForPodVisibility(username=self._usernames[0], visible=True) | 178 self._WaitForPodVisibility(username=self._usernames[0], visible=True) |
179 self._WaitForPodVisibility(username=self._usernames[1], visible=True) | 179 self._WaitForPodVisibility(username=self._usernames[1], visible=True) |
180 | 180 |
181 self.SetDevicePolicy({'show_user_names': True, | 181 self.SetDevicePolicy({'show_user_names': True, |
182 'user_whitelist': [self._usernames[1]]}) | 182 'user_whitelist': [self._usernames[1]]}) |
183 self._WaitForPodVisibility(username=self._usernames[0], visible=False) | 183 self._WaitForPodVisibility(username=self._usernames[0], visible=False) |
184 self._WaitForPodVisibility(username=self._usernames[1], visible=True) | 184 self._WaitForPodVisibility(username=self._usernames[1], visible=True) |
185 | 185 |
186 self.SetDevicePolicy({'show_user_names': True}) | 186 self.SetDevicePolicy({'show_user_names': True}) |
187 self._WaitForPodVisibility(username=self._usernames[0], visible=True) | 187 self._WaitForPodVisibility(username=self._usernames[0], visible=True) |
188 self._WaitForPodVisibility(username=self._usernames[1], visible=True) | 188 self._WaitForPodVisibility(username=self._usernames[1], visible=True) |
189 | 189 |
190 | 190 |
191 if __name__ == '__main__': | 191 if __name__ == '__main__': |
192 pyauto_functional.Main() | 192 pyauto_functional.Main() |
OLD | NEW |