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