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

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

Issue 2737733003: Add Active Directory login UI tests (Closed)
Patch Set: 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 namespace {
190
191 const char kTestRealm[] = "test_realm.com";
192 const char kTestActiveDirectoryUser[] = "test-user";
193 #define JS_AD_PREFIX "document.querySelector('#offline-ad-auth /deep/ "
achuithb 2017/03/07 15:07:03 Hmm, pretty sure new macros are banned.
Roman Sorokin (ftl) 2017/03/07 16:32:05 Done.
194 const char kAdMachineInput[] = JS_AD_PREFIX "#machineNameInput')";
195 const char kAdUserInput[] = JS_AD_PREFIX "#userInput')";
196 const char kAdPasswordInput[] = JS_AD_PREFIX "#passwordInput')";
197 const char kAdWelcomMessage[] = JS_AD_PREFIX "#welcomeMsg')";
198 const char kAdAutocompleteRealm[] =
199 JS_AD_PREFIX "#userInput /deep/ #domainLabel')";
200 #undef JS_AD_PREFIX
201
202 } // namespace
203
204 class ActiveDirectoryLoginTest : public LoginManagerTest {
achuithb 2017/03/07 15:07:03 This should also be in the anonymous namespace - w
Roman Sorokin (ftl) 2017/03/07 16:32:05 Done. My bad - I put anonymous namespace inside an
205 public:
206 ActiveDirectoryLoginTest()
achuithb 2017/03/07 15:07:03 Newlines between methods please. This is very dens
Roman Sorokin (ftl) 2017/03/07 16:32:05 Done.
207 : LoginManagerTest(true),
208 install_attributes_(
209 ScopedStubInstallAttributes::CreateActiveDirectoryEnterprise(
210 kTestRealm)) {}
211 ~ActiveDirectoryLoginTest() override = default;
212 void SetUpCommandLine(base::CommandLine* command_line) override {
213 command_line->AppendSwitch(switches::kOobeSkipPostLogin);
214 LoginManagerTest::SetUpCommandLine(command_line);
215 }
216 void SetUpOnMainThread() override {
217 LoginManagerTest::SetUpOnMainThread();
218 fake_auth_policy_client_ = static_cast<FakeAuthPolicyClient*>(
219 DBusThreadManager::Get()->GetAuthPolicyClient());
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 // Checks if Active Directory login is visible.
230 void TestLoginVisible() {
231 // Checks if Gaia signin is hidden.
232 js_checker().ExpectTrue("document.querySelector('#signin-frame').hidden");
achuithb 2017/03/07 15:07:03 You can replace these with JSExpect() (switch the
Roman Sorokin (ftl) 2017/03/07 16:32:05 Done.
233
234 // Checks if Active Directory signin is visible.
235 js_checker().ExpectFalse(
236 "document.querySelector('#offline-ad-auth').hidden");
237 const std::string hidden(".hidden");
238 js_checker().ExpectTrue(kAdMachineInput + hidden);
239 js_checker().ExpectFalse(kAdUserInput + hidden);
240 js_checker().ExpectFalse(kAdPasswordInput + hidden);
achuithb 2017/03/07 15:07:03 I think a method like JSElement(const std::string&
Roman Sorokin (ftl) 2017/03/07 16:32:05 Done.
241
242 const std::string innerText(".innerText");
243 // Checks if Active Directory welcome message contains realm.
244 EXPECT_EQ(l10n_util::GetStringFUTF8(IDS_AD_DOMAIN_AUTH_WELCOME_MESSAGE,
245 base::UTF8ToUTF16(kTestRealm)),
246 js_checker().GetString(kAdWelcomMessage + innerText));
247
248 // Checks if realm is set to autocomplete username.
249 EXPECT_EQ("@" + std::string(kTestRealm),
250 js_checker().GetString(kAdAutocompleteRealm + innerText));
251
252 // Checks if bottom bar is visible.
253 js_checker().ExpectFalse("Oobe.getInstance().headerHidden");
254 }
255 // Checks if user input is marked as invalid.
256 void TestUserError() {
257 TestLoginVisible();
258 js_checker().ExpectTrue(kAdUserInput + std::string(".isInvalid"));
259 }
260 // Checks if password input is marked as invalid.
261 void TestPasswordError() {
262 TestLoginVisible();
263 js_checker().ExpectTrue(kAdPasswordInput + std::string(".isInvalid"));
264 }
265 // Checks if autocomplete domain is visible for the user input.
266 void TestDomainVisible() {
267 js_checker().ExpectFalse(kAdAutocompleteRealm + std::string(".hidden"));
268 }
269 // Checks if autocomplete domain is hidden for the user input.
270 void TestDomainHidden() {
271 js_checker().ExpectTrue(kAdAutocompleteRealm + std::string(".hidden"));
272 }
273 // Sets username and password for the Active Directory login and submits it.
274 void SubmitActiveDirectoryCredentials(const std::string& username,
275 const std::string& password) {
276 js_checker().ExecuteAsync(kAdUserInput + std::string(".value='") +
277 username + "'");
278 js_checker().ExecuteAsync(kAdPasswordInput + std::string(".value='") +
279 password + "'");
280 js_checker().Evaluate(
281 "document.querySelector('#offline-ad-auth /deep/ "
282 "#button').fire('tap')");
283 }
284
285 protected:
286 FakeAuthPolicyClient* fake_auth_policy_client_ = nullptr;
287
288 private:
289 // Used for the callback from FakeAuthPolicy::RefreshDevicePolicy.
290 void OnRefreshedPolicy(const base::Closure& closure, bool status) {
291 EXPECT_TRUE(status);
292 closure.Run();
293 }
294
295 ScopedStubInstallAttributes install_attributes_;
296 };
achuithb 2017/03/07 15:07:03 DISALLOW_COPY_AND_ASSIGN
Roman Sorokin (ftl) 2017/03/07 16:32:05 Done.
297
182 // Used to make sure that the system tray is visible and within the screen 298 // Used to make sure that the system tray is visible and within the screen
183 // bounds after login. 299 // bounds after login.
184 void TestSystemTrayIsVisible() { 300 void TestSystemTrayIsVisible() {
185 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); 301 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
186 aura::Window* primary_win = ash::Shell::GetPrimaryRootWindow(); 302 aura::Window* primary_win = ash::Shell::GetPrimaryRootWindow();
187 ash::WmWindow* wm_primary_win = ash::WmWindow::Get(primary_win); 303 ash::WmWindow* wm_primary_win = ash::WmWindow::Get(primary_win);
188 ash::WmShelf* wm_shelf = ash::WmShelf::ForWindow(wm_primary_win); 304 ash::WmShelf* wm_shelf = ash::WmShelf::ForWindow(wm_primary_win);
189 SCOPED_TRACE(testing::Message() 305 SCOPED_TRACE(testing::Message()
190 << "ShelfVisibilityState=" << wm_shelf->GetVisibilityState() 306 << "ShelfVisibilityState=" << wm_shelf->GetVisibilityState()
191 << " ShelfAutoHideBehavior=" << wm_shelf->auto_hide_behavior()); 307 << " ShelfAutoHideBehavior=" << wm_shelf->auto_hide_behavior());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 PrepareOfflineLogin(); 388 PrepareOfflineLogin();
273 content::WindowedNotificationObserver session_start_waiter( 389 content::WindowedNotificationObserver session_start_waiter(
274 chrome::NOTIFICATION_SESSION_STARTED, 390 chrome::NOTIFICATION_SESSION_STARTED,
275 content::NotificationService::AllSources()); 391 content::NotificationService::AllSources());
276 SubmitGaiaAuthOfflineForm(kTestUser, kPassword); 392 SubmitGaiaAuthOfflineForm(kTestUser, kPassword);
277 session_start_waiter.Wait(); 393 session_start_waiter.Wait();
278 394
279 TestSystemTrayIsVisible(); 395 TestSystemTrayIsVisible();
280 } 396 }
281 397
398 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginSuccess) {
achuithb 2017/03/07 15:07:03 Test comments for all functions please
Roman Sorokin (ftl) 2017/03/07 16:32:05 Done.
399 MarkAsActiveDirectoryEnterprise();
400 }
401
402 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, LoginSuccess) {
403 TestLoginVisible();
404 TestDomainVisible();
405
406 content::WindowedNotificationObserver session_start_waiter(
407 chrome::NOTIFICATION_SESSION_STARTED,
408 content::NotificationService::AllSources());
409 SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, kPassword);
410 session_start_waiter.Wait();
411
412 // Uncomment once flakiness is fixed, see http://crbug/692364.
413 // TestSystemTrayIsVisible();
achuithb 2017/03/07 15:07:03 Sad
Roman Sorokin (ftl) 2017/03/07 16:32:05 Acknowledged.
414 }
415
416 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginErrors) {
417 MarkAsActiveDirectoryEnterprise();
418 }
419
420 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, LoginErrors) {
421 TestLoginVisible();
422 TestDomainVisible();
423
424 SubmitActiveDirectoryCredentials("", "");
425 TestUserError();
426 TestDomainVisible();
427
428 SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, "");
429 TestPasswordError();
430 TestDomainVisible();
431
432 fake_auth_policy_client_->set_auth_error(authpolicy::ERROR_BAD_USER_NAME);
433 SubmitActiveDirectoryCredentials(std::string(kTestActiveDirectoryUser) + "@",
434 kPassword);
435 TestUserError();
436 TestDomainHidden();
437
438 fake_auth_policy_client_->set_auth_error(authpolicy::ERROR_BAD_PASSWORD);
439 SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, kPassword);
440 TestPasswordError();
441 TestDomainVisible();
442 }
443
282 } // namespace chromeos 444 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698