OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 // Unit tests for Service | 5 // Unit tests for Service |
6 | 6 |
7 #include "service.h" | 7 #include "service.h" |
8 | 8 |
9 #include <base/at_exit.h> | 9 #include <base/at_exit.h> |
10 #include <base/platform_thread.h> | 10 #include <base/platform_thread.h> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // Protected for trivial access | 52 // Protected for trivial access |
53 chromeos::Blob system_salt_; | 53 chromeos::Blob system_salt_; |
54 | 54 |
55 private: | 55 private: |
56 DISALLOW_COPY_AND_ASSIGN(ServiceInterfaceTest); | 56 DISALLOW_COPY_AND_ASSIGN(ServiceInterfaceTest); |
57 }; | 57 }; |
58 | 58 |
59 class ServiceSubclass : public Service { | 59 class ServiceSubclass : public Service { |
60 public: | 60 public: |
61 ServiceSubclass() | 61 ServiceSubclass() |
62 : completed_tasks_() { } | 62 : Service(false), |
| 63 completed_tasks_() { } |
63 virtual ~ServiceSubclass() { } | 64 virtual ~ServiceSubclass() { } |
64 | 65 |
65 virtual void MountTaskObserve(const MountTaskResult& result) { | 66 virtual void MountTaskObserve(const MountTaskResult& result) { |
66 completed_tasks_.push_back(result); | 67 completed_tasks_.push_back(result); |
67 } | 68 } |
68 | 69 |
69 std::vector<MountTaskResult> completed_tasks_; | 70 std::vector<MountTaskResult> completed_tasks_; |
70 }; | 71 }; |
71 | 72 |
72 TEST_F(ServiceInterfaceTest, CheckKeySuccessTest) { | 73 TEST_F(ServiceInterfaceTest, CheckKeySuccessTest) { |
73 MockMount mount; | 74 MockMount mount; |
74 EXPECT_CALL(mount, Init()) | 75 EXPECT_CALL(mount, Init()) |
75 .WillOnce(Return(true)); | 76 .WillOnce(Return(true)); |
76 EXPECT_CALL(mount, TestCredentials(_)) | 77 EXPECT_CALL(mount, TestCredentials(_)) |
77 .WillOnce(Return(true)); | 78 .WillOnce(Return(true)); |
78 | 79 |
79 Service service; | 80 Service service(false); |
80 service.set_mount(&mount); | 81 service.set_mount(&mount); |
81 NiceMock<MockInstallAttributes> attrs; | 82 NiceMock<MockInstallAttributes> attrs; |
82 service.set_install_attrs(&attrs); | 83 service.set_install_attrs(&attrs); |
83 service.set_initialize_tpm(false); | 84 service.set_initialize_tpm(false); |
84 service.Initialize(); | 85 service.Initialize(); |
85 gboolean out = FALSE; | 86 gboolean out = FALSE; |
86 GError *error = NULL; | 87 GError *error = NULL; |
87 | 88 |
88 char user[] = "chromeos-user"; | 89 char user[] = "chromeos-user"; |
89 char key[] = "274146c6e8886a843ddfea373e2dc71b"; | 90 char key[] = "274146c6e8886a843ddfea373e2dc71b"; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 break; | 135 break; |
135 } | 136 } |
136 PlatformThread::Sleep(100); | 137 PlatformThread::Sleep(100); |
137 } | 138 } |
138 EXPECT_TRUE(out); | 139 EXPECT_TRUE(out); |
139 } | 140 } |
140 | 141 |
141 TEST(Standalone, CheckAutoCleanupCallback) { | 142 TEST(Standalone, CheckAutoCleanupCallback) { |
142 // Checks that AutoCleanupCallback() is called periodically. | 143 // Checks that AutoCleanupCallback() is called periodically. |
143 NiceMock<MockMount> mount; | 144 NiceMock<MockMount> mount; |
144 Service service; | 145 Service service(false); |
145 service.set_mount(&mount); | 146 service.set_mount(&mount); |
146 NiceMock<MockInstallAttributes> attrs; | 147 NiceMock<MockInstallAttributes> attrs; |
147 service.set_install_attrs(&attrs); | 148 service.set_install_attrs(&attrs); |
148 service.set_initialize_tpm(false); | 149 service.set_initialize_tpm(false); |
149 | 150 |
150 // Service will schedule periodic clean-ups. Wait a bit and make | 151 // Service will schedule periodic clean-ups. Wait a bit and make |
151 // sure that we had at least 3 executed. | 152 // sure that we had at least 3 executed. |
152 EXPECT_CALL(mount, DoAutomaticFreeDiskSpaceControl()) | 153 EXPECT_CALL(mount, DoAutomaticFreeDiskSpaceControl()) |
153 .Times(::testing::AtLeast(3)); | 154 .Times(::testing::AtLeast(3)); |
154 EXPECT_CALL(mount, UpdateUserActivityTimestamp()) | 155 EXPECT_CALL(mount, UpdateUserActivityTimestamp()) |
155 .Times(::testing::AtLeast(3)); | 156 .Times(::testing::AtLeast(3)); |
156 service.set_auto_cleanup_period(2); // 2ms = 500HZ | 157 service.set_auto_cleanup_period(2); // 2ms = 500HZ |
157 service.set_update_user_activity_period(2); // 2 x 5ms = 25HZ | 158 service.set_update_user_activity_period(2); // 2 x 5ms = 25HZ |
158 service.Initialize(); | 159 service.Initialize(); |
159 PlatformThread::Sleep(100); | 160 PlatformThread::Sleep(100); |
160 } | 161 } |
161 | 162 |
162 } // namespace cryptohome | 163 } // namespace cryptohome |
OLD | NEW |