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

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

Issue 11280287: Magnifier: Prevent useless operation in enabling/disabling magnifier. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix test failure (MagnificationManagerTest.ChangeMagnifierType) Created 8 years 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 "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 SetUpOnMainThread() OVERRIDE {
39 MagnificationManager::Get()->AddObserver(this);
40 }
41
42 virtual void CleanUpOnMainThread() OVERRIDE {
43 MagnificationManager::Get()->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 SetScreenManagnifierType(ash::MagnifierType type) { 62 void SetScreenManagnifierType(ash::MagnifierType type) {
47 MagnificationManager::GetInstance()->SetMagnifier(type); 63 MagnificationManager::Get()->SetMagnifier(type);
48 } 64 }
49 65
50 void SetScreenManagnifierTypeToPref(ash::MagnifierType type) { 66 void SetScreenManagnifierTypeToPref(ash::MagnifierType type) {
51 prefs()->SetString(prefs::kMagnifierType, 67 prefs()->SetString(prefs::kMagnifierType,
52 accessibility::ScreenMagnifierNameFromType(type)); 68 accessibility::ScreenMagnifierNameFromType(type));
53 } 69 }
54 70
55 void CheckCurrentMagnifierType( 71 void CheckCurrentMagnifierType(
56 ash::MagnifierType type) { 72 ash::MagnifierType type) {
57 EXPECT_EQ(MagnificationManager::GetInstance()->GetMagnifierType(), 73 EXPECT_EQ(MagnificationManager::Get()->GetMagnifierType(), type);
58 type);
59 } 74 }
60 75
76 bool observed_;
77 ash::MagnifierType observed_type_;
61 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); 78 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest);
62 }; 79 };
63 80
64 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, Login) { 81 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, Login) {
65 // Confirms that magnifier is disabled on the login screen. 82 // Confirms that magnifier is disabled on the login screen.
66 CheckCurrentMagnifierType(ash::MAGNIFIER_OFF); 83 CheckCurrentMagnifierType(ash::MAGNIFIER_OFF);
67 84
68 // Logs in. 85 // Logs in.
69 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); 86 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true);
70 UserManager::Get()->SessionStarted(); 87 UserManager::Get()->SessionStarted();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Sets the pref as true to enable magnifier before login. 168 // Sets the pref as true to enable magnifier before login.
152 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL); 169 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL);
153 170
154 // Logs in. 171 // Logs in.
155 UserManager::Get()->SessionStarted(); 172 UserManager::Get()->SessionStarted();
156 173
157 // Confirms that magnifier is enabled just after login. 174 // Confirms that magnifier is enabled just after login.
158 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL); 175 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL);
159 } 176 }
160 177
178 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ChangingTypeInvokesObserver) {
179 // Logs in
180 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true);
181 UserManager::Get()->SessionStarted();
182
183 // Before the test, sets to full magnifier.
184 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL);
185 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL);
186
187 // Disables magnifier and confirms observer is invoked.
188 observed_ = false;
189 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_OFF);
190 EXPECT_TRUE(observed_);
191 EXPECT_EQ(observed_type_, ash::MAGNIFIER_OFF);
192 CheckCurrentMagnifierType(ash::MAGNIFIER_OFF);
193
194 // Enables full screen magnifier and confirms observer is invoked.
195 observed_ = false;
196 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_FULL);
197 EXPECT_TRUE(observed_);
198 EXPECT_EQ(observed_type_, ash::MAGNIFIER_FULL);
199 CheckCurrentMagnifierType(ash::MAGNIFIER_FULL);
200
201 // Enables partial screen magnifier and confirms observer is invoked.
202 observed_ = false;
203 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_PARTIAL);
204 EXPECT_TRUE(observed_);
205 EXPECT_EQ(observed_type_, ash::MAGNIFIER_PARTIAL);
206 CheckCurrentMagnifierType(ash::MAGNIFIER_PARTIAL);
207
208 // Disables magnifier again and confirms observer is invoked.
209 observed_ = false;
210 SetScreenManagnifierTypeToPref(ash::MAGNIFIER_OFF);
211 EXPECT_TRUE(observed_);
212 EXPECT_EQ(observed_type_, ash::MAGNIFIER_OFF);
213 CheckCurrentMagnifierType(ash::MAGNIFIER_OFF);
214 }
215
161 } // namespace chromeos 216 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/accessibility/magnification_manager.cc ('k') | chrome/browser/chromeos/chrome_browser_main_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698