Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2885)

Unified Diff: chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_process_win.h

Issue 2890023005: Chrome Cleaner UI: reporter no longer uses mojo. (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_process_win.h
diff --git a/chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_process_win.h b/chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_process_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..dcbaa11f730a19955cdc27e1a075aacef602d78b
--- /dev/null
+++ b/chrome/browser/safe_browsing/chrome_cleaner/mock_chrome_cleaner_process_win.h
@@ -0,0 +1,110 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_MOCK_CHROME_CLEANER_PROCESS_WIN_H_
+#define CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_MOCK_CHROME_CLEANER_PROCESS_WIN_H_
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h"
+
+namespace safe_browsing {
+
+// Class that mocks the behaviour of the Chrome Cleaner process. Intended to be
+// used in multi process tests. Example Usage:
+class MockChromeCleanerProcess {
+ public:
+ enum class CrashPoint {
+ kNone,
+ kOnStartup,
+ kAfterConnection,
+ kAfterRequestSent,
+ kAfterResponseReceived,
+ kNumCrashPoints,
+ };
+
+ static constexpr int kInternalTestFailureExitCode = -1;
+ static constexpr int kDeliberateCrashExitCode = -2;
+ static constexpr int kNothingFoundExitCode = 2;
+ static constexpr int kCanceledExitCode = 3;
+ static constexpr int kRebootRequiredExitCode = 15;
+ static constexpr int kRebootNotRequiredExitCode = 0;
+
+ class Options {
+ public:
+ static bool FromCommandLine(const base::CommandLine& command_line,
+ Options* options);
+
+ Options(bool do_find_uws = false,
+ bool reboot_required = false,
+ CrashPoint crash_point = CrashPoint::kNone);
+ Options(const Options& other);
+
+ void AddSwitchesToCommandLine(base::CommandLine* command_line) const;
+
+ void SetDoFindUws(bool do_find_uws);
+ const std::vector<chrome_cleaner::mojom::UwSPtr>& found_uws() const {
+ return found_uws_;
+ }
+ const std::set<base::FilePath>& files_to_delete() const {
+ return files_to_delete_;
+ }
+
+ void set_reboot_required(bool reboot_required) {
+ reboot_required_ = reboot_required;
+ }
+ bool reboot_required() const { return reboot_required_; }
+
+ void set_crash_point(CrashPoint crash_point) { crash_point_ = crash_point; }
+ CrashPoint crash_point() const { return crash_point_; }
+
+ int ExpectedExitCode(chrome_cleaner::mojom::PromptAcceptance
+ received_prompt_acceptance) const;
+
+ private:
+ // No assignment operator.
+ 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.
+
+ std::vector<chrome_cleaner::mojom::UwSPtr> found_uws_;
+ std::set<base::FilePath> files_to_delete_;
+ bool reboot_required_;
+ CrashPoint crash_point_;
+ };
+
+ MockChromeCleanerProcess(const Options& options,
+ const std::string& chrome_mojo_pipe_token);
+
+ // Call this in the main function of the mock Chrome Cleaner process. Returns
+ // the exit code that should be used when the process exits.
+ //
+ // If a crash point has been specified in the options passed to the
+ // constructor, the process will exit with a kDeliberateCrashExitCode exit
+ // code, and this function will not return.
+ int Run();
+
+ private:
+ // 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.
+ void SendScanResults(
+ chrome_cleaner::mojom::ChromePromptPtrInfo prompt_ptr_info,
+ base::OnceClosure quit_closure);
+ void PromptUserCallback(
+ base::OnceClosure quit_closure,
+ chrome_cleaner::mojom::PromptAcceptance prompt_acceptance);
+
+ Options options_;
+ std::string chrome_mojo_pipe_token_;
+ // The PromptAcceptance received in PromptUserCallback().
+ chrome_cleaner::mojom::PromptAcceptance received_prompt_acceptance_ =
+ chrome_cleaner::mojom::PromptAcceptance::UNSPECIFIED;
+ chrome_cleaner::mojom::ChromePromptPtr* chrome_prompt_ptr_ = nullptr;
+};
+
+} // namespace safe_browsing
+
+#endif // CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_MOCK_CHROME_CLEANER_PROCESS_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698