File: local_input_monitor_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (101 lines) | stat: -rw-r--r-- 3,272 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
// Copyright 2012 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/input_monitor/local_input_monitor.h"

#include <memory>

#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "remoting/host/client_session_control.h"
#include "remoting/host/host_mock_objects.h"
#include "remoting/protocol/protocol_mock_objects.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace remoting {

using testing::_;
using testing::AnyNumber;
using testing::ReturnRef;

namespace {

class LocalInputMonitorTest : public testing::Test {
 public:
  LocalInputMonitorTest();

  void SetUp() override;

  base::test::TaskEnvironment task_environment_ {
#if BUILDFLAG(IS_WIN)
    base::test::TaskEnvironment::MainThreadType::UI
#else   // !BUILDFLAG(IS_WIN)
    // Required to watch a file descriptor from NativeMessageProcessHost.
    base::test::TaskEnvironment::MainThreadType::IO
#endif  // !BUILDFLAG(IS_WIN)
  };

  scoped_refptr<base::SingleThreadTaskRunner> task_runner_;

  std::string client_jid_;
  MockClientSessionControl client_session_control_;
  base::WeakPtrFactory<ClientSessionControl> client_session_control_factory_;
};

LocalInputMonitorTest::LocalInputMonitorTest()
    : client_jid_("user@domain/rest-of-jid"),
      client_session_control_factory_(&client_session_control_) {}

void LocalInputMonitorTest::SetUp() {
  task_runner_ = task_environment_.GetMainThreadTaskRunner();
}

}  // namespace

// This test is really to exercise only the creation and destruction code in
// LocalInputMonitor.
TEST_F(LocalInputMonitorTest, BasicWithClientSession) {
  // Ignore all callbacks.
  EXPECT_CALL(client_session_control_, client_jid())
      .Times(AnyNumber())
      .WillRepeatedly(ReturnRef(client_jid_));
  EXPECT_CALL(client_session_control_, DisconnectSession(_, _, _))
      .Times(AnyNumber());
  EXPECT_CALL(client_session_control_, OnLocalPointerMoved(_, _))
      .Times(AnyNumber());
  EXPECT_CALL(client_session_control_, SetDisableInputs(_)).Times(0);

  {
    std::unique_ptr<LocalInputMonitor> local_input_monitor =
        LocalInputMonitor::Create(task_runner_, task_runner_, task_runner_);
    local_input_monitor->StartMonitoringForClientSession(
        client_session_control_factory_.GetWeakPtr());
  }

  task_runner_->PostTask(FROM_HERE, task_environment_.QuitClosure());
  task_environment_.RunUntilQuit();
}

TEST_F(LocalInputMonitorTest, BasicWithCallbacks) {
  // Ignore all callbacks.
  EXPECT_CALL(client_session_control_, client_jid())
      .Times(AnyNumber())
      .WillRepeatedly(ReturnRef(client_jid_));

  {
    std::unique_ptr<LocalInputMonitor> local_input_monitor =
        LocalInputMonitor::Create(task_runner_, task_runner_, task_runner_);
    local_input_monitor->StartMonitoring(base::DoNothing(), base::DoNothing(),
                                         base::DoNothing());
  }

  task_runner_->PostTask(FROM_HERE, task_environment_.QuitClosure());
  task_environment_.RunUntilQuit();
}

}  // namespace remoting