| 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 20 matching lines...) Expand all Loading... |
| 88 | 110 |
| 89 void SetUp() override { | 111 void SetUp() override { |
| 90 MetricsStatus metrics_status; | 112 MetricsStatus metrics_status; |
| 91 ScoutStatus scout_status; | 113 ScoutStatus scout_status; |
| 92 std::tie(metrics_status, scout_status) = GetParam(); | 114 std::tie(metrics_status, scout_status) = GetParam(); |
| 93 | 115 |
| 94 metrics_enabled_ = metrics_status == MetricsStatus::kEnabled; | 116 metrics_enabled_ = metrics_status == MetricsStatus::kEnabled; |
| 95 scout_enabled_ = scout_status == ScoutStatus::kEnabled; | 117 scout_enabled_ = scout_status == ScoutStatus::kEnabled; |
| 96 | 118 |
| 97 SetChromeCleanerRunnerTestDelegateForTesting(this); | 119 SetChromeCleanerRunnerTestDelegateForTesting(this); |
| 120 ChromeCleanerController::ResetInstanceForTesting(); |
| 98 ChromeCleanerController::GetInstance()->SetDelegateForTesting(this); | 121 ChromeCleanerController::GetInstance()->SetDelegateForTesting(this); |
| 99 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); | 122 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); |
| 100 } | 123 } |
| 101 | 124 |
| 102 void TearDown() override { | 125 void TearDown() override { |
| 103 ChromeCleanerController::GetInstance()->SetDelegateForTesting(nullptr); | 126 ChromeCleanerController::GetInstance()->SetDelegateForTesting(nullptr); |
| 104 SetChromeCleanerRunnerTestDelegateForTesting(nullptr); | 127 SetChromeCleanerRunnerTestDelegateForTesting(nullptr); |
| 105 } | 128 } |
| 106 | 129 |
| 107 // ChromeCleanerControllerDelegate overrides. | 130 // ChromeCleanerControllerDelegate overrides. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 133 // ChromeCleanerRunnerTestDelegate overrides. | 156 // ChromeCleanerRunnerTestDelegate overrides. |
| 134 | 157 |
| 135 base::Process LaunchTestProcess( | 158 base::Process LaunchTestProcess( |
| 136 const base::CommandLine& command_line, | 159 const base::CommandLine& command_line, |
| 137 const base::LaunchOptions& launch_options) override { | 160 const base::LaunchOptions& launch_options) override { |
| 138 command_line_ = command_line; | 161 command_line_ = command_line; |
| 139 // Return an invalid process. | 162 // Return an invalid process. |
| 140 return base::Process(); | 163 return base::Process(); |
| 141 } | 164 } |
| 142 | 165 |
| 166 void OnCleanerProcessDone( |
| 167 const ChromeCleanerRunner::ProcessStatus& process_status) override {} |
| 168 |
| 143 protected: | 169 protected: |
| 144 // We need this because we need UI and IO threads during tests. The thread | 170 // 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 | 171 // bundle should be the first member of the class so that it will be destroyed |
| 146 // last. | 172 // last. |
| 147 content::TestBrowserThreadBundle thread_bundle_; | 173 content::TestBrowserThreadBundle thread_bundle_; |
| 148 base::test::ScopedFeatureList scoped_feature_list_; | 174 base::test::ScopedFeatureList scoped_feature_list_; |
| 149 | 175 |
| 150 bool metrics_enabled_; | 176 bool metrics_enabled_; |
| 151 bool scout_enabled_; | 177 bool scout_enabled_; |
| 152 base::CommandLine command_line_; | 178 base::CommandLine command_line_; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 252 |
| 227 void SetUp() override { | 253 void SetUp() override { |
| 228 std::tie(process_status_, crash_point_, uws_found_status_, user_response_) = | 254 std::tie(process_status_, crash_point_, uws_found_status_, user_response_) = |
| 229 GetParam(); | 255 GetParam(); |
| 230 | 256 |
| 231 cleaner_process_options_.SetDoFindUws(uws_found_status_ != | 257 cleaner_process_options_.SetDoFindUws(uws_found_status_ != |
| 232 UwsFoundStatus::kNoUwsFound); | 258 UwsFoundStatus::kNoUwsFound); |
| 233 cleaner_process_options_.set_reboot_required( | 259 cleaner_process_options_.set_reboot_required( |
| 234 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired); | 260 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired); |
| 235 cleaner_process_options_.set_crash_point(crash_point_); | 261 cleaner_process_options_.set_crash_point(crash_point_); |
| 262 cleaner_process_options_.set_expected_user_response( |
| 263 uws_found_status_ == UwsFoundStatus::kNoUwsFound |
| 264 ? PromptAcceptance::DENIED |
| 265 : UserResponseToPromptAcceptance(user_response_)); |
| 236 | 266 |
| 267 ChromeCleanerController::ResetInstanceForTesting(); |
| 237 controller_ = ChromeCleanerController::GetInstance(); | 268 controller_ = ChromeCleanerController::GetInstance(); |
| 238 ASSERT_TRUE(controller_); | 269 ASSERT_TRUE(controller_); |
| 239 | 270 |
| 240 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); | 271 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); |
| 241 SetChromeCleanerRunnerTestDelegateForTesting(this); | 272 SetChromeCleanerRunnerTestDelegateForTesting(this); |
| 242 controller_->SetDelegateForTesting(this); | 273 controller_->SetDelegateForTesting(this); |
| 243 } | 274 } |
| 244 | 275 |
| 245 void TearDown() override { | 276 void TearDown() override { |
| 246 if (controller_->state() == State::kRebootRequired) | |
| 247 controller_->DismissRebootForTesting(); | |
| 248 | |
| 249 controller_->SetDelegateForTesting(nullptr); | 277 controller_->SetDelegateForTesting(nullptr); |
| 250 SetChromeCleanerRunnerTestDelegateForTesting(nullptr); | 278 SetChromeCleanerRunnerTestDelegateForTesting(nullptr); |
| 251 } | 279 } |
| 252 | 280 |
| 253 // ChromeCleanerControllerDelegate overrides. | 281 // ChromeCleanerControllerDelegate overrides. |
| 254 | 282 |
| 255 void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override { | 283 void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override { |
| 256 base::ThreadTaskRunnerHandle::Get()->PostTask( | 284 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 257 FROM_HERE, | 285 FROM_HERE, |
| 258 base::BindOnce( | 286 base::BindOnce( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 &test_process_command_line); | 332 &test_process_command_line); |
| 305 | 333 |
| 306 base::SpawnChildResult result = base::SpawnMultiProcessTestChild( | 334 base::SpawnChildResult result = base::SpawnMultiProcessTestChild( |
| 307 "MockChromeCleanerProcessMain", test_process_command_line, | 335 "MockChromeCleanerProcessMain", test_process_command_line, |
| 308 launch_options); | 336 launch_options); |
| 309 | 337 |
| 310 EXPECT_TRUE(result.process.IsValid()); | 338 EXPECT_TRUE(result.process.IsValid()); |
| 311 return std::move(result.process); | 339 return std::move(result.process); |
| 312 } | 340 } |
| 313 | 341 |
| 342 void OnCleanerProcessDone( |
| 343 const ChromeCleanerRunner::ProcessStatus& process_status) override { |
| 344 cleaner_process_status_ = process_status; |
| 345 } |
| 346 |
| 314 ChromeCleanerController::State ExpectedFinalState() { | 347 ChromeCleanerController::State ExpectedFinalState() { |
| 315 if (process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | 348 if (process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && |
| 316 crash_point_ == CrashPoint::kNone && | 349 crash_point_ == CrashPoint::kNone && |
| 317 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired && | 350 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired && |
| 318 user_response_ == UserResponse::kAccepted) { | 351 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 352 user_response_ == UserResponse::kAcceptedWithoutLogs)) { |
| 319 return State::kRebootRequired; | 353 return State::kRebootRequired; |
| 320 } | 354 } |
| 321 return State::kIdle; | 355 return State::kIdle; |
| 322 } | 356 } |
| 323 | 357 |
| 324 bool ExpectedOnIdleCalled() { return ExpectedFinalState() == State::kIdle; } | 358 bool ExpectedOnIdleCalled() { return ExpectedFinalState() == State::kIdle; } |
| 325 | 359 |
| 326 bool ExpectedOnInfectedCalled() { | 360 bool ExpectedOnInfectedCalled() { |
| 327 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | 361 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && |
| 328 crash_point_ != CrashPoint::kOnStartup && | 362 crash_point_ != CrashPoint::kOnStartup && |
| 329 crash_point_ != CrashPoint::kAfterConnection && | 363 crash_point_ != CrashPoint::kAfterConnection && |
| 330 uws_found_status_ != UwsFoundStatus::kNoUwsFound; | 364 uws_found_status_ != UwsFoundStatus::kNoUwsFound; |
| 331 } | 365 } |
| 332 | 366 |
| 333 bool ExpectedOnCleaningCalled() { | 367 bool ExpectedOnCleaningCalled() { |
| 334 return ExpectedOnInfectedCalled() && | 368 return ExpectedOnInfectedCalled() && |
| 335 crash_point_ != CrashPoint::kAfterRequestSent && | 369 crash_point_ != CrashPoint::kAfterRequestSent && |
| 336 user_response_ == UserResponse::kAccepted; | 370 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 371 user_response_ == UserResponse::kAcceptedWithoutLogs); |
| 337 } | 372 } |
| 338 | 373 |
| 339 bool ExpectedOnRebootRequiredCalled() { | 374 bool ExpectedOnRebootRequiredCalled() { |
| 340 return ExpectedFinalState() == State::kRebootRequired; | 375 return ExpectedFinalState() == State::kRebootRequired; |
| 341 } | 376 } |
| 342 | 377 |
| 343 bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); } | 378 bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); } |
| 344 | 379 |
| 345 bool ExpectedToTagProfile() { | 380 bool ExpectedToTagProfile() { |
| 346 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | 381 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && |
| 347 (crash_point_ == CrashPoint::kNone || | 382 (crash_point_ == CrashPoint::kNone || |
| 348 crash_point_ == CrashPoint::kAfterResponseReceived) && | 383 crash_point_ == CrashPoint::kAfterResponseReceived) && |
| 349 (uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired || | 384 (uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired || |
| 350 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired) && | 385 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired) && |
| 351 user_response_ == UserResponse::kAccepted; | 386 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 387 user_response_ == UserResponse::kAcceptedWithoutLogs); |
| 352 } | 388 } |
| 353 | 389 |
| 354 bool ExpectedToResetSettings() { | 390 bool ExpectedToResetSettings() { |
| 355 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | 391 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && |
| 356 crash_point_ == CrashPoint::kNone && | 392 crash_point_ == CrashPoint::kNone && |
| 357 uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired && | 393 uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired && |
| 358 user_response_ == UserResponse::kAccepted; | 394 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 395 user_response_ == UserResponse::kAcceptedWithoutLogs); |
| 359 } | 396 } |
| 360 | 397 |
| 361 ChromeCleanerController::IdleReason ExpectedIdleReason() { | 398 ChromeCleanerController::IdleReason ExpectedIdleReason() { |
| 362 EXPECT_EQ(ExpectedFinalState(), State::kIdle); | 399 EXPECT_EQ(ExpectedFinalState(), State::kIdle); |
| 363 | 400 |
| 364 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess || | 401 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess || |
| 365 crash_point_ == CrashPoint::kOnStartup || | 402 crash_point_ == CrashPoint::kOnStartup || |
| 366 crash_point_ == CrashPoint::kAfterConnection) { | 403 crash_point_ == CrashPoint::kAfterConnection) { |
| 367 return IdleReason::kScanningFailed; | 404 return IdleReason::kScanningFailed; |
| 368 } | 405 } |
| 369 | 406 |
| 370 if (uws_found_status_ == UwsFoundStatus::kNoUwsFound) | 407 if (uws_found_status_ == UwsFoundStatus::kNoUwsFound) |
| 371 return IdleReason::kScanningFoundNothing; | 408 return IdleReason::kScanningFoundNothing; |
| 372 | 409 |
| 373 if (ExpectedOnInfectedCalled() && | 410 if (ExpectedOnInfectedCalled() && |
| 374 (user_response_ == UserResponse::kDenied || | 411 (user_response_ == UserResponse::kDenied || |
| 375 user_response_ == UserResponse::kDismissed)) { | 412 user_response_ == UserResponse::kDismissed)) { |
| 376 return IdleReason::kUserDeclinedCleanup; | 413 return IdleReason::kUserDeclinedCleanup; |
| 377 } | 414 } |
| 378 | 415 |
| 379 if (ExpectedOnInfectedCalled() && | 416 if (ExpectedOnInfectedCalled() && |
| 380 user_response_ == UserResponse::kAccepted && | 417 (user_response_ == UserResponse::kAcceptedWithLogs || |
| 418 user_response_ == UserResponse::kAcceptedWithoutLogs) && |
| 381 crash_point_ == CrashPoint::kAfterResponseReceived) { | 419 crash_point_ == CrashPoint::kAfterResponseReceived) { |
| 382 return IdleReason::kCleaningFailed; | 420 return IdleReason::kCleaningFailed; |
| 383 } | 421 } |
| 384 | 422 |
| 385 return IdleReason::kCleaningSucceeded; | 423 return IdleReason::kCleaningSucceeded; |
| 386 } | 424 } |
| 387 | 425 |
| 388 protected: | 426 protected: |
| 389 // We need this because we need UI and IO threads during tests. The thread | 427 // 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 | 428 // bundle should be the first member of the class so that it will be destroyed |
| 391 // last. | 429 // last. |
| 392 content::TestBrowserThreadBundle thread_bundle_; | 430 content::TestBrowserThreadBundle thread_bundle_; |
| 393 base::test::ScopedFeatureList scoped_feature_list_; | 431 base::test::ScopedFeatureList scoped_feature_list_; |
| 394 | 432 |
| 395 CleanerProcessStatus process_status_; | 433 CleanerProcessStatus process_status_; |
| 396 MockChromeCleanerProcess::CrashPoint crash_point_; | 434 MockChromeCleanerProcess::CrashPoint crash_point_; |
| 397 UwsFoundStatus uws_found_status_; | 435 UwsFoundStatus uws_found_status_; |
| 398 ChromeCleanerController::UserResponse user_response_; | 436 ChromeCleanerController::UserResponse user_response_; |
| 399 | 437 |
| 400 MockChromeCleanerProcess::Options cleaner_process_options_; | 438 MockChromeCleanerProcess::Options cleaner_process_options_; |
| 401 | 439 |
| 402 StrictMock<MockChromeCleanerControllerObserver> mock_observer_; | 440 StrictMock<MockChromeCleanerControllerObserver> mock_observer_; |
| 403 ChromeCleanerController* controller_; | 441 ChromeCleanerController* controller_; |
| 442 ChromeCleanerRunner::ProcessStatus cleaner_process_status_; |
| 404 | 443 |
| 405 std::vector<Profile*> profiles_tagged_; | 444 std::vector<Profile*> profiles_tagged_; |
| 406 std::vector<Profile*> profiles_to_reset_if_tagged_; | 445 std::vector<Profile*> profiles_to_reset_if_tagged_; |
| 407 }; | 446 }; |
| 408 | 447 |
| 409 MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) { | 448 MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) { |
| 410 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 449 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 411 MockChromeCleanerProcess::Options options; | 450 MockChromeCleanerProcess::Options options; |
| 412 EXPECT_TRUE(MockChromeCleanerProcess::Options::FromCommandLine(*command_line, | 451 EXPECT_TRUE(MockChromeCleanerProcess::Options::FromCommandLine(*command_line, |
| 413 &options)); | 452 &options)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); | 501 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); |
| 463 } | 502 } |
| 464 | 503 |
| 465 if (ExpectedOnInfectedCalled()) { | 504 if (ExpectedOnInfectedCalled()) { |
| 466 EXPECT_CALL(mock_observer_, OnInfected(_)) | 505 EXPECT_CALL(mock_observer_, OnInfected(_)) |
| 467 .WillOnce(DoAll(SaveArg<0>(&files_to_delete_on_infected), | 506 .WillOnce(DoAll(SaveArg<0>(&files_to_delete_on_infected), |
| 468 InvokeWithoutArgs([this, profile1]() { | 507 InvokeWithoutArgs([this, profile1]() { |
| 469 controller_->ReplyWithUserResponse(profile1, | 508 controller_->ReplyWithUserResponse(profile1, |
| 470 user_response_); | 509 user_response_); |
| 471 }))); | 510 }))); |
| 511 // Since logs upload is enabled by default, OnLogsEnabledChanged() will be |
| 512 // called only if the user response is kAcceptedWithoutLogs. |
| 513 if (user_response_ == UserResponse::kAcceptedWithoutLogs) |
| 514 EXPECT_CALL(mock_observer_, OnLogsEnabledChanged(false)); |
| 472 } | 515 } |
| 473 | 516 |
| 474 if (ExpectedOnCleaningCalled()) { | 517 if (ExpectedOnCleaningCalled()) { |
| 475 EXPECT_CALL(mock_observer_, OnCleaning(_)) | 518 EXPECT_CALL(mock_observer_, OnCleaning(_)) |
| 476 .WillOnce(SaveArg<0>(&files_to_delete_on_cleaning)); | 519 .WillOnce(SaveArg<0>(&files_to_delete_on_cleaning)); |
| 477 } | 520 } |
| 478 | 521 |
| 479 if (ExpectedOnRebootRequiredCalled()) { | 522 if (ExpectedOnRebootRequiredCalled()) { |
| 480 EXPECT_CALL(mock_observer_, OnRebootRequired()) | 523 EXPECT_CALL(mock_observer_, OnRebootRequired()) |
| 481 .WillOnce( | 524 .WillOnce( |
| 482 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); | 525 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); |
| 483 } | 526 } |
| 484 | 527 |
| 485 // Assert here that we expect at least one of OnIdle or OnRebootRequired to be | 528 // 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 | 529 // called, since otherwise, the test is set up incorrectly and is expected to |
| 487 // never stop. | 530 // never stop. |
| 488 ASSERT_TRUE(ExpectedOnIdleCalled() || ExpectedOnRebootRequiredCalled()); | 531 ASSERT_TRUE(ExpectedOnIdleCalled() || ExpectedOnRebootRequiredCalled()); |
| 489 run_loop.Run(); | 532 run_loop.Run(); |
| 533 // Also ensure that we wait until the mock cleaner process has finished and |
| 534 // that all tasks that posted by ChromeCleanerRunner have run. |
| 535 content::RunAllBlockingPoolTasksUntilIdle(); |
| 490 | 536 |
| 537 EXPECT_NE(cleaner_process_status_.exit_code, |
| 538 MockChromeCleanerProcess::kInternalTestFailureExitCode); |
| 491 EXPECT_EQ(controller_->state(), ExpectedFinalState()); | 539 EXPECT_EQ(controller_->state(), ExpectedFinalState()); |
| 492 EXPECT_EQ(!files_to_delete_on_infected.empty(), ExpectedUwsFound()); | 540 EXPECT_EQ(!files_to_delete_on_infected.empty(), ExpectedUwsFound()); |
| 493 EXPECT_EQ(!files_to_delete_on_cleaning.empty(), | 541 EXPECT_EQ(!files_to_delete_on_cleaning.empty(), |
| 494 ExpectedUwsFound() && ExpectedOnCleaningCalled()); | 542 ExpectedUwsFound() && ExpectedOnCleaningCalled()); |
| 495 if (!files_to_delete_on_infected.empty() && | 543 if (!files_to_delete_on_infected.empty() && |
| 496 !files_to_delete_on_cleaning.empty()) { | 544 !files_to_delete_on_cleaning.empty()) { |
| 497 EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning); | 545 EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning); |
| 498 } | 546 } |
| 499 | 547 |
| 500 std::vector<Profile*> expected_tagged; | 548 std::vector<Profile*> expected_tagged; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 522 Values(CrashPoint::kNone, | 570 Values(CrashPoint::kNone, |
| 523 CrashPoint::kOnStartup, | 571 CrashPoint::kOnStartup, |
| 524 CrashPoint::kAfterConnection, | 572 CrashPoint::kAfterConnection, |
| 525 // CrashPoint::kAfterRequestSent is not used because we | 573 // CrashPoint::kAfterRequestSent is not used because we |
| 526 // cannot ensure the order between the Mojo request being | 574 // cannot ensure the order between the Mojo request being |
| 527 // received by Chrome and the connection being lost. | 575 // received by Chrome and the connection being lost. |
| 528 CrashPoint::kAfterResponseReceived), | 576 CrashPoint::kAfterResponseReceived), |
| 529 Values(UwsFoundStatus::kNoUwsFound, | 577 Values(UwsFoundStatus::kNoUwsFound, |
| 530 UwsFoundStatus::kUwsFoundRebootRequired, | 578 UwsFoundStatus::kUwsFoundRebootRequired, |
| 531 UwsFoundStatus::kUwsFoundNoRebootRequired), | 579 UwsFoundStatus::kUwsFoundNoRebootRequired), |
| 532 Values(UserResponse::kAccepted, | 580 Values(UserResponse::kAcceptedWithLogs, |
| 581 UserResponse::kAcceptedWithoutLogs, |
| 533 UserResponse::kDenied, | 582 UserResponse::kDenied, |
| 534 UserResponse::kDismissed))); | 583 UserResponse::kDismissed))); |
| 535 | 584 |
| 536 } // namespace | 585 } // namespace |
| 537 } // namespace safe_browsing | 586 } // namespace safe_browsing |
| OLD | NEW |