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 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | 7 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" |
8 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 8 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | 9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
10 #include "chrome/browser/chromeos/login/helper.h" | 10 #include "chrome/browser/chromeos/login/helper.h" |
11 #include "chrome/browser/chromeos/login/login_utils.h" | 11 #include "chrome/browser/chromeos/login/login_utils.h" |
12 #include "chrome/browser/chromeos/login/user_manager.h" | 12 #include "chrome/browser/chromeos/login/user_manager.h" |
13 #include "chrome/browser/chromeos/login/user_manager_impl.h" | 13 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace chromeos { | 23 namespace chromeos { |
24 | 24 |
25 class MagnificationManagerTest : public CrosInProcessBrowserTest { | 25 class MagnificationManagerTest : public CrosInProcessBrowserTest, |
| 26 public MagnificationObserver { |
26 protected: | 27 protected: |
27 MagnificationManagerTest() {} | 28 MagnificationManagerTest() : observed_(false), |
| 29 observed_type_(ash::MAGNIFIER_OFF) {} |
28 virtual ~MagnificationManagerTest() {} | 30 virtual ~MagnificationManagerTest() {} |
29 | 31 |
30 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
31 command_line->AppendSwitch(switches::kLoginManager); | 33 command_line->AppendSwitch(switches::kLoginManager); |
32 command_line->AppendSwitchASCII(switches::kLoginProfile, | 34 command_line->AppendSwitchASCII(switches::kLoginProfile, |
33 TestingProfile::kTestUserProfileDir); | 35 TestingProfile::kTestUserProfileDir); |
34 } | 36 } |
35 | 37 |
| 38 virtual void SetUp() OVERRIDE { |
| 39 MagnificationManager::GetInstance()->AddObserver(this); |
| 40 } |
| 41 |
| 42 virtual void TearDown() OVERRIDE { |
| 43 MagnificationManager::GetInstance()->RemoveObserver(this); |
| 44 } |
| 45 |
| 46 // Overridden from MagnificationObserever: |
| 47 virtual void OnMagnifierTypeChanged(ash::MagnifierType new_type) OVERRIDE { |
| 48 observed_ = true; |
| 49 observed_type_ = new_type; |
| 50 } |
| 51 |
36 Profile* profile() { | 52 Profile* profile() { |
37 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | 53 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
38 DCHECK(profile); | 54 DCHECK(profile); |
39 return profile; | 55 return profile; |
40 } | 56 } |
41 | 57 |
42 PrefServiceBase* prefs() { | 58 PrefServiceBase* prefs() { |
43 return PrefServiceBase::FromBrowserContext(profile()); | 59 return PrefServiceBase::FromBrowserContext(profile()); |
44 } | 60 } |
45 | 61 |
46 void SetScreenManagnifierTypeToPref(ash::MagnifierType type) { | 62 void SetScreenManagnifierTypeToPref(ash::MagnifierType type) { |
47 prefs()->SetString(prefs::kMagnifierType, | 63 prefs()->SetString(prefs::kMagnifierType, |
48 accessibility::ScreenMagnifierNameFromType(type)); | 64 accessibility::ScreenMagnifierNameFromType(type)); |
49 } | 65 } |
50 | 66 |
51 void CheckCurrentMagnifierType( | 67 void CheckCurrentMagnifierType( |
52 ash::MagnifierType type) { | 68 ash::MagnifierType type) { |
53 EXPECT_EQ(MagnificationManager::GetInstance()->GetMagnifierType(), | 69 EXPECT_EQ(MagnificationManager::GetInstance()->GetMagnifierType(), |
54 type); | 70 type); |
55 } | 71 } |
56 | 72 |
| 73 bool observed_; |
| 74 ash::MagnifierType observed_type_; |
57 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); | 75 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); |
58 }; | 76 }; |
59 | 77 |
60 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, Login) { | 78 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, Login) { |
61 // Confirms that magnifier is enabled on the login screen. | 79 // Confirms that magnifier is enabled on the login screen. |
62 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); | 80 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); |
63 | 81 |
64 // Logs in. | 82 // Logs in. |
65 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); | 83 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); |
66 UserManager::Get()->SessionStarted(); | 84 UserManager::Get()->SessionStarted(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // Sets the pref as true to enable magnifier before login. | 127 // Sets the pref as true to enable magnifier before login. |
110 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); | 128 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); |
111 | 129 |
112 // Logs in. | 130 // Logs in. |
113 UserManager::Get()->SessionStarted(); | 131 UserManager::Get()->SessionStarted(); |
114 | 132 |
115 // Confirms that magnifier is enabled just after login. | 133 // Confirms that magnifier is enabled just after login. |
116 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); | 134 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); |
117 } | 135 } |
118 | 136 |
| 137 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ChangingTypeInvokesObserver) { |
| 138 // Before the test, sets to full magnifier. |
| 139 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); |
| 140 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); |
| 141 |
| 142 // Disables magnifier and confirms observer is invoked. |
| 143 observed_ = false; |
| 144 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_OFF); |
| 145 EXPECT_TRUE(observed_); |
| 146 EXPECT_EQ(observed_type_, ash::MAGNIFIER_OFF); |
| 147 CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); |
| 148 |
| 149 // Enables full screen magnifier and confirms observer is invoked. |
| 150 observed_ = false; |
| 151 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); |
| 152 EXPECT_TRUE(observed_); |
| 153 EXPECT_EQ(observed_type_, ash::MAGNIFIER_FULL); |
| 154 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); |
| 155 |
| 156 // Enables partial screen magnifier and confirms observer is invoked. |
| 157 observed_ = false; |
| 158 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_PARTIAL); |
| 159 EXPECT_TRUE(observed_); |
| 160 EXPECT_EQ(observed_type_, ash::MAGNIFIER_PARTIAL); |
| 161 CheckCurrentMagnifierType(ash::MAGNIFIER_PARTIAL); |
| 162 |
| 163 // Disables magnifier again and confirms observer is invoked. |
| 164 observed_ = false; |
| 165 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_OFF); |
| 166 EXPECT_TRUE(observed_); |
| 167 EXPECT_EQ(observed_type_, ash::MAGNIFIER_OFF); |
| 168 CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); |
| 169 } |
| 170 |
119 } // namespace chromeos | 171 } // namespace chromeos |
OLD | NEW |