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

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

Issue 166273014: Remove dependency on NotificationService for cros a11y settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix magnification manager. Created 6 years, 10 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 | Annotate | Revision Log
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/magnifier/magnification_controller.h" 7 #include "ash/magnifier/magnification_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 UserManager::Get()->UserLoggedIn(name, name, true); 100 UserManager::Get()->UserLoggedIn(name, name, true);
101 // To prepare a non-new profile for tests, we must ensure the profile 101 // To prepare a non-new profile for tests, we must ensure the profile
102 // directory and the preference files are created, because that's what 102 // directory and the preference files are created, because that's what
103 // Profile::IsNewProfile() checks. UserLoggedIn(), however, does not yet 103 // Profile::IsNewProfile() checks. UserLoggedIn(), however, does not yet
104 // create the profile directory until GetActiveUserProfile() is called. 104 // create the profile directory until GetActiveUserProfile() is called.
105 ProfileManager::GetActiveUserProfile(); 105 ProfileManager::GetActiveUserProfile();
106 } 106 }
107 107
108 } // namespace 108 } // namespace
109 109
110 class MagnificationManagerTest : public InProcessBrowserTest, 110 class MagnificationManagerTest : public InProcessBrowserTest {
111 public content::NotificationObserver {
112 protected: 111 protected:
113 MagnificationManagerTest() : observed_(false), 112 MagnificationManagerTest() : observed_(false),
114 observed_enabled_(false), 113 observed_enabled_(false),
115 observed_type_(ash::kDefaultMagnifierType) {} 114 observed_type_(ash::kDefaultMagnifierType) {}
116 virtual ~MagnificationManagerTest() {} 115 virtual ~MagnificationManagerTest() {}
117 116
118 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 117 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
119 command_line->AppendSwitch(switches::kLoginManager); 118 command_line->AppendSwitch(switches::kLoginManager);
120 command_line->AppendSwitchASCII(switches::kLoginProfile, 119 command_line->AppendSwitchASCII(switches::kLoginProfile,
121 TestingProfile::kTestUserProfileDir); 120 TestingProfile::kTestUserProfileDir);
122 } 121 }
123 122
124 virtual void SetUpOnMainThread() OVERRIDE { 123 virtual void SetUpOnMainThread() OVERRIDE {
125 registrar_.Add( 124 AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
126 this, 125 CHECK(accessibility_manager);
127 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER, 126 accessibility_subscription_ = accessibility_manager->RegisterCallback(
128 content::NotificationService::AllSources()); 127 base::Bind(&MagnificationManagerTest::OnAccessibilityStatusChanged,
128 base::Unretained(this)));
129 129
130 // Set the login-screen profile. 130 // Set the login-screen profile.
131 MagnificationManager::Get()->SetProfileForTest( 131 MagnificationManager::Get()->SetProfileForTest(
132 ProfileManager::GetActiveUserProfile()); 132 ProfileManager::GetActiveUserProfile());
133 } 133 }
134 134
135 // content::NotificationObserver implementation. 135 virtual void TearDownOnMainThread() OVERRIDE {
136 virtual void Observe(int type, 136 accessibility_subscription_.reset();
137 const content::NotificationSource& source, 137 }
138 const content::NotificationDetails& details) OVERRIDE {
139 switch (type) {
140 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER: {
141 AccessibilityStatusEventDetails* accessibility_status =
142 content::Details<AccessibilityStatusEventDetails>(details).ptr();
143 138
144 observed_ = true; 139 void OnAccessibilityStatusChanged(
145 observed_enabled_ = accessibility_status->enabled; 140 const AccessibilityStatusEventDetails& details) {
146 observed_type_ = accessibility_status->magnifier_type; 141 if (details.notification_type == ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER) {
147 break; 142 observed_type_ = details.magnifier_type;
148 } 143 observed_enabled_ = details.enabled;
144 observed_ = true;
145 } else if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN) {
146 accessibility_subscription_.reset();
149 } 147 }
150 } 148 }
151 149
152 bool observed_; 150 bool observed_;
153 bool observed_enabled_; 151 bool observed_enabled_;
154 ash::MagnifierType observed_type_; 152 ash::MagnifierType observed_type_;
155 content::NotificationRegistrar registrar_; 153 scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_;
156 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); 154 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest);
157 }; 155 };
158 156
159 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, PRE_LoginOffToOff) { 157 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, PRE_LoginOffToOff) {
160 // Create a new profile once, to run the test with non-new profile. 158 // Create a new profile once, to run the test with non-new profile.
161 PrepareNonNewProfile(kTestUserName); 159 PrepareNonNewProfile(kTestUserName);
162 160
163 // Sets pref to explicitly disable the magnifier. 161 // Sets pref to explicitly disable the magnifier.
164 SetScreenMagnifierEnabledPref(false); 162 SetScreenMagnifierEnabledPref(false);
165 } 163 }
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // Enables full screen magnifier. 499 // Enables full screen magnifier.
502 SetMagnifierEnabled(true); 500 SetMagnifierEnabled(true);
503 EXPECT_TRUE(IsMagnifierEnabled()); 501 EXPECT_TRUE(IsMagnifierEnabled());
504 EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); 502 EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
505 503
506 // Confirms that the actual scale is set to the maximum scale. 504 // Confirms that the actual scale is set to the maximum scale.
507 EXPECT_EQ(4.0, GetFullScreenMagnifierScale()); 505 EXPECT_EQ(4.0, GetFullScreenMagnifierScale());
508 } 506 }
509 507
510 } // namespace chromeos 508 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698