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

Side by Side Diff: chrome/browser/chromeos/accessibility/accessibility_manager_browsertest.cc

Issue 2918203002: cros: Fix loading user profile w/o UserSessionManager (Closed)
Patch Set: rebase Created 3 years, 6 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/browser/chromeos/accessibility/accessibility_manager.h" 5 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
6 6
7 #include "ash/accessibility_types.h" 7 #include "ash/accessibility_types.h"
8 #include "ash/magnifier/magnification_controller.h" 8 #include "ash/magnifier/magnification_controller.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 void SetMonoAudioEnabled(bool enabled) { 154 void SetMonoAudioEnabled(bool enabled) {
155 return AccessibilityManager::Get()->EnableMonoAudio(enabled); 155 return AccessibilityManager::Get()->EnableMonoAudio(enabled);
156 } 156 }
157 157
158 bool IsMonoAudioEnabled() { 158 bool IsMonoAudioEnabled() {
159 return AccessibilityManager::Get()->IsMonoAudioEnabled(); 159 return AccessibilityManager::Get()->IsMonoAudioEnabled();
160 } 160 }
161 161
162 Profile* GetProfile() { 162 Profile* GetProfile() {
163 Profile* profile = ProfileManager::GetActiveUserProfile(); 163 // ProfileManager::GetActiveUserProfile() does not load user profile
164 // implicitly any more. Use ProfileHelper::GetProfileByUserIdHashForTest() to
165 // do an explicit load.
166 Profile* const profile = ProfileHelper::GetProfileByUserIdHashForTest(
167 user_manager::UserManager::Get()->GetActiveUser()->username_hash());
168
164 DCHECK(profile); 169 DCHECK(profile);
165 return profile; 170 return profile;
166 } 171 }
167 172
168 PrefService* GetPrefs() { 173 PrefService* GetPrefs() {
169 return GetProfile()->GetPrefs(); 174 return GetProfile()->GetPrefs();
170 } 175 }
171 176
177 // Simulates how UserSessionManager starts a user session by loading user
178 // profile and marking session as started.
179 void StartUserSession(const AccountId& account_id) {
180 ProfileHelper::GetProfileByUserIdHashForTest(
181 user_manager::UserManager::Get()->FindUser(account_id)->username_hash());
182
183 session_manager::SessionManager::Get()->SessionStarted();
184 }
185
172 void SetLargeCursorEnabledPref(bool enabled) { 186 void SetLargeCursorEnabledPref(bool enabled) {
173 GetPrefs()->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, enabled); 187 GetPrefs()->SetBoolean(prefs::kAccessibilityLargeCursorEnabled, enabled);
174 } 188 }
175 189
176 void SetHighContrastEnabledPref(bool enabled) { 190 void SetHighContrastEnabledPref(bool enabled) {
177 GetPrefs()->SetBoolean(prefs::kAccessibilityHighContrastEnabled, enabled); 191 GetPrefs()->SetBoolean(prefs::kAccessibilityHighContrastEnabled, enabled);
178 } 192 }
179 193
180 void SetSpokenFeedbackEnabledPref(bool enabled) { 194 void SetSpokenFeedbackEnabledPref(bool enabled) {
181 GetPrefs()->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, enabled); 195 GetPrefs()->SetBoolean(prefs::kAccessibilitySpokenFeedbackEnabled, enabled);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return true; 246 return true;
233 } 247 }
234 return false; 248 return false;
235 } 249 }
236 250
237 bool IsBrailleImeCurrent() { 251 bool IsBrailleImeCurrent() {
238 InputMethodManager* imm = InputMethodManager::Get(); 252 InputMethodManager* imm = InputMethodManager::Get();
239 return imm->GetActiveIMEState()->GetCurrentInputMethod().id() == 253 return imm->GetActiveIMEState()->GetCurrentInputMethod().id() ==
240 extension_ime_util::kBrailleImeEngineId; 254 extension_ime_util::kBrailleImeEngineId;
241 } 255 }
256
242 } // anonymous namespace 257 } // anonymous namespace
243 258
244 class AccessibilityManagerTest : public InProcessBrowserTest { 259 class AccessibilityManagerTest : public InProcessBrowserTest {
245 protected: 260 protected:
246 AccessibilityManagerTest() : default_autoclick_delay_(0) {} 261 AccessibilityManagerTest() : default_autoclick_delay_(0) {}
247 ~AccessibilityManagerTest() override {} 262 ~AccessibilityManagerTest() override {}
248 263
249 void SetUpCommandLine(base::CommandLine* command_line) override { 264 void SetUpCommandLine(base::CommandLine* command_line) override {
250 command_line->AppendSwitch(chromeos::switches::kLoginManager); 265 command_line->AppendSwitch(chromeos::switches::kLoginManager);
251 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, 266 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 317
303 // Confirms that the features still disabled just after login. 318 // Confirms that the features still disabled just after login.
304 EXPECT_FALSE(IsLargeCursorEnabled()); 319 EXPECT_FALSE(IsLargeCursorEnabled());
305 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 320 EXPECT_FALSE(IsSpokenFeedbackEnabled());
306 EXPECT_FALSE(IsHighContrastEnabled()); 321 EXPECT_FALSE(IsHighContrastEnabled());
307 EXPECT_FALSE(IsAutoclickEnabled()); 322 EXPECT_FALSE(IsAutoclickEnabled());
308 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 323 EXPECT_FALSE(IsVirtualKeyboardEnabled());
309 EXPECT_FALSE(IsMonoAudioEnabled()); 324 EXPECT_FALSE(IsMonoAudioEnabled());
310 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay()); 325 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
311 326
312 session_manager->SessionStarted(); 327 StartUserSession(test_account_id_);
313 328
314 // Confirms that the features are still disabled just after login. 329 // Confirms that the features are still disabled just after login.
315 EXPECT_FALSE(IsLargeCursorEnabled()); 330 EXPECT_FALSE(IsLargeCursorEnabled());
316 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 331 EXPECT_FALSE(IsSpokenFeedbackEnabled());
317 EXPECT_FALSE(IsHighContrastEnabled()); 332 EXPECT_FALSE(IsHighContrastEnabled());
318 EXPECT_FALSE(IsAutoclickEnabled()); 333 EXPECT_FALSE(IsAutoclickEnabled());
319 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 334 EXPECT_FALSE(IsVirtualKeyboardEnabled());
320 EXPECT_FALSE(IsMonoAudioEnabled()); 335 EXPECT_FALSE(IsMonoAudioEnabled());
321 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay()); 336 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
322 337
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // Signal the accessibility manager that a braille display was connected. 376 // Signal the accessibility manager that a braille display was connected.
362 SetBrailleDisplayAvailability(true); 377 SetBrailleDisplayAvailability(true);
363 // Confirms that the spoken feedback is enabled. 378 // Confirms that the spoken feedback is enabled.
364 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 379 EXPECT_TRUE(IsSpokenFeedbackEnabled());
365 } 380 }
366 381
367 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) { 382 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) {
368 // Logs in. 383 // Logs in.
369 auto* session_manager = session_manager::SessionManager::Get(); 384 auto* session_manager = session_manager::SessionManager::Get();
370 session_manager->CreateSession(test_account_id_, kTestUserName); 385 session_manager->CreateSession(test_account_id_, kTestUserName);
371 session_manager->SessionStarted(); 386 StartUserSession(test_account_id_);
372 387
373 // Confirms that the features are disabled just after login. 388 // Confirms that the features are disabled just after login.
374 EXPECT_FALSE(IsLargeCursorEnabled()); 389 EXPECT_FALSE(IsLargeCursorEnabled());
375 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 390 EXPECT_FALSE(IsSpokenFeedbackEnabled());
376 EXPECT_FALSE(IsHighContrastEnabled()); 391 EXPECT_FALSE(IsHighContrastEnabled());
377 EXPECT_FALSE(IsAutoclickEnabled()); 392 EXPECT_FALSE(IsAutoclickEnabled());
378 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay()); 393 EXPECT_EQ(default_autoclick_delay(), GetAutoclickDelay());
379 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 394 EXPECT_FALSE(IsVirtualKeyboardEnabled());
380 EXPECT_FALSE(IsMonoAudioEnabled()); 395 EXPECT_FALSE(IsMonoAudioEnabled());
381 396
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 476
462 // Sets the pref to enable the on-screen keyboard before login. 477 // Sets the pref to enable the on-screen keyboard before login.
463 SetVirtualKeyboardEnabledPref(true); 478 SetVirtualKeyboardEnabledPref(true);
464 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 479 EXPECT_FALSE(IsVirtualKeyboardEnabled());
465 480
466 // Sets the pref to enable mono audio output before login. 481 // Sets the pref to enable mono audio output before login.
467 SetMonoAudioEnabledPref(true); 482 SetMonoAudioEnabledPref(true);
468 EXPECT_FALSE(IsMonoAudioEnabled()); 483 EXPECT_FALSE(IsMonoAudioEnabled());
469 484
470 // Logs in. 485 // Logs in.
471 session_manager->SessionStarted(); 486 StartUserSession(test_account_id_);
472 487
473 // Confirms that features are enabled by restoring from pref just after login. 488 // Confirms that features are enabled by restoring from pref just after login.
474 EXPECT_TRUE(IsLargeCursorEnabled()); 489 EXPECT_TRUE(IsLargeCursorEnabled());
475 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 490 EXPECT_TRUE(IsSpokenFeedbackEnabled());
476 EXPECT_TRUE(IsHighContrastEnabled()); 491 EXPECT_TRUE(IsHighContrastEnabled());
477 EXPECT_TRUE(IsAutoclickEnabled()); 492 EXPECT_TRUE(IsAutoclickEnabled());
478 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay()); 493 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
479 EXPECT_TRUE(IsVirtualKeyboardEnabled()); 494 EXPECT_TRUE(IsVirtualKeyboardEnabled());
480 EXPECT_TRUE(IsMonoAudioEnabled()); 495 EXPECT_TRUE(IsMonoAudioEnabled());
481 } 496 }
482 497
483 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, 498 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
484 ChangingTypeInvokesNotification) { 499 ChangingTypeInvokesNotification) {
485 MockAccessibilityObserver observer; 500 MockAccessibilityObserver observer;
486 501
487 // Logs in. 502 // Logs in.
488 auto* session_manager = session_manager::SessionManager::Get(); 503 auto* session_manager = session_manager::SessionManager::Get();
489 session_manager->CreateSession(test_account_id_, kTestUserName); 504 session_manager->CreateSession(test_account_id_, kTestUserName);
490 session_manager->SessionStarted(); 505 StartUserSession(test_account_id_);
491 506
492 EXPECT_FALSE(observer.observed()); 507 EXPECT_FALSE(observer.observed());
493 observer.reset(); 508 observer.reset();
494 509
495 SetSpokenFeedbackEnabled(true); 510 SetSpokenFeedbackEnabled(true);
496 EXPECT_TRUE(observer.observed()); 511 EXPECT_TRUE(observer.observed());
497 EXPECT_TRUE(observer.observed_enabled()); 512 EXPECT_TRUE(observer.observed_enabled());
498 EXPECT_EQ(observer.observed_type(), 513 EXPECT_EQ(observer.observed_type(),
499 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); 514 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
500 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 515 EXPECT_TRUE(IsSpokenFeedbackEnabled());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 EXPECT_FALSE(IsMonoAudioEnabled()); 571 EXPECT_FALSE(IsMonoAudioEnabled());
557 } 572 }
558 573
559 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, 574 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
560 ChangingTypePrefInvokesNotification) { 575 ChangingTypePrefInvokesNotification) {
561 MockAccessibilityObserver observer; 576 MockAccessibilityObserver observer;
562 577
563 // Logs in. 578 // Logs in.
564 auto* session_manager = session_manager::SessionManager::Get(); 579 auto* session_manager = session_manager::SessionManager::Get();
565 session_manager->CreateSession(test_account_id_, kTestUserName); 580 session_manager->CreateSession(test_account_id_, kTestUserName);
566 session_manager->SessionStarted(); 581 StartUserSession(test_account_id_);
567 582
568 EXPECT_FALSE(observer.observed()); 583 EXPECT_FALSE(observer.observed());
569 observer.reset(); 584 observer.reset();
570 585
571 SetSpokenFeedbackEnabledPref(true); 586 SetSpokenFeedbackEnabledPref(true);
572 EXPECT_TRUE(observer.observed()); 587 EXPECT_TRUE(observer.observed());
573 EXPECT_TRUE(observer.observed_enabled()); 588 EXPECT_TRUE(observer.observed_enabled());
574 EXPECT_EQ(observer.observed_type(), 589 EXPECT_EQ(observer.observed_type(),
575 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); 590 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
576 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 591 EXPECT_TRUE(IsSpokenFeedbackEnabled());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 session_manager->CreateSession(account_id, account_id.GetUserEmail()); 692 session_manager->CreateSession(account_id, account_id.GetUserEmail());
678 693
679 // Confirms that the features are still enabled just after login. 694 // Confirms that the features are still enabled just after login.
680 EXPECT_TRUE(IsLargeCursorEnabled()); 695 EXPECT_TRUE(IsLargeCursorEnabled());
681 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 696 EXPECT_TRUE(IsSpokenFeedbackEnabled());
682 EXPECT_TRUE(IsHighContrastEnabled()); 697 EXPECT_TRUE(IsHighContrastEnabled());
683 EXPECT_TRUE(IsAutoclickEnabled()); 698 EXPECT_TRUE(IsAutoclickEnabled());
684 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay()); 699 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
685 EXPECT_TRUE(IsMonoAudioEnabled()); 700 EXPECT_TRUE(IsMonoAudioEnabled());
686 701
687 session_manager->SessionStarted(); 702 StartUserSession(account_id);
688 703
689 // Confirms that the features keep enabled after session starts. 704 // Confirms that the features keep enabled after session starts.
690 EXPECT_TRUE(IsLargeCursorEnabled()); 705 EXPECT_TRUE(IsLargeCursorEnabled());
691 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 706 EXPECT_TRUE(IsSpokenFeedbackEnabled());
692 EXPECT_TRUE(IsHighContrastEnabled()); 707 EXPECT_TRUE(IsHighContrastEnabled());
693 EXPECT_TRUE(IsAutoclickEnabled()); 708 EXPECT_TRUE(IsAutoclickEnabled());
694 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay()); 709 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelay());
695 EXPECT_TRUE(IsMonoAudioEnabled()); 710 EXPECT_TRUE(IsMonoAudioEnabled());
696 711
697 // Confirms that the prefs have been copied to the user's profile. 712 // Confirms that the prefs have been copied to the user's profile.
698 EXPECT_TRUE(GetLargeCursorEnabledFromPref()); 713 EXPECT_TRUE(GetLargeCursorEnabledFromPref());
699 EXPECT_TRUE(GetSpokenFeedbackEnabledFromPref()); 714 EXPECT_TRUE(GetSpokenFeedbackEnabledFromPref());
700 EXPECT_TRUE(GetHighContrastEnabledFromPref()); 715 EXPECT_TRUE(GetHighContrastEnabledFromPref());
701 EXPECT_TRUE(GetAutoclickEnabledFromPref()); 716 EXPECT_TRUE(GetAutoclickEnabledFromPref());
702 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelayFromPref()); 717 EXPECT_EQ(kTestAutoclickDelayMs, GetAutoclickDelayFromPref());
703 EXPECT_TRUE(GetMonoAudioEnabledFromPref()); 718 EXPECT_TRUE(GetMonoAudioEnabledFromPref());
704 } 719 }
705 720
706 IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest, BrailleWhenLoggedIn) { 721 IN_PROC_BROWSER_TEST_P(AccessibilityManagerUserTypeTest, BrailleWhenLoggedIn) {
707 // Logs in. 722 // Logs in.
708 const AccountId account_id = AccountId::FromUserEmail(GetParam()); 723 const AccountId account_id = AccountId::FromUserEmail(GetParam());
709 auto* session_manager = session_manager::SessionManager::Get(); 724 auto* session_manager = session_manager::SessionManager::Get();
710 session_manager->CreateSession(account_id, account_id.GetUserEmail()); 725 session_manager->CreateSession(account_id, account_id.GetUserEmail());
711 session_manager->SessionStarted(); 726 StartUserSession(account_id);
712 // This object watches for IME preference changes and reflects those in 727 // This object watches for IME preference changes and reflects those in
713 // the IME framework state. 728 // the IME framework state.
714 chromeos::Preferences prefs; 729 chromeos::Preferences prefs;
715 prefs.InitUserPrefsForTesting( 730 prefs.InitUserPrefsForTesting(
716 PrefServiceSyncableFromProfile(GetProfile()), 731 PrefServiceSyncableFromProfile(GetProfile()),
717 user_manager::UserManager::Get()->GetActiveUser(), 732 user_manager::UserManager::Get()->GetActiveUser(),
718 UserSessionManager::GetInstance()->GetDefaultIMEState(GetProfile())); 733 UserSessionManager::GetInstance()->GetDefaultIMEState(GetProfile()));
719 734
720 // Make sure we start in the expected state. 735 // Make sure we start in the expected state.
721 EXPECT_FALSE(IsBrailleImeActive()); 736 EXPECT_FALSE(IsBrailleImeActive());
(...skipping 25 matching lines...) Expand all
747 // the Braille IME. 762 // the Braille IME.
748 SetBrailleDisplayAvailability(true); 763 SetBrailleDisplayAvailability(true);
749 EXPECT_TRUE(IsSpokenFeedbackEnabled()); 764 EXPECT_TRUE(IsSpokenFeedbackEnabled());
750 EXPECT_TRUE(IsBrailleImeActive()); 765 EXPECT_TRUE(IsBrailleImeActive());
751 } 766 }
752 767
753 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, AccessibilityMenuVisibility) { 768 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, AccessibilityMenuVisibility) {
754 // Log in. 769 // Log in.
755 auto* session_manager = session_manager::SessionManager::Get(); 770 auto* session_manager = session_manager::SessionManager::Get();
756 session_manager->CreateSession(test_account_id_, kTestUserName); 771 session_manager->CreateSession(test_account_id_, kTestUserName);
757 session_manager->SessionStarted(); 772 StartUserSession(test_account_id_);
758 773
759 // Confirms that the features are disabled. 774 // Confirms that the features are disabled.
760 EXPECT_FALSE(IsLargeCursorEnabled()); 775 EXPECT_FALSE(IsLargeCursorEnabled());
761 EXPECT_FALSE(IsSpokenFeedbackEnabled()); 776 EXPECT_FALSE(IsSpokenFeedbackEnabled());
762 EXPECT_FALSE(IsHighContrastEnabled()); 777 EXPECT_FALSE(IsHighContrastEnabled());
763 EXPECT_FALSE(IsAutoclickEnabled()); 778 EXPECT_FALSE(IsAutoclickEnabled());
764 EXPECT_FALSE(ShouldShowAccessibilityMenu()); 779 EXPECT_FALSE(ShouldShowAccessibilityMenu());
765 EXPECT_FALSE(IsVirtualKeyboardEnabled()); 780 EXPECT_FALSE(IsVirtualKeyboardEnabled());
766 EXPECT_FALSE(IsMonoAudioEnabled()); 781 EXPECT_FALSE(IsMonoAudioEnabled());
767 782
(...skipping 28 matching lines...) Expand all
796 EXPECT_FALSE(ShouldShowAccessibilityMenu()); 811 EXPECT_FALSE(ShouldShowAccessibilityMenu());
797 812
798 // Check mono audio output. 813 // Check mono audio output.
799 SetMonoAudioEnabled(true); 814 SetMonoAudioEnabled(true);
800 EXPECT_TRUE(ShouldShowAccessibilityMenu()); 815 EXPECT_TRUE(ShouldShowAccessibilityMenu());
801 SetMonoAudioEnabled(false); 816 SetMonoAudioEnabled(false);
802 EXPECT_FALSE(ShouldShowAccessibilityMenu()); 817 EXPECT_FALSE(ShouldShowAccessibilityMenu());
803 } 818 }
804 819
805 } // namespace chromeos 820 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chrome_browser_main.cc ('k') | chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698