OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/location.h" | 6 #include "base/location.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "chrome/browser/extensions/extension_install_checker.h" | 10 #include "chrome/browser/extensions/extension_install_checker.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const BlacklistState kBlacklistStateError = BLACKLISTED_MALWARE; | 17 const BlacklistState kBlacklistStateError = BLACKLISTED_MALWARE; |
18 const char kDummyRequirementsError[] = "Requirements error"; | 18 const char kDummyRequirementsError[] = "Requirements error"; |
19 const char kDummyPolicyError[] = "Cannot install extension"; | 19 const char kDummyPolicyError[] = "Cannot install extension"; |
20 | 20 |
21 const char kDummyPolicyError2[] = "Another policy error"; | |
22 const char kDummyRequirementsError2[] = "Another requirements error"; | |
23 const BlacklistState kBlacklistState2 = BLACKLISTED_SECURITY_VULNERABILITY; | |
24 | |
25 } // namespace | 21 } // namespace |
26 | 22 |
27 // Stubs most of the checks since we are interested in validating the logic in | 23 // Stubs most of the checks since we are interested in validating the logic in |
28 // the install checker. This class implements a synchronous version of all | 24 // the install checker. This class implements a synchronous version of all |
29 // checks. | 25 // checks. |
30 class ExtensionInstallCheckerForTest : public ExtensionInstallChecker { | 26 class ExtensionInstallCheckerForTest : public ExtensionInstallChecker { |
31 public: | 27 public: |
32 ExtensionInstallCheckerForTest() | 28 ExtensionInstallCheckerForTest(int enabled_checks, bool fail_fast) |
33 : ExtensionInstallChecker(NULL), | 29 : ExtensionInstallChecker(nullptr, nullptr, enabled_checks, fail_fast), |
34 requirements_check_called_(false), | 30 requirements_check_called_(false), |
35 blacklist_check_called_(false), | 31 blacklist_check_called_(false), |
36 policy_check_called_(false), | 32 policy_check_called_(false), |
37 blacklist_state_(NOT_BLACKLISTED) {} | 33 blacklist_state_(NOT_BLACKLISTED) {} |
38 | 34 |
39 ~ExtensionInstallCheckerForTest() override {} | 35 ~ExtensionInstallCheckerForTest() override {} |
40 | 36 |
41 void set_requirements_error(const std::string& error) { | 37 void set_requirements_error(const std::string& error) { |
42 requirements_error_ = error; | 38 requirements_error_ = error; |
43 } | 39 } |
44 void set_policy_check_error(const std::string& error) { | 40 void set_policy_check_error(const std::string& error) { |
45 policy_check_error_ = error; | 41 policy_check_error_ = error; |
46 } | 42 } |
47 void set_blacklist_state(BlacklistState state) { blacklist_state_ = state; } | 43 void set_blacklist_state(BlacklistState state) { blacklist_state_ = state; } |
48 | 44 |
49 bool requirements_check_called() const { return requirements_check_called_; } | 45 bool requirements_check_called() const { return requirements_check_called_; } |
50 bool blacklist_check_called() const { return blacklist_check_called_; } | 46 bool blacklist_check_called() const { return blacklist_check_called_; } |
51 bool policy_check_called() const { return policy_check_called_; } | 47 bool policy_check_called() const { return policy_check_called_; } |
52 | 48 |
53 void MockCheckRequirements(int sequence_number) { | 49 void MockCheckRequirements() { |
54 std::vector<std::string> errors; | 50 std::vector<std::string> errors; |
55 if (!requirements_error_.empty()) | 51 if (!requirements_error_.empty()) |
56 errors.push_back(requirements_error_); | 52 errors.push_back(requirements_error_); |
57 OnRequirementsCheckDone(sequence_number, errors); | 53 OnRequirementsCheckDone(errors); |
58 } | 54 } |
59 | 55 |
60 void MockCheckBlacklistState(int sequence_number) { | 56 void MockCheckBlacklistState() { |
61 OnBlacklistStateCheckDone(sequence_number, blacklist_state_); | 57 OnBlacklistStateCheckDone(blacklist_state_); |
62 } | 58 } |
63 | 59 |
64 protected: | 60 protected: |
65 void CheckRequirements() override { | 61 void CheckRequirements() override { |
66 requirements_check_called_ = true; | 62 requirements_check_called_ = true; |
67 MockCheckRequirements(current_sequence_number()); | 63 MockCheckRequirements(); |
68 } | 64 } |
69 | 65 |
70 void CheckManagementPolicy() override { | 66 void CheckManagementPolicy() override { |
71 policy_check_called_ = true; | 67 policy_check_called_ = true; |
72 OnManagementPolicyCheckDone(policy_check_error_.empty(), | 68 OnManagementPolicyCheckDone(policy_check_error_.empty(), |
73 policy_check_error_); | 69 policy_check_error_); |
74 } | 70 } |
75 | 71 |
76 void CheckBlacklistState() override { | 72 void CheckBlacklistState() override { |
77 blacklist_check_called_ = true; | 73 blacklist_check_called_ = true; |
78 MockCheckBlacklistState(current_sequence_number()); | 74 MockCheckBlacklistState(); |
79 } | |
80 | |
81 void ResetResults() override { | |
82 ExtensionInstallChecker::ResetResults(); | |
83 | |
84 requirements_check_called_ = false; | |
85 blacklist_check_called_ = false; | |
86 policy_check_called_ = false; | |
87 } | 75 } |
88 | 76 |
89 bool requirements_check_called_; | 77 bool requirements_check_called_; |
90 bool blacklist_check_called_; | 78 bool blacklist_check_called_; |
91 bool policy_check_called_; | 79 bool policy_check_called_; |
92 | 80 |
93 // Dummy errors for testing. | 81 // Dummy errors for testing. |
94 std::string requirements_error_; | 82 std::string requirements_error_; |
95 std::string policy_check_error_; | 83 std::string policy_check_error_; |
96 BlacklistState blacklist_state_; | 84 BlacklistState blacklist_state_; |
97 }; | 85 }; |
98 | 86 |
99 // This class implements asynchronous mocks of the requirements and blacklist | 87 // This class implements asynchronous mocks of the requirements and blacklist |
100 // checks. | 88 // checks. |
101 class ExtensionInstallCheckerAsync : public ExtensionInstallCheckerForTest { | 89 class ExtensionInstallCheckerAsync : public ExtensionInstallCheckerForTest { |
90 public: | |
91 ExtensionInstallCheckerAsync(int enabled_checks, bool fail_fast) | |
92 : ExtensionInstallCheckerForTest(enabled_checks, fail_fast) {} | |
93 | |
102 protected: | 94 protected: |
103 void CheckRequirements() override { | 95 void CheckRequirements() override { |
104 requirements_check_called_ = true; | 96 requirements_check_called_ = true; |
105 | 97 |
106 base::ThreadTaskRunnerHandle::Get()->PostTask( | 98 base::ThreadTaskRunnerHandle::Get()->PostTask( |
107 FROM_HERE, | 99 FROM_HERE, |
108 base::Bind(&ExtensionInstallCheckerForTest::MockCheckRequirements, | 100 base::Bind(&ExtensionInstallCheckerForTest::MockCheckRequirements, |
109 base::Unretained(this), current_sequence_number())); | 101 base::Unretained(this))); |
110 } | 102 } |
111 | 103 |
112 void CheckBlacklistState() override { | 104 void CheckBlacklistState() override { |
113 blacklist_check_called_ = true; | 105 blacklist_check_called_ = true; |
114 | 106 |
115 base::ThreadTaskRunnerHandle::Get()->PostTask( | 107 base::ThreadTaskRunnerHandle::Get()->PostTask( |
116 FROM_HERE, | 108 FROM_HERE, |
117 base::Bind(&ExtensionInstallCheckerForTest::MockCheckBlacklistState, | 109 base::Bind(&ExtensionInstallCheckerForTest::MockCheckBlacklistState, |
118 base::Unretained(this), current_sequence_number())); | 110 base::Unretained(this))); |
119 } | 111 } |
120 }; | 112 }; |
121 | 113 |
122 class CheckObserver { | 114 class CheckObserver { |
123 public: | 115 public: |
124 CheckObserver() : result_(0), call_count_(0) {} | 116 CheckObserver() : result_(0), call_count_(0) {} |
125 | 117 |
126 int result() const { return result_; } | 118 int result() const { return result_; } |
127 int call_count() const { return call_count_; } | 119 int call_count() const { return call_count_; } |
128 | 120 |
(...skipping 12 matching lines...) Expand all Loading... | |
141 private: | 133 private: |
142 int result_; | 134 int result_; |
143 int call_count_; | 135 int call_count_; |
144 }; | 136 }; |
145 | 137 |
146 class ExtensionInstallCheckerTest : public testing::Test { | 138 class ExtensionInstallCheckerTest : public testing::Test { |
147 public: | 139 public: |
148 ExtensionInstallCheckerTest() {} | 140 ExtensionInstallCheckerTest() {} |
149 ~ExtensionInstallCheckerTest() override {} | 141 ~ExtensionInstallCheckerTest() override {} |
150 | 142 |
151 void RunSecondInvocation(ExtensionInstallCheckerForTest* checker, | |
152 int checks_failed) { | |
153 EXPECT_GT(checks_failed, 0); | |
154 EXPECT_FALSE(checker->is_running()); | |
155 ValidateExpectedCalls(ExtensionInstallChecker::CHECK_ALL, *checker); | |
156 | |
157 // Set up different return values. | |
158 checker->set_blacklist_state(kBlacklistState2); | |
159 checker->set_policy_check_error(kDummyPolicyError2); | |
160 checker->set_requirements_error(kDummyRequirementsError2); | |
161 | |
162 // Run the install checker again and ensure the second set of return values | |
163 // is received. | |
164 checker->Start( | |
165 ExtensionInstallChecker::CHECK_ALL, | |
166 false /* fail fast */, | |
167 base::Bind(&ExtensionInstallCheckerTest::ValidateSecondInvocation, | |
168 base::Unretained(this), | |
169 checker)); | |
170 } | |
171 | |
172 void ValidateSecondInvocation(ExtensionInstallCheckerForTest* checker, | |
173 int checks_failed) { | |
174 EXPECT_FALSE(checker->is_running()); | |
175 EXPECT_EQ(ExtensionInstallChecker::CHECK_REQUIREMENTS | | |
176 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, | |
177 checks_failed); | |
178 ValidateExpectedCalls(ExtensionInstallChecker::CHECK_ALL, *checker); | |
179 | |
180 EXPECT_EQ(kBlacklistState2, checker->blacklist_state()); | |
181 ExpectPolicyError(kDummyPolicyError2, *checker); | |
182 ExpectRequirementsError(kDummyRequirementsError2, *checker); | |
183 } | |
184 | |
185 protected: | 143 protected: |
186 void SetAllErrors(ExtensionInstallCheckerForTest* checker) { | 144 void SetAllErrors(ExtensionInstallCheckerForTest* checker) { |
187 checker->set_blacklist_state(kBlacklistStateError); | 145 checker->set_blacklist_state(kBlacklistStateError); |
188 checker->set_policy_check_error(kDummyPolicyError); | 146 checker->set_policy_check_error(kDummyPolicyError); |
189 checker->set_requirements_error(kDummyRequirementsError); | 147 checker->set_requirements_error(kDummyRequirementsError); |
190 } | 148 } |
191 | 149 |
192 void ValidateExpectedCalls(int call_mask, | 150 void ValidateExpectedCalls(int call_mask, |
193 const ExtensionInstallCheckerForTest& checker) { | 151 const ExtensionInstallCheckerForTest& checker) { |
194 bool expect_blacklist_checked = | 152 bool expect_blacklist_checked = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 EXPECT_FALSE(checker.policy_allows_load()); | 193 EXPECT_FALSE(checker.policy_allows_load()); |
236 EXPECT_FALSE(checker.policy_error().empty()); | 194 EXPECT_FALSE(checker.policy_error().empty()); |
237 EXPECT_EQ(std::string(expected_error), checker.policy_error()); | 195 EXPECT_EQ(std::string(expected_error), checker.policy_error()); |
238 } | 196 } |
239 | 197 |
240 void ExpectPolicyError(const ExtensionInstallCheckerForTest& checker) { | 198 void ExpectPolicyError(const ExtensionInstallCheckerForTest& checker) { |
241 ExpectPolicyError(kDummyPolicyError, checker); | 199 ExpectPolicyError(kDummyPolicyError, checker); |
242 } | 200 } |
243 | 201 |
244 void RunChecker(ExtensionInstallCheckerForTest* checker, | 202 void RunChecker(ExtensionInstallCheckerForTest* checker, |
245 bool fail_fast, | |
246 int checks_to_run, | |
247 int expected_checks_run, | 203 int expected_checks_run, |
248 int expected_result) { | 204 int expected_result) { |
249 CheckObserver observer; | 205 CheckObserver observer; |
250 checker->Start(checks_to_run, | 206 checker->Start(base::Bind(&CheckObserver::OnChecksComplete, |
251 fail_fast, | |
252 base::Bind(&CheckObserver::OnChecksComplete, | |
253 base::Unretained(&observer))); | 207 base::Unretained(&observer))); |
254 observer.Wait(); | 208 observer.Wait(); |
255 | 209 |
256 EXPECT_FALSE(checker->is_running()); | 210 EXPECT_FALSE(checker->is_running()); |
257 EXPECT_EQ(expected_result, observer.result()); | 211 EXPECT_EQ(expected_result, observer.result()); |
258 EXPECT_EQ(1, observer.call_count()); | 212 EXPECT_EQ(1, observer.call_count()); |
259 ValidateExpectedCalls(expected_checks_run, *checker); | 213 ValidateExpectedCalls(expected_checks_run, *checker); |
260 } | 214 } |
261 | 215 |
262 void DoRunAllChecksPass(ExtensionInstallCheckerForTest* checker) { | 216 void DoRunAllChecksPass(ExtensionInstallCheckerForTest* checker) { |
263 RunChecker(checker, | 217 RunChecker(checker, |
264 false /* fail fast */, | |
265 ExtensionInstallChecker::CHECK_ALL, | |
266 ExtensionInstallChecker::CHECK_ALL, | 218 ExtensionInstallChecker::CHECK_ALL, |
267 0); | 219 0); |
268 | 220 |
269 ExpectRequirementsPass(*checker); | 221 ExpectRequirementsPass(*checker); |
270 ExpectPolicyPass(*checker); | 222 ExpectPolicyPass(*checker); |
271 ExpectBlacklistPass(*checker); | 223 ExpectBlacklistPass(*checker); |
272 } | 224 } |
273 | 225 |
274 void DoRunAllChecksFail(ExtensionInstallCheckerForTest* checker) { | 226 void DoRunAllChecksFail(ExtensionInstallCheckerForTest* checker) { |
275 SetAllErrors(checker); | 227 SetAllErrors(checker); |
276 RunChecker(checker, | 228 RunChecker(checker, |
277 false /* fail fast */, | |
278 ExtensionInstallChecker::CHECK_ALL, | |
279 ExtensionInstallChecker::CHECK_ALL, | 229 ExtensionInstallChecker::CHECK_ALL, |
280 ExtensionInstallChecker::CHECK_ALL); | 230 ExtensionInstallChecker::CHECK_ALL); |
281 | 231 |
282 ExpectRequirementsError(*checker); | 232 ExpectRequirementsError(*checker); |
283 ExpectPolicyError(*checker); | 233 ExpectPolicyError(*checker); |
284 ExpectBlacklistError(*checker); | 234 ExpectBlacklistError(*checker); |
285 } | 235 } |
286 | 236 |
287 void DoRunSubsetOfChecks(ExtensionInstallCheckerForTest* checker) { | 237 void DoRunSubsetOfChecks(int checks_to_run) { |
288 // Test check set 1. | 238 ExtensionInstallCheckerForTest sync_checker(checks_to_run, |
289 int tests_to_run = ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY | | 239 /*fail_fast=*/false); |
290 ExtensionInstallChecker::CHECK_REQUIREMENTS; | 240 ExtensionInstallCheckerAsync async_checker(checks_to_run, |
291 SetAllErrors(checker); | 241 /*fail_fast=*/false); |
292 RunChecker(checker, false, tests_to_run, tests_to_run, tests_to_run); | 242 ExtensionInstallCheckerForTest* checkers[] = { |
243 &sync_checker, &async_checker, | |
244 }; | |
293 | 245 |
294 ExpectRequirementsError(*checker); | 246 for (auto* checker : checkers) { |
295 ExpectPolicyError(*checker); | 247 SetAllErrors(checker); |
296 ExpectBlacklistPass(*checker); | 248 RunChecker(checker, checks_to_run, checks_to_run); |
297 | 249 |
298 // Test check set 2. | 250 if (checks_to_run & ExtensionInstallChecker::CHECK_REQUIREMENTS) |
299 tests_to_run = ExtensionInstallChecker::CHECK_BLACKLIST | | 251 ExpectRequirementsError(*checker); |
300 ExtensionInstallChecker::CHECK_REQUIREMENTS; | 252 else |
301 SetAllErrors(checker); | 253 ExpectRequirementsPass(*checker); |
302 RunChecker(checker, false, tests_to_run, tests_to_run, tests_to_run); | |
303 | 254 |
304 ExpectRequirementsError(*checker); | 255 if (checks_to_run & ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY) |
305 ExpectPolicyPass(*checker); | 256 ExpectPolicyError(*checker); |
306 ExpectBlacklistError(*checker); | 257 else |
258 ExpectPolicyPass(*checker); | |
307 | 259 |
308 // Test a single check. | 260 if (checks_to_run & ExtensionInstallChecker::CHECK_BLACKLIST) |
309 tests_to_run = ExtensionInstallChecker::CHECK_BLACKLIST; | 261 ExpectBlacklistError(*checker); |
310 SetAllErrors(checker); | 262 else |
311 RunChecker(checker, false, tests_to_run, tests_to_run, tests_to_run); | 263 ExpectBlacklistPass(*checker); |
312 | 264 } |
313 ExpectRequirementsPass(*checker); | |
314 ExpectPolicyPass(*checker); | |
315 ExpectBlacklistError(*checker); | |
316 } | 265 } |
317 | 266 |
318 private: | 267 private: |
319 // A message loop is required for the asynchronous tests. | 268 // A message loop is required for the asynchronous tests. |
320 base::MessageLoop message_loop; | 269 base::MessageLoop message_loop; |
321 }; | 270 }; |
322 | 271 |
323 class ExtensionInstallCheckerMultipleInvocationTest | |
324 : public ExtensionInstallCheckerTest { | |
325 public: | |
326 ExtensionInstallCheckerMultipleInvocationTest() : callback_count_(0) {} | |
327 ~ExtensionInstallCheckerMultipleInvocationTest() override {} | |
328 | |
329 void RunSecondInvocation(ExtensionInstallCheckerForTest* checker, | |
330 int checks_failed) { | |
331 ASSERT_EQ(0, callback_count_); | |
332 ++callback_count_; | |
333 EXPECT_FALSE(checker->is_running()); | |
334 EXPECT_GT(checks_failed, 0); | |
335 ValidateExpectedCalls(ExtensionInstallChecker::CHECK_ALL, *checker); | |
336 | |
337 // Set up different return values. | |
338 checker->set_blacklist_state(kBlacklistState2); | |
339 checker->set_policy_check_error(kDummyPolicyError2); | |
340 checker->set_requirements_error(kDummyRequirementsError2); | |
341 | |
342 // Run the install checker again and ensure the second set of return values | |
343 // is received. | |
344 checker->Start(ExtensionInstallChecker::CHECK_ALL, | |
345 false /* fail fast */, | |
346 base::Bind(&ExtensionInstallCheckerMultipleInvocationTest:: | |
347 ValidateSecondInvocation, | |
348 base::Unretained(this), | |
349 checker)); | |
350 } | |
351 | |
352 void ValidateSecondInvocation(ExtensionInstallCheckerForTest* checker, | |
353 int checks_failed) { | |
354 ASSERT_EQ(1, callback_count_); | |
355 EXPECT_FALSE(checker->is_running()); | |
356 EXPECT_EQ(ExtensionInstallChecker::CHECK_REQUIREMENTS | | |
357 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, | |
358 checks_failed); | |
359 ValidateExpectedCalls(ExtensionInstallChecker::CHECK_ALL, *checker); | |
360 | |
361 EXPECT_EQ(kBlacklistState2, checker->blacklist_state()); | |
362 ExpectPolicyError(kDummyPolicyError2, *checker); | |
363 ExpectRequirementsError(kDummyRequirementsError2, *checker); | |
364 } | |
365 | |
366 private: | |
367 int callback_count_; | |
368 }; | |
369 | |
370 // Test the case where all tests pass. | 272 // Test the case where all tests pass. |
371 TEST_F(ExtensionInstallCheckerTest, AllSucceeded) { | 273 TEST_F(ExtensionInstallCheckerTest, AllSucceeded) { |
372 ExtensionInstallCheckerForTest sync_checker; | 274 ExtensionInstallCheckerForTest sync_checker( |
275 ExtensionInstallChecker::CHECK_ALL, /*fail_fast=*/false); | |
373 DoRunAllChecksPass(&sync_checker); | 276 DoRunAllChecksPass(&sync_checker); |
374 | 277 |
375 ExtensionInstallCheckerAsync async_checker; | 278 ExtensionInstallCheckerAsync async_checker(ExtensionInstallChecker::CHECK_ALL, |
279 /*fail_fast=*/false); | |
376 DoRunAllChecksPass(&async_checker); | 280 DoRunAllChecksPass(&async_checker); |
377 } | 281 } |
378 | 282 |
379 // Test the case where all tests fail. | 283 // Test the case where all tests fail. |
380 TEST_F(ExtensionInstallCheckerTest, AllFailed) { | 284 TEST_F(ExtensionInstallCheckerTest, AllFailed) { |
381 ExtensionInstallCheckerForTest sync_checker; | 285 ExtensionInstallCheckerForTest sync_checker( |
286 ExtensionInstallChecker::CHECK_ALL, /*fail_fast=*/false); | |
382 DoRunAllChecksFail(&sync_checker); | 287 DoRunAllChecksFail(&sync_checker); |
383 | 288 |
384 ExtensionInstallCheckerAsync async_checker; | 289 ExtensionInstallCheckerAsync async_checker(ExtensionInstallChecker::CHECK_ALL, |
290 /*fail_fast=*/false); | |
385 DoRunAllChecksFail(&async_checker); | 291 DoRunAllChecksFail(&async_checker); |
386 } | 292 } |
387 | 293 |
388 // Test running only a subset of tests. | 294 // Test running only a subset of tests. |
389 TEST_F(ExtensionInstallCheckerTest, RunSubsetOfChecks) { | 295 TEST_F(ExtensionInstallCheckerTest, RunSubsetOfChecks) { |
390 ExtensionInstallCheckerForTest sync_checker; | 296 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY | |
391 ExtensionInstallCheckerAsync async_checker; | 297 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
392 DoRunSubsetOfChecks(&sync_checker); | 298 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_BLACKLIST | |
393 DoRunSubsetOfChecks(&async_checker); | 299 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
300 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_BLACKLIST); | |
394 } | 301 } |
395 | 302 |
396 // Test fail fast with synchronous callbacks. | 303 // Test fail fast with synchronous callbacks. |
397 TEST_F(ExtensionInstallCheckerTest, FailFastSync) { | 304 TEST_F(ExtensionInstallCheckerTest, FailFastSync) { |
398 // This test assumes some internal knowledge of the implementation - that | 305 // This test assumes some internal knowledge of the implementation - that |
399 // the policy check runs first. | 306 // the policy check runs first. |
400 ExtensionInstallCheckerForTest checker; | 307 { |
401 SetAllErrors(&checker); | 308 ExtensionInstallCheckerForTest checker(ExtensionInstallChecker::CHECK_ALL, |
402 RunChecker(&checker, | 309 /*fail_fast=*/true); |
michaelpg
2017/03/17 04:25:23
for some reason the test functions and constructor
Devlin
2017/03/20 15:36:46
Yeah, I think enum -> bool can be implicit. bool
| |
403 true /* fail fast */, | 310 SetAllErrors(&checker); |
404 ExtensionInstallChecker::CHECK_ALL, | 311 RunChecker(&checker, ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, |
405 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, | 312 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY); |
406 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY); | |
407 | 313 |
408 ExpectRequirementsPass(checker); | 314 ExpectRequirementsPass(checker); |
409 ExpectPolicyError(checker); | 315 ExpectPolicyError(checker); |
410 ExpectBlacklistPass(checker); | 316 ExpectBlacklistPass(checker); |
317 } | |
411 | 318 |
412 // This test assumes some internal knowledge of the implementation - that | 319 { |
413 // the requirements check runs before the blacklist check. | 320 ExtensionInstallCheckerForTest checker( |
414 SetAllErrors(&checker); | 321 ExtensionInstallChecker::CHECK_REQUIREMENTS | |
415 RunChecker(&checker, | 322 ExtensionInstallChecker::CHECK_BLACKLIST, |
416 true /* fail fast */, | 323 /*fail_fast=*/true); |
417 ExtensionInstallChecker::CHECK_REQUIREMENTS | | 324 SetAllErrors(&checker); |
418 ExtensionInstallChecker::CHECK_BLACKLIST, | 325 RunChecker(&checker, ExtensionInstallChecker::CHECK_REQUIREMENTS, |
419 ExtensionInstallChecker::CHECK_REQUIREMENTS, | 326 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
420 ExtensionInstallChecker::CHECK_REQUIREMENTS); | |
421 | 327 |
422 ExpectRequirementsError(checker); | 328 ExpectRequirementsError(checker); |
423 ExpectPolicyPass(checker); | 329 ExpectPolicyPass(checker); |
424 ExpectBlacklistPass(checker); | 330 ExpectBlacklistPass(checker); |
331 } | |
425 } | 332 } |
426 | 333 |
427 // Test fail fast with asynchronous callbacks. | 334 // Test fail fast with asynchronous callbacks. |
428 TEST_F(ExtensionInstallCheckerTest, FailFastAsync) { | 335 TEST_F(ExtensionInstallCheckerTest, FailFastAsync) { |
429 // This test assumes some internal knowledge of the implementation - that | 336 // This test assumes some internal knowledge of the implementation - that |
430 // the requirements check runs before the blacklist check. Both checks should | 337 // the requirements check runs before the blacklist check. Both checks should |
431 // be called, but the requirements check callback arrives first and the | 338 // be called, but the requirements check callback arrives first and the |
432 // blacklist result will be discarded. | 339 // blacklist result will be discarded. |
433 ExtensionInstallCheckerAsync checker; | 340 ExtensionInstallCheckerAsync checker(ExtensionInstallChecker::CHECK_ALL, |
341 /*fail_fast=*/true); | |
342 | |
434 SetAllErrors(&checker); | 343 SetAllErrors(&checker); |
435 | 344 |
436 // The policy check is synchronous and needs to pass for the other tests to | 345 // The policy check is synchronous and needs to pass for the other tests to |
437 // run. | 346 // run. |
438 checker.set_policy_check_error(std::string()); | 347 checker.set_policy_check_error(std::string()); |
439 | 348 |
440 RunChecker(&checker, | 349 RunChecker(&checker, |
441 true /* fail fast */, | |
442 ExtensionInstallChecker::CHECK_ALL, | |
443 ExtensionInstallChecker::CHECK_ALL, | 350 ExtensionInstallChecker::CHECK_ALL, |
444 ExtensionInstallChecker::CHECK_REQUIREMENTS); | 351 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
445 | 352 |
446 ExpectRequirementsError(checker); | 353 ExpectRequirementsError(checker); |
447 ExpectPolicyPass(checker); | 354 ExpectPolicyPass(checker); |
448 ExpectBlacklistPass(checker); | 355 ExpectBlacklistPass(checker); |
449 } | 356 } |
450 | 357 |
451 // Test multiple invocations of the install checker. Wait for all checks to | |
452 // complete. | |
453 TEST_F(ExtensionInstallCheckerMultipleInvocationTest, CompleteAll) { | |
454 ExtensionInstallCheckerAsync checker; | |
455 SetAllErrors(&checker); | |
456 | |
457 // Start the second check as soon as the callback of the first run is invoked. | |
458 checker.Start( | |
459 ExtensionInstallChecker::CHECK_ALL, | |
460 false /* fail fast */, | |
461 base::Bind( | |
462 &ExtensionInstallCheckerMultipleInvocationTest::RunSecondInvocation, | |
463 base::Unretained(this), | |
464 &checker)); | |
465 base::RunLoop().RunUntilIdle(); | |
466 } | |
467 | |
468 // Test multiple invocations of the install checker and fail fast. | |
469 TEST_F(ExtensionInstallCheckerMultipleInvocationTest, FailFast) { | |
470 ExtensionInstallCheckerAsync checker; | |
471 SetAllErrors(&checker); | |
472 | |
473 // The policy check is synchronous and needs to pass for the other tests to | |
474 // run. | |
475 checker.set_policy_check_error(std::string()); | |
476 | |
477 // Start the second check as soon as the callback of the first run is invoked. | |
478 checker.Start( | |
479 ExtensionInstallChecker::CHECK_ALL, | |
480 true /* fail fast */, | |
481 base::Bind( | |
482 &ExtensionInstallCheckerMultipleInvocationTest::RunSecondInvocation, | |
483 base::Unretained(this), | |
484 &checker)); | |
485 base::RunLoop().RunUntilIdle(); | |
486 } | |
487 | |
488 } // namespace extensions | 358 } // namespace extensions |
OLD | NEW |