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

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

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