| 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..818587e15455c467d6a4fce0937caf610abbb86f 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"
|
| @@ -33,6 +38,7 @@ using ::testing::DoAll;
|
| using ::testing::InvokeWithoutArgs;
|
| using ::testing::SaveArg;
|
| using ::testing::StrictMock;
|
| +using ::testing::UnorderedElementsAreArray;
|
| using ::testing::Values;
|
| using ::testing::_;
|
| using CrashPoint = MockChromeCleanerProcess::CrashPoint;
|
| @@ -112,6 +118,18 @@ class ChromeCleanerControllerSimpleTest
|
|
|
| bool IsMetricsAndCrashReportingEnabled() override { return metrics_enabled_; }
|
|
|
| + void InvokeTagProfileForResetting(Profile* profile) override {
|
| + // This function should never be called by these tests.
|
| + EXPECT_TRUE(false);
|
| + }
|
| +
|
| + void InvokeResetPostCleanupSettingsIfTagged(
|
| + std::vector<Profile*> profiles,
|
| + base::OnceClosure continuation) override {
|
| + // This function should never be called by these tests.
|
| + EXPECT_TRUE(false);
|
| + }
|
| +
|
| // ChromeCleanerRunnerTestDelegate overrides.
|
|
|
| base::Process LaunchTestProcess(
|
| @@ -203,9 +221,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();
|
|
|
| @@ -229,8 +251,11 @@ class ChromeCleanerControllerTest
|
|
|
| controller_->SetDelegateForTesting(nullptr);
|
| SetChromeCleanerRunnerTestDelegateForTesting(nullptr);
|
| + profile_manager_.DeleteAllTestingProfiles();
|
| }
|
|
|
| + TestingProfileManager* profile_manager() { return &profile_manager_; }
|
| +
|
| // ChromeCleanerControllerDelegate overrides.
|
|
|
| void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override {
|
| @@ -255,6 +280,18 @@ class ChromeCleanerControllerTest
|
| return false;
|
| }
|
|
|
| + void InvokeTagProfileForResetting(Profile* profile) override {
|
| + profiles_tagged_.push_back(profile);
|
| + }
|
| +
|
| + void InvokeResetPostCleanupSettingsIfTagged(
|
| + std::vector<Profile*> profiles,
|
| + base::OnceClosure continuation) override {
|
| + for (Profile* profile : profiles)
|
| + profiles_to_reset_if_tagged_.push_back(profile);
|
| + std::move(continuation).Run();
|
| + }
|
| +
|
| // ChromeCleanerRunnerTestDelegate overrides.
|
|
|
| base::Process LaunchTestProcess(
|
| @@ -312,6 +349,22 @@ class ChromeCleanerControllerTest
|
|
|
| bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); }
|
|
|
| + bool ExpectedToTagProfile() {
|
| + 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 +408,10 @@ class ChromeCleanerControllerTest
|
|
|
| StrictMock<MockChromeCleanerControllerObserver> mock_observer_;
|
| ChromeCleanerController* controller_;
|
| +
|
| + TestingProfileManager profile_manager_;
|
| + std::vector<Profile*> profiles_tagged_;
|
| + std::vector<Profile*> profiles_to_reset_if_tagged_;
|
| };
|
|
|
| MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) {
|
| @@ -379,6 +436,14 @@ MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) {
|
| }
|
|
|
| TEST_P(ChromeCleanerControllerTest, WithMockCleanerProcess) {
|
| + Profile* profile1 = profile_manager()->CreateTestingProfile("Test 1");
|
| + ASSERT_TRUE(profile1);
|
| + Profile* profile2 = profile_manager()->CreateTestingProfile("Test 2");
|
| + ASSERT_TRUE(profile2);
|
| + const int num_profiles =
|
| + profile_manager()->profile_manager()->GetNumberOfProfiles();
|
| + ASSERT_EQ(2, num_profiles);
|
| +
|
| EXPECT_CALL(mock_observer_, OnIdle(_)).Times(1);
|
| controller_->AddObserver(&mock_observer_);
|
| EXPECT_EQ(controller_->state(), State::kIdle);
|
| @@ -401,8 +466,9 @@ TEST_P(ChromeCleanerControllerTest, WithMockCleanerProcess) {
|
| if (ExpectedOnInfectedCalled()) {
|
| EXPECT_CALL(mock_observer_, OnInfected(_))
|
| .WillOnce(DoAll(SaveArg<0>(&files_to_delete_on_infected),
|
| - InvokeWithoutArgs([this]() {
|
| - controller_->ReplyWithUserResponse(user_response_);
|
| + InvokeWithoutArgs([this, profile1]() {
|
| + controller_->ReplyWithUserResponse(profile1,
|
| + user_response_);
|
| })));
|
| }
|
|
|
| @@ -432,6 +498,19 @@ TEST_P(ChromeCleanerControllerTest, WithMockCleanerProcess) {
|
| EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning);
|
| }
|
|
|
| + std::vector<Profile*> expected_tagged;
|
| + if (ExpectedToTagProfile())
|
| + expected_tagged.push_back(profile1);
|
| + EXPECT_THAT(expected_tagged, UnorderedElementsAreArray(profiles_tagged_));
|
| +
|
| + std::vector<Profile*> expected_reset_if_tagged;
|
| + if (ExpectedToResetSettings()) {
|
| + expected_reset_if_tagged.push_back(profile1);
|
| + expected_reset_if_tagged.push_back(profile2);
|
| + }
|
| + EXPECT_THAT(expected_reset_if_tagged,
|
| + UnorderedElementsAreArray(profiles_to_reset_if_tagged_));
|
| +
|
| controller_->RemoveObserver(&mock_observer_);
|
| }
|
|
|
|
|