| 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 <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 Loading... |
| 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 MockMagnificationObserver { |
| 111 public content::NotificationObserver { | 111 public: |
| 112 MockMagnificationObserver() : observed_(false), |
| 113 observed_enabled_(false), |
| 114 magnifier_type_(-1) |
| 115 { |
| 116 AccessibilityManager* accessibility_manager = AccessibilityManager::Get(); |
| 117 CHECK(accessibility_manager); |
| 118 accessibility_subscription_ = accessibility_manager->RegisterCallback( |
| 119 base::Bind(&MockMagnificationObserver::OnAccessibilityStatusChanged, |
| 120 base::Unretained(this))); |
| 121 } |
| 122 |
| 123 virtual ~MockMagnificationObserver() {} |
| 124 |
| 125 bool observed() const { return observed_; } |
| 126 bool observed_enabled() const { return observed_enabled_; } |
| 127 int magnifier_type() const { return magnifier_type_; } |
| 128 |
| 129 void reset() { observed_ = false; } |
| 130 |
| 131 private: |
| 132 void OnAccessibilityStatusChanged( |
| 133 const AccessibilityStatusEventDetails& details) { |
| 134 if (details.notification_type == ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER) { |
| 135 magnifier_type_ = details.magnifier_type; |
| 136 observed_enabled_ = details.enabled; |
| 137 observed_ = true; |
| 138 } |
| 139 } |
| 140 |
| 141 bool observed_; |
| 142 bool observed_enabled_; |
| 143 int magnifier_type_; |
| 144 |
| 145 scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_; |
| 146 |
| 147 DISALLOW_COPY_AND_ASSIGN(MockMagnificationObserver); |
| 148 }; |
| 149 |
| 150 |
| 151 class MagnificationManagerTest : public InProcessBrowserTest { |
| 112 protected: | 152 protected: |
| 113 MagnificationManagerTest() : observed_(false), | 153 MagnificationManagerTest() {} |
| 114 observed_enabled_(false), | |
| 115 observed_type_(ash::kDefaultMagnifierType) {} | |
| 116 virtual ~MagnificationManagerTest() {} | 154 virtual ~MagnificationManagerTest() {} |
| 117 | 155 |
| 118 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 156 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 119 command_line->AppendSwitch(switches::kLoginManager); | 157 command_line->AppendSwitch(switches::kLoginManager); |
| 120 command_line->AppendSwitchASCII(switches::kLoginProfile, | 158 command_line->AppendSwitchASCII(switches::kLoginProfile, |
| 121 TestingProfile::kTestUserProfileDir); | 159 TestingProfile::kTestUserProfileDir); |
| 122 } | 160 } |
| 123 | 161 |
| 124 virtual void SetUpOnMainThread() OVERRIDE { | 162 virtual void SetUpOnMainThread() OVERRIDE { |
| 125 registrar_.Add( | |
| 126 this, | |
| 127 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER, | |
| 128 content::NotificationService::AllSources()); | |
| 129 | |
| 130 // Set the login-screen profile. | 163 // Set the login-screen profile. |
| 131 MagnificationManager::Get()->SetProfileForTest( | 164 MagnificationManager::Get()->SetProfileForTest( |
| 132 ProfileManager::GetActiveUserProfile()); | 165 ProfileManager::GetActiveUserProfile()); |
| 133 } | 166 } |
| 134 | 167 |
| 135 // content::NotificationObserver implementation. | |
| 136 virtual void Observe(int type, | |
| 137 const content::NotificationSource& source, | |
| 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 | |
| 144 observed_ = true; | |
| 145 observed_enabled_ = accessibility_status->enabled; | |
| 146 observed_type_ = accessibility_status->magnifier_type; | |
| 147 break; | |
| 148 } | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 bool observed_; | |
| 153 bool observed_enabled_; | |
| 154 ash::MagnifierType observed_type_; | |
| 155 content::NotificationRegistrar registrar_; | |
| 156 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); | 168 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); |
| 157 }; | 169 }; |
| 158 | 170 |
| 159 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, PRE_LoginOffToOff) { | 171 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, PRE_LoginOffToOff) { |
| 160 // Create a new profile once, to run the test with non-new profile. | 172 // Create a new profile once, to run the test with non-new profile. |
| 161 PrepareNonNewProfile(kTestUserName); | 173 PrepareNonNewProfile(kTestUserName); |
| 162 | 174 |
| 163 // Sets pref to explicitly disable the magnifier. | 175 // Sets pref to explicitly disable the magnifier. |
| 164 SetScreenMagnifierEnabledPref(false); | 176 SetScreenMagnifierEnabledPref(false); |
| 165 } | 177 } |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 512 |
| 501 // Enables full screen magnifier. | 513 // Enables full screen magnifier. |
| 502 SetMagnifierEnabled(true); | 514 SetMagnifierEnabled(true); |
| 503 EXPECT_TRUE(IsMagnifierEnabled()); | 515 EXPECT_TRUE(IsMagnifierEnabled()); |
| 504 EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); | 516 EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType()); |
| 505 | 517 |
| 506 // Confirms that the actual scale is set to the maximum scale. | 518 // Confirms that the actual scale is set to the maximum scale. |
| 507 EXPECT_EQ(4.0, GetFullScreenMagnifierScale()); | 519 EXPECT_EQ(4.0, GetFullScreenMagnifierScale()); |
| 508 } | 520 } |
| 509 | 521 |
| 522 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, |
| 523 ChangingTypeInvokesNotification) { |
| 524 MockMagnificationObserver observer; |
| 525 |
| 526 EXPECT_FALSE(observer.observed()); |
| 527 |
| 528 // Set full screen magnifier, and confirm the observer is called. |
| 529 SetMagnifierEnabled(true); |
| 530 SetMagnifierType(ash::MAGNIFIER_FULL); |
| 531 EXPECT_TRUE(observer.observed()); |
| 532 EXPECT_TRUE(observer.observed_enabled()); |
| 533 EXPECT_EQ(observer.magnifier_type(), ash::MAGNIFIER_FULL); |
| 534 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); |
| 535 observer.reset(); |
| 536 |
| 537 // Set full screen magnifier again, and confirm the observer is not called. |
| 538 SetMagnifierType(ash::MAGNIFIER_FULL); |
| 539 EXPECT_FALSE(observer.observed()); |
| 540 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); |
| 541 observer.reset(); |
| 542 } |
| 543 |
| 510 } // namespace chromeos | 544 } // namespace chromeos |
| OLD | NEW |