| 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 "chrome/browser/extensions/extension_install_checker.h" |
| 6 |
| 5 #include "base/bind.h" | 7 #include "base/bind.h" |
| 6 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" |
| 7 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 8 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "chrome/browser/extensions/extension_install_checker.h" | 14 #include "extensions/browser/preload_check_test_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 16 |
| 13 namespace extensions { | 17 namespace extensions { |
| 14 | 18 |
| 15 namespace { | 19 namespace { |
| 16 | 20 |
| 17 const BlacklistState kBlacklistStateError = BLACKLISTED_MALWARE; | 21 const PreloadCheck::Error kBlacklistError = PreloadCheck::BLACKLISTED_ID; |
| 18 const char kDummyRequirementsError[] = "Requirements error"; | 22 const char kDummyRequirementsError[] = "Requirements error"; |
| 19 const char kDummyPolicyError[] = "Cannot install extension"; | 23 const char kDummyPolicyError[] = "Cannot install extension"; |
| 20 | 24 |
| 21 } // namespace | 25 } // namespace |
| 22 | 26 |
| 23 // Stubs most of the checks since we are interested in validating the logic in | 27 // Stubs most of the checks since we are interested in validating the logic in |
| 24 // the install checker. This class implements a synchronous version of all | 28 // the install checker. This class implements a synchronous version of all |
| 25 // checks. | 29 // checks. |
| 26 class ExtensionInstallCheckerForTest : public ExtensionInstallChecker { | 30 class ExtensionInstallCheckerForTest : public ExtensionInstallChecker { |
| 27 public: | 31 public: |
| 28 ExtensionInstallCheckerForTest(int enabled_checks, bool fail_fast) | 32 ExtensionInstallCheckerForTest(int enabled_checks, bool fail_fast) |
| 29 : ExtensionInstallChecker(nullptr, nullptr, enabled_checks, fail_fast), | 33 : ExtensionInstallChecker(nullptr, nullptr, enabled_checks, fail_fast) {} |
| 30 requirements_check_called_(false), | |
| 31 blacklist_check_called_(false), | |
| 32 policy_check_called_(false), | |
| 33 blacklist_state_(NOT_BLACKLISTED) {} | |
| 34 | 34 |
| 35 ~ExtensionInstallCheckerForTest() override {} | 35 ~ExtensionInstallCheckerForTest() override {} |
| 36 | 36 |
| 37 void set_requirements_error(const std::string& error) { | 37 void set_requirements_error(const std::string& error) { |
| 38 requirements_error_ = error; | 38 requirements_error_ = error; |
| 39 } | 39 } |
| 40 void set_policy_check_error(const std::string& error) { | |
| 41 policy_check_error_ = error; | |
| 42 } | |
| 43 void set_blacklist_state(BlacklistState state) { blacklist_state_ = state; } | |
| 44 | 40 |
| 45 bool requirements_check_called() const { return requirements_check_called_; } | 41 bool is_async() const { return is_async_; } |
| 46 bool blacklist_check_called() const { return blacklist_check_called_; } | 42 void set_is_async(bool is_async) { is_async_ = is_async; } |
| 47 bool policy_check_called() const { return policy_check_called_; } | |
| 48 | 43 |
| 44 protected: |
| 49 void MockCheckRequirements() { | 45 void MockCheckRequirements() { |
| 50 if (!is_running()) | 46 if (!is_running()) |
| 51 return; | 47 return; |
| 52 std::vector<std::string> errors; | 48 std::vector<std::string> errors; |
| 53 if (!requirements_error_.empty()) | 49 if (!requirements_error_.empty()) |
| 54 errors.push_back(requirements_error_); | 50 errors.push_back(requirements_error_); |
| 55 OnRequirementsCheckDone(errors); | 51 OnRequirementsCheckDone(errors); |
| 56 } | 52 } |
| 57 | 53 |
| 58 void MockCheckBlacklistState() { | 54 void CheckRequirements() override { |
| 59 if (!is_running()) | 55 if (is_async_) { |
| 60 return; | 56 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 61 OnBlacklistStateCheckDone(blacklist_state_); | 57 FROM_HERE, |
| 58 base::Bind(&ExtensionInstallCheckerForTest::MockCheckRequirements, |
| 59 base::Unretained(this))); |
| 60 } else { |
| 61 MockCheckRequirements(); |
| 62 } |
| 62 } | 63 } |
| 63 | 64 |
| 64 protected: | 65 private: |
| 65 void CheckRequirements() override { | 66 // Whether to run the requirements and blacklist checks asynchronously, as |
| 66 requirements_check_called_ = true; | 67 // they often do in ExtensionInstallChecker. |
| 67 MockCheckRequirements(); | 68 bool is_async_ = false; |
| 68 } | |
| 69 | 69 |
| 70 void CheckManagementPolicy() override { | 70 // Dummy error for testing. |
| 71 policy_check_called_ = true; | |
| 72 OnManagementPolicyCheckDone(policy_check_error_.empty(), | |
| 73 policy_check_error_); | |
| 74 } | |
| 75 | |
| 76 void CheckBlacklistState() override { | |
| 77 blacklist_check_called_ = true; | |
| 78 MockCheckBlacklistState(); | |
| 79 } | |
| 80 | |
| 81 bool requirements_check_called_; | |
| 82 bool blacklist_check_called_; | |
| 83 bool policy_check_called_; | |
| 84 | |
| 85 // Dummy errors for testing. | |
| 86 std::string requirements_error_; | 71 std::string requirements_error_; |
| 87 std::string policy_check_error_; | |
| 88 BlacklistState blacklist_state_; | |
| 89 }; | |
| 90 | |
| 91 // This class implements asynchronous mocks of the requirements and blacklist | |
| 92 // checks. | |
| 93 class ExtensionInstallCheckerAsync : public ExtensionInstallCheckerForTest { | |
| 94 public: | |
| 95 ExtensionInstallCheckerAsync(int enabled_checks, bool fail_fast) | |
| 96 : ExtensionInstallCheckerForTest(enabled_checks, fail_fast) {} | |
| 97 | |
| 98 protected: | |
| 99 void CheckRequirements() override { | |
| 100 requirements_check_called_ = true; | |
| 101 | |
| 102 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 103 FROM_HERE, | |
| 104 base::Bind(&ExtensionInstallCheckerForTest::MockCheckRequirements, | |
| 105 base::Unretained(this))); | |
| 106 } | |
| 107 | |
| 108 void CheckBlacklistState() override { | |
| 109 blacklist_check_called_ = true; | |
| 110 | |
| 111 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 112 FROM_HERE, | |
| 113 base::Bind(&ExtensionInstallCheckerForTest::MockCheckBlacklistState, | |
| 114 base::Unretained(this))); | |
| 115 } | |
| 116 }; | 72 }; |
| 117 | 73 |
| 118 class CheckObserver { | 74 class CheckObserver { |
| 119 public: | 75 public: |
| 120 CheckObserver() : result_(0), call_count_(0) {} | 76 CheckObserver() : result_(0), call_count_(0) {} |
| 121 | 77 |
| 122 int result() const { return result_; } | 78 int result() const { return result_; } |
| 123 int call_count() const { return call_count_; } | 79 int call_count() const { return call_count_; } |
| 124 | 80 |
| 125 void OnChecksComplete(int checks_failed) { | 81 void OnChecksComplete(int checks_failed) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 137 private: | 93 private: |
| 138 int result_; | 94 int result_; |
| 139 int call_count_; | 95 int call_count_; |
| 140 }; | 96 }; |
| 141 | 97 |
| 142 class ExtensionInstallCheckerTest : public testing::Test { | 98 class ExtensionInstallCheckerTest : public testing::Test { |
| 143 public: | 99 public: |
| 144 ExtensionInstallCheckerTest() {} | 100 ExtensionInstallCheckerTest() {} |
| 145 ~ExtensionInstallCheckerTest() override {} | 101 ~ExtensionInstallCheckerTest() override {} |
| 146 | 102 |
| 103 void SetBlacklistError(ExtensionInstallCheckerForTest* checker, |
| 104 PreloadCheck::Error error) { |
| 105 auto blacklist_check = base::MakeUnique<PreloadCheckStub>(); |
| 106 blacklist_check->set_is_async(checker->is_async()); |
| 107 if (error != PreloadCheck::NONE) |
| 108 blacklist_check->AddError(error); |
| 109 checker->SetBlacklistCheckForTesting(std::move(blacklist_check)); |
| 110 } |
| 111 |
| 112 void SetPolicyError(ExtensionInstallCheckerForTest* checker, |
| 113 PreloadCheck::Error error, |
| 114 std::string message) { |
| 115 // The policy check always runs synchronously. |
| 116 auto policy_check = base::MakeUnique<PreloadCheckStub>(); |
| 117 if (error != PreloadCheck::NONE) { |
| 118 policy_check->AddError(error); |
| 119 policy_check->set_error_message(base::UTF8ToUTF16(message)); |
| 120 } |
| 121 checker->SetPolicyCheckForTesting(std::move(policy_check)); |
| 122 } |
| 123 |
| 147 protected: | 124 protected: |
| 125 void SetAllPass(ExtensionInstallCheckerForTest* checker) { |
| 126 SetBlacklistError(checker, PreloadCheck::NONE); |
| 127 SetPolicyError(checker, PreloadCheck::NONE, ""); |
| 128 checker->set_requirements_error(""); |
| 129 } |
| 130 |
| 148 void SetAllErrors(ExtensionInstallCheckerForTest* checker) { | 131 void SetAllErrors(ExtensionInstallCheckerForTest* checker) { |
| 149 checker->set_blacklist_state(kBlacklistStateError); | 132 SetBlacklistError(checker, kBlacklistError); |
| 150 checker->set_policy_check_error(kDummyPolicyError); | 133 SetPolicyError(checker, PreloadCheck::DISALLOWED_BY_POLICY, |
| 134 kDummyPolicyError); |
| 151 checker->set_requirements_error(kDummyRequirementsError); | 135 checker->set_requirements_error(kDummyRequirementsError); |
| 152 } | 136 } |
| 153 | 137 |
| 154 void ValidateExpectedCalls(int call_mask, | |
| 155 const ExtensionInstallCheckerForTest& checker) { | |
| 156 bool expect_blacklist_checked = | |
| 157 (call_mask & ExtensionInstallChecker::CHECK_BLACKLIST) != 0; | |
| 158 bool expect_requirements_checked = | |
| 159 (call_mask & ExtensionInstallChecker::CHECK_REQUIREMENTS) != 0; | |
| 160 bool expect_policy_checked = | |
| 161 (call_mask & ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY) != 0; | |
| 162 EXPECT_EQ(expect_blacklist_checked, checker.blacklist_check_called()); | |
| 163 EXPECT_EQ(expect_policy_checked, checker.policy_check_called()); | |
| 164 EXPECT_EQ(expect_requirements_checked, checker.requirements_check_called()); | |
| 165 } | |
| 166 | |
| 167 void ExpectRequirementsPass(const ExtensionInstallCheckerForTest& checker) { | 138 void ExpectRequirementsPass(const ExtensionInstallCheckerForTest& checker) { |
| 168 EXPECT_TRUE(checker.requirement_errors().empty()); | 139 EXPECT_TRUE(checker.requirement_errors().empty()); |
| 169 } | 140 } |
| 170 | 141 |
| 171 void ExpectRequirementsError(const char* expected_error, | 142 void ExpectRequirementsError(const char* expected_error, |
| 172 const ExtensionInstallCheckerForTest& checker) { | 143 const ExtensionInstallCheckerForTest& checker) { |
| 173 EXPECT_FALSE(checker.requirement_errors().empty()); | 144 EXPECT_FALSE(checker.requirement_errors().empty()); |
| 174 EXPECT_EQ(std::string(expected_error), | 145 EXPECT_EQ(std::string(expected_error), |
| 175 checker.requirement_errors().front()); | 146 checker.requirement_errors().front()); |
| 176 } | 147 } |
| 177 | 148 |
| 178 void ExpectRequirementsError(const ExtensionInstallCheckerForTest& checker) { | 149 void ExpectRequirementsError(const ExtensionInstallCheckerForTest& checker) { |
| 179 ExpectRequirementsError(kDummyRequirementsError, checker); | 150 ExpectRequirementsError(kDummyRequirementsError, checker); |
| 180 } | 151 } |
| 181 | 152 |
| 182 void ExpectBlacklistPass(const ExtensionInstallCheckerForTest& checker) { | 153 void ExpectBlacklistPass(const ExtensionInstallCheckerForTest& checker) { |
| 183 EXPECT_EQ(NOT_BLACKLISTED, checker.blacklist_state()); | 154 EXPECT_EQ(PreloadCheck::NONE, checker.blacklist_error()); |
| 184 } | 155 } |
| 185 | 156 |
| 186 void ExpectBlacklistError(const ExtensionInstallCheckerForTest& checker) { | 157 void ExpectBlacklistError(const ExtensionInstallCheckerForTest& checker) { |
| 187 EXPECT_EQ(kBlacklistStateError, checker.blacklist_state()); | 158 EXPECT_EQ(kBlacklistError, checker.blacklist_error()); |
| 188 } | 159 } |
| 189 | 160 |
| 190 void ExpectPolicyPass(const ExtensionInstallCheckerForTest& checker) { | 161 void ExpectPolicyPass(const ExtensionInstallCheckerForTest& checker) { |
| 191 EXPECT_TRUE(checker.policy_allows_load()); | |
| 192 EXPECT_TRUE(checker.policy_error().empty()); | 162 EXPECT_TRUE(checker.policy_error().empty()); |
| 193 } | 163 } |
| 194 | 164 |
| 195 void ExpectPolicyError(const char* expected_error, | 165 void ExpectPolicyError(const char* expected_error, |
| 196 const ExtensionInstallCheckerForTest& checker) { | 166 const ExtensionInstallCheckerForTest& checker) { |
| 197 EXPECT_FALSE(checker.policy_allows_load()); | |
| 198 EXPECT_FALSE(checker.policy_error().empty()); | 167 EXPECT_FALSE(checker.policy_error().empty()); |
| 199 EXPECT_EQ(std::string(expected_error), checker.policy_error()); | 168 EXPECT_EQ(std::string(expected_error), checker.policy_error()); |
| 200 } | 169 } |
| 201 | 170 |
| 202 void ExpectPolicyError(const ExtensionInstallCheckerForTest& checker) { | 171 void ExpectPolicyError(const ExtensionInstallCheckerForTest& checker) { |
| 203 ExpectPolicyError(kDummyPolicyError, checker); | 172 ExpectPolicyError(kDummyPolicyError, checker); |
| 204 } | 173 } |
| 205 | 174 |
| 206 void RunChecker(ExtensionInstallCheckerForTest* checker, | 175 void RunChecker(ExtensionInstallCheckerForTest* checker, |
| 207 int expected_checks_run, | |
| 208 int expected_result) { | 176 int expected_result) { |
| 209 CheckObserver observer; | 177 CheckObserver observer; |
| 210 checker->Start(base::Bind(&CheckObserver::OnChecksComplete, | 178 checker->Start(base::Bind(&CheckObserver::OnChecksComplete, |
| 211 base::Unretained(&observer))); | 179 base::Unretained(&observer))); |
| 212 observer.Wait(); | 180 observer.Wait(); |
| 213 | 181 |
| 214 EXPECT_FALSE(checker->is_running()); | 182 EXPECT_FALSE(checker->is_running()); |
| 215 EXPECT_EQ(expected_result, observer.result()); | 183 EXPECT_EQ(expected_result, observer.result()); |
| 216 EXPECT_EQ(1, observer.call_count()); | 184 EXPECT_EQ(1, observer.call_count()); |
| 217 ValidateExpectedCalls(expected_checks_run, *checker); | |
| 218 } | 185 } |
| 219 | 186 |
| 220 void DoRunAllChecksPass(ExtensionInstallCheckerForTest* checker) { | 187 void DoRunAllChecksPass(ExtensionInstallCheckerForTest* checker) { |
| 188 SetAllPass(checker); |
| 221 RunChecker(checker, | 189 RunChecker(checker, |
| 222 ExtensionInstallChecker::CHECK_ALL, | |
| 223 0); | 190 0); |
| 224 | 191 |
| 225 ExpectRequirementsPass(*checker); | 192 ExpectRequirementsPass(*checker); |
| 226 ExpectPolicyPass(*checker); | 193 ExpectPolicyPass(*checker); |
| 227 ExpectBlacklistPass(*checker); | 194 ExpectBlacklistPass(*checker); |
| 228 } | 195 } |
| 229 | 196 |
| 230 void DoRunAllChecksFail(ExtensionInstallCheckerForTest* checker) { | 197 void DoRunAllChecksFail(ExtensionInstallCheckerForTest* checker) { |
| 231 SetAllErrors(checker); | 198 SetAllErrors(checker); |
| 232 RunChecker(checker, | 199 RunChecker(checker, |
| 233 ExtensionInstallChecker::CHECK_ALL, | |
| 234 ExtensionInstallChecker::CHECK_ALL); | 200 ExtensionInstallChecker::CHECK_ALL); |
| 235 | 201 |
| 236 ExpectRequirementsError(*checker); | 202 ExpectRequirementsError(*checker); |
| 237 ExpectPolicyError(*checker); | 203 ExpectPolicyError(*checker); |
| 238 ExpectBlacklistError(*checker); | 204 ExpectBlacklistError(*checker); |
| 239 } | 205 } |
| 240 | 206 |
| 241 void DoRunSubsetOfChecks(int checks_to_run) { | 207 void DoRunSubsetOfChecks(int checks_to_run) { |
| 242 ExtensionInstallCheckerForTest sync_checker(checks_to_run, | 208 ExtensionInstallCheckerForTest sync_checker(checks_to_run, |
| 243 /*fail_fast=*/false); | 209 /*fail_fast=*/false); |
| 244 ExtensionInstallCheckerAsync async_checker(checks_to_run, | 210 ExtensionInstallCheckerForTest async_checker(checks_to_run, |
| 245 /*fail_fast=*/false); | 211 /*fail_fast=*/false); |
| 246 ExtensionInstallCheckerForTest* checkers[] = { | 212 async_checker.set_is_async(true); |
| 247 &sync_checker, &async_checker, | |
| 248 }; | |
| 249 | 213 |
| 250 for (auto* checker : checkers) { | 214 for (auto* checker : {&sync_checker, &async_checker}) { |
| 251 SetAllErrors(checker); | 215 SetAllErrors(checker); |
| 252 RunChecker(checker, checks_to_run, checks_to_run); | 216 RunChecker(checker, checks_to_run); |
| 253 | 217 |
| 254 if (checks_to_run & ExtensionInstallChecker::CHECK_REQUIREMENTS) | 218 if (checks_to_run & ExtensionInstallChecker::CHECK_REQUIREMENTS) |
| 255 ExpectRequirementsError(*checker); | 219 ExpectRequirementsError(*checker); |
| 256 else | 220 else |
| 257 ExpectRequirementsPass(*checker); | 221 ExpectRequirementsPass(*checker); |
| 258 | 222 |
| 259 if (checks_to_run & ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY) | 223 if (checks_to_run & ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY) |
| 260 ExpectPolicyError(*checker); | 224 ExpectPolicyError(*checker); |
| 261 else | 225 else |
| 262 ExpectPolicyPass(*checker); | 226 ExpectPolicyPass(*checker); |
| 263 | 227 |
| 264 if (checks_to_run & ExtensionInstallChecker::CHECK_BLACKLIST) | 228 if (checks_to_run & ExtensionInstallChecker::CHECK_BLACKLIST) |
| 265 ExpectBlacklistError(*checker); | 229 ExpectBlacklistError(*checker); |
| 266 else | 230 else |
| 267 ExpectBlacklistPass(*checker); | 231 ExpectBlacklistPass(*checker); |
| 268 } | 232 } |
| 269 } | 233 } |
| 270 | 234 |
| 271 private: | 235 private: |
| 272 // A message loop is required for the asynchronous tests. | 236 // A message loop is required for the asynchronous tests. |
| 273 base::MessageLoop message_loop; | 237 base::MessageLoop message_loop; |
| 274 }; | 238 }; |
| 275 | 239 |
| 276 // Test the case where all tests pass. | 240 // Test the case where all tests pass. |
| 277 TEST_F(ExtensionInstallCheckerTest, AllSucceeded) { | 241 TEST_F(ExtensionInstallCheckerTest, AllSucceeded) { |
| 278 ExtensionInstallCheckerForTest sync_checker( | 242 ExtensionInstallCheckerForTest sync_checker( |
| 279 ExtensionInstallChecker::CHECK_ALL, /*fail_fast=*/false); | 243 ExtensionInstallChecker::CHECK_ALL, /*fail_fast=*/false); |
| 280 DoRunAllChecksPass(&sync_checker); | 244 DoRunAllChecksPass(&sync_checker); |
| 281 | 245 |
| 282 ExtensionInstallCheckerAsync async_checker(ExtensionInstallChecker::CHECK_ALL, | 246 ExtensionInstallCheckerForTest async_checker( |
| 283 /*fail_fast=*/false); | 247 ExtensionInstallChecker::CHECK_ALL, /*fail_fast=*/false); |
| 248 async_checker.set_is_async(true); |
| 284 DoRunAllChecksPass(&async_checker); | 249 DoRunAllChecksPass(&async_checker); |
| 285 } | 250 } |
| 286 | 251 |
| 287 // Test the case where all tests fail. | 252 // Test the case where all tests fail. |
| 288 TEST_F(ExtensionInstallCheckerTest, AllFailed) { | 253 TEST_F(ExtensionInstallCheckerTest, AllFailed) { |
| 289 ExtensionInstallCheckerForTest sync_checker( | 254 ExtensionInstallCheckerForTest sync_checker( |
| 290 ExtensionInstallChecker::CHECK_ALL, /*fail_fast=*/false); | 255 ExtensionInstallChecker::CHECK_ALL, /*fail_fast=*/false); |
| 291 DoRunAllChecksFail(&sync_checker); | 256 DoRunAllChecksFail(&sync_checker); |
| 292 | 257 |
| 293 ExtensionInstallCheckerAsync async_checker(ExtensionInstallChecker::CHECK_ALL, | 258 ExtensionInstallCheckerForTest async_checker( |
| 294 /*fail_fast=*/false); | 259 ExtensionInstallChecker::CHECK_ALL, /*fail_fast=*/false); |
| 260 async_checker.set_is_async(true); |
| 295 DoRunAllChecksFail(&async_checker); | 261 DoRunAllChecksFail(&async_checker); |
| 296 } | 262 } |
| 297 | 263 |
| 298 // Test running only a subset of tests. | 264 // Test running only a subset of tests. |
| 299 TEST_F(ExtensionInstallCheckerTest, RunSubsetOfChecks) { | 265 TEST_F(ExtensionInstallCheckerTest, RunSubsetOfChecks) { |
| 300 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY | | 266 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY | |
| 301 ExtensionInstallChecker::CHECK_REQUIREMENTS); | 267 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
| 302 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_BLACKLIST | | 268 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_BLACKLIST | |
| 303 ExtensionInstallChecker::CHECK_REQUIREMENTS); | 269 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
| 304 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_BLACKLIST); | 270 DoRunSubsetOfChecks(ExtensionInstallChecker::CHECK_BLACKLIST); |
| 305 } | 271 } |
| 306 | 272 |
| 307 // Test fail fast with synchronous callbacks. | 273 // Test fail fast with synchronous callbacks. |
| 308 TEST_F(ExtensionInstallCheckerTest, FailFastSync) { | 274 TEST_F(ExtensionInstallCheckerTest, FailFastSync) { |
| 309 // This test assumes some internal knowledge of the implementation - that | 275 // This test assumes some internal knowledge of the implementation - that |
| 310 // the policy check runs first. | 276 // the policy check runs first. |
| 311 { | 277 { |
| 312 ExtensionInstallCheckerForTest checker(ExtensionInstallChecker::CHECK_ALL, | 278 ExtensionInstallCheckerForTest checker(ExtensionInstallChecker::CHECK_ALL, |
| 313 /*fail_fast=*/true); | 279 /*fail_fast=*/true); |
| 314 SetAllErrors(&checker); | 280 SetAllErrors(&checker); |
| 315 RunChecker(&checker, ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, | 281 RunChecker(&checker, ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY); |
| 316 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY); | |
| 317 | 282 |
| 318 ExpectRequirementsPass(checker); | 283 ExpectRequirementsPass(checker); |
| 319 ExpectPolicyError(checker); | 284 ExpectPolicyError(checker); |
| 320 ExpectBlacklistPass(checker); | 285 ExpectBlacklistPass(checker); |
| 321 } | 286 } |
| 322 | 287 |
| 323 { | 288 { |
| 324 ExtensionInstallCheckerForTest checker( | 289 ExtensionInstallCheckerForTest checker( |
| 325 ExtensionInstallChecker::CHECK_REQUIREMENTS | | 290 ExtensionInstallChecker::CHECK_REQUIREMENTS | |
| 326 ExtensionInstallChecker::CHECK_BLACKLIST, | 291 ExtensionInstallChecker::CHECK_BLACKLIST, |
| 327 /*fail_fast=*/true); | 292 /*fail_fast=*/true); |
| 328 SetAllErrors(&checker); | 293 SetAllErrors(&checker); |
| 329 RunChecker(&checker, ExtensionInstallChecker::CHECK_REQUIREMENTS, | 294 RunChecker(&checker, ExtensionInstallChecker::CHECK_REQUIREMENTS); |
| 330 ExtensionInstallChecker::CHECK_REQUIREMENTS); | |
| 331 | 295 |
| 332 ExpectRequirementsError(checker); | 296 ExpectRequirementsError(checker); |
| 333 ExpectPolicyPass(checker); | 297 ExpectPolicyPass(checker); |
| 334 ExpectBlacklistPass(checker); | 298 ExpectBlacklistPass(checker); |
| 335 } | 299 } |
| 336 } | 300 } |
| 337 | 301 |
| 338 // Test fail fast with asynchronous callbacks. | 302 // Test fail fast with asynchronous callbacks. |
| 339 TEST_F(ExtensionInstallCheckerTest, FailFastAsync) { | 303 TEST_F(ExtensionInstallCheckerTest, FailFastAsync) { |
| 340 // This test assumes some internal knowledge of the implementation - that | 304 // This test assumes some internal knowledge of the implementation - that |
| 341 // the requirements check runs before the blacklist check. Both checks should | 305 // the requirements check runs before the blacklist check. Both checks should |
| 342 // be called, but the requirements check callback arrives first and the | 306 // be called, but the requirements check callback arrives first and the |
| 343 // blacklist result will be discarded. | 307 // blacklist result will be discarded. |
| 344 ExtensionInstallCheckerAsync checker(ExtensionInstallChecker::CHECK_ALL, | 308 ExtensionInstallCheckerForTest checker(ExtensionInstallChecker::CHECK_ALL, |
| 345 /*fail_fast=*/true); | 309 /*fail_fast=*/true); |
| 346 | 310 checker.set_is_async(true); |
| 347 SetAllErrors(&checker); | 311 SetAllErrors(&checker); |
| 348 | 312 |
| 349 // The policy check is synchronous and needs to pass for the other tests to | 313 // The policy check is synchronous and needs to pass for the other tests to |
| 350 // run. | 314 // run. |
| 351 checker.set_policy_check_error(std::string()); | 315 SetPolicyError(&checker, PreloadCheck::NONE, ""); |
| 352 | 316 |
| 353 RunChecker(&checker, | 317 RunChecker(&checker, |
| 354 ExtensionInstallChecker::CHECK_ALL, | |
| 355 ExtensionInstallChecker::CHECK_REQUIREMENTS); | 318 ExtensionInstallChecker::CHECK_REQUIREMENTS); |
| 356 | 319 |
| 357 ExpectRequirementsError(checker); | 320 ExpectRequirementsError(checker); |
| 358 ExpectPolicyPass(checker); | 321 ExpectPolicyPass(checker); |
| 359 ExpectBlacklistPass(checker); | 322 ExpectBlacklistPass(checker); |
| 360 } | 323 } |
| 361 | 324 |
| 362 } // namespace extensions | 325 } // namespace extensions |
| OLD | NEW |