File: mock_paint_preview_recorder.h

package info (click to toggle)
chromium 141.0.7390.107-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,246,132 kB
  • sloc: cpp: 35,264,965; ansic: 7,169,920; javascript: 4,250,185; python: 1,460,635; asm: 950,788; xml: 751,751; pascal: 187,972; sh: 89,459; perl: 88,691; objc: 79,953; sql: 53,924; cs: 44,622; fortran: 24,137; makefile: 22,313; tcl: 15,277; php: 14,018; yacc: 8,995; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (85 lines) | stat: -rw-r--r-- 3,267 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PAINT_PREVIEW_COMMON_MOCK_PAINT_PREVIEW_RECORDER_H_
#define COMPONENTS_PAINT_PREVIEW_COMMON_MOCK_PAINT_PREVIEW_RECORDER_H_

#include "base/functional/callback.h"
#include "components/paint_preview/common/mojom/paint_preview_recorder.mojom.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"

namespace paint_preview {

class MockPaintPreviewRecorder : public mojom::PaintPreviewRecorder {
 public:
  MockPaintPreviewRecorder();

  MockPaintPreviewRecorder(const MockPaintPreviewRecorder&) = delete;
  MockPaintPreviewRecorder& operator=(const MockPaintPreviewRecorder&) = delete;

  ~MockPaintPreviewRecorder() override;

  // mojom::PaintPreviewRecorder:
  void CapturePaintPreview(
      mojom::PaintPreviewCaptureParamsPtr params,
      mojom::PaintPreviewRecorder::CapturePaintPreviewCallback callback)
      override;
  void GetGeometryMetadata(mojom::GeometryMetadataParamsPtr params,
                           GetGeometryMetadataCallback callback) override;

  // Stores the expected params to compare against in `CheckParams`.
  void SetExpectedParams(mojom::PaintPreviewCaptureParamsPtr params);
  void SetExpectedGeometryParams(mojom::GeometryMetadataParamsPtr params);

  // Sets the status and response that will be sent. If `response` is nullptr, a
  // new response will be conructed on demand when needed.
  void SetResponse(mojom::PaintPreviewStatus status,
                   mojom::PaintPreviewCaptureResponsePtr response = nullptr);
  void SetGeometryResponse(
      mojom::GeometryMetadataResponsePtr response = nullptr);

  // Sets a closure to run during `CapturePaintPreview`, instead of immediately
  // invoking the callback. This can be used with a TestFuture or RunLoop to
  // return control flow to the test.
  void SetReceivedRequestClosure(base::OnceClosure closure);

  // Runs the callback received in `CapturePaintPreview`. This may only be used
  // if `SetReceivedRequestClosure` was used prior.
  void SendResponse();
  void SendGeometryResponse();

  void BindRequest(mojo::ScopedInterfaceEndpointHandle handle);

  static mojom::PaintPreviewCaptureResponsePtr NewResponse();

 protected:
  virtual void CheckParams(
      const mojom::PaintPreviewCaptureParamsPtr& input_params);

  virtual void CheckGeometryParams(
      const mojom::GeometryMetadataParamsPtr& input_params);

  // If non-null, this is invoked when the recorder receives a paint preview
  // request.
  base::OnceClosure received_request_closure_;

  mojom::PaintPreviewRecorder::CapturePaintPreviewCallback
      send_response_callback_;
  mojom::PaintPreviewRecorder::GetGeometryMetadataCallback
      send_geometry_response_callback_;

  mojom::PaintPreviewCaptureParamsPtr expected_params_;
  mojom::GeometryMetadataParamsPtr expected_geometry_params_;

  mojom::PaintPreviewStatus status_;

  mojom::PaintPreviewCaptureResponsePtr response_;
  mojom::GeometryMetadataResponsePtr geometry_response_;

  mojo::AssociatedReceiver<mojom::PaintPreviewRecorder> binding_{this};
};

}  // namespace paint_preview

#endif  // COMPONENTS_PAINT_PREVIEW_COMMON_MOCK_PAINT_PREVIEW_RECORDER_H_