OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/command_line.h" | |
6 #include "chrome/browser/browser_process.h" | |
7 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | |
8 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | |
9 #include "chrome/browser/chromeos/cros/cros_mock.h" | |
10 #include "chrome/browser/chromeos/cros/mock_network_library.h" | |
11 #include "chrome/browser/chromeos/login/helper.h" | |
12 #include "chrome/browser/chromeos/login/login_utils.h" | |
13 #include "chrome/browser/chromeos/login/user_manager.h" | |
14 #include "chrome/browser/chromeos/login/user_manager_impl.h" | |
15 #include "chrome/browser/prefs/pref_service.h" | |
16 #include "chrome/browser/profiles/profile.h" | |
17 #include "chrome/browser/profiles/profile_manager.h" | |
18 #include "chrome/common/pref_names.h" | |
19 #include "chrome/common/chrome_notification_types.h" | |
20 #include "chrome/common/chrome_switches.h" | |
21 #include "chrome/test/base/testing_profile.h" | |
22 #include "chromeos/dbus/mock_cros_disks_client.h" | |
23 #include "chromeos/dbus/mock_dbus_thread_manager.h" | |
24 #include "chromeos/dbus/mock_power_manager_client.h" | |
25 #include "chromeos/dbus/mock_session_manager_client.h" | |
26 #include "content/public/test/test_utils.h" | |
27 #include "testing/gmock/include/gmock/gmock.h" | |
28 #include "testing/gtest/include/gtest/gtest.h" | |
29 | |
30 using ::testing::_; | |
31 using ::testing::AnyNumber; | |
32 using ::testing::Return; | |
33 | |
34 namespace chromeos { | |
35 | |
36 class MagnificationManagerTest : public CrosInProcessBrowserTest { | |
37 protected: | |
38 MagnificationManagerTest() {} | |
39 virtual ~MagnificationManagerTest() {} | |
40 | |
41 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
42 MockDBusThreadManager* mock_dbus_thread_manager = | |
43 new MockDBusThreadManager; | |
44 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | |
45 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | |
46 | |
47 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | |
48 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
49 cros_mock_->InitStatusAreaMocks(); | |
50 cros_mock_->SetStatusAreaMocksExpectations(); | |
51 | |
52 MockNetworkLibrary* mock_network_library_ = | |
53 cros_mock_->mock_network_library(); | |
54 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) | |
55 .Times(AnyNumber()); | |
56 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _, _)) | |
57 .WillRepeatedly(Return(true)); | |
58 | |
59 MockSessionManagerClient* mock_session_manager_client = | |
60 mock_dbus_thread_manager->mock_session_manager_client(); | |
61 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_)) | |
62 .Times(AnyNumber()); | |
63 EXPECT_CALL(*mock_session_manager_client, HasObserver(_)) | |
64 .WillRepeatedly(Return(false)); | |
65 | |
66 MockPowerManagerClient* mock_update_engine_client = | |
67 mock_dbus_thread_manager->mock_power_manager_client(); | |
68 EXPECT_CALL(*mock_update_engine_client, HasObserver(_)) | |
69 .WillRepeatedly(Return(false)); | |
70 | |
71 MockCrosDisksClient* mock_cros_disks_client = | |
72 mock_dbus_thread_manager->mock_cros_disks_client(); | |
73 EXPECT_CALL(*mock_cros_disks_client, EnumerateAutoMountableDevices(_, _)) | |
74 .Times(AnyNumber()); | |
75 EXPECT_CALL(*mock_cros_disks_client, SetUpConnections(_, _)) | |
76 .Times(AnyNumber()); | |
77 } | |
78 | |
79 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
80 command_line->AppendSwitch(switches::kLoginManager); | |
81 command_line->AppendSwitchASCII(switches::kLoginProfile, | |
82 TestingProfile::kTestUserProfileDir); | |
83 } | |
84 | |
85 Profile* profile() { | |
86 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | |
87 DCHECK(profile); | |
88 return profile; | |
89 } | |
90 | |
91 PrefServiceBase* prefs() { | |
92 return PrefServiceBase::FromBrowserContext(profile()); | |
93 } | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); | |
96 }; | |
97 | |
98 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, Login) { | |
99 // Confirms that magnifier is enabled on the login screen. | |
100 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
101 | |
102 // Logs in. | |
103 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); | |
104 UserManager::Get()->SessionStarted(); | |
105 | |
106 // Confirms that magnifier is disabled just after login. | |
107 EXPECT_FALSE(MagnificationManager::GetInstance()->IsEnabled()); | |
108 | |
109 // Enables magnifier. | |
110 MagnificationManager::GetInstance()->SetEnabled(true); | |
111 | |
112 // Confirms that magnifier is enabled. | |
113 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
114 } | |
115 | |
116 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, WorkingWithPref) { | |
117 // Logs in | |
118 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); | |
119 UserManager::Get()->SessionStarted(); | |
120 | |
121 // Confirms that magnifier is disabled just after login. | |
122 EXPECT_FALSE(MagnificationManager::GetInstance()->IsEnabled()); | |
123 | |
124 // Sets the pref as true to enable magnifier. | |
125 prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, true); | |
126 | |
127 // Confirms that magnifier is enabled. | |
128 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
129 | |
130 // Sets the pref as false to disabled magnifier. | |
131 prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, false); | |
132 | |
133 // Confirms that magnifier is disabled. | |
134 EXPECT_FALSE(MagnificationManager::GetInstance()->IsEnabled()); | |
135 | |
136 // Sets the pref as true to enable magnifier again. | |
137 prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, true); | |
138 | |
139 // Confirms that magnifier is enabled. | |
140 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
141 } | |
142 | |
143 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ResumeSavedPref) { | |
144 // Loads the profile of the user. | |
145 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); | |
146 | |
147 // Sets the pref as true to enable magnifier before login. | |
148 prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, true); | |
149 | |
150 // Logs in. | |
151 UserManager::Get()->SessionStarted(); | |
152 | |
153 // Confirms that magnifier is enabled just after login. | |
154 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
155 } | |
156 | |
157 } // namespace chromeos | |
OLD | NEW |