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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 42 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
43 #include "mojo/edk/embedder/embedder.h" | 43 #include "mojo/edk/embedder/embedder.h" |
44 #include "mojo/edk/embedder/scoped_ipc_support.h" | 44 #include "mojo/edk/embedder/scoped_ipc_support.h" |
45 #include "mojo/edk/system/core.h" | 45 #include "mojo/edk/system/core.h" |
46 #include "testing/multiprocess_func_list.h" | 46 #include "testing/multiprocess_func_list.h" |
47 | 47 |
48 namespace safe_browsing { | 48 namespace safe_browsing { |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
| 52 using chrome_cleaner::mojom::ElevationStatus; |
52 using chrome_cleaner::mojom::PromptAcceptance; | 53 using chrome_cleaner::mojom::PromptAcceptance; |
53 | 54 |
54 // Special switches passed by the parent process (test case) to the reporter | 55 // Special switches passed by the parent process (test case) to the reporter |
55 // child process to indicate the behavior that should be mocked. | 56 // child process to indicate the behavior that should be mocked. |
56 constexpr char kExitCodeToReturnSwitch[] = "exit-code-to-return"; | 57 constexpr char kExitCodeToReturnSwitch[] = "exit-code-to-return"; |
57 constexpr char kReportUwSFoundSwitch[] = "report-uws-found"; | 58 constexpr char kReportUwSFoundSwitch[] = "report-uws-found"; |
58 constexpr char kReportElevationRequiredSwitch[] = "report-elevation-required"; | 59 constexpr char kReportElevationRequiredSwitch[] = "report-elevation-required"; |
59 constexpr char kExpectedPromptAcceptanceSwitch[] = "expected-prompt-acceptance"; | 60 constexpr char kExpectedPromptAcceptanceSwitch[] = "expected-prompt-acceptance"; |
60 | 61 |
61 // The exit code to be returned in case of failure in the child process. | 62 // The exit code to be returned in case of failure in the child process. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 std::move(message_pipe_handle), 0)); | 130 std::move(message_pipe_handle), 0)); |
130 | 131 |
131 std::vector<chrome_cleaner::mojom::UwSPtr> removable_uws_found; | 132 std::vector<chrome_cleaner::mojom::UwSPtr> removable_uws_found; |
132 if (command_line.HasSwitch(kReportUwSFoundSwitch)) { | 133 if (command_line.HasSwitch(kReportUwSFoundSwitch)) { |
133 chrome_cleaner::mojom::UwSPtr uws = chrome_cleaner::mojom::UwS::New(); | 134 chrome_cleaner::mojom::UwSPtr uws = chrome_cleaner::mojom::UwS::New(); |
134 uws->id = kDefaultUwSId; | 135 uws->id = kDefaultUwSId; |
135 uws->name = kDefaultUwSName; | 136 uws->name = kDefaultUwSName; |
136 uws->observed_behaviours = chrome_cleaner::mojom::ObservedBehaviours::New(); | 137 uws->observed_behaviours = chrome_cleaner::mojom::ObservedBehaviours::New(); |
137 removable_uws_found.push_back(std::move(uws)); | 138 removable_uws_found.push_back(std::move(uws)); |
138 } | 139 } |
139 const bool elevation_required = | 140 const ElevationStatus elevation_status = |
140 command_line.HasSwitch(kReportElevationRequiredSwitch); | 141 command_line.HasSwitch(kReportElevationRequiredSwitch) |
| 142 ? ElevationStatus::REQUIRED |
| 143 : ElevationStatus::NOT_REQUIRED; |
141 const PromptAcceptance expected_prompt_acceptance = | 144 const PromptAcceptance expected_prompt_acceptance = |
142 PromptAcceptanceFromCommandLine(command_line); | 145 PromptAcceptanceFromCommandLine(command_line); |
143 | 146 |
144 (*g_chrome_prompt_ptr) | 147 (*g_chrome_prompt_ptr) |
145 ->PromptUser( | 148 ->PromptUser( |
146 std::move(removable_uws_found), elevation_required, | 149 std::move(removable_uws_found), elevation_status, |
147 base::Bind(&PromptUserCallback, done, expected_prompt_acceptance, | 150 base::Bind(&PromptUserCallback, done, expected_prompt_acceptance, |
148 expected_value_received)); | 151 expected_value_received)); |
149 } | 152 } |
150 | 153 |
151 // Connects to the parent process and sends mocked scan results. Returns true | 154 // Connects to the parent process and sends mocked scan results. Returns true |
152 // if connection was successful and the prompt acceptance results sent by the | 155 // if connection was successful and the prompt acceptance results sent by the |
153 // parent process are the same as expected. | 156 // parent process are the same as expected. |
154 bool ConnectAndSendDataToParentProcess( | 157 bool ConnectAndSendDataToParentProcess( |
155 const std::string& chrome_mojo_pipe_token, | 158 const std::string& chrome_mojo_pipe_token, |
156 const base::CommandLine& command_line) { | 159 const base::CommandLine& command_line) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 (chrome_mojo_pipe_token.empty() || | 204 (chrome_mojo_pipe_token.empty() || |
202 ConnectAndSendDataToParentProcess(chrome_mojo_pipe_token, | 205 ConnectAndSendDataToParentProcess(chrome_mojo_pipe_token, |
203 *command_line)); | 206 *command_line)); |
204 return success ? exit_code_to_report : kFailureExitCode; | 207 return success ? exit_code_to_report : kFailureExitCode; |
205 } | 208 } |
206 | 209 |
207 // Parameters for this test: | 210 // Parameters for this test: |
208 // - bool in_browser_cleaner_ui: indicates if InBrowserCleanerUI experiment | 211 // - bool in_browser_cleaner_ui: indicates if InBrowserCleanerUI experiment |
209 // is enabled; if so, the parent and the child processes will communicate | 212 // is enabled; if so, the parent and the child processes will communicate |
210 // via a Mojo IPC; | 213 // via a Mojo IPC; |
211 // - bool elevation_required: indicates if the scan results sent by the child | 214 // - ElevationStatus elevation_status: indicates if the scan results sent by |
212 // process should consider that elevation will be required for cleanup. | 215 // the child process should consider that elevation will be required for |
| 216 // cleanup. |
213 class SRTFetcherTest | 217 class SRTFetcherTest |
214 : public InProcessBrowserTest, | 218 : public InProcessBrowserTest, |
215 public SwReporterTestingDelegate, | 219 public SwReporterTestingDelegate, |
216 public ::testing::WithParamInterface<std::tuple<bool, bool>> { | 220 public ::testing::WithParamInterface<std::tuple<bool, ElevationStatus>> { |
217 public: | 221 public: |
218 void SetUpInProcessBrowserTestFixture() override { | 222 void SetUpInProcessBrowserTestFixture() override { |
219 SetSwReporterTestingDelegate(this); | 223 SetSwReporterTestingDelegate(this); |
220 | 224 |
221 std::tie(in_browser_cleaner_ui_, elevation_required_) = GetParam(); | 225 std::tie(in_browser_cleaner_ui_, elevation_status_) = GetParam(); |
222 // The config should only accept elevation_required_ if InBrowserCleanerUI | 226 // The config should only accept elevation_status_ if InBrowserCleanerUI |
223 // feature is enabled. | 227 // feature is enabled. |
224 ASSERT_TRUE(!elevation_required_ || in_browser_cleaner_ui_); | 228 ASSERT_TRUE(elevation_status_ == ElevationStatus::NOT_REQUIRED || |
| 229 in_browser_cleaner_ui_); |
225 | 230 |
226 if (in_browser_cleaner_ui_) | 231 if (in_browser_cleaner_ui_) |
227 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); | 232 scoped_feature_list_.InitAndEnableFeature(kInBrowserCleanerUIFeature); |
228 else | 233 else |
229 scoped_feature_list_.InitAndDisableFeature(kInBrowserCleanerUIFeature); | 234 scoped_feature_list_.InitAndDisableFeature(kInBrowserCleanerUIFeature); |
230 } | 235 } |
231 | 236 |
232 void SetUpOnMainThread() override { | 237 void SetUpOnMainThread() override { |
233 // During the test, use a task runner with a mock clock. | 238 // During the test, use a task runner with a mock clock. |
234 saved_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 239 saved_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 base::CommandLine command_line( | 282 base::CommandLine command_line( |
278 base::GetMultiProcessTestChildBaseCommandLine()); | 283 base::GetMultiProcessTestChildBaseCommandLine()); |
279 command_line.AppendArguments(invocation.command_line, | 284 command_line.AppendArguments(invocation.command_line, |
280 /*include_program=*/false); | 285 /*include_program=*/false); |
281 command_line.AppendSwitchASCII(kExitCodeToReturnSwitch, | 286 command_line.AppendSwitchASCII(kExitCodeToReturnSwitch, |
282 base::IntToString(exit_code_to_report_)); | 287 base::IntToString(exit_code_to_report_)); |
283 if (in_browser_cleaner_ui_) { | 288 if (in_browser_cleaner_ui_) { |
284 AddPromptAcceptanceToCommandLine(PromptAcceptance::DENIED, &command_line); | 289 AddPromptAcceptanceToCommandLine(PromptAcceptance::DENIED, &command_line); |
285 if (exit_code_to_report_ == kSwReporterCleanupNeeded) { | 290 if (exit_code_to_report_ == kSwReporterCleanupNeeded) { |
286 command_line.AppendSwitch(kReportUwSFoundSwitch); | 291 command_line.AppendSwitch(kReportUwSFoundSwitch); |
287 if (elevation_required_) | 292 if (elevation_status_ == ElevationStatus::REQUIRED) |
288 command_line.AppendSwitch(kReportElevationRequiredSwitch); | 293 command_line.AppendSwitch(kReportElevationRequiredSwitch); |
289 } | 294 } |
290 } | 295 } |
291 base::SpawnChildResult result = base::SpawnMultiProcessTestChild( | 296 base::SpawnChildResult result = base::SpawnMultiProcessTestChild( |
292 "MockSwReporterProcess", command_line, launch_options); | 297 "MockSwReporterProcess", command_line, launch_options); |
293 return std::move(result.process); | 298 return std::move(result.process); |
294 } | 299 } |
295 | 300 |
296 // Returns the test's idea of the current time. | 301 // Returns the test's idea of the current time. |
297 base::Time Now() const override { return mock_time_task_runner_->Now(); } | 302 base::Time Now() const override { return mock_time_task_runner_->Now(); } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 } | 457 } |
453 | 458 |
454 // A task runner with a mock clock. | 459 // A task runner with a mock clock. |
455 scoped_refptr<base::TestMockTimeTaskRunner> mock_time_task_runner_ = | 460 scoped_refptr<base::TestMockTimeTaskRunner> mock_time_task_runner_ = |
456 new base::TestMockTimeTaskRunner(); | 461 new base::TestMockTimeTaskRunner(); |
457 | 462 |
458 // The task runner that was in use before installing |mock_time_task_runner_|. | 463 // The task runner that was in use before installing |mock_time_task_runner_|. |
459 scoped_refptr<base::SingleThreadTaskRunner> saved_task_runner_; | 464 scoped_refptr<base::SingleThreadTaskRunner> saved_task_runner_; |
460 | 465 |
461 bool in_browser_cleaner_ui_; | 466 bool in_browser_cleaner_ui_; |
462 bool elevation_required_; | 467 ElevationStatus elevation_status_; |
463 | 468 |
464 bool prompt_trigger_called_ = false; | 469 bool prompt_trigger_called_ = false; |
465 int reporter_launch_count_ = 0; | 470 int reporter_launch_count_ = 0; |
466 std::vector<SwReporterInvocation> reporter_launch_parameters_; | 471 std::vector<SwReporterInvocation> reporter_launch_parameters_; |
467 int exit_code_to_report_ = kReporterFailureExitCode; | 472 int exit_code_to_report_ = kReporterFailureExitCode; |
468 | 473 |
469 // A callback to invoke when the first reporter of a queue is launched. This | 474 // A callback to invoke when the first reporter of a queue is launched. This |
470 // can be used to perform actions in the middle of a queue of reporters which | 475 // can be used to perform actions in the middle of a queue of reporters which |
471 // all launch on the same mock clock tick. | 476 // all launch on the same mock clock tick. |
472 base::OnceClosure first_launch_callback_; | 477 base::OnceClosure first_launch_callback_; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 // Logs should also be sent for the next run, even though LastTimeSentReport | 792 // Logs should also be sent for the next run, even though LastTimeSentReport |
788 // is now recent, because the run is part of the same set of invocations. | 793 // is now recent, because the run is part of the same set of invocations. |
789 { | 794 { |
790 SCOPED_TRACE("second launch"); | 795 SCOPED_TRACE("second launch"); |
791 ExpectLoggingSwitches(reporter_launch_parameters_[1], true); | 796 ExpectLoggingSwitches(reporter_launch_parameters_[1], true); |
792 ExpectLastReportSentInTheLastHour(); | 797 ExpectLastReportSentInTheLastHour(); |
793 } | 798 } |
794 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 799 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
795 } | 800 } |
796 | 801 |
797 INSTANTIATE_TEST_CASE_P(NoInBrowserCleanerUI, | 802 INSTANTIATE_TEST_CASE_P( |
798 SRTFetcherTest, | 803 NoInBrowserCleanerUI, |
799 testing::Combine(testing::Values(false), | 804 SRTFetcherTest, |
800 testing::Values(false))); | 805 testing::Combine(testing::Values(false), |
| 806 testing::Values(ElevationStatus::NOT_REQUIRED))); |
801 | 807 |
802 INSTANTIATE_TEST_CASE_P(InBrowserCleanerUI, | 808 INSTANTIATE_TEST_CASE_P( |
803 SRTFetcherTest, | 809 InBrowserCleanerUI, |
804 testing::Combine(testing::Values(true), | 810 SRTFetcherTest, |
805 testing::Bool())); | 811 testing::Combine(testing::Values(true), |
| 812 testing::Values(ElevationStatus::NOT_REQUIRED, |
| 813 ElevationStatus::REQUIRED))); |
806 | 814 |
807 // This provide tests which allows explicit invocation of the SRT Prompt | 815 // This provide tests which allows explicit invocation of the SRT Prompt |
808 // useful for checking dialog layout or any other interactive functionality | 816 // useful for checking dialog layout or any other interactive functionality |
809 // tests. See docs/testing/test_browser_dialog.md for description of the | 817 // tests. See docs/testing/test_browser_dialog.md for description of the |
810 // testing framework. | 818 // testing framework. |
811 IN_PROC_BROWSER_TEST_F(SRTFetcherPromptTest, InvokeDialog_SRTErrorNoFile) { | 819 IN_PROC_BROWSER_TEST_F(SRTFetcherPromptTest, InvokeDialog_SRTErrorNoFile) { |
812 RunDialog(); | 820 RunDialog(); |
813 } | 821 } |
814 | 822 |
815 IN_PROC_BROWSER_TEST_F(SRTFetcherPromptTest, InvokeDialog_SRTErrorFile) { | 823 IN_PROC_BROWSER_TEST_F(SRTFetcherPromptTest, InvokeDialog_SRTErrorFile) { |
816 RunDialog(); | 824 RunDialog(); |
817 } | 825 } |
818 | 826 |
819 } // namespace safe_browsing | 827 } // namespace safe_browsing |
OLD | NEW |