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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
7 #include "ash/magnifier/magnifier_constants.h"
8 #include "ash/test/ash_test_base.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/browser/notification_service.h"
14 #include "testing/gtest/include/gtest/gtest.h"
19 class MockMagnificationObserver
: public content::NotificationObserver
{
21 MockMagnificationObserver() : observed_(false),
22 observed_enabled_(false),
23 observed_type_(ash::kDefaultMagnifierType
) {
26 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER
,
27 content::NotificationService::AllSources());
30 bool observed() const { return observed_
; }
31 bool observed_enabled() const { return observed_enabled_
; }
32 ash::MagnifierType
observed_type() const { return observed_type_
; }
34 void reset() { observed_
= false; }
37 // content::NotificationObserver implimentation:
38 virtual void Observe(int type
,
39 const content::NotificationSource
& source
,
40 const content::NotificationDetails
& details
) OVERRIDE
{
42 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER
:
43 AccessibilityStatusEventDetails
* accessibility_status
=
44 content::Details
<AccessibilityStatusEventDetails
>(details
).ptr();
47 observed_enabled_
= accessibility_status
->enabled
;
48 observed_type_
= accessibility_status
->magnifier_type
;
53 bool observed_enabled_
;
54 ash::MagnifierType observed_type_
;
56 content::NotificationRegistrar registrar_
;
59 void EnableMagnifier() {
60 return MagnificationManager::Get()->SetMagnifierEnabled(true);
63 void DisableMagnifier() {
64 return MagnificationManager::Get()->SetMagnifierEnabled(false);
67 bool IsMagnifierEnabled() {
68 return MagnificationManager::Get()->IsMagnifierEnabled();
71 ash::MagnifierType
GetMagnifierType() {
72 return MagnificationManager::Get()->GetMagnifierType();
75 void SetMagnifierType(ash::MagnifierType type
) {
76 return MagnificationManager::Get()->SetMagnifierType(type
);
81 class MagnificationManagerTest
: public ash::test::AshTestBase
{
83 MagnificationManagerTest() {
86 virtual void SetUp() OVERRIDE
{
87 ash::test::AshTestBase::SetUp();
88 MagnificationManager::Initialize();
89 ASSERT_TRUE(MagnificationManager::Get());
90 MagnificationManager::Get()->SetProfileForTest(&profile_
);
93 virtual void TearDown() OVERRIDE
{
94 MagnificationManager::Shutdown();
95 ash::test::AshTestBase::TearDown();
98 TestingProfile profile_
;
101 TEST_F(MagnificationManagerTest
, MagnificationObserver
) {
102 MockMagnificationObserver observer
;
104 EXPECT_FALSE(observer
.observed());
106 // Set full screen magnifier, and confirm the observer is called.
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
);
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
);
122 TEST_F(MagnificationManagerTest
, ChangeType
) {
123 // Set full screen magnifier, and confirm the status is set successfully.
125 SetMagnifierType(ash::MAGNIFIER_FULL
);
126 EXPECT_TRUE(IsMagnifierEnabled());
127 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL
);
129 // Set partial screen magnifier, and confirm the change is ignored.
130 SetMagnifierType(ash::MAGNIFIER_PARTIAL
);
131 EXPECT_TRUE(IsMagnifierEnabled());
132 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL
);
134 // Disables magnifier, and confirm the status is set successfully.
136 EXPECT_FALSE(IsMagnifierEnabled());
137 EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL
);
140 } // namespace chromeos