forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_api_bindings.h
58 lines (46 loc) · 2.16 KB
/
fake_api_bindings.h
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
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FUCHSIA_WEB_RUNNERS_CAST_FAKE_API_BINDINGS_H_
#define FUCHSIA_WEB_RUNNERS_CAST_FAKE_API_BINDINGS_H_
#include <string>
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/containers/flat_map.h"
#include "base/strings/string_piece.h"
#include "fuchsia_web/runners/cast/fidl/fidl/chromium/cast/cpp/fidl.h"
// Simple implementation of the ApiBindings service, for use by tests.
class FakeApiBindingsImpl : public chromium::cast::ApiBindings {
public:
FakeApiBindingsImpl();
~FakeApiBindingsImpl() override;
FakeApiBindingsImpl(const FakeApiBindingsImpl&) = delete;
FakeApiBindingsImpl& operator=(const FakeApiBindingsImpl&) = delete;
// Returns the message port with the specified |name|. Runs the message loop
// if a port of the specified name has not yet been received, and returns an
// invalid handle if that times out before a |Connect()| call is received.
fidl::InterfaceHandle<fuchsia::web::MessagePort> RunAndReturnConnectedPort(
base::StringPiece name);
// Sets the list of bindings which will be returned by GetAll().
void set_bindings(std::vector<chromium::cast::ApiBinding> bindings) {
bindings_ = std::move(bindings);
}
private:
// chromium::cast::ApiBindings implementation.
void GetAll(GetAllCallback callback) override;
void Connect(
std::string name,
fidl::InterfaceHandle<fuchsia::web::MessagePort> message_port) override;
// Bindings to return from GetAll().
std::vector<chromium::cast::ApiBinding> bindings_;
// Holds ports received via Connect(), for tests to take by calling
// RunAndReturnConnectedPort(). Uses std::less<> as the comparator so that
// StringPieces can be used for lookup without requiring a conversion.
base::flat_map<std::string, fidl::InterfaceHandle<fuchsia::web::MessagePort>>
ports_;
// Used to wait for a specific port to be Connect()ed.
base::StringPiece expected_port_name_;
base::OnceClosure on_expected_port_received_;
};
#endif // FUCHSIA_WEB_RUNNERS_CAST_FAKE_API_BINDINGS_H_