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/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/task_scheduler/post_task.h" | 13 #include "base/task_scheduler/post_task.h" |
| 14 #include "base/test/multiprocess_test.h" | 14 #include "base/test/multiprocess_test.h" |
| 15 #include "base/test/scoped_feature_list.h" | 15 #include "base/test/scoped_feature_list.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 17 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 19 #include "chrome/browser/profiles/profile_manager.h" | |
| 18 #include "chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_proces s_win.h" | 20 #include "chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_proces s_win.h" |
| 19 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h" | 21 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h" |
| 20 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" | 22 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" |
| 23 #include "chrome/test/base/testing_browser_process.h" | |
| 24 #include "chrome/test/base/testing_profile.h" | |
| 25 #include "chrome/test/base/testing_profile_manager.h" | |
| 21 #include "components/chrome_cleaner/public/constants/constants.h" | 26 #include "components/chrome_cleaner/public/constants/constants.h" |
| 22 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "testing/multiprocess_func_list.h" | 31 #include "testing/multiprocess_func_list.h" |
| 27 | 32 |
| 28 namespace safe_browsing { | 33 namespace safe_browsing { |
| 29 namespace { | 34 namespace { |
| 30 | 35 |
| 31 using ::testing::Combine; | 36 using ::testing::Combine; |
| 32 using ::testing::DoAll; | 37 using ::testing::DoAll; |
| 33 using ::testing::InvokeWithoutArgs; | 38 using ::testing::InvokeWithoutArgs; |
| 34 using ::testing::SaveArg; | 39 using ::testing::SaveArg; |
| 35 using ::testing::StrictMock; | 40 using ::testing::StrictMock; |
| 41 using ::testing::UnorderedElementsAreArray; | |
| 36 using ::testing::Values; | 42 using ::testing::Values; |
| 37 using ::testing::_; | 43 using ::testing::_; |
| 38 using CrashPoint = MockChromeCleanerProcess::CrashPoint; | 44 using CrashPoint = MockChromeCleanerProcess::CrashPoint; |
| 39 using IdleReason = ChromeCleanerController::IdleReason; | 45 using IdleReason = ChromeCleanerController::IdleReason; |
| 40 using State = ChromeCleanerController::State; | 46 using State = ChromeCleanerController::State; |
| 41 using UserResponse = ChromeCleanerController::UserResponse; | 47 using UserResponse = ChromeCleanerController::UserResponse; |
| 42 | 48 |
| 43 class MockChromeCleanerControllerObserver | 49 class MockChromeCleanerControllerObserver |
| 44 : public ChromeCleanerController::Observer { | 50 : public ChromeCleanerController::Observer { |
| 45 public: | 51 public: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 std::move(fetched_callback) | 111 std::move(fetched_callback) |
| 106 .Run(base::FilePath(FILE_PATH_LITERAL("chrome_cleaner.exe"))); | 112 .Run(base::FilePath(FILE_PATH_LITERAL("chrome_cleaner.exe"))); |
| 107 } | 113 } |
| 108 | 114 |
| 109 bool SafeBrowsingExtendedReportingScoutEnabled() override { | 115 bool SafeBrowsingExtendedReportingScoutEnabled() override { |
| 110 return scout_enabled_; | 116 return scout_enabled_; |
| 111 } | 117 } |
| 112 | 118 |
| 113 bool IsMetricsAndCrashReportingEnabled() override { return metrics_enabled_; } | 119 bool IsMetricsAndCrashReportingEnabled() override { return metrics_enabled_; } |
| 114 | 120 |
| 121 void InvokeTagProfileForResetting(Profile* profile) override { | |
| 122 // This function should never be called by these tests. | |
| 123 ASSERT_TRUE(false); | |
|
alito
2017/06/07 19:54:03
Since failed asserts in helper functions do not pr
ftirelo
2017/06/08 21:54:11
Done.
| |
| 124 } | |
| 125 | |
| 126 void InvokeResetPostCleanupSettingsIfTagged( | |
| 127 std::vector<Profile*> profiles, | |
| 128 base::OnceClosure continuation) override { | |
| 129 // This function should never be called by these tests. | |
| 130 ASSERT_TRUE(false); | |
| 131 } | |
| 132 | |
| 115 // ChromeCleanerRunnerTestDelegate overrides. | 133 // ChromeCleanerRunnerTestDelegate overrides. |
| 116 | 134 |
| 117 base::Process LaunchTestProcess( | 135 base::Process LaunchTestProcess( |
| 118 const base::CommandLine& command_line, | 136 const base::CommandLine& command_line, |
| 119 const base::LaunchOptions& launch_options) override { | 137 const base::LaunchOptions& launch_options) override { |
| 120 command_line_ = command_line; | 138 command_line_ = command_line; |
| 121 // Return an invalid process. | 139 // Return an invalid process. |
| 122 return base::Process(); | 140 return base::Process(); |
| 123 } | 141 } |
| 124 | 142 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 // configurations and mocks the user's response. | 214 // configurations and mocks the user's response. |
| 197 class ChromeCleanerControllerTest | 215 class ChromeCleanerControllerTest |
| 198 : public testing::TestWithParam< | 216 : public testing::TestWithParam< |
| 199 std::tuple<CleanerProcessStatus, | 217 std::tuple<CleanerProcessStatus, |
| 200 MockChromeCleanerProcess::CrashPoint, | 218 MockChromeCleanerProcess::CrashPoint, |
| 201 UwsFoundStatus, | 219 UwsFoundStatus, |
| 202 ChromeCleanerController::UserResponse>>, | 220 ChromeCleanerController::UserResponse>>, |
| 203 public ChromeCleanerRunnerTestDelegate, | 221 public ChromeCleanerRunnerTestDelegate, |
| 204 public ChromeCleanerControllerDelegate { | 222 public ChromeCleanerControllerDelegate { |
| 205 public: | 223 public: |
| 224 ChromeCleanerControllerTest() | |
| 225 : profile_manager_(TestingBrowserProcess::GetGlobal()) {} | |
| 206 ~ChromeCleanerControllerTest() override {} | 226 ~ChromeCleanerControllerTest() override {} |
| 207 | 227 |
| 208 void SetUp() override { | 228 void SetUp() override { |
| 229 ASSERT_TRUE(profile_manager_.SetUp()); | |
| 230 | |
| 209 std::tie(process_status_, crash_point_, uws_found_status_, user_response_) = | 231 std::tie(process_status_, crash_point_, uws_found_status_, user_response_) = |
| 210 GetParam(); | 232 GetParam(); |
| 211 | 233 |
| 212 cleaner_process_options_.SetDoFindUws(uws_found_status_ != | 234 cleaner_process_options_.SetDoFindUws(uws_found_status_ != |
| 213 UwsFoundStatus::kNoUwsFound); | 235 UwsFoundStatus::kNoUwsFound); |
| 214 cleaner_process_options_.set_reboot_required( | 236 cleaner_process_options_.set_reboot_required( |
| 215 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired); | 237 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired); |
| 216 cleaner_process_options_.set_crash_point(crash_point_); | 238 cleaner_process_options_.set_crash_point(crash_point_); |
| 217 | 239 |
| 218 controller_ = ChromeCleanerController::GetInstance(); | 240 controller_ = ChromeCleanerController::GetInstance(); |
| 219 ASSERT_TRUE(controller_); | 241 ASSERT_TRUE(controller_); |
| 220 | 242 |
| 221 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); | 243 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); |
| 222 SetChromeCleanerRunnerTestDelegateForTesting(this); | 244 SetChromeCleanerRunnerTestDelegateForTesting(this); |
| 223 controller_->SetDelegateForTesting(this); | 245 controller_->SetDelegateForTesting(this); |
| 224 } | 246 } |
| 225 | 247 |
| 226 void TearDown() override { | 248 void TearDown() override { |
| 227 if (controller_->state() == State::kRebootRequired) | 249 if (controller_->state() == State::kRebootRequired) |
| 228 controller_->DismissRebootForTesting(); | 250 controller_->DismissRebootForTesting(); |
| 229 | 251 |
| 230 controller_->SetDelegateForTesting(nullptr); | 252 controller_->SetDelegateForTesting(nullptr); |
| 231 SetChromeCleanerRunnerTestDelegateForTesting(nullptr); | 253 SetChromeCleanerRunnerTestDelegateForTesting(nullptr); |
| 232 } | 254 } |
| 233 | 255 |
| 256 TestingProfileManager* profile_manager() { return &profile_manager_; } | |
| 257 | |
| 234 // ChromeCleanerControllerDelegate overrides. | 258 // ChromeCleanerControllerDelegate overrides. |
| 235 | 259 |
| 236 void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override { | 260 void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override { |
| 237 base::ThreadTaskRunnerHandle::Get()->PostTask( | 261 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 238 FROM_HERE, | 262 FROM_HERE, |
| 239 base::BindOnce( | 263 base::BindOnce( |
| 240 std::move(fetched_callback), | 264 std::move(fetched_callback), |
| 241 process_status_ != CleanerProcessStatus::kFetchFailure | 265 process_status_ != CleanerProcessStatus::kFetchFailure |
| 242 ? base::FilePath(FILE_PATH_LITERAL("chrome_cleaner.exe")) | 266 ? base::FilePath(FILE_PATH_LITERAL("chrome_cleaner.exe")) |
| 243 : base::FilePath())); | 267 : base::FilePath())); |
| 244 } | 268 } |
| 245 | 269 |
| 246 bool SafeBrowsingExtendedReportingScoutEnabled() override { | 270 bool SafeBrowsingExtendedReportingScoutEnabled() override { |
| 247 // Returning an arbitrary value since this is not being tested in this | 271 // Returning an arbitrary value since this is not being tested in this |
| 248 // fixture. | 272 // fixture. |
| 249 return false; | 273 return false; |
| 250 } | 274 } |
| 251 | 275 |
| 252 bool IsMetricsAndCrashReportingEnabled() override { | 276 bool IsMetricsAndCrashReportingEnabled() override { |
| 253 // Returning an arbitrary value since this is not being tested in this | 277 // Returning an arbitrary value since this is not being tested in this |
| 254 // fixture. | 278 // fixture. |
| 255 return false; | 279 return false; |
| 256 } | 280 } |
| 257 | 281 |
| 282 void InvokeTagProfileForResetting(Profile* profile) override { | |
| 283 profiles_tagged_.push_back(profile); | |
| 284 } | |
| 285 | |
| 286 void InvokeResetPostCleanupSettingsIfTagged( | |
| 287 std::vector<Profile*> profiles, | |
| 288 base::OnceClosure continuation) override { | |
| 289 for (Profile* profile : profiles) | |
| 290 profiles_to_reset_if_tagged_.push_back(profile); | |
| 291 std::move(continuation).Run(); | |
| 292 } | |
| 293 | |
| 258 // ChromeCleanerRunnerTestDelegate overrides. | 294 // ChromeCleanerRunnerTestDelegate overrides. |
| 259 | 295 |
| 260 base::Process LaunchTestProcess( | 296 base::Process LaunchTestProcess( |
| 261 const base::CommandLine& command_line, | 297 const base::CommandLine& command_line, |
| 262 const base::LaunchOptions& launch_options) override { | 298 const base::LaunchOptions& launch_options) override { |
| 263 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess) | 299 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess) |
| 264 return base::Process(); | 300 return base::Process(); |
| 265 | 301 |
| 266 // Add switches and program name that the test process needs for the multi | 302 // Add switches and program name that the test process needs for the multi |
| 267 // process tests. | 303 // process tests. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 crash_point_ != CrashPoint::kAfterRequestSent && | 341 crash_point_ != CrashPoint::kAfterRequestSent && |
| 306 user_response_ == UserResponse::kAccepted; | 342 user_response_ == UserResponse::kAccepted; |
| 307 } | 343 } |
| 308 | 344 |
| 309 bool ExpectedOnRebootRequiredCalled() { | 345 bool ExpectedOnRebootRequiredCalled() { |
| 310 return ExpectedFinalState() == State::kRebootRequired; | 346 return ExpectedFinalState() == State::kRebootRequired; |
| 311 } | 347 } |
| 312 | 348 |
| 313 bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); } | 349 bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); } |
| 314 | 350 |
| 351 bool ExpectedToTagProfile() { | |
| 352 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | |
| 353 (crash_point_ == CrashPoint::kNone || | |
| 354 crash_point_ == CrashPoint::kAfterResponseReceived) && | |
| 355 (uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired || | |
| 356 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired) && | |
| 357 user_response_ == UserResponse::kAccepted; | |
| 358 } | |
| 359 | |
| 360 bool ExpectedToResetSettings() { | |
| 361 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && | |
| 362 crash_point_ == CrashPoint::kNone && | |
| 363 uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired && | |
| 364 user_response_ == UserResponse::kAccepted; | |
| 365 } | |
| 366 | |
| 315 ChromeCleanerController::IdleReason ExpectedIdleReason() { | 367 ChromeCleanerController::IdleReason ExpectedIdleReason() { |
| 316 EXPECT_EQ(ExpectedFinalState(), State::kIdle); | 368 EXPECT_EQ(ExpectedFinalState(), State::kIdle); |
| 317 | 369 |
| 318 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess || | 370 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess || |
| 319 crash_point_ == CrashPoint::kOnStartup || | 371 crash_point_ == CrashPoint::kOnStartup || |
| 320 crash_point_ == CrashPoint::kAfterConnection) { | 372 crash_point_ == CrashPoint::kAfterConnection) { |
| 321 return IdleReason::kScanningFailed; | 373 return IdleReason::kScanningFailed; |
| 322 } | 374 } |
| 323 | 375 |
| 324 if (uws_found_status_ == UwsFoundStatus::kNoUwsFound) | 376 if (uws_found_status_ == UwsFoundStatus::kNoUwsFound) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 348 | 400 |
| 349 CleanerProcessStatus process_status_; | 401 CleanerProcessStatus process_status_; |
| 350 MockChromeCleanerProcess::CrashPoint crash_point_; | 402 MockChromeCleanerProcess::CrashPoint crash_point_; |
| 351 UwsFoundStatus uws_found_status_; | 403 UwsFoundStatus uws_found_status_; |
| 352 ChromeCleanerController::UserResponse user_response_; | 404 ChromeCleanerController::UserResponse user_response_; |
| 353 | 405 |
| 354 MockChromeCleanerProcess::Options cleaner_process_options_; | 406 MockChromeCleanerProcess::Options cleaner_process_options_; |
| 355 | 407 |
| 356 StrictMock<MockChromeCleanerControllerObserver> mock_observer_; | 408 StrictMock<MockChromeCleanerControllerObserver> mock_observer_; |
| 357 ChromeCleanerController* controller_; | 409 ChromeCleanerController* controller_; |
| 410 | |
| 411 TestingProfileManager profile_manager_; | |
| 412 std::vector<Profile*> profiles_tagged_; | |
| 413 std::vector<Profile*> profiles_to_reset_if_tagged_; | |
| 358 }; | 414 }; |
| 359 | 415 |
| 360 MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) { | 416 MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) { |
| 361 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 417 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 362 MockChromeCleanerProcess::Options options; | 418 MockChromeCleanerProcess::Options options; |
| 363 EXPECT_TRUE(MockChromeCleanerProcess::Options::FromCommandLine(*command_line, | 419 EXPECT_TRUE(MockChromeCleanerProcess::Options::FromCommandLine(*command_line, |
| 364 &options)); | 420 &options)); |
| 365 | 421 |
| 366 std::string chrome_mojo_pipe_token = command_line->GetSwitchValueASCII( | 422 std::string chrome_mojo_pipe_token = command_line->GetSwitchValueASCII( |
| 367 chrome_cleaner::kChromeMojoPipeTokenSwitch); | 423 chrome_cleaner::kChromeMojoPipeTokenSwitch); |
| 368 EXPECT_FALSE(chrome_mojo_pipe_token.empty()); | 424 EXPECT_FALSE(chrome_mojo_pipe_token.empty()); |
| 369 | 425 |
| 370 // Since failures in any of the above calls to EXPECT_*() do not actually fail | 426 // Since failures in any of the above calls to EXPECT_*() do not actually fail |
| 371 // the test, we need to ensure that we return an exit code to indicate test | 427 // the test, we need to ensure that we return an exit code to indicate test |
| 372 // failure in such cases. | 428 // failure in such cases. |
| 373 if (::testing::Test::HasFailure()) | 429 if (::testing::Test::HasFailure()) |
| 374 return MockChromeCleanerProcess::kInternalTestFailureExitCode; | 430 return MockChromeCleanerProcess::kInternalTestFailureExitCode; |
| 375 | 431 |
| 376 MockChromeCleanerProcess mock_cleaner_process(options, | 432 MockChromeCleanerProcess mock_cleaner_process(options, |
| 377 chrome_mojo_pipe_token); | 433 chrome_mojo_pipe_token); |
| 378 return mock_cleaner_process.Run(); | 434 return mock_cleaner_process.Run(); |
| 379 } | 435 } |
| 380 | 436 |
| 381 TEST_P(ChromeCleanerControllerTest, WithMockCleanerProcess) { | 437 TEST_P(ChromeCleanerControllerTest, WithMockCleanerProcess) { |
| 438 Profile* profile1 = profile_manager()->CreateTestingProfile("Test 1"); | |
| 439 ASSERT_TRUE(profile1); | |
| 440 Profile* profile2 = profile_manager()->CreateTestingProfile("Test 2"); | |
| 441 ASSERT_TRUE(profile2); | |
| 442 const int num_profiles = | |
| 443 profile_manager()->profile_manager()->GetNumberOfProfiles(); | |
| 444 ASSERT_EQ(2, num_profiles); | |
| 445 | |
| 382 EXPECT_CALL(mock_observer_, OnIdle(_)).Times(1); | 446 EXPECT_CALL(mock_observer_, OnIdle(_)).Times(1); |
| 383 controller_->AddObserver(&mock_observer_); | 447 controller_->AddObserver(&mock_observer_); |
| 384 EXPECT_EQ(controller_->state(), State::kIdle); | 448 EXPECT_EQ(controller_->state(), State::kIdle); |
| 385 | 449 |
| 386 EXPECT_CALL(mock_observer_, OnScanning()).Times(1); | 450 EXPECT_CALL(mock_observer_, OnScanning()).Times(1); |
| 387 controller_->Scan(GetInvocationWithPromptTrigger()); | 451 controller_->Scan(GetInvocationWithPromptTrigger()); |
| 388 EXPECT_EQ(controller_->state(), State::kScanning); | 452 EXPECT_EQ(controller_->state(), State::kScanning); |
| 389 | 453 |
| 390 base::RunLoop run_loop; | 454 base::RunLoop run_loop; |
| 391 | 455 |
| 392 std::set<base::FilePath> files_to_delete_on_infected; | 456 std::set<base::FilePath> files_to_delete_on_infected; |
| 393 std::set<base::FilePath> files_to_delete_on_cleaning; | 457 std::set<base::FilePath> files_to_delete_on_cleaning; |
| 394 | 458 |
| 395 if (ExpectedOnIdleCalled()) { | 459 if (ExpectedOnIdleCalled()) { |
| 396 EXPECT_CALL(mock_observer_, OnIdle(ExpectedIdleReason())) | 460 EXPECT_CALL(mock_observer_, OnIdle(ExpectedIdleReason())) |
| 397 .WillOnce( | 461 .WillOnce( |
| 398 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); | 462 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); |
| 399 } | 463 } |
| 400 | 464 |
| 401 if (ExpectedOnInfectedCalled()) { | 465 if (ExpectedOnInfectedCalled()) { |
| 402 EXPECT_CALL(mock_observer_, OnInfected(_)) | 466 EXPECT_CALL(mock_observer_, OnInfected(_)) |
| 403 .WillOnce(DoAll(SaveArg<0>(&files_to_delete_on_infected), | 467 .WillOnce(DoAll(SaveArg<0>(&files_to_delete_on_infected), |
| 404 InvokeWithoutArgs([this]() { | 468 InvokeWithoutArgs([this, profile1]() { |
| 405 controller_->ReplyWithUserResponse(user_response_); | 469 controller_->ReplyWithUserResponse(profile1, |
| 470 user_response_); | |
| 406 }))); | 471 }))); |
| 407 } | 472 } |
| 408 | 473 |
| 409 if (ExpectedOnCleaningCalled()) { | 474 if (ExpectedOnCleaningCalled()) { |
| 410 EXPECT_CALL(mock_observer_, OnCleaning(_)) | 475 EXPECT_CALL(mock_observer_, OnCleaning(_)) |
| 411 .WillOnce(SaveArg<0>(&files_to_delete_on_cleaning)); | 476 .WillOnce(SaveArg<0>(&files_to_delete_on_cleaning)); |
| 412 } | 477 } |
| 413 | 478 |
| 414 if (ExpectedOnRebootRequiredCalled()) { | 479 if (ExpectedOnRebootRequiredCalled()) { |
| 415 EXPECT_CALL(mock_observer_, OnRebootRequired()) | 480 EXPECT_CALL(mock_observer_, OnRebootRequired()) |
| 416 .WillOnce( | 481 .WillOnce( |
| 417 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); | 482 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); |
| 418 } | 483 } |
| 419 | 484 |
| 420 // Assert here that we expect at least one of OnIdle or OnRebootRequired to be | 485 // Assert here that we expect at least one of OnIdle or OnRebootRequired to be |
| 421 // called, since otherwise, the test is set up incorrectly and is expected to | 486 // called, since otherwise, the test is set up incorrectly and is expected to |
| 422 // never stop. | 487 // never stop. |
| 423 ASSERT_TRUE(ExpectedOnIdleCalled() || ExpectedOnRebootRequiredCalled()); | 488 ASSERT_TRUE(ExpectedOnIdleCalled() || ExpectedOnRebootRequiredCalled()); |
| 424 run_loop.Run(); | 489 run_loop.Run(); |
| 425 | 490 |
| 426 EXPECT_EQ(controller_->state(), ExpectedFinalState()); | 491 EXPECT_EQ(controller_->state(), ExpectedFinalState()); |
| 427 EXPECT_EQ(!files_to_delete_on_infected.empty(), ExpectedUwsFound()); | 492 EXPECT_EQ(!files_to_delete_on_infected.empty(), ExpectedUwsFound()); |
| 428 EXPECT_EQ(!files_to_delete_on_cleaning.empty(), | 493 EXPECT_EQ(!files_to_delete_on_cleaning.empty(), |
| 429 ExpectedUwsFound() && ExpectedOnCleaningCalled()); | 494 ExpectedUwsFound() && ExpectedOnCleaningCalled()); |
| 430 if (!files_to_delete_on_infected.empty() && | 495 if (!files_to_delete_on_infected.empty() && |
| 431 !files_to_delete_on_cleaning.empty()) { | 496 !files_to_delete_on_cleaning.empty()) { |
| 432 EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning); | 497 EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning); |
| 433 } | 498 } |
| 434 | 499 |
| 500 std::vector<Profile*> expected_tagged; | |
| 501 if (ExpectedToTagProfile()) | |
| 502 expected_tagged.push_back(profile1); | |
| 503 EXPECT_THAT(expected_tagged, UnorderedElementsAreArray(profiles_tagged_)); | |
| 504 | |
| 505 std::vector<Profile*> expected_reset_if_tagged; | |
| 506 if (ExpectedToResetSettings()) { | |
| 507 expected_reset_if_tagged.push_back(profile1); | |
| 508 expected_reset_if_tagged.push_back(profile2); | |
| 509 } | |
| 510 EXPECT_THAT(expected_reset_if_tagged, | |
| 511 UnorderedElementsAreArray(profiles_to_reset_if_tagged_)); | |
| 512 | |
| 435 controller_->RemoveObserver(&mock_observer_); | 513 controller_->RemoveObserver(&mock_observer_); |
| 436 } | 514 } |
| 437 | 515 |
| 438 INSTANTIATE_TEST_CASE_P( | 516 INSTANTIATE_TEST_CASE_P( |
| 439 All, | 517 All, |
| 440 ChromeCleanerControllerTest, | 518 ChromeCleanerControllerTest, |
| 441 Combine(Values(CleanerProcessStatus::kFetchFailure, | 519 Combine(Values(CleanerProcessStatus::kFetchFailure, |
| 442 CleanerProcessStatus::kFetchSuccessInvalidProcess, | 520 CleanerProcessStatus::kFetchSuccessInvalidProcess, |
| 443 CleanerProcessStatus::kFetchSuccessValidProcess), | 521 CleanerProcessStatus::kFetchSuccessValidProcess), |
| 444 Values(CrashPoint::kNone, | 522 Values(CrashPoint::kNone, |
| 445 CrashPoint::kOnStartup, | 523 CrashPoint::kOnStartup, |
| 446 CrashPoint::kAfterConnection, | 524 CrashPoint::kAfterConnection, |
| 447 // CrashPoint::kAfterRequestSent is not used because we | 525 // CrashPoint::kAfterRequestSent is not used because we |
| 448 // cannot ensure the order between the Mojo request being | 526 // cannot ensure the order between the Mojo request being |
| 449 // received by Chrome and the connection being lost. | 527 // received by Chrome and the connection being lost. |
| 450 CrashPoint::kAfterResponseReceived), | 528 CrashPoint::kAfterResponseReceived), |
| 451 Values(UwsFoundStatus::kNoUwsFound, | 529 Values(UwsFoundStatus::kNoUwsFound, |
| 452 UwsFoundStatus::kUwsFoundRebootRequired, | 530 UwsFoundStatus::kUwsFoundRebootRequired, |
| 453 UwsFoundStatus::kUwsFoundNoRebootRequired), | 531 UwsFoundStatus::kUwsFoundNoRebootRequired), |
| 454 Values(UserResponse::kAccepted, | 532 Values(UserResponse::kAccepted, |
| 455 UserResponse::kDenied, | 533 UserResponse::kDenied, |
| 456 UserResponse::kDismissed))); | 534 UserResponse::kDismissed))); |
| 457 | 535 |
| 458 } // namespace | 536 } // namespace |
| 459 } // namespace safe_browsing | 537 } // namespace safe_browsing |
| OLD | NEW |