OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/cros/cros_mock.h" | 5 #include "chrome/browser/chromeos/cros/cros_mock.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" | 10 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" |
11 #include "chrome/browser/chromeos/cros/mock_library_loader.h" | 11 #include "chrome/browser/chromeos/cros/mock_library_loader.h" |
12 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 12 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
13 #include "chrome/browser/chromeos/cros/mock_power_library.h" | 13 #include "chrome/browser/chromeos/cros/mock_power_library.h" |
14 #include "chrome/browser/chromeos/cros/mock_screen_lock_library.h" | 14 #include "chrome/browser/chromeos/cros/mock_screen_lock_library.h" |
15 #include "chrome/browser/chromeos/cros/mock_speech_synthesis_library.h" | |
16 #include "chrome/browser/chromeos/login/wizard_controller.h" | 15 #include "chrome/browser/chromeos/login/wizard_controller.h" |
17 #include "chrome/browser/chromeos/login/wizard_screen.h" | 16 #include "chrome/browser/chromeos/login/wizard_screen.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
22 | 21 |
23 namespace chromeos { | 22 namespace chromeos { |
24 | 23 |
25 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
26 using ::testing::AtMost; | 25 using ::testing::AtMost; |
27 using ::testing::InSequence; | 26 using ::testing::InSequence; |
28 using ::testing::InvokeWithoutArgs; | 27 using ::testing::InvokeWithoutArgs; |
29 using ::testing::Return; | 28 using ::testing::Return; |
30 using ::testing::ReturnRef; | 29 using ::testing::ReturnRef; |
31 using ::testing::StrictMock; | 30 using ::testing::StrictMock; |
32 using ::testing::_; | 31 using ::testing::_; |
33 | 32 |
34 CrosMock::CrosMock() | 33 CrosMock::CrosMock() |
35 : loader_(NULL), | 34 : loader_(NULL), |
36 mock_cryptohome_library_(NULL), | 35 mock_cryptohome_library_(NULL), |
37 mock_network_library_(NULL), | 36 mock_network_library_(NULL), |
38 mock_power_library_(NULL), | 37 mock_power_library_(NULL), |
39 mock_screen_lock_library_(NULL), | 38 mock_screen_lock_library_(NULL) { |
40 mock_speech_synthesis_library_(NULL) { | |
41 } | 39 } |
42 | 40 |
43 CrosMock::~CrosMock() { | 41 CrosMock::~CrosMock() { |
44 } | 42 } |
45 | 43 |
46 chromeos::CrosLibrary::TestApi* CrosMock::test_api() { | 44 chromeos::CrosLibrary::TestApi* CrosMock::test_api() { |
47 return chromeos::CrosLibrary::Get()->GetTestApi(); | 45 return chromeos::CrosLibrary::Get()->GetTestApi(); |
48 } | 46 } |
49 | 47 |
50 void CrosMock::InitStatusAreaMocks() { | 48 void CrosMock::InitStatusAreaMocks() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 85 } |
88 | 86 |
89 void CrosMock::InitMockScreenLockLibrary() { | 87 void CrosMock::InitMockScreenLockLibrary() { |
90 InitMockLibraryLoader(); | 88 InitMockLibraryLoader(); |
91 if (mock_screen_lock_library_) | 89 if (mock_screen_lock_library_) |
92 return; | 90 return; |
93 mock_screen_lock_library_ = new StrictMock<MockScreenLockLibrary>(); | 91 mock_screen_lock_library_ = new StrictMock<MockScreenLockLibrary>(); |
94 test_api()->SetScreenLockLibrary(mock_screen_lock_library_, true); | 92 test_api()->SetScreenLockLibrary(mock_screen_lock_library_, true); |
95 } | 93 } |
96 | 94 |
97 void CrosMock::InitMockSpeechSynthesisLibrary() { | |
98 InitMockLibraryLoader(); | |
99 if (mock_speech_synthesis_library_) | |
100 return; | |
101 mock_speech_synthesis_library_ = | |
102 new StrictMock<MockSpeechSynthesisLibrary>(); | |
103 test_api()->SetSpeechSynthesisLibrary(mock_speech_synthesis_library_, true); | |
104 } | |
105 | |
106 // Initialization of mocks. | 95 // Initialization of mocks. |
107 MockCryptohomeLibrary* CrosMock::mock_cryptohome_library() { | 96 MockCryptohomeLibrary* CrosMock::mock_cryptohome_library() { |
108 return mock_cryptohome_library_; | 97 return mock_cryptohome_library_; |
109 } | 98 } |
110 | 99 |
111 MockNetworkLibrary* CrosMock::mock_network_library() { | 100 MockNetworkLibrary* CrosMock::mock_network_library() { |
112 return mock_network_library_; | 101 return mock_network_library_; |
113 } | 102 } |
114 | 103 |
115 MockPowerLibrary* CrosMock::mock_power_library() { | 104 MockPowerLibrary* CrosMock::mock_power_library() { |
116 return mock_power_library_; | 105 return mock_power_library_; |
117 } | 106 } |
118 | 107 |
119 MockScreenLockLibrary* CrosMock::mock_screen_lock_library() { | 108 MockScreenLockLibrary* CrosMock::mock_screen_lock_library() { |
120 return mock_screen_lock_library_; | 109 return mock_screen_lock_library_; |
121 } | 110 } |
122 | 111 |
123 MockSpeechSynthesisLibrary* CrosMock::mock_speech_synthesis_library() { | |
124 return mock_speech_synthesis_library_; | |
125 } | |
126 | |
127 void CrosMock::SetStatusAreaMocksExpectations() { | 112 void CrosMock::SetStatusAreaMocksExpectations() { |
128 SetNetworkLibraryStatusAreaExpectations(); | 113 SetNetworkLibraryStatusAreaExpectations(); |
129 SetPowerLibraryStatusAreaExpectations(); | 114 SetPowerLibraryStatusAreaExpectations(); |
130 SetPowerLibraryExpectations(); | 115 SetPowerLibraryExpectations(); |
131 } | 116 } |
132 | 117 |
133 void CrosMock::SetNetworkLibraryStatusAreaExpectations() { | 118 void CrosMock::SetNetworkLibraryStatusAreaExpectations() { |
134 // We don't care how often these are called, just set their return values: | 119 // We don't care how often these are called, just set their return values: |
135 EXPECT_CALL(*mock_network_library_, AddNetworkManagerObserver(_)) | 120 EXPECT_CALL(*mock_network_library_, AddNetworkManagerObserver(_)) |
136 .Times(AnyNumber()); | 121 .Times(AnyNumber()); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 .RetiresOnSaturation(); | 253 .RetiresOnSaturation(); |
269 } | 254 } |
270 | 255 |
271 void CrosMock::SetPowerLibraryExpectations() { | 256 void CrosMock::SetPowerLibraryExpectations() { |
272 // EnableScreenLock is currently bounded with a prefs value and thus is | 257 // EnableScreenLock is currently bounded with a prefs value and thus is |
273 // always called when loading | 258 // always called when loading |
274 EXPECT_CALL(*mock_power_library_, EnableScreenLock(_)) | 259 EXPECT_CALL(*mock_power_library_, EnableScreenLock(_)) |
275 .Times(AnyNumber()); | 260 .Times(AnyNumber()); |
276 } | 261 } |
277 | 262 |
278 void CrosMock::SetSpeechSynthesisLibraryExpectations() { | |
279 InSequence s; | |
280 EXPECT_CALL(*mock_speech_synthesis_library_, StopSpeaking()) | |
281 .WillOnce(Return(true)) | |
282 .RetiresOnSaturation(); | |
283 EXPECT_CALL(*mock_speech_synthesis_library_, SetSpeakProperties(_)) | |
284 .WillOnce(Return(true)) | |
285 .RetiresOnSaturation(); | |
286 EXPECT_CALL(*mock_speech_synthesis_library_, Speak(_)) | |
287 .WillOnce(Return(true)) | |
288 .RetiresOnSaturation(); | |
289 EXPECT_CALL(*mock_speech_synthesis_library_, IsSpeaking()) | |
290 .WillOnce(Return(true)) | |
291 .RetiresOnSaturation(); | |
292 EXPECT_CALL(*mock_speech_synthesis_library_, StopSpeaking()) | |
293 .WillOnce(Return(true)) | |
294 .RetiresOnSaturation(); | |
295 EXPECT_CALL(*mock_speech_synthesis_library_, SetSpeakProperties(_)) | |
296 .WillOnce(Return(true)) | |
297 .RetiresOnSaturation(); | |
298 EXPECT_CALL(*mock_speech_synthesis_library_, Speak(_)) | |
299 .WillOnce(Return(true)) | |
300 .RetiresOnSaturation(); | |
301 EXPECT_CALL(*mock_speech_synthesis_library_, IsSpeaking()) | |
302 .WillOnce(Return(true)) | |
303 .WillOnce(Return(true)) | |
304 .WillOnce(Return(false)) | |
305 .RetiresOnSaturation(); | |
306 } | |
307 | |
308 void CrosMock::TearDownMocks() { | 263 void CrosMock::TearDownMocks() { |
309 // Prevent bogus gMock leak check from firing. | 264 // Prevent bogus gMock leak check from firing. |
310 if (loader_) | 265 if (loader_) |
311 test_api()->SetLibraryLoader(NULL, false); | 266 test_api()->SetLibraryLoader(NULL, false); |
312 if (mock_cryptohome_library_) | 267 if (mock_cryptohome_library_) |
313 test_api()->SetCryptohomeLibrary(NULL, false); | 268 test_api()->SetCryptohomeLibrary(NULL, false); |
314 if (mock_network_library_) | 269 if (mock_network_library_) |
315 test_api()->SetNetworkLibrary(NULL, false); | 270 test_api()->SetNetworkLibrary(NULL, false); |
316 if (mock_power_library_) | 271 if (mock_power_library_) |
317 test_api()->SetPowerLibrary(NULL, false); | 272 test_api()->SetPowerLibrary(NULL, false); |
318 if (mock_screen_lock_library_) | 273 if (mock_screen_lock_library_) |
319 test_api()->SetScreenLockLibrary(NULL, false); | 274 test_api()->SetScreenLockLibrary(NULL, false); |
320 if (mock_speech_synthesis_library_) | |
321 test_api()->SetSpeechSynthesisLibrary(NULL, false); | |
322 } | 275 } |
323 | 276 |
324 } // namespace chromeos | 277 } // namespace chromeos |
OLD | NEW |