File: fake_cros_camera_service.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (102 lines) | stat: -rw-r--r-- 4,548 bytes parent folder | download | duplicates (6)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_KIOSK_VISION_INTERNAL_FAKE_CROS_CAMERA_SERVICE_H_
#define CHROMEOS_ASH_COMPONENTS_KIOSK_VISION_INTERNAL_FAKE_CROS_CAMERA_SERVICE_H_

#include <string>

#include "base/test/test_future.h"
#include "chromeos/ash/components/mojo_service_manager/fake_mojo_service_manager.h"
#include "chromeos/ash/components/mojo_service_manager/mojom/mojo_service_manager.mojom-forward.h"
#include "media/capture/video/chromeos/mojom/cros_camera_service.mojom-forward.h"
#include "media/capture/video/chromeos/mojom/cros_camera_service.mojom.h"
#include "media/capture/video/chromeos/mojom/effects_pipeline.mojom-forward.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/message_pipe.h"

namespace ash::kiosk_vision {

// Fake implementation of `CrosCameraService` for `KioskVision` tests.
//
// Upon construction it creates a `FakeMojoServiceManager`, and registers itself
// under the `chromeos::mojo_services::kCrosCameraService` service name. This
// makes it available to `KioskVision` via the service manager.
//
// Upon deletion, `FakeMojoServiceManager` gets destroyed and cleans up the
// registrations from this class.
class FakeCrosCameraService
    : public cros::mojom::CrosCameraService,
      public chromeos::mojo_service_manager::mojom::ServiceProvider {
 public:
  FakeCrosCameraService();
  FakeCrosCameraService(const FakeCrosCameraService&) = delete;
  FakeCrosCameraService& operator=(const FakeCrosCameraService&) = delete;
  ~FakeCrosCameraService() override;

  // Returns true if `observer_remote_` is currently bound.
  //
  // `observer_remote_` is bound after a call to `StartKioskVisionDetection`.
  bool HasObserver();

  // Waits until the observer is ready. See `HasObserver()`.
  [[nodiscard]] bool WaitForObserver() { return bound_future_.Wait(); }

  // Emits a fake detection event to `observer_remote_`. An observer must have
  // been previously bound with `StartKioskVisionDetection`.
  void EmitFakeDetection(cros::mojom::KioskVisionDetectionPtr detection);

  // Emits a fake track completed event to `observer_remote_`. An observer must
  // have been previously bound with `StartKioskVisionDetection`.
  void EmitFakeTrack(cros::mojom::KioskVisionTrackPtr track);

  // Emits a fake error event to `observer_remote_`. An observer must have been
  // previously bound with `StartKioskVisionDetection`.
  void EmitFakeError(cros::mojom::KioskVisionError error);

 private:
  // `cros::mojom::CrosCameraService` implementation of relevant functions.
  void StartKioskVisionDetection(
      const std::string& dlc_path,
      ::mojo::PendingRemote<cros::mojom::KioskVisionObserver> observer)
      override;

  // `cros::mojom::CrosCameraService` implementation of unused functions.
  void GetCameraModule(cros::mojom::CameraClientType type,
                       GetCameraModuleCallback callback) override {}
  void SetTracingEnabled(bool enabled) override {}
  void SetAutoFramingState(cros::mojom::CameraAutoFramingState state) override {
  }
  void GetCameraSWPrivacySwitchState(
      GetCameraSWPrivacySwitchStateCallback callback) override {}
  void SetCameraSWPrivacySwitchState(
      cros::mojom::CameraPrivacySwitchState state) override {}
  void GetAutoFramingSupported(
      GetAutoFramingSupportedCallback callback) override {}
  void SetCameraEffect(::cros::mojom::EffectsConfigPtr config,
                       SetCameraEffectCallback callback) override {}
  void AddCrosCameraServiceObserver(
      ::mojo::PendingRemote<cros::mojom::CrosCameraServiceObserver> observer)
      override {}

  // `chromeos::mojo_service_manager::mojom::ServiceProvider` implementation.
  void Request(
      chromeos::mojo_service_manager::mojom::ProcessIdentityPtr client_identity,
      mojo::ScopedMessagePipeHandle handle) override;

  mojo_service_manager::FakeMojoServiceManager fake_mojo_service_manager_;

  mojo::Remote<cros::mojom::KioskVisionObserver> observer_remote_;
  mojo::Receiver<cros::mojom::CrosCameraService> camera_receiver_;
  mojo::Receiver<chromeos::mojo_service_manager::mojom::ServiceProvider>
      provider_receiver_;

  base::test::TestFuture<void> bound_future_;
};

}  // namespace ash::kiosk_vision

#endif  // CHROMEOS_ASH_COMPONENTS_KIOSK_VISION_INTERNAL_FAKE_CROS_CAMERA_SERVICE_H_