| Index: chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win_unittest.cc
|
| diff --git a/chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win_unittest.cc b/chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win_unittest.cc
|
| index fd9a195eaff81d1e01c969919d63dfb481e6d6bc..bfc0895b4eaa6b873a06c1180b4e934ef13fa7aa 100644
|
| --- a/chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win_unittest.cc
|
| +++ b/chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win_unittest.cc
|
| @@ -15,9 +15,14 @@
|
| #include "base/test/scoped_feature_list.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_process_win.h"
|
| #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h"
|
| #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h"
|
| +#include "chrome/test/base/testing_browser_process.h"
|
| +#include "chrome/test/base/testing_profile.h"
|
| +#include "chrome/test/base/testing_profile_manager.h"
|
| #include "components/chrome_cleaner/public/constants/constants.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/test/test_browser_thread_bundle.h"
|
| @@ -112,6 +117,18 @@ class ChromeCleanerControllerSimpleTest
|
|
|
| bool IsMetricsAndCrashReportingEnabled() override { return metrics_enabled_; }
|
|
|
| + void InvokeTagProfileForResetting(Profile* profile) override {
|
| + // This function should never be called by these tests.
|
| + ASSERT_TRUE(false);
|
| + }
|
| +
|
| + void InvokeResetPostCleanupSettingsIfTagged(
|
| + std::vector<Profile*> profiles,
|
| + base::OnceClosure continuation) override {
|
| + // This function should never be called by these tests.
|
| + ASSERT_TRUE(false);
|
| + }
|
| +
|
| // ChromeCleanerRunnerTestDelegate overrides.
|
|
|
| base::Process LaunchTestProcess(
|
| @@ -203,9 +220,13 @@ class ChromeCleanerControllerTest
|
| public ChromeCleanerRunnerTestDelegate,
|
| public ChromeCleanerControllerDelegate {
|
| public:
|
| + ChromeCleanerControllerTest()
|
| + : profile_manager_(TestingBrowserProcess::GetGlobal()) {}
|
| ~ChromeCleanerControllerTest() override {}
|
|
|
| void SetUp() override {
|
| + ASSERT_TRUE(profile_manager_.SetUp());
|
| +
|
| std::tie(process_status_, crash_point_, uws_found_status_, user_response_) =
|
| GetParam();
|
|
|
| @@ -231,6 +252,8 @@ class ChromeCleanerControllerTest
|
| SetChromeCleanerRunnerTestDelegateForTesting(nullptr);
|
| }
|
|
|
| + TestingProfileManager* profile_manager() { return &profile_manager_; }
|
| +
|
| // ChromeCleanerControllerDelegate overrides.
|
|
|
| void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override {
|
| @@ -255,6 +278,16 @@ class ChromeCleanerControllerTest
|
| return false;
|
| }
|
|
|
| + void InvokeTagProfileForResetting(Profile* profile) override {
|
| + ++tagged_profiles_;
|
| + }
|
| +
|
| + void InvokeResetPostCleanupSettingsIfTagged(
|
| + std::vector<Profile*> profiles,
|
| + base::OnceClosure continuation) override {
|
| + profiles_reset_ += profiles.size();
|
| + }
|
| +
|
| // ChromeCleanerRunnerTestDelegate overrides.
|
|
|
| base::Process LaunchTestProcess(
|
| @@ -312,6 +345,22 @@ class ChromeCleanerControllerTest
|
|
|
| bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); }
|
|
|
| + bool ExpectedToTagProfiles() {
|
| + return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess &&
|
| + (crash_point_ == CrashPoint::kNone ||
|
| + crash_point_ == CrashPoint::kAfterResponseReceived) &&
|
| + (uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired ||
|
| + uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired) &&
|
| + user_response_ == UserResponse::kAccepted;
|
| + }
|
| +
|
| + bool ExpectedToResetSettings() {
|
| + return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess &&
|
| + crash_point_ == CrashPoint::kNone &&
|
| + uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired &&
|
| + user_response_ == UserResponse::kAccepted;
|
| + }
|
| +
|
| ChromeCleanerController::IdleReason ExpectedIdleReason() {
|
| EXPECT_EQ(ExpectedFinalState(), State::kIdle);
|
|
|
| @@ -355,6 +404,10 @@ class ChromeCleanerControllerTest
|
|
|
| StrictMock<MockChromeCleanerControllerObserver> mock_observer_;
|
| ChromeCleanerController* controller_;
|
| +
|
| + TestingProfileManager profile_manager_;
|
| + int tagged_profiles_ = 0;
|
| + int profiles_reset_ = 0;
|
| };
|
|
|
| MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) {
|
| @@ -379,6 +432,13 @@ MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) {
|
| }
|
|
|
| TEST_P(ChromeCleanerControllerTest, WithMockCleanerProcess) {
|
| + ASSERT_TRUE(profile_manager()->CreateTestingProfile("Test 1"));
|
| + ASSERT_TRUE(profile_manager()->CreateTestingProfile("Test 2"));
|
| + ASSERT_TRUE(profile_manager()->CreateTestingProfile("Test 3"));
|
| + const int num_profiles =
|
| + profile_manager()->profile_manager()->GetNumberOfProfiles();
|
| + ASSERT_EQ(3, num_profiles);
|
| +
|
| EXPECT_CALL(mock_observer_, OnIdle(_)).Times(1);
|
| controller_->AddObserver(&mock_observer_);
|
| EXPECT_EQ(controller_->state(), State::kIdle);
|
| @@ -432,6 +492,9 @@ TEST_P(ChromeCleanerControllerTest, WithMockCleanerProcess) {
|
| EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning);
|
| }
|
|
|
| + EXPECT_EQ(ExpectedToTagProfiles() ? num_profiles : 0, tagged_profiles_);
|
| + EXPECT_EQ(ExpectedToResetSettings() ? num_profiles : 0, profiles_reset_);
|
| +
|
| controller_->RemoveObserver(&mock_observer_);
|
| }
|
|
|
|
|