OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/srt_fetcher_win.h" | 5 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" |
6 | 6 |
7 #include <initializer_list> | 7 #include <initializer_list> |
8 #include <set> | 8 #include <set> |
9 #include <tuple> | 9 #include <tuple> |
10 #include <utility> | 10 #include <utility> |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/lifetime/keep_alive_types.h" | 30 #include "chrome/browser/lifetime/keep_alive_types.h" |
31 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 31 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/safe_browsing/srt_client_info_win.h" | 33 #include "chrome/browser/safe_browsing/srt_client_info_win.h" |
34 #include "chrome/browser/ui/browser.h" | 34 #include "chrome/browser/ui/browser.h" |
35 #include "chrome/browser/ui/browser_finder.h" | 35 #include "chrome/browser/ui/browser_finder.h" |
36 #include "chrome/browser/ui/test/test_browser_dialog.h" | 36 #include "chrome/browser/ui/test/test_browser_dialog.h" |
37 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
38 #include "chrome/test/base/in_process_browser_test.h" | 38 #include "chrome/test/base/in_process_browser_test.h" |
39 #include "components/chrome_cleaner/constants/constants.h" | |
39 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h" | 40 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h" |
40 #include "components/component_updater/pref_names.h" | 41 #include "components/component_updater/pref_names.h" |
41 #include "components/prefs/pref_service.h" | 42 #include "components/prefs/pref_service.h" |
42 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 43 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
43 #include "mojo/edk/embedder/embedder.h" | 44 #include "mojo/edk/embedder/embedder.h" |
44 #include "mojo/edk/embedder/scoped_ipc_support.h" | 45 #include "mojo/edk/embedder/scoped_ipc_support.h" |
45 #include "mojo/edk/system/core.h" | 46 #include "mojo/edk/system/core.h" |
46 #include "testing/multiprocess_func_list.h" | 47 #include "testing/multiprocess_func_list.h" |
47 | 48 |
48 namespace safe_browsing { | 49 namespace safe_browsing { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 } | 188 } |
188 | 189 |
189 // Mocks a Software Reporter process that returns an exit code specified by | 190 // Mocks a Software Reporter process that returns an exit code specified by |
190 // command line switch kExitCodeToReturnSwitch. If a Mojo IPC is available, | 191 // command line switch kExitCodeToReturnSwitch. If a Mojo IPC is available, |
191 // this will also connect to the parent process and send mocked scan results | 192 // this will also connect to the parent process and send mocked scan results |
192 // to the parent process using data passed as command line switches. | 193 // to the parent process using data passed as command line switches. |
193 MULTIPROCESS_TEST_MAIN(MockSwReporterProcess) { | 194 MULTIPROCESS_TEST_MAIN(MockSwReporterProcess) { |
194 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 195 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
195 const std::string& str = | 196 const std::string& str = |
196 command_line->GetSwitchValueASCII(kExitCodeToReturnSwitch); | 197 command_line->GetSwitchValueASCII(kExitCodeToReturnSwitch); |
197 const std::string& chrome_mojo_pipe_token = | 198 const std::string& chrome_mojo_pipe_token = command_line->GetSwitchValueASCII( |
198 command_line->GetSwitchValueASCII(kChromeMojoPipeTokenSwitch); | 199 chrome_cleaner::kChromeMojoPipeTokenSwitch); |
199 int exit_code_to_report = kFailureExitCode; | 200 int exit_code_to_report = kFailureExitCode; |
200 bool success = base::StringToInt(str, &exit_code_to_report) && | 201 bool success = base::StringToInt(str, &exit_code_to_report) && |
201 (chrome_mojo_pipe_token.empty() || | 202 (chrome_mojo_pipe_token.empty() || |
202 ConnectAndSendDataToParentProcess(chrome_mojo_pipe_token, | 203 ConnectAndSendDataToParentProcess(chrome_mojo_pipe_token, |
203 *command_line)); | 204 *command_line)); |
204 return success ? exit_code_to_report : kFailureExitCode; | 205 return success ? exit_code_to_report : kFailureExitCode; |
205 } | 206 } |
206 | 207 |
207 // Parameters for this test: | 208 // Parameters for this test: |
208 // - bool in_browser_cleaner_ui: indicates if InBrowserCleanerUI experiment | 209 // - bool in_browser_cleaner_ui: indicates if InBrowserCleanerUI experiment |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 std::move(first_launch_callback_).Run(); | 276 std::move(first_launch_callback_).Run(); |
276 | 277 |
277 base::CommandLine command_line( | 278 base::CommandLine command_line( |
278 base::GetMultiProcessTestChildBaseCommandLine()); | 279 base::GetMultiProcessTestChildBaseCommandLine()); |
279 command_line.AppendArguments(invocation.command_line, | 280 command_line.AppendArguments(invocation.command_line, |
280 /*include_program=*/false); | 281 /*include_program=*/false); |
281 command_line.AppendSwitchASCII(kExitCodeToReturnSwitch, | 282 command_line.AppendSwitchASCII(kExitCodeToReturnSwitch, |
282 base::IntToString(exit_code_to_report_)); | 283 base::IntToString(exit_code_to_report_)); |
283 if (in_browser_cleaner_ui_) { | 284 if (in_browser_cleaner_ui_) { |
284 AddPromptAcceptanceToCommandLine(PromptAcceptance::DENIED, &command_line); | 285 AddPromptAcceptanceToCommandLine(PromptAcceptance::DENIED, &command_line); |
285 if (exit_code_to_report_ == kSwReporterCleanupNeeded) { | 286 if (exit_code_to_report_ == chrome_cleaner::kSwReporterCleanupNeeded) { |
286 command_line.AppendSwitch(kReportUwSFoundSwitch); | 287 command_line.AppendSwitch(kReportUwSFoundSwitch); |
287 if (elevation_required_) | 288 if (elevation_required_) |
288 command_line.AppendSwitch(kReportElevationRequiredSwitch); | 289 command_line.AppendSwitch(kReportElevationRequiredSwitch); |
289 } | 290 } |
290 } | 291 } |
291 base::SpawnChildResult result = base::SpawnMultiProcessTestChild( | 292 base::SpawnChildResult result = base::SpawnMultiProcessTestChild( |
292 "MockSwReporterProcess", command_line, launch_options); | 293 "MockSwReporterProcess", command_line, launch_options); |
293 return std::move(result.process); | 294 return std::move(result.process); |
294 } | 295 } |
295 | 296 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 // which should be enough time if the execution does not fail. | 432 // which should be enough time if the execution does not fail. |
432 EXPECT_LT(now - base::TimeDelta::FromHours(1), last_time_sent_logs); | 433 EXPECT_LT(now - base::TimeDelta::FromHours(1), last_time_sent_logs); |
433 EXPECT_GE(now, last_time_sent_logs); | 434 EXPECT_GE(now, last_time_sent_logs); |
434 } | 435 } |
435 | 436 |
436 // Expects |invocation|'s command line to contain all the switches required | 437 // Expects |invocation|'s command line to contain all the switches required |
437 // for reporter logging if and only if |expect_switches| is true. | 438 // for reporter logging if and only if |expect_switches| is true. |
438 void ExpectLoggingSwitches(const SwReporterInvocation& invocation, | 439 void ExpectLoggingSwitches(const SwReporterInvocation& invocation, |
439 bool expect_switches) { | 440 bool expect_switches) { |
440 static const std::set<std::string> logging_switches{ | 441 static const std::set<std::string> logging_switches{ |
441 kExtendedSafeBrowsingEnabledSwitch, kChromeVersionSwitch, | 442 chrome_cleaner::kExtendedSafeBrowsingEnabledSwitch, |
442 kChromeChannelSwitch}; | 443 chrome_cleaner::kChromeVersionSwitch, |
444 chrome_cleaner::kChromeChannelSwitch}; | |
443 | 445 |
444 const base::CommandLine::SwitchMap& invocation_switches = | 446 const base::CommandLine::SwitchMap& invocation_switches = |
445 invocation.command_line.GetSwitches(); | 447 invocation.command_line.GetSwitches(); |
446 // Checks if switches that enable logging on the reporter are present on | 448 // Checks if switches that enable logging on the reporter are present on |
447 // the invocation if and only if logging is allowed. | 449 // the invocation if and only if logging is allowed. |
448 for (const std::string& logging_switch : logging_switches) { | 450 for (const std::string& logging_switch : logging_switches) { |
449 EXPECT_EQ(expect_switches, invocation_switches.find(logging_switch) != | 451 EXPECT_EQ(expect_switches, invocation_switches.find(logging_switch) != |
450 invocation_switches.end()); | 452 invocation_switches.end()); |
451 } | 453 } |
452 } | 454 } |
(...skipping 29 matching lines...) Expand all Loading... | |
482 else if (name == "SRTErrorFile") | 484 else if (name == "SRTErrorFile") |
483 DisplaySRTPromptForTesting( | 485 DisplaySRTPromptForTesting( |
484 base::FilePath().Append(FILE_PATH_LITERAL("c:\temp\testfile.txt"))); | 486 base::FilePath().Append(FILE_PATH_LITERAL("c:\temp\testfile.txt"))); |
485 else | 487 else |
486 ADD_FAILURE() << "Unknown dialog type."; | 488 ADD_FAILURE() << "Unknown dialog type."; |
487 } | 489 } |
488 }; | 490 }; |
489 | 491 |
490 } // namespace | 492 } // namespace |
491 | 493 |
492 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, NothingFound) { | 494 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, NothingFound) { |
joenotcharles
2017/04/12 15:44:42
Bad merge here.
ftirelo
2017/04/12 19:40:41
Done.
| |
493 RunReporter(kSwReporterNothingFound); | 495 RunReporter(chrome_cleaner::kSwReporterNothingFound); |
494 ExpectReporterLaunches(0, 1, false); | 496 ExpectReporterLaunches(0, 1, false); |
495 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 497 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
496 } | 498 } |
497 | 499 |
498 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, CleanupNeeded) { | 500 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, CleanupNeeded) { |
joenotcharles
2017/04/12 15:44:42
Bad merge here.
ftirelo
2017/04/12 19:40:41
Done.
| |
499 RunReporter(kSwReporterCleanupNeeded); | 501 RunReporter(chrome_cleaner::kSwReporterCleanupNeeded); |
500 ExpectReporterLaunches(0, 1, true); | 502 ExpectReporterLaunches(0, 1, true); |
501 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 503 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
502 } | 504 } |
503 | 505 |
504 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, RanRecently) { | 506 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, RanRecently) { |
505 constexpr int kDaysLeft = 1; | 507 constexpr int kDaysLeft = 1; |
506 SetDaysSinceLastTriggered(kDaysBetweenSuccessfulSwReporterRuns - kDaysLeft); | 508 SetDaysSinceLastTriggered(kDaysBetweenSuccessfulSwReporterRuns - kDaysLeft); |
507 RunReporter(kSwReporterNothingFound); | 509 RunReporter(chrome_cleaner::kSwReporterNothingFound); |
508 ExpectReporterLaunches(0, 0, false); | 510 ExpectReporterLaunches(0, 0, false); |
509 ExpectToRunAgain(kDaysLeft); | 511 ExpectToRunAgain(kDaysLeft); |
510 ExpectReporterLaunches(kDaysLeft, 1, false); | 512 ExpectReporterLaunches(kDaysLeft, 1, false); |
511 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 513 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
512 } | 514 } |
513 | 515 |
514 // Test is flaky. crbug.com/705608 | 516 // Test is flaky. crbug.com/705608 |
515 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, DISABLED_WaitForBrowser) { | 517 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, DISABLED_WaitForBrowser) { |
516 Profile* profile = browser()->profile(); | 518 Profile* profile = browser()->profile(); |
517 | 519 |
518 // Ensure that even though we're closing the last browser, we don't enter the | 520 // Ensure that even though we're closing the last browser, we don't enter the |
519 // "shutting down" state, which will prevent the test from starting another | 521 // "shutting down" state, which will prevent the test from starting another |
520 // browser. | 522 // browser. |
521 ScopedKeepAlive test_keep_alive(KeepAliveOrigin::SESSION_RESTORE, | 523 ScopedKeepAlive test_keep_alive(KeepAliveOrigin::SESSION_RESTORE, |
522 KeepAliveRestartOption::ENABLED); | 524 KeepAliveRestartOption::ENABLED); |
523 | 525 |
524 // Use the standard task runner for browser cleanup, which will wait forever | 526 // Use the standard task runner for browser cleanup, which will wait forever |
525 // with the mock clock. | 527 // with the mock clock. |
526 base::MessageLoop::current()->SetTaskRunner(saved_task_runner_); | 528 base::MessageLoop::current()->SetTaskRunner(saved_task_runner_); |
527 CloseBrowserSynchronously(browser()); | 529 CloseBrowserSynchronously(browser()); |
528 base::MessageLoop::current()->SetTaskRunner(mock_time_task_runner_); | 530 base::MessageLoop::current()->SetTaskRunner(mock_time_task_runner_); |
529 ASSERT_EQ(0u, chrome::GetTotalBrowserCount()); | 531 ASSERT_EQ(0u, chrome::GetTotalBrowserCount()); |
530 ASSERT_FALSE(chrome::FindLastActive()); | 532 ASSERT_FALSE(chrome::FindLastActive()); |
531 | 533 |
532 // Start the reporter while the browser is closed. The prompt should not open. | 534 // Start the reporter while the browser is closed. The prompt should not open. |
533 RunReporter(kSwReporterCleanupNeeded); | 535 RunReporter(chrome_cleaner::kSwReporterCleanupNeeded); |
534 ExpectReporterLaunches(0, 1, false); | 536 ExpectReporterLaunches(0, 1, false); |
535 | 537 |
536 // Create a Browser object directly instead of using helper functions like | 538 // Create a Browser object directly instead of using helper functions like |
537 // CreateBrowser, because they all wait on timed events but do not advance the | 539 // CreateBrowser, because they all wait on timed events but do not advance the |
538 // mock timer. The Browser constructor registers itself with the global | 540 // mock timer. The Browser constructor registers itself with the global |
539 // BrowserList, which is cleaned up when InProcessBrowserTest exits. | 541 // BrowserList, which is cleaned up when InProcessBrowserTest exits. |
540 new Browser(Browser::CreateParams(profile, /*user_gesture=*/false)); | 542 new Browser(Browser::CreateParams(profile, /*user_gesture=*/false)); |
541 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); | 543 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); |
542 | 544 |
543 // Some browser startup tasks are scheduled to run in the first few minutes | 545 // Some browser startup tasks are scheduled to run in the first few minutes |
(...skipping 13 matching lines...) Expand all Loading... | |
557 ExpectReporterLaunches(0, 1, false); | 559 ExpectReporterLaunches(0, 1, false); |
558 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 560 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
559 } | 561 } |
560 | 562 |
561 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, RunDaily) { | 563 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, RunDaily) { |
562 PrefService* local_state = g_browser_process->local_state(); | 564 PrefService* local_state = g_browser_process->local_state(); |
563 local_state->SetBoolean(prefs::kSwReporterPendingPrompt, true); | 565 local_state->SetBoolean(prefs::kSwReporterPendingPrompt, true); |
564 SetDaysSinceLastTriggered(kDaysBetweenSuccessfulSwReporterRuns - 1); | 566 SetDaysSinceLastTriggered(kDaysBetweenSuccessfulSwReporterRuns - 1); |
565 ASSERT_GT(kDaysBetweenSuccessfulSwReporterRuns - 1, | 567 ASSERT_GT(kDaysBetweenSuccessfulSwReporterRuns - 1, |
566 kDaysBetweenSwReporterRunsForPendingPrompt); | 568 kDaysBetweenSwReporterRunsForPendingPrompt); |
567 RunReporter(kSwReporterNothingFound); | 569 RunReporter(chrome_cleaner::kSwReporterNothingFound); |
568 | 570 |
569 // Expect the reporter to run immediately, since a prompt is pending and it | 571 // Expect the reporter to run immediately, since a prompt is pending and it |
570 // has been more than kDaysBetweenSwReporterRunsForPendingPrompt days. | 572 // has been more than kDaysBetweenSwReporterRunsForPendingPrompt days. |
571 ExpectReporterLaunches(0, 1, false); | 573 ExpectReporterLaunches(0, 1, false); |
572 ExpectToRunAgain(kDaysBetweenSwReporterRunsForPendingPrompt); | 574 ExpectToRunAgain(kDaysBetweenSwReporterRunsForPendingPrompt); |
573 | 575 |
574 // Move the clock ahead kDaysBetweenSwReporterRunsForPendingPrompt days. The | 576 // Move the clock ahead kDaysBetweenSwReporterRunsForPendingPrompt days. The |
575 // expected run should trigger, but not cause the reporter to launch because | 577 // expected run should trigger, but not cause the reporter to launch because |
576 // a prompt is no longer pending. | 578 // a prompt is no longer pending. |
577 local_state->SetBoolean(prefs::kSwReporterPendingPrompt, false); | 579 local_state->SetBoolean(prefs::kSwReporterPendingPrompt, false); |
(...skipping 15 matching lines...) Expand all Loading... | |
593 const base::FilePath path1(L"path1"); | 595 const base::FilePath path1(L"path1"); |
594 const base::FilePath path2(L"path2"); | 596 const base::FilePath path2(L"path2"); |
595 const base::FilePath path3(L"path3"); | 597 const base::FilePath path3(L"path3"); |
596 | 598 |
597 // Schedule path1 with a day left in the reporting period. | 599 // Schedule path1 with a day left in the reporting period. |
598 // The reporter should not launch. | 600 // The reporter should not launch. |
599 constexpr int kDaysLeft = 1; | 601 constexpr int kDaysLeft = 1; |
600 { | 602 { |
601 SCOPED_TRACE("N days left until next reporter run"); | 603 SCOPED_TRACE("N days left until next reporter run"); |
602 SetDaysSinceLastTriggered(kDaysBetweenSuccessfulSwReporterRuns - kDaysLeft); | 604 SetDaysSinceLastTriggered(kDaysBetweenSuccessfulSwReporterRuns - kDaysLeft); |
603 RunReporter(kSwReporterNothingFound, path1); | 605 RunReporter(chrome_cleaner::kSwReporterNothingFound, path1); |
604 ExpectReporterLaunches(0, {}, false); | 606 ExpectReporterLaunches(0, {}, false); |
605 } | 607 } |
606 | 608 |
607 // Schedule path2 just as we enter the next reporting period. | 609 // Schedule path2 just as we enter the next reporting period. |
608 // Now the reporter should launch, just once, using path2. | 610 // Now the reporter should launch, just once, using path2. |
609 { | 611 { |
610 SCOPED_TRACE("Reporter runs now"); | 612 SCOPED_TRACE("Reporter runs now"); |
611 RunReporter(kSwReporterNothingFound, path2); | 613 RunReporter(chrome_cleaner::kSwReporterNothingFound, path2); |
612 // Schedule it twice; it should only actually run once. | 614 // Schedule it twice; it should only actually run once. |
613 RunReporter(kSwReporterNothingFound, path2); | 615 RunReporter(chrome_cleaner::kSwReporterNothingFound, path2); |
614 ExpectReporterLaunches(kDaysLeft, {path2}, false); | 616 ExpectReporterLaunches(kDaysLeft, {path2}, false); |
615 } | 617 } |
616 | 618 |
617 // Schedule path3 before any more time has passed. | 619 // Schedule path3 before any more time has passed. |
618 // The reporter should not launch. | 620 // The reporter should not launch. |
619 { | 621 { |
620 SCOPED_TRACE("No more time passed"); | 622 SCOPED_TRACE("No more time passed"); |
621 RunReporter(kSwReporterNothingFound, path3); | 623 RunReporter(chrome_cleaner::kSwReporterNothingFound, path3); |
622 ExpectReporterLaunches(0, {}, false); | 624 ExpectReporterLaunches(0, {}, false); |
623 } | 625 } |
624 | 626 |
625 // Enter the next reporting period as path3 is still scheduled. | 627 // Enter the next reporting period as path3 is still scheduled. |
626 // Now the reporter should launch again using path3. (Tests that the | 628 // Now the reporter should launch again using path3. (Tests that the |
627 // parameters from the first launch aren't reused.) | 629 // parameters from the first launch aren't reused.) |
628 { | 630 { |
629 SCOPED_TRACE("Previous run still scheduled"); | 631 SCOPED_TRACE("Previous run still scheduled"); |
630 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path3}, | 632 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path3}, |
631 false); | 633 false); |
632 } | 634 } |
633 | 635 |
634 // Schedule path3 again in the next reporting period. | 636 // Schedule path3 again in the next reporting period. |
635 // The reporter should launch again using path3, since enough time has | 637 // The reporter should launch again using path3, since enough time has |
636 // passed, even though the parameters haven't changed. | 638 // passed, even though the parameters haven't changed. |
637 { | 639 { |
638 SCOPED_TRACE("Run with same parameters"); | 640 SCOPED_TRACE("Run with same parameters"); |
639 RunReporter(kSwReporterNothingFound, path3); | 641 RunReporter(chrome_cleaner::kSwReporterNothingFound, path3); |
640 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path3}, | 642 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path3}, |
641 false); | 643 false); |
642 } | 644 } |
643 | 645 |
644 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 646 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
645 } | 647 } |
646 | 648 |
647 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, MultipleLaunches) { | 649 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, MultipleLaunches) { |
648 const base::FilePath path1(L"path1"); | 650 const base::FilePath path1(L"path1"); |
649 const base::FilePath path2(L"path2"); | 651 const base::FilePath path2(L"path2"); |
650 const base::FilePath path3(L"path3"); | 652 const base::FilePath path3(L"path3"); |
651 | 653 |
652 SwReporterQueue invocations; | 654 SwReporterQueue invocations; |
653 invocations.push(SwReporterInvocation::FromFilePath(path1)); | 655 invocations.push(SwReporterInvocation::FromFilePath(path1)); |
654 invocations.push(SwReporterInvocation::FromFilePath(path2)); | 656 invocations.push(SwReporterInvocation::FromFilePath(path2)); |
655 | 657 |
656 { | 658 { |
657 SCOPED_TRACE("Launch 2 times"); | 659 SCOPED_TRACE("Launch 2 times"); |
658 SetDaysSinceLastTriggered(kDaysBetweenSuccessfulSwReporterRuns); | 660 SetDaysSinceLastTriggered(kDaysBetweenSuccessfulSwReporterRuns); |
659 RunReporterQueue(kSwReporterNothingFound, invocations); | 661 RunReporterQueue(chrome_cleaner::kSwReporterNothingFound, invocations); |
660 ExpectReporterLaunches(0, {path1, path2}, false); | 662 ExpectReporterLaunches(0, {path1, path2}, false); |
661 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 663 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
662 } | 664 } |
663 | 665 |
664 // Schedule a launch with 2 elements, then another with the same 2. It should | 666 // Schedule a launch with 2 elements, then another with the same 2. It should |
665 // just run 2 times, not 4. | 667 // just run 2 times, not 4. |
666 { | 668 { |
667 SCOPED_TRACE("Launch 2 times with retry"); | 669 SCOPED_TRACE("Launch 2 times with retry"); |
668 RunReporterQueue(kSwReporterNothingFound, invocations); | 670 RunReporterQueue(chrome_cleaner::kSwReporterNothingFound, invocations); |
669 RunReporterQueue(kSwReporterNothingFound, invocations); | 671 RunReporterQueue(chrome_cleaner::kSwReporterNothingFound, invocations); |
670 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path1, path2}, | 672 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path1, path2}, |
671 false); | 673 false); |
672 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 674 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
673 } | 675 } |
674 | 676 |
675 // Another launch with 2 elements is already scheduled. Add a third while the | 677 // Another launch with 2 elements is already scheduled. Add a third while the |
676 // queue is running. | 678 // queue is running. |
677 { | 679 { |
678 SCOPED_TRACE("Add third launch while running"); | 680 SCOPED_TRACE("Add third launch while running"); |
679 invocations.push(SwReporterInvocation::FromFilePath(path3)); | 681 invocations.push(SwReporterInvocation::FromFilePath(path3)); |
680 first_launch_callback_ = base::BindOnce( | 682 first_launch_callback_ = base::BindOnce( |
681 &SRTFetcherTest::RunReporterQueue, base::Unretained(this), | 683 &SRTFetcherTest::RunReporterQueue, base::Unretained(this), |
682 kSwReporterNothingFound, invocations); | 684 chrome_cleaner::kSwReporterNothingFound, invocations); |
683 | 685 |
684 // Only the first two elements should execute since the third was added | 686 // Only the first two elements should execute since the third was added |
685 // during the cycle. | 687 // during the cycle. |
686 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path1, path2}, | 688 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path1, path2}, |
687 false); | 689 false); |
688 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 690 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
689 | 691 |
690 // Time passes... Now the 3-element queue should run. | 692 // Time passes... Now the 3-element queue should run. |
691 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, | 693 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, |
692 {path1, path2, path3}, false); | 694 {path1, path2, path3}, false); |
(...skipping 12 matching lines...) Expand all Loading... | |
705 // anything. | 707 // anything. |
706 ExpectReporterLaunches(0, {}, false); | 708 ExpectReporterLaunches(0, {}, false); |
707 | 709 |
708 // After enough time has passed, should try the queue again. | 710 // After enough time has passed, should try the queue again. |
709 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path1}, | 711 ExpectReporterLaunches(kDaysBetweenSuccessfulSwReporterRuns, {path1}, |
710 false); | 712 false); |
711 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 713 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
712 } | 714 } |
713 } | 715 } |
714 | 716 |
715 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, ReporterLogging_NoSBExtendedReporting) { | 717 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_NoSBExtendedReporting) { |
joenotcharles
2017/04/12 15:44:42
Bad merge here.
ftirelo
2017/04/12 19:40:41
Done.
| |
716 RunReporter(kSwReporterNothingFound); | 718 RunReporter(chrome_cleaner::kSwReporterNothingFound); |
717 ExpectReporterLaunches(0, 1, false); | 719 ExpectReporterLaunches(0, 1, false); |
718 ExpectLoggingSwitches(reporter_launch_parameters_.front(), false); | 720 ExpectLoggingSwitches(reporter_launch_parameters_.front(), false); |
719 ExpectLastTimeSentReportNotSet(); | 721 ExpectLastTimeSentReportNotSet(); |
720 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 722 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
721 } | 723 } |
722 | 724 |
723 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, ReporterLogging_EnabledFirstRun) { | 725 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, ReporterLogging_EnabledFirstRun) { |
724 EnableSBExtendedReporting(); | 726 EnableSBExtendedReporting(); |
725 // Note: don't set last time sent logs in the local state. | 727 // Note: don't set last time sent logs in the local state. |
726 // SBER is enabled and there is no record in the local state of the last time | 728 // SBER is enabled and there is no record in the local state of the last time |
727 // logs have been sent, so we should send logs in this run. | 729 // logs have been sent, so we should send logs in this run. |
728 RunReporter(kSwReporterNothingFound); | 730 RunReporter(chrome_cleaner::kSwReporterNothingFound); |
729 ExpectReporterLaunches(0, 1, false); | 731 ExpectReporterLaunches(0, 1, false); |
730 ExpectLoggingSwitches(reporter_launch_parameters_.front(), true); | 732 ExpectLoggingSwitches(reporter_launch_parameters_.front(), true); |
731 ExpectLastReportSentInTheLastHour(); | 733 ExpectLastReportSentInTheLastHour(); |
732 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 734 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
733 } | 735 } |
734 | 736 |
735 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, ReporterLogging_EnabledNoRecentLogging) { | 737 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, ReporterLogging_EnabledNoRecentLogging) { |
736 // SBER is enabled and last time logs were sent was more than | 738 // SBER is enabled and last time logs were sent was more than |
737 // |kDaysBetweenReporterLogsSent| day ago, so we should send logs in this run. | 739 // |kDaysBetweenReporterLogsSent| day ago, so we should send logs in this run. |
738 EnableSBExtendedReporting(); | 740 EnableSBExtendedReporting(); |
739 SetLastTimeSentReport(kDaysBetweenReporterLogsSent + 3); | 741 SetLastTimeSentReport(kDaysBetweenReporterLogsSent + 3); |
740 RunReporter(kSwReporterNothingFound); | 742 RunReporter(chrome_cleaner::kSwReporterNothingFound); |
741 ExpectReporterLaunches(0, 1, false); | 743 ExpectReporterLaunches(0, 1, false); |
742 ExpectLoggingSwitches(reporter_launch_parameters_.front(), true); | 744 ExpectLoggingSwitches(reporter_launch_parameters_.front(), true); |
743 ExpectLastReportSentInTheLastHour(); | 745 ExpectLastReportSentInTheLastHour(); |
744 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 746 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
745 } | 747 } |
746 | 748 |
747 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, ReporterLogging_EnabledRecentlyLogged) { | 749 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, ReporterLogging_EnabledRecentlyLogged) { |
748 // SBER is enabled, but logs have been sent less than | 750 // SBER is enabled, but logs have been sent less than |
749 // |kDaysBetweenReporterLogsSent| day ago, so we shouldn't send any logs in | 751 // |kDaysBetweenReporterLogsSent| day ago, so we shouldn't send any logs in |
750 // this run. | 752 // this run. |
751 EnableSBExtendedReporting(); | 753 EnableSBExtendedReporting(); |
752 SetLastTimeSentReport(kDaysBetweenReporterLogsSent - 1); | 754 SetLastTimeSentReport(kDaysBetweenReporterLogsSent - 1); |
753 int64_t last_time_sent_logs = GetLastTimeSentReport(); | 755 int64_t last_time_sent_logs = GetLastTimeSentReport(); |
754 RunReporter(kSwReporterNothingFound); | 756 RunReporter(chrome_cleaner::kSwReporterNothingFound); |
755 ExpectReporterLaunches(0, 1, false); | 757 ExpectReporterLaunches(0, 1, false); |
756 ExpectLoggingSwitches(reporter_launch_parameters_.front(), false); | 758 ExpectLoggingSwitches(reporter_launch_parameters_.front(), false); |
757 EXPECT_EQ(last_time_sent_logs, GetLastTimeSentReport()); | 759 EXPECT_EQ(last_time_sent_logs, GetLastTimeSentReport()); |
758 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 760 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
759 } | 761 } |
760 | 762 |
761 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, ReporterLogging_MultipleLaunches) { | 763 IN_PROC_BROWSER_TEST_P(SRTFetcherTest, ReporterLogging_MultipleLaunches) { |
762 EnableSBExtendedReporting(); | 764 EnableSBExtendedReporting(); |
763 SetLastTimeSentReport(kDaysBetweenReporterLogsSent + 3); | 765 SetLastTimeSentReport(kDaysBetweenReporterLogsSent + 3); |
764 | 766 |
765 const base::FilePath path1(L"path1"); | 767 const base::FilePath path1(L"path1"); |
766 const base::FilePath path2(L"path2"); | 768 const base::FilePath path2(L"path2"); |
767 SwReporterQueue invocations; | 769 SwReporterQueue invocations; |
768 for (const auto& path : {path1, path2}) { | 770 for (const auto& path : {path1, path2}) { |
769 auto invocation = SwReporterInvocation::FromFilePath(path); | 771 auto invocation = SwReporterInvocation::FromFilePath(path); |
770 invocation.supported_behaviours = | 772 invocation.supported_behaviours = |
771 SwReporterInvocation::BEHAVIOUR_ALLOW_SEND_REPORTER_LOGS; | 773 SwReporterInvocation::BEHAVIOUR_ALLOW_SEND_REPORTER_LOGS; |
772 invocations.push(invocation); | 774 invocations.push(invocation); |
773 } | 775 } |
774 RunReporterQueue(kSwReporterNothingFound, invocations); | 776 RunReporterQueue(chrome_cleaner::kSwReporterNothingFound, invocations); |
775 | 777 |
776 // SBER is enabled and last time logs were sent was more than | 778 // SBER is enabled and last time logs were sent was more than |
777 // |kDaysBetweenReporterLogsSent| day ago, so we should send logs in this run. | 779 // |kDaysBetweenReporterLogsSent| day ago, so we should send logs in this run. |
778 { | 780 { |
779 SCOPED_TRACE("first launch"); | 781 SCOPED_TRACE("first launch"); |
780 first_launch_callback_ = | 782 first_launch_callback_ = |
781 base::BindOnce(&SRTFetcherTest::ExpectLastReportSentInTheLastHour, | 783 base::BindOnce(&SRTFetcherTest::ExpectLastReportSentInTheLastHour, |
782 base::Unretained(this)); | 784 base::Unretained(this)); |
783 ExpectReporterLaunches(0, {path1, path2}, false); | 785 ExpectReporterLaunches(0, {path1, path2}, false); |
784 ExpectLoggingSwitches(reporter_launch_parameters_[0], true); | 786 ExpectLoggingSwitches(reporter_launch_parameters_[0], true); |
(...skipping 25 matching lines...) Expand all Loading... | |
810 // testing framework. | 812 // testing framework. |
811 IN_PROC_BROWSER_TEST_F(SRTFetcherPromptTest, InvokeDialog_SRTErrorNoFile) { | 813 IN_PROC_BROWSER_TEST_F(SRTFetcherPromptTest, InvokeDialog_SRTErrorNoFile) { |
812 RunDialog(); | 814 RunDialog(); |
813 } | 815 } |
814 | 816 |
815 IN_PROC_BROWSER_TEST_F(SRTFetcherPromptTest, InvokeDialog_SRTErrorFile) { | 817 IN_PROC_BROWSER_TEST_F(SRTFetcherPromptTest, InvokeDialog_SRTErrorFile) { |
816 RunDialog(); | 818 RunDialog(); |
817 } | 819 } |
818 | 820 |
819 } // namespace safe_browsing | 821 } // namespace safe_browsing |
OLD | NEW |