Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win_unittest.cc

Issue 2966453002: Chrome Cleaner UI: Add logs upload permission checkbox to the dialog (Closed)
Patch Set: Addressed comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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_);
270 // Since tests may change the logs collection permissions, ensure that the
271 // controller always starts off with logs collection enabled.
272 controller_->SetLogsEnabled(true);
proberge 2017/06/29 17:58:36 Can this line be removed now (since the instance s
alito 2017/06/29 18:13:51 Done.
239 273
240 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); 274 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature);
241 SetChromeCleanerRunnerTestDelegateForTesting(this); 275 SetChromeCleanerRunnerTestDelegateForTesting(this);
242 controller_->SetDelegateForTesting(this); 276 controller_->SetDelegateForTesting(this);
243 } 277 }
244 278
245 void TearDown() override { 279 void TearDown() override {
246 if (controller_->state() == State::kRebootRequired)
247 controller_->DismissRebootForTesting();
248
249 controller_->SetDelegateForTesting(nullptr); 280 controller_->SetDelegateForTesting(nullptr);
250 SetChromeCleanerRunnerTestDelegateForTesting(nullptr); 281 SetChromeCleanerRunnerTestDelegateForTesting(nullptr);
251 } 282 }
252 283
253 // ChromeCleanerControllerDelegate overrides. 284 // ChromeCleanerControllerDelegate overrides.
254 285
255 void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override { 286 void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback) override {
256 base::ThreadTaskRunnerHandle::Get()->PostTask( 287 base::ThreadTaskRunnerHandle::Get()->PostTask(
257 FROM_HERE, 288 FROM_HERE,
258 base::BindOnce( 289 base::BindOnce(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 &test_process_command_line); 335 &test_process_command_line);
305 336
306 base::SpawnChildResult result = base::SpawnMultiProcessTestChild( 337 base::SpawnChildResult result = base::SpawnMultiProcessTestChild(
307 "MockChromeCleanerProcessMain", test_process_command_line, 338 "MockChromeCleanerProcessMain", test_process_command_line,
308 launch_options); 339 launch_options);
309 340
310 EXPECT_TRUE(result.process.IsValid()); 341 EXPECT_TRUE(result.process.IsValid());
311 return std::move(result.process); 342 return std::move(result.process);
312 } 343 }
313 344
345 void OnCleanerProcessDone(
346 const ChromeCleanerRunner::ProcessStatus& process_status) override {
347 cleaner_process_status_ = process_status;
348 }
349
314 ChromeCleanerController::State ExpectedFinalState() { 350 ChromeCleanerController::State ExpectedFinalState() {
315 if (process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && 351 if (process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess &&
316 crash_point_ == CrashPoint::kNone && 352 crash_point_ == CrashPoint::kNone &&
317 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired && 353 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired &&
318 user_response_ == UserResponse::kAccepted) { 354 (user_response_ == UserResponse::kAcceptedWithLogs ||
355 user_response_ == UserResponse::kAcceptedWithoutLogs)) {
319 return State::kRebootRequired; 356 return State::kRebootRequired;
320 } 357 }
321 return State::kIdle; 358 return State::kIdle;
322 } 359 }
323 360
324 bool ExpectedOnIdleCalled() { return ExpectedFinalState() == State::kIdle; } 361 bool ExpectedOnIdleCalled() { return ExpectedFinalState() == State::kIdle; }
325 362
326 bool ExpectedOnInfectedCalled() { 363 bool ExpectedOnInfectedCalled() {
327 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && 364 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess &&
328 crash_point_ != CrashPoint::kOnStartup && 365 crash_point_ != CrashPoint::kOnStartup &&
329 crash_point_ != CrashPoint::kAfterConnection && 366 crash_point_ != CrashPoint::kAfterConnection &&
330 uws_found_status_ != UwsFoundStatus::kNoUwsFound; 367 uws_found_status_ != UwsFoundStatus::kNoUwsFound;
331 } 368 }
332 369
333 bool ExpectedOnCleaningCalled() { 370 bool ExpectedOnCleaningCalled() {
334 return ExpectedOnInfectedCalled() && 371 return ExpectedOnInfectedCalled() &&
335 crash_point_ != CrashPoint::kAfterRequestSent && 372 crash_point_ != CrashPoint::kAfterRequestSent &&
336 user_response_ == UserResponse::kAccepted; 373 (user_response_ == UserResponse::kAcceptedWithLogs ||
374 user_response_ == UserResponse::kAcceptedWithoutLogs);
337 } 375 }
338 376
339 bool ExpectedOnRebootRequiredCalled() { 377 bool ExpectedOnRebootRequiredCalled() {
340 return ExpectedFinalState() == State::kRebootRequired; 378 return ExpectedFinalState() == State::kRebootRequired;
341 } 379 }
342 380
343 bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); } 381 bool ExpectedUwsFound() { return ExpectedOnInfectedCalled(); }
344 382
345 bool ExpectedToTagProfile() { 383 bool ExpectedToTagProfile() {
346 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && 384 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess &&
347 (crash_point_ == CrashPoint::kNone || 385 (crash_point_ == CrashPoint::kNone ||
348 crash_point_ == CrashPoint::kAfterResponseReceived) && 386 crash_point_ == CrashPoint::kAfterResponseReceived) &&
349 (uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired || 387 (uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired ||
350 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired) && 388 uws_found_status_ == UwsFoundStatus::kUwsFoundRebootRequired) &&
351 user_response_ == UserResponse::kAccepted; 389 (user_response_ == UserResponse::kAcceptedWithLogs ||
390 user_response_ == UserResponse::kAcceptedWithoutLogs);
352 } 391 }
353 392
354 bool ExpectedToResetSettings() { 393 bool ExpectedToResetSettings() {
355 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess && 394 return process_status_ == CleanerProcessStatus::kFetchSuccessValidProcess &&
356 crash_point_ == CrashPoint::kNone && 395 crash_point_ == CrashPoint::kNone &&
357 uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired && 396 uws_found_status_ == UwsFoundStatus::kUwsFoundNoRebootRequired &&
358 user_response_ == UserResponse::kAccepted; 397 (user_response_ == UserResponse::kAcceptedWithLogs ||
398 user_response_ == UserResponse::kAcceptedWithoutLogs);
359 } 399 }
360 400
361 ChromeCleanerController::IdleReason ExpectedIdleReason() { 401 ChromeCleanerController::IdleReason ExpectedIdleReason() {
362 EXPECT_EQ(ExpectedFinalState(), State::kIdle); 402 EXPECT_EQ(ExpectedFinalState(), State::kIdle);
363 403
364 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess || 404 if (process_status_ != CleanerProcessStatus::kFetchSuccessValidProcess ||
365 crash_point_ == CrashPoint::kOnStartup || 405 crash_point_ == CrashPoint::kOnStartup ||
366 crash_point_ == CrashPoint::kAfterConnection) { 406 crash_point_ == CrashPoint::kAfterConnection) {
367 return IdleReason::kScanningFailed; 407 return IdleReason::kScanningFailed;
368 } 408 }
369 409
370 if (uws_found_status_ == UwsFoundStatus::kNoUwsFound) 410 if (uws_found_status_ == UwsFoundStatus::kNoUwsFound)
371 return IdleReason::kScanningFoundNothing; 411 return IdleReason::kScanningFoundNothing;
372 412
373 if (ExpectedOnInfectedCalled() && 413 if (ExpectedOnInfectedCalled() &&
374 (user_response_ == UserResponse::kDenied || 414 (user_response_ == UserResponse::kDenied ||
375 user_response_ == UserResponse::kDismissed)) { 415 user_response_ == UserResponse::kDismissed)) {
376 return IdleReason::kUserDeclinedCleanup; 416 return IdleReason::kUserDeclinedCleanup;
377 } 417 }
378 418
379 if (ExpectedOnInfectedCalled() && 419 if (ExpectedOnInfectedCalled() &&
380 user_response_ == UserResponse::kAccepted && 420 (user_response_ == UserResponse::kAcceptedWithLogs ||
421 user_response_ == UserResponse::kAcceptedWithoutLogs) &&
381 crash_point_ == CrashPoint::kAfterResponseReceived) { 422 crash_point_ == CrashPoint::kAfterResponseReceived) {
382 return IdleReason::kCleaningFailed; 423 return IdleReason::kCleaningFailed;
383 } 424 }
384 425
385 return IdleReason::kCleaningSucceeded; 426 return IdleReason::kCleaningSucceeded;
386 } 427 }
387 428
388 protected: 429 protected:
389 // We need this because we need UI and IO threads during tests. The thread 430 // 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 431 // bundle should be the first member of the class so that it will be destroyed
391 // last. 432 // last.
392 content::TestBrowserThreadBundle thread_bundle_; 433 content::TestBrowserThreadBundle thread_bundle_;
393 base::test::ScopedFeatureList scoped_feature_list_; 434 base::test::ScopedFeatureList scoped_feature_list_;
394 435
395 CleanerProcessStatus process_status_; 436 CleanerProcessStatus process_status_;
396 MockChromeCleanerProcess::CrashPoint crash_point_; 437 MockChromeCleanerProcess::CrashPoint crash_point_;
397 UwsFoundStatus uws_found_status_; 438 UwsFoundStatus uws_found_status_;
398 ChromeCleanerController::UserResponse user_response_; 439 ChromeCleanerController::UserResponse user_response_;
399 440
400 MockChromeCleanerProcess::Options cleaner_process_options_; 441 MockChromeCleanerProcess::Options cleaner_process_options_;
401 442
402 StrictMock<MockChromeCleanerControllerObserver> mock_observer_; 443 StrictMock<MockChromeCleanerControllerObserver> mock_observer_;
403 ChromeCleanerController* controller_; 444 ChromeCleanerController* controller_;
445 ChromeCleanerRunner::ProcessStatus cleaner_process_status_;
404 446
405 std::vector<Profile*> profiles_tagged_; 447 std::vector<Profile*> profiles_tagged_;
406 std::vector<Profile*> profiles_to_reset_if_tagged_; 448 std::vector<Profile*> profiles_to_reset_if_tagged_;
407 }; 449 };
408 450
409 MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) { 451 MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) {
410 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 452 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
411 MockChromeCleanerProcess::Options options; 453 MockChromeCleanerProcess::Options options;
412 EXPECT_TRUE(MockChromeCleanerProcess::Options::FromCommandLine(*command_line, 454 EXPECT_TRUE(MockChromeCleanerProcess::Options::FromCommandLine(*command_line,
413 &options)); 455 &options));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); 504 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); }));
463 } 505 }
464 506
465 if (ExpectedOnInfectedCalled()) { 507 if (ExpectedOnInfectedCalled()) {
466 EXPECT_CALL(mock_observer_, OnInfected(_)) 508 EXPECT_CALL(mock_observer_, OnInfected(_))
467 .WillOnce(DoAll(SaveArg<0>(&files_to_delete_on_infected), 509 .WillOnce(DoAll(SaveArg<0>(&files_to_delete_on_infected),
468 InvokeWithoutArgs([this, profile1]() { 510 InvokeWithoutArgs([this, profile1]() {
469 controller_->ReplyWithUserResponse(profile1, 511 controller_->ReplyWithUserResponse(profile1,
470 user_response_); 512 user_response_);
471 }))); 513 })));
514 // Since logs upload is enabled by default, OnLogsEnabledChanged() will be
515 // called only if the user response is kAcceptedWithoutLogs.
516 if (user_response_ == UserResponse::kAcceptedWithoutLogs)
517 EXPECT_CALL(mock_observer_, OnLogsEnabledChanged(false));
472 } 518 }
473 519
474 if (ExpectedOnCleaningCalled()) { 520 if (ExpectedOnCleaningCalled()) {
475 EXPECT_CALL(mock_observer_, OnCleaning(_)) 521 EXPECT_CALL(mock_observer_, OnCleaning(_))
476 .WillOnce(SaveArg<0>(&files_to_delete_on_cleaning)); 522 .WillOnce(SaveArg<0>(&files_to_delete_on_cleaning));
477 } 523 }
478 524
479 if (ExpectedOnRebootRequiredCalled()) { 525 if (ExpectedOnRebootRequiredCalled()) {
480 EXPECT_CALL(mock_observer_, OnRebootRequired()) 526 EXPECT_CALL(mock_observer_, OnRebootRequired())
481 .WillOnce( 527 .WillOnce(
482 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); })); 528 InvokeWithoutArgs([&run_loop]() { run_loop.QuitWhenIdle(); }));
483 } 529 }
484 530
485 // Assert here that we expect at least one of OnIdle or OnRebootRequired to be 531 // 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 532 // called, since otherwise, the test is set up incorrectly and is expected to
487 // never stop. 533 // never stop.
488 ASSERT_TRUE(ExpectedOnIdleCalled() || ExpectedOnRebootRequiredCalled()); 534 ASSERT_TRUE(ExpectedOnIdleCalled() || ExpectedOnRebootRequiredCalled());
489 run_loop.Run(); 535 run_loop.Run();
536 // Also ensure that we wait until the mock cleaner process has finished and
537 // that all tasks that posted by ChromeCleanerRunner have run.
538 content::RunAllBlockingPoolTasksUntilIdle();
490 539
540 EXPECT_NE(cleaner_process_status_.exit_code,
541 MockChromeCleanerProcess::kInternalTestFailureExitCode);
491 EXPECT_EQ(controller_->state(), ExpectedFinalState()); 542 EXPECT_EQ(controller_->state(), ExpectedFinalState());
492 EXPECT_EQ(!files_to_delete_on_infected.empty(), ExpectedUwsFound()); 543 EXPECT_EQ(!files_to_delete_on_infected.empty(), ExpectedUwsFound());
493 EXPECT_EQ(!files_to_delete_on_cleaning.empty(), 544 EXPECT_EQ(!files_to_delete_on_cleaning.empty(),
494 ExpectedUwsFound() && ExpectedOnCleaningCalled()); 545 ExpectedUwsFound() && ExpectedOnCleaningCalled());
495 if (!files_to_delete_on_infected.empty() && 546 if (!files_to_delete_on_infected.empty() &&
496 !files_to_delete_on_cleaning.empty()) { 547 !files_to_delete_on_cleaning.empty()) {
497 EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning); 548 EXPECT_EQ(files_to_delete_on_infected, files_to_delete_on_cleaning);
498 } 549 }
499 550
500 std::vector<Profile*> expected_tagged; 551 std::vector<Profile*> expected_tagged;
(...skipping 21 matching lines...) Expand all
522 Values(CrashPoint::kNone, 573 Values(CrashPoint::kNone,
523 CrashPoint::kOnStartup, 574 CrashPoint::kOnStartup,
524 CrashPoint::kAfterConnection, 575 CrashPoint::kAfterConnection,
525 // CrashPoint::kAfterRequestSent is not used because we 576 // CrashPoint::kAfterRequestSent is not used because we
526 // cannot ensure the order between the Mojo request being 577 // cannot ensure the order between the Mojo request being
527 // received by Chrome and the connection being lost. 578 // received by Chrome and the connection being lost.
528 CrashPoint::kAfterResponseReceived), 579 CrashPoint::kAfterResponseReceived),
529 Values(UwsFoundStatus::kNoUwsFound, 580 Values(UwsFoundStatus::kNoUwsFound,
530 UwsFoundStatus::kUwsFoundRebootRequired, 581 UwsFoundStatus::kUwsFoundRebootRequired,
531 UwsFoundStatus::kUwsFoundNoRebootRequired), 582 UwsFoundStatus::kUwsFoundNoRebootRequired),
532 Values(UserResponse::kAccepted, 583 Values(UserResponse::kAcceptedWithLogs,
584 UserResponse::kAcceptedWithoutLogs,
533 UserResponse::kDenied, 585 UserResponse::kDenied,
534 UserResponse::kDismissed))); 586 UserResponse::kDismissed)));
535 587
536 } // namespace 588 } // namespace
537 } // namespace safe_browsing 589 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698