Enable chrome with aura for tizen
[platform/framework/web/chromium-efl.git] / printing / test_printing_context.h
1 // Copyright 2021 The Chromium Authors
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 PRINTING_TEST_PRINTING_CONTEXT_H_
6 #define PRINTING_TEST_PRINTING_CONTEXT_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/containers/flat_map.h"
12 #include "base/functional/callback_forward.h"
13 #include "build/build_config.h"
14 #include "printing/mojom/print.mojom.h"
15 #include "printing/print_settings.h"
16 #include "printing/printing_context.h"
17
18 #if BUILDFLAG(IS_WIN)
19 #include "third_party/abseil-cpp/absl/types/optional.h"
20 #endif
21
22 namespace printing {
23
24 class TestPrintingContextDelegate : public PrintingContext::Delegate {
25  public:
26   TestPrintingContextDelegate();
27   TestPrintingContextDelegate(const TestPrintingContextDelegate&) = delete;
28   TestPrintingContextDelegate& operator=(const TestPrintingContextDelegate&) =
29       delete;
30   ~TestPrintingContextDelegate() override;
31
32   // PrintingContext::Delegate overrides:
33   gfx::NativeView GetParentView() override;
34   std::string GetAppLocale() override;
35 };
36
37 class TestPrintingContext : public PrintingContext {
38  public:
39   TestPrintingContext(Delegate* delegate, bool skip_system_calls);
40   TestPrintingContext(const TestPrintingContext&) = delete;
41   TestPrintingContext& operator=(const TestPrintingContext&) = delete;
42   ~TestPrintingContext() override;
43
44   // Methods for test setup:
45
46   // Provide settings that will be used as the current settings for the
47   // indicated device.
48   void SetDeviceSettings(const std::string& device_name,
49                          std::unique_ptr<PrintSettings> settings);
50
51   // Enables tests to fail with an access-denied error.
52   void SetNewDocumentBlockedByPermissions() {
53     new_document_blocked_by_permissions_ = true;
54   }
55 #if BUILDFLAG(IS_WIN)
56   void SetOnRenderPageBlockedByPermissions() {
57     render_page_blocked_by_permissions_ = true;
58   }
59   void SetOnRenderPageFailsForPage(uint32_t page_number) {
60     render_page_fail_for_page_number_ = page_number;
61   }
62 #endif
63   void SetOnRenderDocumentBlockedByPermissions() {
64     render_document_blocked_by_permissions_ = true;
65   }
66   void SetDocumentDoneBlockedByPermissions() {
67     document_done_blocked_by_permissions_ = true;
68   }
69
70   // Enables tests to fail with a failed error.
71   void SetUseDefaultSettingsFails() { use_default_settings_fails_ = true; }
72
73   // Enables tests to fail with a canceled error.
74   void SetAskUserForSettingsCanceled() { ask_user_for_settings_cancel_ = true; }
75
76   void SetNewDocumentCalledClosure(base::RepeatingClosure closure) {
77     new_document_called_ = std::move(closure);
78   }
79
80   // PrintingContext overrides:
81   void AskUserForSettings(int max_pages,
82                           bool has_selection,
83                           bool is_scripted,
84                           PrintSettingsCallback callback) override;
85   mojom::ResultCode UseDefaultSettings() override;
86   gfx::Size GetPdfPaperSizeDeviceUnits() override;
87   mojom::ResultCode UpdatePrinterSettings(
88       const PrinterSettings& printer_settings) override;
89   mojom::ResultCode NewDocument(const std::u16string& document_name) override;
90 #if BUILDFLAG(IS_WIN)
91   mojom::ResultCode RenderPage(const PrintedPage& page,
92                                const PageSetup& page_setup) override;
93 #endif
94   mojom::ResultCode PrintDocument(const MetafilePlayer& metafile,
95                                   const PrintSettings& settings,
96                                   uint32_t num_pages) override;
97   mojom::ResultCode DocumentDone() override;
98   void Cancel() override;
99   void ReleaseContext() override;
100   NativeDrawingContext context() const override;
101 #if BUILDFLAG(IS_WIN)
102   mojom::ResultCode InitWithSettingsForTest(
103       std::unique_ptr<PrintSettings> settings) override;
104 #endif
105
106  private:
107   base::flat_map<std::string, std::unique_ptr<PrintSettings>> device_settings_;
108   bool use_default_settings_fails_ = false;
109   bool ask_user_for_settings_cancel_ = false;
110   bool new_document_blocked_by_permissions_ = false;
111 #if BUILDFLAG(IS_WIN)
112   bool render_page_blocked_by_permissions_ = false;
113   absl::optional<uint32_t> render_page_fail_for_page_number_;
114 #endif
115   bool render_document_blocked_by_permissions_ = false;
116   bool document_done_blocked_by_permissions_ = false;
117
118   // Called every time `NewDocument` is called.
119   base::RepeatingClosure new_document_called_;
120 };
121
122 }  // namespace printing
123
124 #endif  // PRINTING_TEST_PRINTING_CONTEXT_H_