Chromium Code Reviews| 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() |
| 33 : ExtensionInstallChecker(NULL), | 29 : ExtensionInstallChecker(nullptr, nullptr), |
| 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 { |
| 102 protected: | 90 protected: |
| 103 void CheckRequirements() override { | 91 void CheckRequirements() override { |
| 104 requirements_check_called_ = true; | 92 requirements_check_called_ = true; |
| 105 | 93 |
| 106 base::ThreadTaskRunnerHandle::Get()->PostTask( | 94 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 107 FROM_HERE, | 95 FROM_HERE, |
| 108 base::Bind(&ExtensionInstallCheckerForTest::MockCheckRequirements, | 96 base::Bind(&ExtensionInstallCheckerForTest::MockCheckRequirements, |
| 109 base::Unretained(this), current_sequence_number())); | 97 base::Unretained(this))); |
| 110 } | 98 } |
| 111 | 99 |
| 112 void CheckBlacklistState() override { | 100 void CheckBlacklistState() override { |
| 113 blacklist_check_called_ = true; | 101 blacklist_check_called_ = true; |
| 114 | 102 |
| 115 base::ThreadTaskRunnerHandle::Get()->PostTask( | 103 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 116 FROM_HERE, | 104 FROM_HERE, |
| 117 base::Bind(&ExtensionInstallCheckerForTest::MockCheckBlacklistState, | 105 base::Bind(&ExtensionInstallCheckerForTest::MockCheckBlacklistState, |
| 118 base::Unretained(this), current_sequence_number())); | 106 base::Unretained(this))); |
| 119 } | 107 } |
| 120 }; | 108 }; |
| 121 | 109 |
| 122 class CheckObserver { | 110 class CheckObserver { |
| 123 public: | 111 public: |
| 124 CheckObserver() : result_(0), call_count_(0) {} | 112 CheckObserver() : result_(0), call_count_(0) {} |
| 125 | 113 |
| 126 int result() const { return result_; } | 114 int result() const { return result_; } |
| 127 int call_count() const { return call_count_; } | 115 int call_count() const { return call_count_; } |
| 128 | 116 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 141 private: | 129 private: |
| 142 int result_; | 130 int result_; |
| 143 int call_count_; | 131 int call_count_; |
| 144 }; | 132 }; |
| 145 | 133 |
| 146 class ExtensionInstallCheckerTest : public testing::Test { | 134 class ExtensionInstallCheckerTest : public testing::Test { |
| 147 public: | 135 public: |
| 148 ExtensionInstallCheckerTest() {} | 136 ExtensionInstallCheckerTest() {} |
| 149 ~ExtensionInstallCheckerTest() override {} | 137 ~ExtensionInstallCheckerTest() override {} |
| 150 | 138 |
| 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: | 139 protected: |
| 186 void SetAllErrors(ExtensionInstallCheckerForTest* checker) { | 140 void SetAllErrors(ExtensionInstallCheckerForTest* checker) { |
| 187 checker->set_blacklist_state(kBlacklistStateError); | 141 checker->set_blacklist_state(kBlacklistStateError); |
| 188 checker->set_policy_check_error(kDummyPolicyError); | 142 checker->set_policy_check_error(kDummyPolicyError); |
| 189 checker->set_requirements_error(kDummyRequirementsError); | 143 checker->set_requirements_error(kDummyRequirementsError); |
| 190 } | 144 } |
| 191 | 145 |
| 192 void ValidateExpectedCalls(int call_mask, | 146 void ValidateExpectedCalls(int call_mask, |
| 193 const ExtensionInstallCheckerForTest& checker) { | 147 const ExtensionInstallCheckerForTest& checker) { |
| 194 bool expect_blacklist_checked = | 148 bool expect_blacklist_checked = |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 false /* fail fast */, | 231 false /* fail fast */, |
| 278 ExtensionInstallChecker::CHECK_ALL, | 232 ExtensionInstallChecker::CHECK_ALL, |
| 279 ExtensionInstallChecker::CHECK_ALL, | 233 ExtensionInstallChecker::CHECK_ALL, |
| 280 ExtensionInstallChecker::CHECK_ALL); | 234 ExtensionInstallChecker::CHECK_ALL); |
| 281 | 235 |
| 282 ExpectRequirementsError(*checker); | 236 ExpectRequirementsError(*checker); |
| 283 ExpectPolicyError(*checker); | 237 ExpectPolicyError(*checker); |
| 284 ExpectBlacklistError(*checker); | 238 ExpectBlacklistError(*checker); |
| 285 } | 239 } |
| 286 | 240 |
| 287 void DoRunSubsetOfChecks(ExtensionInstallCheckerForTest* checker) { | 241 void DoRunSubsetOfChecks(int checks_to_run) { |
| 288 // Test check set 1. | 242 ExtensionInstallCheckerForTest sync_checker; |
| 289 int tests_to_run = ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY | | 243 ExtensionInstallCheckerAsync async_checker; |
| 290 ExtensionInstallChecker::CHECK_REQUIREMENTS; | 244 ExtensionInstallCheckerForTest* checkers[] = { |
| 291 SetAllErrors(checker); | 245 &sync_checker, &async_checker, |
| 292 RunChecker(checker, false, tests_to_run, tests_to_run, tests_to_run); | 246 }; |
| 293 | 247 |
| 294 ExpectRequirementsError(*checker); | 248 for (ExtensionInstallCheckerForTest* checker : checkers) { |
|
Devlin
2017/03/16 19:29:41
optional nit: just inline checkers
michaelpg
2017/03/17 04:25:23
IMO the polymorphism is a bit more obvious being e
| |
| 295 ExpectPolicyError(*checker); | 249 SetAllErrors(checker); |
| 296 ExpectBlacklistPass(*checker); | 250 RunChecker(checker, false, checks_to_run, checks_to_run, checks_to_run); |
| 297 | 251 |
| 298 // Test check set 2. | 252 if (checks_to_run & ExtensionInstallChecker::CHECK_REQUIREMENTS) |
| 299 tests_to_run = ExtensionInstallChecker::CHECK_BLACKLIST | | 253 ExpectRequirementsError(*checker); |
| 300 ExtensionInstallChecker::CHECK_REQUIREMENTS; | 254 else |
| 301 SetAllErrors(checker); | 255 ExpectRequirementsPass(*checker); |
| 302 RunChecker(checker, false, tests_to_run, tests_to_run, tests_to_run); | |
| 303 | 256 |
| 304 ExpectRequirementsError(*checker); | 257 if (checks_to_run & ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY) |
| 305 ExpectPolicyPass(*checker); | 258 ExpectPolicyError(*checker); |
| 306 ExpectBlacklistError(*checker); | 259 else |
| 260 ExpectPolicyPass(*checker); | |
| 307 | 261 |
| 308 // Test a single check. | 262 if (checks_to_run & ExtensionInstallChecker::CHECK_BLACKLIST) |
| 309 tests_to_run = ExtensionInstallChecker::CHECK_BLACKLIST; | 263 ExpectBlacklistError(*checker); |
| 310 SetAllErrors(checker); | 264 else |
| 311 RunChecker(checker, false, tests_to_run, tests_to_run, tests_to_run); | 265 ExpectBlacklistPass(*checker); |
| 312 | 266 } |
| 313 ExpectRequirementsPass(*checker); | |
| 314 ExpectPolicyPass(*checker); | |
| 315 ExpectBlacklistError(*checker); | |
| 316 } | 267 } |
| 317 | 268 |
| 318 private: | 269 private: |
| 319 // A message loop is required for the asynchronous tests. | 270 // A message loop is required for the asynchronous tests. |
| 320 base::MessageLoop message_loop; | 271 base::MessageLoop message_loop; |
| 321 }; | 272 }; |
| 322 | 273 |
| 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. | 274 // Test the case where all tests pass. |
| 371 TEST_F(ExtensionInstallCheckerTest, AllSucceeded) { | 275 TEST_F(ExtensionInstallCheckerTest, AllSucceeded) { |
| 372 ExtensionInstallCheckerForTest sync_checker; | 276 ExtensionInstallCheckerForTest sync_checker; |
| 373 DoRunAllChecksPass(&sync_checker); | 277 DoRunAllChecksPass(&sync_checker); |
| 374 | 278 |
| 375 ExtensionInstallCheckerAsync async_checker; | 279 ExtensionInstallCheckerAsync async_checker; |
| 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; |
| 382 DoRunAllChecksFail(&sync_checker); | 286 DoRunAllChecksFail(&sync_checker); |
| 383 | 287 |
| 384 ExtensionInstallCheckerAsync async_checker; | 288 ExtensionInstallCheckerAsync async_checker; |
| 385 DoRunAllChecksFail(&async_checker); | 289 DoRunAllChecksFail(&async_checker); |
| 386 } | 290 } |
| 387 | 291 |
| 388 // Test running only a subset of tests. | 292 // Test running only a subset of tests. |
| 389 TEST_F(ExtensionInstallCheckerTest, RunSubsetOfChecks) { | 293 TEST_F(ExtensionInstallCheckerTest, RunSubsetOfChecks) { |
| 390 ExtensionInstallCheckerForTest sync_checker; | 294 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY | |
| 391 ExtensionInstallCheckerAsync async_checker; | 295 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
| 392 DoRunSubsetOfChecks(&sync_checker); | 296 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_BLACKLIST | |
| 393 DoRunSubsetOfChecks(&async_checker); | 297 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
| 298 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_BLACKLIST); | |
| 394 } | 299 } |
| 395 | 300 |
| 396 // Test fail fast with synchronous callbacks. | 301 // Test fail fast with synchronous callbacks. |
| 397 TEST_F(ExtensionInstallCheckerTest, FailFastSync) { | 302 TEST_F(ExtensionInstallCheckerTest, FailFastSync) { |
| 398 // This test assumes some internal knowledge of the implementation - that | 303 // This test assumes some internal knowledge of the implementation - that |
| 399 // the policy check runs first. | 304 // the policy check runs first. |
| 400 ExtensionInstallCheckerForTest checker; | 305 { |
| 401 SetAllErrors(&checker); | 306 ExtensionInstallCheckerForTest checker; |
| 402 RunChecker(&checker, | 307 SetAllErrors(&checker); |
| 403 true /* fail fast */, | 308 RunChecker(&checker, true /* fail fast */, |
| 404 ExtensionInstallChecker::CHECK_ALL, | 309 ExtensionInstallChecker::CHECK_ALL, |
| 405 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, | 310 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, |
| 406 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY); | 311 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY); |
| 407 | 312 |
| 408 ExpectRequirementsPass(checker); | 313 ExpectRequirementsPass(checker); |
| 409 ExpectPolicyError(checker); | 314 ExpectPolicyError(checker); |
| 410 ExpectBlacklistPass(checker); | 315 ExpectBlacklistPass(checker); |
| 316 } | |
| 411 | 317 |
| 412 // This test assumes some internal knowledge of the implementation - that | 318 { |
| 413 // the requirements check runs before the blacklist check. | 319 ExtensionInstallCheckerForTest checker; |
| 414 SetAllErrors(&checker); | 320 SetAllErrors(&checker); |
| 415 RunChecker(&checker, | 321 RunChecker(&checker, true /* fail fast */, |
| 416 true /* fail fast */, | 322 ExtensionInstallChecker::CHECK_REQUIREMENTS | |
| 417 ExtensionInstallChecker::CHECK_REQUIREMENTS | | 323 ExtensionInstallChecker::CHECK_BLACKLIST, |
| 418 ExtensionInstallChecker::CHECK_BLACKLIST, | 324 ExtensionInstallChecker::CHECK_REQUIREMENTS, |
| 419 ExtensionInstallChecker::CHECK_REQUIREMENTS, | 325 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
| 420 ExtensionInstallChecker::CHECK_REQUIREMENTS); | |
| 421 | 326 |
| 422 ExpectRequirementsError(checker); | 327 ExpectRequirementsError(checker); |
| 423 ExpectPolicyPass(checker); | 328 ExpectPolicyPass(checker); |
| 424 ExpectBlacklistPass(checker); | 329 ExpectBlacklistPass(checker); |
| 330 } | |
| 425 } | 331 } |
| 426 | 332 |
| 427 // Test fail fast with asynchronous callbacks. | 333 // Test fail fast with asynchronous callbacks. |
| 428 TEST_F(ExtensionInstallCheckerTest, FailFastAsync) { | 334 TEST_F(ExtensionInstallCheckerTest, FailFastAsync) { |
| 429 // This test assumes some internal knowledge of the implementation - that | 335 // This test assumes some internal knowledge of the implementation - that |
| 430 // the requirements check runs before the blacklist check. Both checks should | 336 // the requirements check runs before the blacklist check. Both checks should |
| 431 // be called, but the requirements check callback arrives first and the | 337 // be called, but the requirements check callback arrives first and the |
| 432 // blacklist result will be discarded. | 338 // blacklist result will be discarded. |
| 433 ExtensionInstallCheckerAsync checker; | 339 ExtensionInstallCheckerAsync checker; |
| 434 SetAllErrors(&checker); | 340 SetAllErrors(&checker); |
| 435 | 341 |
| 436 // The policy check is synchronous and needs to pass for the other tests to | 342 // The policy check is synchronous and needs to pass for the other tests to |
| 437 // run. | 343 // run. |
| 438 checker.set_policy_check_error(std::string()); | 344 checker.set_policy_check_error(std::string()); |
| 439 | 345 |
| 440 RunChecker(&checker, | 346 RunChecker(&checker, |
| 441 true /* fail fast */, | 347 true /* fail fast */, |
| 442 ExtensionInstallChecker::CHECK_ALL, | 348 ExtensionInstallChecker::CHECK_ALL, |
| 443 ExtensionInstallChecker::CHECK_ALL, | 349 ExtensionInstallChecker::CHECK_ALL, |
| 444 ExtensionInstallChecker::CHECK_REQUIREMENTS); | 350 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
| 445 | 351 |
| 446 ExpectRequirementsError(checker); | 352 ExpectRequirementsError(checker); |
| 447 ExpectPolicyPass(checker); | 353 ExpectPolicyPass(checker); |
| 448 ExpectBlacklistPass(checker); | 354 ExpectBlacklistPass(checker); |
| 449 } | 355 } |
| 450 | 356 |
| 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 | 357 } // namespace extensions |
| OLD | NEW |