OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_MOCK_CHROME_CLEANER_PROCESS_
WIN_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_MOCK_CHROME_CLEANER_PROCESS_
WIN_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" |
| 15 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h" |
| 16 |
| 17 namespace safe_browsing { |
| 18 |
| 19 // Class that mocks the behaviour of the Chrome Cleaner process. Intended to be |
| 20 // used in multi process tests. Example Usage: |
| 21 // |
| 22 // MULTIPROCESS_TEST_MAIN(MockChromeCleanerProcessMain) { |
| 23 // base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 24 // MockChromeCleanerProcess::Options options; |
| 25 // EXPECT_TRUE(MockChromeCleanerProcess::Options::FromCommandLine( |
| 26 // *command_line, &options)); |
| 27 // std::string chrome_mojo_pipe_token = ... |
| 28 // EXPECT_FALSE(chrome_mojo_pipe_token.empty()) |
| 29 // |
| 30 // if (::testing::Test::HasFailure()) |
| 31 // return MockChromeCleanerProcess::kInternalTestFailureExitCode; |
| 32 // MockChromeCleanerProcess mock_cleaner_process(options, |
| 33 // chrome_mojo_pipe_token); |
| 34 // return mock_cleaner_process.Run(); |
| 35 // } |
| 36 class MockChromeCleanerProcess { |
| 37 public: |
| 38 enum class CrashPoint { |
| 39 kNone, |
| 40 kOnStartup, |
| 41 kAfterConnection, |
| 42 kAfterRequestSent, |
| 43 kAfterResponseReceived, |
| 44 kNumCrashPoints, |
| 45 }; |
| 46 |
| 47 static constexpr int kInternalTestFailureExitCode = -1; |
| 48 static constexpr int kDeliberateCrashExitCode = -2; |
| 49 static constexpr int kNothingFoundExitCode = 2; |
| 50 static constexpr int kDeclinedExitCode = 44; |
| 51 static constexpr int kRebootRequiredExitCode = 15; |
| 52 static constexpr int kRebootNotRequiredExitCode = 0; |
| 53 |
| 54 class Options { |
| 55 public: |
| 56 static bool FromCommandLine(const base::CommandLine& command_line, |
| 57 Options* options); |
| 58 |
| 59 Options(); |
| 60 Options(const Options& other); |
| 61 Options& operator=(const Options& other); |
| 62 ~Options(); |
| 63 |
| 64 void AddSwitchesToCommandLine(base::CommandLine* command_line) const; |
| 65 |
| 66 void SetDoFindUws(bool do_find_uws); |
| 67 const std::vector<chrome_cleaner::mojom::UwSPtr>& found_uws() const { |
| 68 return found_uws_; |
| 69 } |
| 70 const std::set<base::FilePath>& files_to_delete() const { |
| 71 return files_to_delete_; |
| 72 } |
| 73 |
| 74 void set_reboot_required(bool reboot_required) { |
| 75 reboot_required_ = reboot_required; |
| 76 } |
| 77 bool reboot_required() const { return reboot_required_; } |
| 78 |
| 79 void set_crash_point(CrashPoint crash_point) { crash_point_ = crash_point; } |
| 80 CrashPoint crash_point() const { return crash_point_; } |
| 81 |
| 82 int ExpectedExitCode(chrome_cleaner::mojom::PromptAcceptance |
| 83 received_prompt_acceptance) const; |
| 84 |
| 85 private: |
| 86 std::vector<chrome_cleaner::mojom::UwSPtr> found_uws_; |
| 87 std::set<base::FilePath> files_to_delete_; |
| 88 bool reboot_required_ = false; |
| 89 CrashPoint crash_point_ = CrashPoint::kNone; |
| 90 }; |
| 91 |
| 92 MockChromeCleanerProcess(const Options& options, |
| 93 const std::string& chrome_mojo_pipe_token); |
| 94 |
| 95 // Call this in the main function of the mock Chrome Cleaner process. Returns |
| 96 // the exit code that should be used when the process exits. |
| 97 // |
| 98 // If a crash point has been specified in the options passed to the |
| 99 // constructor, the process will exit with a kDeliberateCrashExitCode exit |
| 100 // code, and this function will not return. |
| 101 int Run(); |
| 102 |
| 103 private: |
| 104 // Function that receives the Mojo response to the PromptUser message. |
| 105 void SendScanResults( |
| 106 chrome_cleaner::mojom::ChromePromptPtrInfo prompt_ptr_info, |
| 107 base::OnceClosure quit_closure); |
| 108 void PromptUserCallback( |
| 109 base::OnceClosure quit_closure, |
| 110 chrome_cleaner::mojom::PromptAcceptance prompt_acceptance); |
| 111 |
| 112 Options options_; |
| 113 std::string chrome_mojo_pipe_token_; |
| 114 // The PromptAcceptance received in PromptUserCallback(). |
| 115 chrome_cleaner::mojom::PromptAcceptance received_prompt_acceptance_ = |
| 116 chrome_cleaner::mojom::PromptAcceptance::UNSPECIFIED; |
| 117 chrome_cleaner::mojom::ChromePromptPtr* chrome_prompt_ptr_ = nullptr; |
| 118 }; |
| 119 |
| 120 } // namespace safe_browsing |
| 121 |
| 122 #endif // CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_MOCK_CHROME_CLEANER_PROCE
SS_WIN_H_ |
OLD | NEW |