Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/safe_browsing/chrome_cleaner/chrome_cleaner_controller_ win.h" | 5 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_ win.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/task_scheduler/post_task.h" | 14 #include "base/task_scheduler/post_task.h" |
| 15 #include "base/test/multiprocess_test.h" | 15 #include "base/test/multiprocess_test.h" |
| 16 #include "base/test/scoped_feature_list.h" | 16 #include "base/test/scoped_feature_list.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_proces s_win.h" | 21 #include "chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_proces s_win.h" |
| 22 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h" | 22 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h" |
| 23 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" | 23 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" |
| 24 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 26 #include "chrome/test/base/testing_profile_manager.h" | 26 #include "chrome/test/base/testing_profile_manager.h" |
| 27 #include "components/chrome_cleaner/public/constants/constants.h" | 27 #include "components/chrome_cleaner/public/constants/constants.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
| 30 #include "content/public/test/test_utils.h" | |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "testing/multiprocess_func_list.h" | 33 #include "testing/multiprocess_func_list.h" |
| 33 | 34 |
| 34 namespace safe_browsing { | 35 namespace safe_browsing { |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 38 using ::chrome_cleaner::mojom::PromptAcceptance; | |
| 37 using ::testing::Combine; | 39 using ::testing::Combine; |
| 38 using ::testing::DoAll; | 40 using ::testing::DoAll; |
| 39 using ::testing::InvokeWithoutArgs; | 41 using ::testing::InvokeWithoutArgs; |
| 40 using ::testing::SaveArg; | 42 using ::testing::SaveArg; |
| 41 using ::testing::StrictMock; | 43 using ::testing::StrictMock; |
| 42 using ::testing::UnorderedElementsAreArray; | 44 using ::testing::UnorderedElementsAreArray; |
| 43 using ::testing::Values; | 45 using ::testing::Values; |
| 44 using ::testing::_; | 46 using ::testing::_; |
| 45 using CrashPoint = MockChromeCleanerProcess::CrashPoint; | 47 using CrashPoint = MockChromeCleanerProcess::CrashPoint; |
| 46 using IdleReason = ChromeCleanerController::IdleReason; | 48 using IdleReason = ChromeCleanerController::IdleReason; |
| 47 using State = ChromeCleanerController::State; | 49 using State = ChromeCleanerController::State; |
| 48 using UserResponse = ChromeCleanerController::UserResponse; | 50 using UserResponse = ChromeCleanerController::UserResponse; |
| 49 | 51 |
| 52 // Returns the PromptAcceptance value that ChromeCleanerController is supposed | |
| 53 // to send to the Chrome Cleaner process when ReplyWithUserResponse() is | |
| 54 // called with |user_response|. | |
| 55 PromptAcceptance UserResponseToPromptAcceptance(UserResponse user_response) { | |
| 56 switch (user_response) { | |
| 57 case UserResponse::kAcceptedWithLogs: | |
| 58 return PromptAcceptance::ACCEPTED_WITH_LOGS; | |
| 59 case UserResponse::kAcceptedWithoutLogs: | |
| 60 return PromptAcceptance::ACCEPTED_WITHOUT_LOGS; | |
| 61 case UserResponse::kDenied: // Fallthrough | |
| 62 case UserResponse::kDismissed: | |
| 63 return PromptAcceptance::DENIED; | |
| 64 } | |
| 65 | |
| 66 NOTREACHED(); | |
| 67 return PromptAcceptance::UNSPECIFIED; | |
| 68 } | |
| 69 | |
| 50 class MockChromeCleanerControllerObserver | 70 class MockChromeCleanerControllerObserver |
| 51 : public ChromeCleanerController::Observer { | 71 : public ChromeCleanerController::Observer { |
| 52 public: | 72 public: |
| 53 MOCK_METHOD1(OnIdle, void(ChromeCleanerController::IdleReason)); | 73 MOCK_METHOD1(OnIdle, void(ChromeCleanerController::IdleReason)); |
| 54 MOCK_METHOD0(OnScanning, void()); | 74 MOCK_METHOD0(OnScanning, void()); |
| 55 MOCK_METHOD1(OnInfected, void(const std::set<base::FilePath>&)); | 75 MOCK_METHOD1(OnInfected, void(const std::set<base::FilePath>&)); |
| 56 MOCK_METHOD1(OnCleaning, void(const std::set<base::FilePath>&)); | 76 MOCK_METHOD1(OnCleaning, void(const std::set<base::FilePath>&)); |
| 57 MOCK_METHOD0(OnRebootRequired, void()); | 77 MOCK_METHOD0(OnRebootRequired, void()); |
| 78 MOCK_METHOD0(OnRebootFailed, void()); | |
| 79 MOCK_METHOD1(OnLogsEnabledChanged, void(bool)); | |
| 58 }; | 80 }; |
| 59 | 81 |
| 60 enum class MetricsStatus { | 82 enum class MetricsStatus { |
| 61 kEnabled, | 83 kEnabled, |
| 62 kDisabled, | 84 kDisabled, |
| 63 }; | 85 }; |
| 64 | 86 |
| 65 enum class ScoutStatus { | 87 enum class ScoutStatus { |
| 66 kEnabled, | 88 kEnabled, |
| 67 kDisabled, | 89 kDisabled, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 // ChromeCleanerRunnerTestDelegate overrides. | 155 // ChromeCleanerRunnerTestDelegate overrides. |
| 134 | 156 |
| 135 base::Process LaunchTestProcess( | 157 base::Process LaunchTestProcess( |
| 136 const base::CommandLine& command_line, | 158 const base::CommandLine& command_line, |
| 137 const base::LaunchOptions& launch_options) override { | 159 const base::LaunchOptions& launch_options) override { |
| 138 command_line_ = command_line; | 160 command_line_ = command_line; |
| 139 // Return an invalid process. | 161 // Return an invalid process. |
| 140 return base::Process(); | 162 return base::Process(); |
| 141 } | 163 } |
| 142 | 164 |
| 165 void OnCleanerProcessDone( | |
| 166 const ChromeCleanerRunner::ProcessStatus& process_status) override {} | |
| 167 | |
| 143 protected: | 168 protected: |
| 144 // We need this because we need UI and IO threads during tests. The thread | 169 // We need this because we need UI and IO threads during tests. The thread |
| 145 // bundle should be the first member of the class so that it will be destroyed | 170 // bundle should be the first member of the class so that it will be destroyed |
| 146 // last. | 171 // last. |
| 147 content::TestBrowserThreadBundle thread_bundle_; | 172 content::TestBrowserThreadBundle thread_bundle_; |
| 148 base::test::ScopedFeatureList scoped_feature_list_; | 173 base::test::ScopedFeatureList scoped_feature_list_; |
| 149 | 174 |
| 150 bool metrics_enabled_; | 175 bool metrics_enabled_; |
| 151 bool scout_enabled_; | 176 bool scout_enabled_; |
| 152 base::CommandLine command_line_; | 177 base::CommandLine command_line_; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 251 |
| 227 void SetUp() override { | 252 void SetUp() override { |
| 228 std::tie(process_status_, crash_point_, uws_found_status_, user_response_) = | 253 std::tie(process_status_, crash_point_, uws_found_status_, user_response_) = |
| 229 GetParam(); | 254 GetParam(); |
| 230 | 255 |
| 231 cleaner_process_options_.SetDoFindUws(uws_found_status_ != | 256 cleaner_process_options_.SetDoFindUws(uws_found_status_ != |
| 232 UwsFoundStatus::kNoUwsFound); | 257 UwsFoundStatus::kNoUwsFound); |
| 233 cleaner_process_options_.set_reboot_required( | 258 cleaner_process_options_.set_reboot_required( |
| 234 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired); | 259 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired); |
| 235 cleaner_process_options_.set_crash_point(crash_point_); | 260 cleaner_process_options_.set_crash_point(crash_point_); |
| 261 cleaner_process_options_.set_expected_user_response( | |
| 262 uws_found_status_ == UwsFoundStatus::kNoUwsFound | |
| 263 ? PromptAcceptance::DENIED | |
| 264 : UserResponseToPromptAcceptance(user_response_)); | |
| 236 | 265 |
| 237 controller_ = ChromeCleanerController::GetInstance(); | 266 controller_ = ChromeCleanerController::GetInstance(); |
| 238 ASSERT_TRUE(controller_); | 267 ASSERT_TRUE(controller_); |
| 268 // Since tests may change the logs collection permissions, ensure that the | |
| 269 // controller always starts off with logs collection enabled. | |
| 270 controller_->SetLogsEnabled(true); | |
|
proberge
2017/06/29 13:55:53
Shouldn't the entire controller be reset to a new
alito
2017/06/29 17:14:27
Done.
| |
| 239 | 271 |
| 240 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); | 272 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); |
| 241 SetChromeCleanerRunnerTestDelegateForTesting(this); | 273 SetChromeCleanerRunnerTestDelegateForTesting(this); |
| 242 controller_->SetDelegateForTesting(this); | 274 controller_->SetDelegateForTesting(this); |
| 243 } | 275 } |
| 244 | 276 |
| 245 void TearDown() override { | 277 void TearDown() override { |
| 246 if (controller_->state() == State::kRebootRequired) | 278 if (controller_->state() == State::kRebootRequired) |
| 247 controller_->DismissRebootForTesting(); | 279 controller_->DismissRebootForTesting(); |
|
proberge
2017/06/29 17:58:36
Are all instances of DismissRebootForTesting remov
alito
2017/06/29 18:13:51
Done.
| |
| 248 | 280 |
| 249 controller_->SetDelegateForTesting(nullptr); | 281 controller_->SetDelegateForTesting(nullptr); |
| 250 SetChromeCleanerRunnerTestDelegateForTesting(nullptr); | 282 SetChromeCleanerRunnerTestDelegateForTesting(nullptr); |
| 251 } | 283 } |
| 252 | 284 |
| 253 // ChromeCleanerControllerDelegate overrides. | 285 // ChromeCleanerControllerDelegate overrides. |
| 254 | 286 |
| 255 void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override { | 287 void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override { |
| 256 base::ThreadTaskRunnerHandle::Get()->PostTask( | 288 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 257 FROM_HERE, | 289 FROM_HERE, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 &test_process_command_line); | 336 &test_process_command_line); |
| 305 | 337 |
| 306 base::SpawnChildResult result = base::SpawnMultiProcessTestChild( | 338 base::SpawnChildResult result = base::SpawnMultiProcessTestChild( |
| 307 "MockChromeCleanerProcessMain", test_process_command_line, | 339 "MockChromeCleanerProcessMain", test_process_command_line, |
| 308 launch_options); | 340 launch_options); |
| 309 | 341 |
| 310 EXPECT_TRUE(result.process.IsValid()); | 342 EXPECT_TRUE(result.process.IsValid()); |
| 311 return std::move(result.process); | 343 return std::move(result.process); |
| 312 } | 344 } |
| 313 | 345 |
| 346 void OnCleanerProcessDone( | |
| 347 const ChromeCleanerRunner::ProcessStatus& process_status) override { | |
| 348 cleaner_process_status_ = process_status; | |
| 349 } | |
| 350 | |
| 314 ChromeCleanerController::State ExpectedFinalState() { | 351 ChromeCleanerController::State ExpectedFinalState() { |
| 315 if (process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | 352 if (process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && |
| 316 crash_point_ == CrashPoint::kNone && | 353 crash_point_ == CrashPoint::kNone && |
| 317 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired && | 354 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired && |
| 318 user_response_ == UserResponse::kAccepted) { | 355 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 356 user_response_ == UserResponse::kAcceptedWithoutLogs)) { | |
| 319 return State::kRebootRequired; | 357 return State::kRebootRequired; |
| 320 } | 358 } |
| 321 return State::kIdle; | 359 return State::kIdle; |
| 322 } | 360 } |
| 323 | 361 |
| 324 bool ExpectedOnIdleCalled() { return ExpectedFinalState() == State::kIdle; } | 362 bool ExpectedOnIdleCalled() { return ExpectedFinalState() == State::kIdle; } |
| 325 | 363 |
| 326 bool ExpectedOnInfectedCalled() { | 364 bool ExpectedOnInfectedCalled() { |
| 327 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | 365 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && |
| 328 crash_point_ != CrashPoint::kOnStartup && | 366 crash_point_ != CrashPoint::kOnStartup && |
| 329 crash_point_ != CrashPoint::kAfterConnection && | 367 crash_point_ != CrashPoint::kAfterConnection && |
| 330 uws_found_status_ != UwsFoundStatus::kNoUwsFound; | 368 uws_found_status_ != UwsFoundStatus::kNoUwsFound; |
| 331 } | 369 } |
| 332 | 370 |
| 333 bool ExpectedOnCleaningCalled() { | 371 bool ExpectedOnCleaningCalled() { |
| 334 return ExpectedOnInfectedCalled() && | 372 return ExpectedOnInfectedCalled() && |
| 335 crash_point_ != CrashPoint::kAfterRequestSent && | 373 crash_point_ != CrashPoint::kAfterRequestSent && |
| 336 user_response_ == UserResponse::kAccepted; | 374 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 375 user_response_ == UserResponse::kAcceptedWithoutLogs); | |
| 337 } | 376 } |
| 338 | 377 |
| 339 bool ExpectedOnRebootRequiredCalled() { | 378 bool ExpectedOnRebootRequiredCalled() { |
| 340 return ExpectedFinalState() == State::kRebootRequired; | 379 return ExpectedFinalState() == State::kRebootRequired; |
| 341 } | 380 } |
| 342 | 381 |
| 343 bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); } | 382 bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); } |
| 344 | 383 |
| 345 bool ExpectedToTagProfile() { | 384 bool ExpectedToTagProfile() { |
| 346 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | 385 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && |
| 347 (crash_point_ == CrashPoint::kNone || | 386 (crash_point_ == CrashPoint::kNone || |
| 348 crash_point_ == CrashPoint::kAfterResponseReceived) && | 387 crash_point_ == CrashPoint::kAfterResponseReceived) && |
| 349 (uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired || | 388 (uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired || |
| 350 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired) && | 389 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired) && |
| 351 user_response_ == UserResponse::kAccepted; | 390 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 391 user_response_ == UserResponse::kAcceptedWithoutLogs); | |
| 352 } | 392 } |
| 353 | 393 |
| 354 bool ExpectedToResetSettings() { | 394 bool ExpectedToResetSettings() { |
| 355 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | 395 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && |
| 356 crash_point_ == CrashPoint::kNone && | 396 crash_point_ == CrashPoint::kNone && |
| 357 uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired && | 397 uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired && |
| 358 user_response_ == UserResponse::kAccepted; | 398 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 399 user_response_ == UserResponse::kAcceptedWithoutLogs); | |
| 359 } | 400 } |
| 360 | 401 |
| 361 ChromeCleanerController::IdleReason ExpectedIdleReason() { | 402 ChromeCleanerController::IdleReason ExpectedIdleReason() { |
| 362 EXPECT_EQ(ExpectedFinalState(), State::kIdle); | 403 EXPECT_EQ(ExpectedFinalState(), State::kIdle); |
| 363 | 404 |
| 364 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess || | 405 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess || |
| 365 crash_point_ == CrashPoint::kOnStartup || | 406 crash_point_ == CrashPoint::kOnStartup || |
| 366 crash_point_ == CrashPoint::kAfterConnection) { | 407 crash_point_ == CrashPoint::kAfterConnection) { |
| 367 return IdleReason::kScanningFailed; | 408 return IdleReason::kScanningFailed; |
| 368 } | 409 } |
| 369 | 410 |
| 370 if (uws_found_status_ == UwsFoundStatus::kNoUwsFound) | 411 if (uws_found_status_ == UwsFoundStatus::kNoUwsFound) |
| 371 return IdleReason::kScanningFoundNothing; | 412 return IdleReason::kScanningFoundNothing; |
| 372 | 413 |
| 373 if (ExpectedOnInfectedCalled() && | 414 if (ExpectedOnInfectedCalled() && |
| 374 (user_response_ == UserResponse::kDenied || | 415 (user_response_ == UserResponse::kDenied || |
| 375 user_response_ == UserResponse::kDismissed)) { | 416 user_response_ == UserResponse::kDismissed)) { |
| 376 return IdleReason::kUserDeclinedCleanup; | 417 return IdleReason::kUserDeclinedCleanup; |
| 377 } | 418 } |
| 378 | 419 |
| 379 if (ExpectedOnInfectedCalled() && | 420 if (ExpectedOnInfectedCalled() && |
| 380 user_response_ == UserResponse::kAccepted && | 421 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 422 user_response_ == UserResponse::kAcceptedWithoutLogs) && | |
| 381 crash_point_ == CrashPoint::kAfterResponseReceived) { | 423 crash_point_ == CrashPoint::kAfterResponseReceived) { |
| 382 return IdleReason::kCleaningFailed; | 424 return IdleReason::kCleaningFailed; |
| 383 } | 425 } |
| 384 | 426 |
| 385 return IdleReason::kCleaningSucceeded; | 427 return IdleReason::kCleaningSucceeded; |
| 386 } | 428 } |
| 387 | 429 |
| 388 protected: | 430 protected: |
| 389 // We need this because we need UI and IO threads during tests. The thread | 431 // We need this because we need UI and IO threads during tests. The thread |
| 390 // bundle should be the first member of the class so that it will be destroyed | 432 // bundle should be the first member of the class so that it will be destroyed |
| 391 // last. | 433 // last. |
| 392 content::TestBrowserThreadBundle thread_bundle_; | 434 content::TestBrowserThreadBundle thread_bundle_; |
| 393 base::test::ScopedFeatureList scoped_feature_list_; | 435 base::test::ScopedFeatureList scoped_feature_list_; |
| 394 | 436 |
| 395 CleanerProcessStatus process_status_; | 437 CleanerProcessStatus process_status_; |
| 396 MockChromeCleanerProcess::CrashPoint crash_point_; | 438 MockChromeCleanerProcess::CrashPoint crash_point_; |
| 397 UwsFoundStatus uws_found_status_; | 439 UwsFoundStatus uws_found_status_; |
| 398 ChromeCleanerController::UserResponse user_response_; | 440 ChromeCleanerController::UserResponse user_response_; |
| 399 | 441 |
| 400 MockChromeCleanerProcess::Options cleaner_process_options_; | 442 MockChromeCleanerProcess::Options cleaner_process_options_; |
| 401 | 443 |
| 402 StrictMock<MockChromeCleanerControllerObserver> mock_observer_; | 444 StrictMock<MockChromeCleanerControllerObserver> mock_observer_; |
| 403 ChromeCleanerController* controller_; | 445 ChromeCleanerController* controller_; |
| 446 ChromeCleanerRunner::ProcessStatus cleaner_process_status_; | |
| 404 | 447 |
| 405 std::vector<Profile*> profiles_tagged_; | 448 std::vector<Profile*> profiles_tagged_; |
| 406 std::vector<Profile*> profiles_to_reset_if_tagged_; | 449 std::vector<Profile*> profiles_to_reset_if_tagged_; |
| 407 }; | 450 }; |
| 408 | 451 |
| 409 MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) { | 452 MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) { |
| 410 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 453 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 411 MockChromeCleanerProcess::Options options; | 454 MockChromeCleanerProcess::Options options; |
| 412 EXPECT_TRUE(MockChromeCleanerProcess::Options::FromCommandLine(*command_line, | 455 EXPECT_TRUE(MockChromeCleanerProcess::Options::FromCommandLine(*command_line, |
| 413 &options)); | 456 &options)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); | 505 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); |
| 463 } | 506 } |
| 464 | 507 |
| 465 if (ExpectedOnInfectedCalled()) { | 508 if (ExpectedOnInfectedCalled()) { |
| 466 EXPECT_CALL(mock_observer_, OnInfected(_)) | 509 EXPECT_CALL(mock_observer_, OnInfected(_)) |
| 467 .WillOnce(DoAll(SaveArg<0>(&files_to_delete_on_infected), | 510 .WillOnce(DoAll(SaveArg<0>(&files_to_delete_on_infected), |
| 468 InvokeWithoutArgs([this, profile1]() { | 511 InvokeWithoutArgs([this, profile1]() { |
| 469 controller_->ReplyWithUserResponse(profile1, | 512 controller_->ReplyWithUserResponse(profile1, |
| 470 user_response_); | 513 user_response_); |
| 471 }))); | 514 }))); |
| 515 // Since logs upload is enabled by default, OnLogsEnabledChanged() will be | |
| 516 // called only if the user response is kAcceptedWithoutLogs. | |
| 517 if (user_response_ == UserResponse::kAcceptedWithoutLogs) | |
| 518 EXPECT_CALL(mock_observer_, OnLogsEnabledChanged(false)); | |
| 472 } | 519 } |
| 473 | 520 |
| 474 if (ExpectedOnCleaningCalled()) { | 521 if (ExpectedOnCleaningCalled()) { |
| 475 EXPECT_CALL(mock_observer_, OnCleaning(_)) | 522 EXPECT_CALL(mock_observer_, OnCleaning(_)) |
| 476 .WillOnce(SaveArg<0>(&files_to_delete_on_cleaning)); | 523 .WillOnce(SaveArg<0>(&files_to_delete_on_cleaning)); |
| 477 } | 524 } |
| 478 | 525 |
| 479 if (ExpectedOnRebootRequiredCalled()) { | 526 if (ExpectedOnRebootRequiredCalled()) { |
| 480 EXPECT_CALL(mock_observer_, OnRebootRequired()) | 527 EXPECT_CALL(mock_observer_, OnRebootRequired()) |
| 481 .WillOnce( | 528 .WillOnce( |
| 482 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); | 529 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); |
| 483 } | 530 } |
| 484 | 531 |
| 485 // Assert here that we expect at least one of OnIdle or OnRebootRequired to be | 532 // Assert here that we expect at least one of OnIdle or OnRebootRequired to be |
| 486 // called, since otherwise, the test is set up incorrectly and is expected to | 533 // called, since otherwise, the test is set up incorrectly and is expected to |
| 487 // never stop. | 534 // never stop. |
| 488 ASSERT_TRUE(ExpectedOnIdleCalled() || ExpectedOnRebootRequiredCalled()); | 535 ASSERT_TRUE(ExpectedOnIdleCalled() || ExpectedOnRebootRequiredCalled()); |
| 489 run_loop.Run(); | 536 run_loop.Run(); |
| 537 // Also ensure that we wait until the mock cleaner process has finished and | |
| 538 // that all tasks that posted by ChromeCleanerRunner have run. | |
| 539 content::RunAllBlockingPoolTasksUntilIdle(); | |
| 490 | 540 |
| 541 EXPECT_NE(cleaner_process_status_.exit_code, | |
| 542 MockChromeCleanerProcess::kInternalTestFailureExitCode); | |
| 491 EXPECT_EQ(controller_->state(), ExpectedFinalState()); | 543 EXPECT_EQ(controller_->state(), ExpectedFinalState()); |
| 492 EXPECT_EQ(!files_to_delete_on_infected.empty(), ExpectedUwsFound()); | 544 EXPECT_EQ(!files_to_delete_on_infected.empty(), ExpectedUwsFound()); |
| 493 EXPECT_EQ(!files_to_delete_on_cleaning.empty(), | 545 EXPECT_EQ(!files_to_delete_on_cleaning.empty(), |
| 494 ExpectedUwsFound() && ExpectedOnCleaningCalled()); | 546 ExpectedUwsFound() && ExpectedOnCleaningCalled()); |
| 495 if (!files_to_delete_on_infected.empty() && | 547 if (!files_to_delete_on_infected.empty() && |
| 496 !files_to_delete_on_cleaning.empty()) { | 548 !files_to_delete_on_cleaning.empty()) { |
| 497 EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning); | 549 EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning); |
| 498 } | 550 } |
| 499 | 551 |
| 500 std::vector<Profile*> expected_tagged; | 552 std::vector<Profile*> expected_tagged; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 522 Values(CrashPoint::kNone, | 574 Values(CrashPoint::kNone, |
| 523 CrashPoint::kOnStartup, | 575 CrashPoint::kOnStartup, |
| 524 CrashPoint::kAfterConnection, | 576 CrashPoint::kAfterConnection, |
| 525 // CrashPoint::kAfterRequestSent is not used because we | 577 // CrashPoint::kAfterRequestSent is not used because we |
| 526 // cannot ensure the order between the Mojo request being | 578 // cannot ensure the order between the Mojo request being |
| 527 // received by Chrome and the connection being lost. | 579 // received by Chrome and the connection being lost. |
| 528 CrashPoint::kAfterResponseReceived), | 580 CrashPoint::kAfterResponseReceived), |
| 529 Values(UwsFoundStatus::kNoUwsFound, | 581 Values(UwsFoundStatus::kNoUwsFound, |
| 530 UwsFoundStatus::kUwsFoundRebootRequired, | 582 UwsFoundStatus::kUwsFoundRebootRequired, |
| 531 UwsFoundStatus::kUwsFoundNoRebootRequired), | 583 UwsFoundStatus::kUwsFoundNoRebootRequired), |
| 532 Values(UserResponse::kAccepted, | 584 Values(UserResponse::kAcceptedWithLogs, |
| 585 UserResponse::kAcceptedWithoutLogs, | |
| 533 UserResponse::kDenied, | 586 UserResponse::kDenied, |
| 534 UserResponse::kDismissed))); | 587 UserResponse::kDismissed))); |
| 535 | 588 |
| 536 } // namespace | 589 } // namespace |
| 537 } // namespace safe_browsing | 590 } // namespace safe_browsing |
| OLD | NEW |