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 class MockChromeCleanerProcess { | |
22 public: | |
23 enum class CrashPoint { | |
24 kNone, | |
25 kOnStartup, | |
26 kAfterConnection, | |
27 kAfterRequestSent, | |
28 kAfterResponseReceived, | |
29 kNumCrashPoints, | |
30 }; | |
31 | |
32 static constexpr int kInternalTestFailureExitCode = -1; | |
33 static constexpr int kDeliberateCrashExitCode = -2; | |
34 static constexpr int kNothingFoundExitCode = 2; | |
35 static constexpr int kCanceledExitCode = 3; | |
36 static constexpr int kRebootRequiredExitCode = 15; | |
37 static constexpr int kRebootNotRequiredExitCode = 0; | |
38 | |
39 class Options { | |
40 public: | |
41 static bool FromCommandLine(const base::CommandLine& command_line, | |
42 Options* options); | |
43 | |
44 Options(bool do_find_uws = false, | |
45 bool reboot_required = false, | |
46 CrashPoint crash_point = CrashPoint::kNone); | |
47 Options(const Options& other); | |
48 | |
49 void AddSwitchesToCommandLine(base::CommandLine* command_line) const; | |
50 | |
51 void SetDoFindUws(bool do_find_uws); | |
52 const std::vector<chrome_cleaner::mojom::UwSPtr>& found_uws() const { | |
53 return found_uws_; | |
54 } | |
55 const std::set<base::FilePath>& files_to_delete() const { | |
56 return files_to_delete_; | |
57 } | |
58 | |
59 void set_reboot_required(bool reboot_required) { | |
60 reboot_required_ = reboot_required; | |
61 } | |
62 bool reboot_required() const { return reboot_required_; } | |
63 | |
64 void set_crash_point(CrashPoint crash_point) { crash_point_ = crash_point; } | |
65 CrashPoint crash_point() const { return crash_point_; } | |
66 | |
67 int ExpectedExitCode(chrome_cleaner::mojom::PromptAcceptance | |
68 received_prompt_acceptance) const; | |
69 | |
70 private: | |
71 // No assignment operator. | |
72 Options& operator=(const Options&) = delete; | |
Joe Mason
2017/05/23 15:39:36
Coding style says to define both copy constructor
alito
2017/05/23 18:58:57
Done.
| |
73 | |
74 std::vector<chrome_cleaner::mojom::UwSPtr> found_uws_; | |
75 std::set<base::FilePath> files_to_delete_; | |
76 bool reboot_required_; | |
77 CrashPoint crash_point_; | |
78 }; | |
79 | |
80 MockChromeCleanerProcess(const Options& options, | |
81 const std::string& chrome_mojo_pipe_token); | |
82 | |
83 // Call this in the main function of the mock Chrome Cleaner process. Returns | |
84 // the exit code that should be used when the process exits. | |
85 // | |
86 // If a crash point has been specified in the options passed to the | |
87 // constructor, the process will exit with a kDeliberateCrashExitCode exit | |
88 // code, and this function will not return. | |
89 int Run(); | |
90 | |
91 private: | |
92 // Function that recieves the Mojo response to the PromptUser message. | |
Joe Mason
2017/05/23 15:39:36
Nit: typo "receives"
alito
2017/05/23 18:58:57
Done.
| |
93 void SendScanResults( | |
94 chrome_cleaner::mojom::ChromePromptPtrInfo prompt_ptr_info, | |
95 base::OnceClosure quit_closure); | |
96 void PromptUserCallback( | |
97 base::OnceClosure quit_closure, | |
98 chrome_cleaner::mojom::PromptAcceptance prompt_acceptance); | |
99 | |
100 Options options_; | |
101 std::string chrome_mojo_pipe_token_; | |
102 // The PromptAcceptance received in PromptUserCallback(). | |
103 chrome_cleaner::mojom::PromptAcceptance received_prompt_acceptance_ = | |
104 chrome_cleaner::mojom::PromptAcceptance::UNSPECIFIED; | |
105 chrome_cleaner::mojom::ChromePromptPtr* chrome_prompt_ptr_ = nullptr; | |
106 }; | |
107 | |
108 } // namespace safe_browsing | |
109 | |
110 #endif // CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_MOCK_CHROME_CLEANER_PROCE SS_WIN_H_ | |
OLD | NEW |