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 "content/public/test/test_utils.h" | |
23 #include "chromeos/dbus/mock_cros_disks_client.h" | |
24 #include "chromeos/dbus/mock_dbus_thread_manager.h" | |
25 #include "chromeos/dbus/mock_media_transfer_protocol_daemon_client.h" | |
26 #include "chromeos/dbus/mock_power_manager_client.h" | |
27 #include "chromeos/dbus/mock_session_manager_client.h" | |
28 #include "testing/gmock/include/gmock/gmock.h" | |
29 #include "testing/gtest/include/gtest/gtest.h" | |
DaveMoore
2012/10/11 20:09:27
I believe we are avoiding new uses of gmock. Addin
yoshiki
2012/10/12 15:00:55
Thanks, waiting for Ben's comment.
| |
30 | |
31 using ::testing::_; | |
32 using ::testing::AnyNumber; | |
33 using ::testing::Return; | |
34 | |
35 namespace chromeos { | |
36 | |
37 class MagnificationManagerTest : public CrosInProcessBrowserTest { | |
38 protected: | |
39 MagnificationManagerTest() {} | |
40 virtual ~MagnificationManagerTest() {} | |
41 | |
42 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
43 MockDBusThreadManager* mock_dbus_thread_manager = | |
44 new MockDBusThreadManager; | |
45 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | |
46 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | |
47 | |
48 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | |
49 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
50 cros_mock_->InitStatusAreaMocks(); | |
51 cros_mock_->SetStatusAreaMocksExpectations(); | |
52 | |
53 MockNetworkLibrary* mock_network_library_ = | |
54 cros_mock_->mock_network_library(); | |
55 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) | |
56 .Times(AnyNumber()); | |
57 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _, _)) | |
58 .WillRepeatedly(Return(true)); | |
59 | |
60 MockSessionManagerClient* mock_session_manager_client = | |
61 mock_dbus_thread_manager->mock_session_manager_client(); | |
62 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_)) | |
63 .Times(AnyNumber()); | |
64 EXPECT_CALL(*mock_session_manager_client, HasObserver(_)) | |
65 .WillRepeatedly(Return(false)); | |
66 | |
67 MockPowerManagerClient* mock_update_engine_client = | |
68 mock_dbus_thread_manager->mock_power_manager_client(); | |
69 EXPECT_CALL(*mock_update_engine_client, HasObserver(_)) | |
70 .WillRepeatedly(Return(false)); | |
71 | |
72 MockCrosDisksClient* mock_cros_disks_client = | |
73 mock_dbus_thread_manager->mock_cros_disks_client(); | |
74 EXPECT_CALL(*mock_cros_disks_client, EnumerateAutoMountableDevices(_, _)) | |
75 .Times(AnyNumber()); | |
76 EXPECT_CALL(*mock_cros_disks_client, SetUpConnections(_, _)) | |
77 .Times(AnyNumber()); | |
78 | |
79 MockMediaTransferProtocolDaemonClient* | |
80 mock_media_transfer_protocol_daemon_client = | |
81 mock_dbus_thread_manager-> | |
82 mock_media_transfer_protocol_daemon_client(); | |
83 EXPECT_CALL(*mock_media_transfer_protocol_daemon_client, | |
84 SetUpConnections(_)) | |
85 .Times(AnyNumber()); | |
86 EXPECT_CALL(*mock_media_transfer_protocol_daemon_client, | |
87 EnumerateStorage(_, _)) | |
88 .Times(AnyNumber()); | |
89 } | |
90 | |
91 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
92 command_line->AppendSwitch(switches::kLoginManager); | |
93 command_line->AppendSwitchASCII(switches::kLoginProfile, | |
94 TestingProfile::kTestUserProfileDir); | |
95 } | |
96 | |
97 Profile* profile() { | |
98 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | |
99 DCHECK(profile); | |
100 return profile; | |
101 } | |
102 | |
103 PrefServiceBase* prefs() { | |
104 return PrefServiceBase::FromBrowserContext(profile()); | |
105 } | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); | |
108 }; | |
109 | |
110 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, Login) { | |
111 // Confirms that magnifier is enabled on the login screen. | |
112 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
113 | |
114 // Logs in. | |
115 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); | |
116 UserManager::Get()->SessionStarted(); | |
117 | |
118 // Confirms that magnifier is disabled just after login. | |
119 EXPECT_FALSE(MagnificationManager::GetInstance()->IsEnabled()); | |
120 | |
121 // Enables magnifier. | |
122 MagnificationManager::GetInstance()->SetEnabled(true); | |
123 | |
124 // Confirms that magnifier is enabled. | |
125 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
126 } | |
127 | |
128 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, WorkingWithPref) { | |
129 // Logs in | |
130 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); | |
131 UserManager::Get()->SessionStarted(); | |
132 | |
133 // Confirms that magnifier is disabled just after login. | |
134 EXPECT_FALSE(MagnificationManager::GetInstance()->IsEnabled()); | |
135 | |
136 // Sets the pref as true to enable magnifier. | |
137 prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, true); | |
138 | |
139 // Confirms that magnifier is enabled. | |
140 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
141 | |
142 // Sets the pref as false to disabled magnifier. | |
143 prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, false); | |
144 | |
145 // Confirms that magnifier is disabled. | |
146 EXPECT_FALSE(MagnificationManager::GetInstance()->IsEnabled()); | |
147 | |
148 // Sets the pref as true to enable magnifier again. | |
149 prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, true); | |
150 | |
151 // Confirms that magnifier is enabled. | |
152 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
153 } | |
154 | |
155 IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ResumeSavedPref) { | |
156 // Loads the profile of the user. | |
157 UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); | |
158 | |
159 // Sets the pref as true to enable magnifier before login. | |
160 prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, true); | |
161 | |
162 // Logs in. | |
163 UserManager::Get()->SessionStarted(); | |
164 | |
165 // Confirms that magnifier is enabled just after login. | |
166 EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); | |
167 } | |
168 | |
169 } // namespace chromeos | |
OLD | NEW |