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

Side by Side Diff: chrome/browser/chromeos/login/login_browsertest.cc

Issue 2737733003: Add Active Directory login UI tests (Closed)
Patch Set: Rebase Created 3 years, 9 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
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 #include <string> 5 #include <string>
6 6
7 #include "ash/common/shelf/wm_shelf.h" 7 #include "ash/common/shelf/wm_shelf.h"
8 #include "ash/common/system/tray/system_tray.h" 8 #include "ash/common/system/tray/system_tray.h"
9 #include "ash/common/wm_window.h" 9 #include "ash/common/wm_window.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/chromeos/login/login_manager_test.h" 18 #include "chrome/browser/chromeos/login/login_manager_test.h"
18 #include "chrome/browser/chromeos/login/login_wizard.h" 19 #include "chrome/browser/chromeos/login/login_wizard.h"
19 #include "chrome/browser/chromeos/login/startup_utils.h" 20 #include "chrome/browser/chromeos/login/startup_utils.h"
21 #include "chrome/browser/chromeos/login/test/js_checker.h"
20 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" 22 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
21 #include "chrome/browser/chromeos/login/wizard_controller.h" 23 #include "chrome/browser/chromeos/login/wizard_controller.h"
22 #include "chrome/browser/chromeos/settings/cros_settings.h" 24 #include "chrome/browser/chromeos/settings/cros_settings.h"
25 #include "chrome/browser/chromeos/settings/stub_install_attributes.h"
23 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/profiles/profiles_state.h" 27 #include "chrome/browser/profiles/profiles_state.h"
25 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
26 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
27 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/grit/generated_resources.h"
28 #include "chrome/test/base/in_process_browser_test.h" 32 #include "chrome/test/base/in_process_browser_test.h"
29 #include "chrome/test/base/interactive_test_utils.h" 33 #include "chrome/test/base/interactive_test_utils.h"
30 #include "chromeos/chromeos_switches.h" 34 #include "chromeos/chromeos_switches.h"
35 #include "chromeos/dbus/dbus_thread_manager.h"
36 #include "chromeos/dbus/fake_auth_policy_client.h"
31 #include "chromeos/settings/cros_settings_names.h" 37 #include "chromeos/settings/cros_settings_names.h"
32 #include "components/signin/core/account_id/account_id.h" 38 #include "components/signin/core/account_id/account_id.h"
33 #include "components/user_manager/user_names.h" 39 #include "components/user_manager/user_names.h"
34 #include "content/public/test/browser_test_utils.h" 40 #include "content/public/test/browser_test_utils.h"
35 #include "content/public/test/test_utils.h" 41 #include "content/public/test/test_utils.h"
36 #include "extensions/browser/extension_system.h" 42 #include "extensions/browser/extension_system.h"
37 #include "testing/gmock/include/gmock/gmock.h" 43 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
45 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/gfx/geometry/test/rect_test_util.h" 46 #include "ui/gfx/geometry/test/rect_test_util.h"
40 47
41 using ::gfx::test::RectContains; 48 using ::gfx::test::RectContains;
42 using ::testing::_; 49 using ::testing::_;
43 using ::testing::AnyNumber; 50 using ::testing::AnyNumber;
44 using ::testing::Return; 51 using ::testing::Return;
45 52
46 namespace chromeos { 53 namespace chromeos {
47 namespace { 54 namespace {
48 55
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 179
173 StartGaiaAuthOffline(); 180 StartGaiaAuthOffline();
174 181
175 UserContext user_context( 182 UserContext user_context(
176 AccountId::FromUserEmailGaiaId(kTestUser, kGaiaId)); 183 AccountId::FromUserEmailGaiaId(kTestUser, kGaiaId));
177 user_context.SetKey(Key(kPassword)); 184 user_context.SetKey(Key(kPassword));
178 SetExpectedCredentials(user_context); 185 SetExpectedCredentials(user_context);
179 } 186 }
180 }; 187 };
181 188
189 const char kDeviceId[] = "device_id";
190 const char kTestRealm[] = "test_realm.com";
191 const char kTestActiveDirectoryUser[] = "test-user";
192 const char kAdMachineInput[] = "machineNameInput";
193 const char kAdUserInput[] = "userInput";
194 const char kAdPasswordInput[] = "passwordInput";
195 const char kAdButton[] = "button";
196 const char kAdWelcomMessage[] = "welcomeMsg";
197 const char kAdAutocompleteRealm[] = "userInput /deep/ #domainLabel";
198
199 class ActiveDirectoryLoginTest : public LoginManagerTest {
200 public:
201 ActiveDirectoryLoginTest()
202 : LoginManagerTest(true),
203 install_attributes_(
204 ScopedStubInstallAttributes::CreateActiveDirectoryManaged(
205 kTestRealm,
206 kDeviceId)) {}
207
208 ~ActiveDirectoryLoginTest() override = default;
209
210 void SetUpCommandLine(base::CommandLine* command_line) override {
211 command_line->AppendSwitch(switches::kOobeSkipPostLogin);
212 LoginManagerTest::SetUpCommandLine(command_line);
213 }
214
215 void SetUpOnMainThread() override {
216 LoginManagerTest::SetUpOnMainThread();
217 fake_auth_policy_client_ = static_cast<FakeAuthPolicyClient*>(
218 DBusThreadManager::Get()->GetAuthPolicyClient());
219 }
220
221 void MarkAsActiveDirectoryEnterprise() {
222 StartupUtils::MarkOobeCompleted();
223 base::RunLoop loop;
224 fake_auth_policy_client_->RefreshDevicePolicy(
225 base::Bind(&ActiveDirectoryLoginTest::OnRefreshedPolicy,
226 base::Unretained(this), loop.QuitClosure()));
227 loop.Run();
228 }
229
230 // Checks if Active Directory login is visible.
231 void TestLoginVisible() {
232 // Checks if Gaia signin is hidden.
233 JSExpect("document.querySelector('#signin-frame').hidden");
234
235 // Checks if Active Directory signin is visible.
236 JSExpect("!document.querySelector('#offline-ad-auth').hidden");
237 JSExpect(JSElement(kAdMachineInput) + ".hidden");
238 JSExpect("!" + JSElement(kAdUserInput) + ".hidden");
239 JSExpect("!" + JSElement(kAdPasswordInput) + ".hidden");
240
241 const std::string innerText(".innerText");
242 // Checks if Active Directory welcome message contains realm.
243 EXPECT_EQ(l10n_util::GetStringFUTF8(IDS_AD_DOMAIN_AUTH_WELCOME_MESSAGE,
244 base::UTF8ToUTF16(kTestRealm)),
245 js_checker().GetString(JSElement(kAdWelcomMessage) + innerText));
246
247 // Checks if realm is set to autocomplete username.
248 EXPECT_EQ(
249 "@" + std::string(kTestRealm),
250 js_checker().GetString(JSElement(kAdAutocompleteRealm) + innerText));
251
252 // Checks if bottom bar is visible.
253 JSExpect("!Oobe.getInstance().headerHidden");
254 }
255
256 // Checks if user input is marked as invalid.
257 void TestUserError() {
258 TestLoginVisible();
259 JSExpect(JSElement(kAdUserInput) + ".isInvalid");
260 }
261
262 // Checks if password input is marked as invalid.
263 void TestPasswordError() {
264 TestLoginVisible();
265 JSExpect(JSElement(kAdPasswordInput) + ".isInvalid");
266 }
267
268 // Checks if autocomplete domain is visible for the user input.
269 void TestDomainVisible() {
270 JSExpect("!" + JSElement(kAdAutocompleteRealm) + ".hidden");
271 }
272
273 // Checks if autocomplete domain is hidden for the user input.
274 void TestDomainHidden() {
275 JSExpect(JSElement(kAdAutocompleteRealm) + ".hidden");
276 }
277
278 // Sets username and password for the Active Directory login and submits it.
279 void SubmitActiveDirectoryCredentials(const std::string& username,
280 const std::string& password) {
281 js_checker().ExecuteAsync(JSElement(kAdUserInput) + ".value='" + username +
282 "'");
283 js_checker().ExecuteAsync(JSElement(kAdPasswordInput) + ".value='" +
284 password + "'");
285 js_checker().Evaluate(JSElement(kAdButton) + ".fire('tap')");
286 }
287
288 protected:
289 // Returns string representing element with id=|element_id| inside Active
290 // Directory login element.
291 std::string JSElement(const std::string& element_id) {
292 return "document.querySelector('#offline-ad-auth /deep/ #" + element_id +
293 "')";
294 }
295 FakeAuthPolicyClient* fake_auth_policy_client_ = nullptr;
296
297 private:
298 // Used for the callback from FakeAuthPolicy::RefreshDevicePolicy.
299 void OnRefreshedPolicy(const base::Closure& closure, bool status) {
300 EXPECT_TRUE(status);
301 closure.Run();
302 }
303
304 ScopedStubInstallAttributes install_attributes_;
305
306 DISALLOW_COPY_AND_ASSIGN(ActiveDirectoryLoginTest);
307 };
308
182 // Used to make sure that the system tray is visible and within the screen 309 // Used to make sure that the system tray is visible and within the screen
183 // bounds after login. 310 // bounds after login.
184 void TestSystemTrayIsVisible(bool otr) { 311 void TestSystemTrayIsVisible(bool otr) {
185 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); 312 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
186 aura::Window* primary_win = ash::Shell::GetPrimaryRootWindow(); 313 aura::Window* primary_win = ash::Shell::GetPrimaryRootWindow();
187 ash::WmWindow* wm_primary_win = ash::WmWindow::Get(primary_win); 314 ash::WmWindow* wm_primary_win = ash::WmWindow::Get(primary_win);
188 ash::WmShelf* wm_shelf = ash::WmShelf::ForWindow(wm_primary_win); 315 ash::WmShelf* wm_shelf = ash::WmShelf::ForWindow(wm_primary_win);
189 SCOPED_TRACE(testing::Message() 316 SCOPED_TRACE(testing::Message()
190 << "ShelfVisibilityState=" << wm_shelf->GetVisibilityState() 317 << "ShelfVisibilityState=" << wm_shelf->GetVisibilityState()
191 << " ShelfAutoHideBehavior=" << wm_shelf->auto_hide_behavior()); 318 << " ShelfAutoHideBehavior=" << wm_shelf->auto_hide_behavior());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 PrepareOfflineLogin(); 400 PrepareOfflineLogin();
274 content::WindowedNotificationObserver session_start_waiter( 401 content::WindowedNotificationObserver session_start_waiter(
275 chrome::NOTIFICATION_SESSION_STARTED, 402 chrome::NOTIFICATION_SESSION_STARTED,
276 content::NotificationService::AllSources()); 403 content::NotificationService::AllSources());
277 SubmitGaiaAuthOfflineForm(kTestUser, kPassword); 404 SubmitGaiaAuthOfflineForm(kTestUser, kPassword);
278 session_start_waiter.Wait(); 405 session_start_waiter.Wait();
279 406
280 TestSystemTrayIsVisible(false); 407 TestSystemTrayIsVisible(false);
281 } 408 }
282 409
410 // Marks as Active Directory enterprise device and OOBE as completed.
411 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginSuccess) {
412 MarkAsActiveDirectoryEnterprise();
413 }
414
415 // Test successful Active Directory login.
416 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, LoginSuccess) {
417 TestLoginVisible();
418 TestDomainVisible();
419
420 content::WindowedNotificationObserver session_start_waiter(
421 chrome::NOTIFICATION_SESSION_STARTED,
422 content::NotificationService::AllSources());
423 SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, kPassword);
424 session_start_waiter.Wait();
425
426 // Uncomment once flakiness is fixed, see http://crbug/692364.
427 // TestSystemTrayIsVisible();
428 }
429
430 // Marks as Active Directory enterprise device and OOBE as completed.
431 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginErrors) {
432 MarkAsActiveDirectoryEnterprise();
433 }
434
435 // Test different UI errors for Active Directory login.
436 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, LoginErrors) {
437 TestLoginVisible();
438 TestDomainVisible();
439
440 SubmitActiveDirectoryCredentials("", "");
441 TestUserError();
442 TestDomainVisible();
443
444 SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, "");
445 TestPasswordError();
446 TestDomainVisible();
447
448 fake_auth_policy_client_->set_auth_error(authpolicy::ERROR_BAD_USER_NAME);
449 SubmitActiveDirectoryCredentials(std::string(kTestActiveDirectoryUser) + "@",
450 kPassword);
451 TestUserError();
452 TestDomainHidden();
453
454 fake_auth_policy_client_->set_auth_error(authpolicy::ERROR_BAD_PASSWORD);
455 SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, kPassword);
456 TestPasswordError();
457 TestDomainVisible();
458 }
459
283 } // namespace chromeos 460 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698