File: scoped_fake_ash_proxy.cc

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 (159 lines) | stat: -rw-r--r-- 4,745 bytes parent folder | download | duplicates (5)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/host/chromeos/scoped_fake_ash_proxy.h"

#include "base/check.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "components/viz/host/client_frame_sink_video_capturer.h"
#include "ui/aura/scoped_window_capture_request.h"
#include "ui/display/manager/managed_display_info.h"

namespace remoting::test {

ScopedFakeAshProxy::ScopedFakeAshProxy() : ScopedFakeAshProxy(nullptr) {}

ScopedFakeAshProxy::ScopedFakeAshProxy(
    ash::curtain::SecurityCurtainController* controller)
    : security_curtain_controller_(controller) {
  AshProxy::SetInstanceForTesting(this);
}

ScopedFakeAshProxy::~ScopedFakeAshProxy() {
  AshProxy::SetInstanceForTesting(nullptr);
}

display::Display& ScopedFakeAshProxy::AddPrimaryDisplayFromSpec(
    const std::string& spec,
    DisplayId id) {
  primary_display_id_ = id;
  return AddDisplayFromSpecWithId(spec, id);
}

display::Display& ScopedFakeAshProxy::AddPrimaryDisplay(DisplayId id) {
  return AddPrimaryDisplayFromSpec("800x600", id);
}

display::Display& ScopedFakeAshProxy::AddDisplayWithId(DisplayId id) {
  // Give the display a valid size.
  return AddDisplayFromSpecWithId("800x600", id);
}

display::Display& ScopedFakeAshProxy::AddDisplayFromSpecWithId(
    const std::string& spec,
    DisplayId id) {
  auto display_info =
      display::ManagedDisplayInfo::CreateFromSpecWithID(spec, id);

  display::Display new_display(display_info.id());

  // We use size_in_pixel() and not bounds_in_native() because size_in_pixel()
  // takes rotation into account (which is also what happens when adding a real
  // Display in the DisplayManager).
  gfx::Rect bounds_in_pixels(display_info.bounds_in_native().origin(),
                             display_info.size_in_pixel());

  float device_scale_factor = display_info.GetEffectiveDeviceScaleFactor();
  new_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels);
  new_display.set_rotation(display_info.GetActiveRotation());

  return AddDisplay(new_display);
}

display::Display& ScopedFakeAshProxy::AddDisplay(display::Display new_display) {
  displays_.push_back(new_display);
  return displays_.back();
}

void ScopedFakeAshProxy::RemoveDisplay(DisplayId id) {
  for (auto it = displays_.begin(); it != displays_.end(); it++) {
    if (it->id() == id) {
      displays_.erase(it);
      return;
    }
  }

  NOTREACHED();
}

void ScopedFakeAshProxy::UpdateDisplaySpec(DisplayId id,
                                           const std::string& spec) {
  RemoveDisplay(id);
  AddDisplayFromSpecWithId(spec, id);
}

void ScopedFakeAshProxy::UpdatePrimaryDisplaySpec(const std::string& spec) {
  UpdateDisplaySpec(GetPrimaryDisplayId(), spec);
}

DisplayId ScopedFakeAshProxy::GetPrimaryDisplayId() const {
  return primary_display_id_;
}

bool ScopedFakeAshProxy::HasPrimaryDisplay() const {
  return primary_display_id_ != -1;
}

const std::vector<display::Display>& ScopedFakeAshProxy::GetActiveDisplays()
    const {
  return displays_;
}

const display::Display* ScopedFakeAshProxy::GetDisplayForId(
    DisplayId display_id) const {
  for (const auto& display : displays_) {
    if (display_id == display.id()) {
      return &display;
    }
  }
  return nullptr;
}

aura::Window* ScopedFakeAshProxy::GetSelectFileContainer() {
  return nullptr;
}

void ScopedFakeAshProxy::CreateVideoCapturer(
    mojo::PendingReceiver<viz::mojom::FrameSinkVideoCapturer> video_capturer) {
  DCHECK(receiver_) << "Your test must call SetVideoCapturerReceiver() first";

  receiver_->Bind(std::move(video_capturer));
}

aura::ScopedWindowCaptureRequest ScopedFakeAshProxy::MakeDisplayCapturable(
    DisplayId source_display_id) {
  return aura::ScopedWindowCaptureRequest();
}

viz::FrameSinkId ScopedFakeAshProxy::GetFrameSinkId(
    DisplayId source_display_id) {
  return viz::FrameSinkId(source_display_id, source_display_id);
}

void ScopedFakeAshProxy::SetVideoCapturerReceiver(
    mojo::Receiver<viz::mojom::FrameSinkVideoCapturer>* receiver) {
  receiver_ = receiver;
}

ash::curtain::SecurityCurtainController&
ScopedFakeAshProxy::GetSecurityCurtainController() {
  DCHECK(security_curtain_controller_)
      << "Your test must pass a SecurityCurtainController to the constructor "
         "of ScopedFakeAshProxy before it can be used.";
  return *security_curtain_controller_;
}

void ScopedFakeAshProxy::RequestSignOut() {
  request_sign_out_count_++;
}

int ScopedFakeAshProxy::request_sign_out_count() const {
  return request_sign_out_count_;
}

bool ScopedFakeAshProxy::IsScreenReaderEnabled() const {
  return false;
}

}  // namespace remoting::test