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