OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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" | |
12 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 11 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
13 #include "chrome/browser/chromeos/login/wizard_controller.h" | 12 #include "chrome/browser/chromeos/login/wizard_controller.h" |
14 #include "chrome/browser/chromeos/login/wizard_screen.h" | 13 #include "chrome/browser/chromeos/login/wizard_screen.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
19 | 18 |
20 namespace chromeos { | 19 namespace chromeos { |
21 | 20 |
22 using ::testing::AnyNumber; | 21 using ::testing::AnyNumber; |
23 using ::testing::AtMost; | 22 using ::testing::AtMost; |
24 using ::testing::InSequence; | 23 using ::testing::InSequence; |
25 using ::testing::InvokeWithoutArgs; | 24 using ::testing::InvokeWithoutArgs; |
26 using ::testing::Return; | 25 using ::testing::Return; |
27 using ::testing::ReturnRef; | 26 using ::testing::ReturnRef; |
28 using ::testing::StrictMock; | 27 using ::testing::StrictMock; |
29 using ::testing::_; | 28 using ::testing::_; |
30 | 29 |
31 CrosMock::CrosMock() | 30 CrosMock::CrosMock() |
32 : loader_(NULL), | 31 : mock_cryptohome_library_(NULL), |
33 mock_cryptohome_library_(NULL), | |
34 mock_network_library_(NULL) { | 32 mock_network_library_(NULL) { |
35 } | 33 } |
36 | 34 |
37 CrosMock::~CrosMock() { | 35 CrosMock::~CrosMock() { |
38 } | 36 } |
39 | 37 |
40 chromeos::CrosLibrary::TestApi* CrosMock::test_api() { | 38 chromeos::CrosLibrary::TestApi* CrosMock::test_api() { |
41 return chromeos::CrosLibrary::Get()->GetTestApi(); | 39 return chromeos::CrosLibrary::Get()->GetTestApi(); |
42 } | 40 } |
43 | 41 |
44 void CrosMock::InitStatusAreaMocks() { | 42 void CrosMock::InitStatusAreaMocks() { |
45 InitMockNetworkLibrary(); | 43 InitMockNetworkLibrary(); |
46 } | 44 } |
47 | 45 |
48 void CrosMock::InitMockLibraryLoader() { | |
49 if (loader_) | |
50 return; | |
51 loader_ = new StrictMock<MockLibraryLoader>(); | |
52 EXPECT_CALL(*loader_, Load(_)) | |
53 .Times(AnyNumber()) | |
54 .WillRepeatedly(Return(true)); | |
55 test_api()->SetLibraryLoader(loader_, true); | |
56 } | |
57 | |
58 void CrosMock::InitMockCryptohomeLibrary() { | 46 void CrosMock::InitMockCryptohomeLibrary() { |
59 InitMockLibraryLoader(); | |
60 if (mock_cryptohome_library_) | 47 if (mock_cryptohome_library_) |
61 return; | 48 return; |
62 mock_cryptohome_library_ = new StrictMock<MockCryptohomeLibrary>(); | 49 mock_cryptohome_library_ = new StrictMock<MockCryptohomeLibrary>(); |
63 test_api()->SetCryptohomeLibrary(mock_cryptohome_library_, true); | 50 test_api()->SetCryptohomeLibrary(mock_cryptohome_library_, true); |
64 } | 51 } |
65 | 52 |
66 void CrosMock::InitMockNetworkLibrary() { | 53 void CrosMock::InitMockNetworkLibrary() { |
67 InitMockLibraryLoader(); | |
68 if (mock_network_library_) | 54 if (mock_network_library_) |
69 return; | 55 return; |
70 mock_network_library_ = new StrictMock<MockNetworkLibrary>(); | 56 mock_network_library_ = new StrictMock<MockNetworkLibrary>(); |
71 test_api()->SetNetworkLibrary(mock_network_library_, true); | 57 test_api()->SetNetworkLibrary(mock_network_library_, true); |
72 } | 58 } |
73 | 59 |
74 // Initialization of mocks. | 60 // Initialization of mocks. |
75 MockCryptohomeLibrary* CrosMock::mock_cryptohome_library() { | 61 MockCryptohomeLibrary* CrosMock::mock_cryptohome_library() { |
76 return mock_cryptohome_library_; | 62 return mock_cryptohome_library_; |
77 } | 63 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 .WillRepeatedly((Return(false))) | 191 .WillRepeatedly((Return(false))) |
206 .RetiresOnSaturation(); | 192 .RetiresOnSaturation(); |
207 EXPECT_CALL(*mock_network_library_, ethernet_connecting()) | 193 EXPECT_CALL(*mock_network_library_, ethernet_connecting()) |
208 .Times(AnyNumber()) | 194 .Times(AnyNumber()) |
209 .WillRepeatedly((Return(false))) | 195 .WillRepeatedly((Return(false))) |
210 .RetiresOnSaturation(); | 196 .RetiresOnSaturation(); |
211 } | 197 } |
212 | 198 |
213 void CrosMock::TearDownMocks() { | 199 void CrosMock::TearDownMocks() { |
214 // Prevent bogus gMock leak check from firing. | 200 // Prevent bogus gMock leak check from firing. |
215 if (loader_) | |
216 test_api()->SetLibraryLoader(NULL, false); | |
217 if (mock_cryptohome_library_) | 201 if (mock_cryptohome_library_) |
218 test_api()->SetCryptohomeLibrary(NULL, false); | 202 test_api()->SetCryptohomeLibrary(NULL, false); |
219 if (mock_network_library_) | 203 if (mock_network_library_) |
220 test_api()->SetNetworkLibrary(NULL, false); | 204 test_api()->SetNetworkLibrary(NULL, false); |
221 } | 205 } |
222 | 206 |
223 } // namespace chromeos | 207 } // namespace chromeos |
OLD | NEW |