Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/magnification_manager.h" | 5 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
| 6 | 6 |
| 7 #include "ash/magnifier/magnifier_constants.h" | 7 #include "ash/magnifier/magnifier_constants.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | |
| 11 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 13 #include "content/public/browser/notification_service.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 13 |
| 16 namespace chromeos { | 14 namespace chromeos { |
| 17 namespace { | 15 namespace { |
| 18 | 16 |
| 19 class MockMagnificationObserver : public content::NotificationObserver { | |
| 20 public: | |
| 21 MockMagnificationObserver() : observed_(false), | |
| 22 observed_enabled_(false), | |
| 23 observed_type_(ash::kDefaultMagnifierType) { | |
| 24 registrar_.Add( | |
| 25 this, | |
| 26 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER, | |
| 27 content::NotificationService::AllSources()); | |
| 28 } | |
| 29 | |
| 30 bool observed() const { return observed_; } | |
| 31 bool observed_enabled() const { return observed_enabled_; } | |
| 32 ash::MagnifierType observed_type() const { return observed_type_; } | |
| 33 | |
| 34 void reset() { observed_ = false; } | |
| 35 | |
| 36 private: | |
| 37 // content::NotificationObserver implimentation: | |
| 38 virtual void Observe(int type, | |
| 39 const content::NotificationSource& source, | |
| 40 const content::NotificationDetails& details) OVERRIDE { | |
| 41 switch (type) { | |
| 42 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER: | |
| 43 AccessibilityStatusEventDetails* accessibility_status = | |
| 44 content::Details<AccessibilityStatusEventDetails>(details).ptr(); | |
| 45 | |
| 46 observed_ = true; | |
| 47 observed_enabled_ = accessibility_status->enabled; | |
| 48 observed_type_ = accessibility_status->magnifier_type; | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 bool observed_; | |
| 53 bool observed_enabled_; | |
| 54 ash::MagnifierType observed_type_; | |
| 55 | |
| 56 content::NotificationRegistrar registrar_; | |
| 57 }; | |
| 58 | |
| 59 void EnableMagnifier() { | 17 void EnableMagnifier() { |
| 60 return MagnificationManager::Get()->SetMagnifierEnabled(true); | 18 return MagnificationManager::Get()->SetMagnifierEnabled(true); |
| 61 } | 19 } |
| 62 | 20 |
| 63 void DisableMagnifier() { | 21 void DisableMagnifier() { |
| 64 return MagnificationManager::Get()->SetMagnifierEnabled(false); | 22 return MagnificationManager::Get()->SetMagnifierEnabled(false); |
| 65 } | 23 } |
| 66 | 24 |
| 67 bool IsMagnifierEnabled() { | 25 bool IsMagnifierEnabled() { |
| 68 return MagnificationManager::Get()->IsMagnifierEnabled(); | 26 return MagnificationManager::Get()->IsMagnifierEnabled(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 91 } | 49 } |
| 92 | 50 |
| 93 virtual void TearDown() OVERRIDE { | 51 virtual void TearDown() OVERRIDE { |
| 94 MagnificationManager::Shutdown(); | 52 MagnificationManager::Shutdown(); |
| 95 ash::test::AshTestBase::TearDown(); | 53 ash::test::AshTestBase::TearDown(); |
| 96 } | 54 } |
| 97 | 55 |
| 98 TestingProfile profile_; | 56 TestingProfile profile_; |
| 99 }; | 57 }; |
| 100 | 58 |
| 101 TEST_F(MagnificationManagerTest, MagnificationObserver) { | |
|
kevers
2014/02/20 17:00:50
Moved to browser test since notifications are via
| |
| 102 MockMagnificationObserver observer; | |
| 103 | |
| 104 EXPECT_FALSE(observer.observed()); | |
| 105 | |
| 106 // Set full screen magnifier, and confirm the observer is called. | |
| 107 EnableMagnifier(); | |
| 108 SetMagnifierType(ash::MAGNIFIER_FULL); | |
| 109 EXPECT_TRUE(observer.observed()); | |
| 110 EXPECT_TRUE(observer.observed_enabled()); | |
| 111 EXPECT_EQ(observer.observed_type(), ash::MAGNIFIER_FULL); | |
| 112 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); | |
| 113 observer.reset(); | |
| 114 | |
| 115 // Set full screen magnifier again, and confirm the observer is not called. | |
| 116 SetMagnifierType(ash::MAGNIFIER_FULL); | |
| 117 EXPECT_FALSE(observer.observed()); | |
| 118 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); | |
| 119 observer.reset(); | |
| 120 } | |
| 121 | |
| 122 TEST_F(MagnificationManagerTest, ChangeType) { | 59 TEST_F(MagnificationManagerTest, ChangeType) { |
| 123 // Set full screen magnifier, and confirm the status is set successfully. | 60 // Set full screen magnifier, and confirm the status is set successfully. |
| 124 EnableMagnifier(); | 61 EnableMagnifier(); |
| 125 SetMagnifierType(ash::MAGNIFIER_FULL); | 62 SetMagnifierType(ash::MAGNIFIER_FULL); |
| 126 EXPECT_TRUE(IsMagnifierEnabled()); | 63 EXPECT_TRUE(IsMagnifierEnabled()); |
| 127 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); | 64 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); |
| 128 | 65 |
| 129 // Set partial screen magnifier, and confirm the change is ignored. | 66 // Set partial screen magnifier, and confirm the change is ignored. |
| 130 SetMagnifierType(ash::MAGNIFIER_PARTIAL); | 67 SetMagnifierType(ash::MAGNIFIER_PARTIAL); |
| 131 EXPECT_TRUE(IsMagnifierEnabled()); | 68 EXPECT_TRUE(IsMagnifierEnabled()); |
| 132 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); | 69 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); |
| 133 | 70 |
| 134 // Disables magnifier, and confirm the status is set successfully. | 71 // Disables magnifier, and confirm the status is set successfully. |
| 135 DisableMagnifier(); | 72 DisableMagnifier(); |
| 136 EXPECT_FALSE(IsMagnifierEnabled()); | 73 EXPECT_FALSE(IsMagnifierEnabled()); |
| 137 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); | 74 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL); |
| 138 } | 75 } |
| 139 | 76 |
| 140 } // namespace chromeos | 77 } // namespace chromeos |
| OLD | NEW |