[CleanUp] Move PowerApiManager to power_api and Rename
[chromium-blink-merge.git] / remoting / test / fake_port_allocator.cc
blobcabd67b3bc527112fa753a19039d0816f0e71783
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "remoting/test/fake_port_allocator.h"
7 #include "remoting/test/fake_network_dispatcher.h"
8 #include "remoting/test/fake_network_manager.h"
9 #include "remoting/test/fake_socket_factory.h"
11 namespace remoting {
13 namespace {
15 class FakePortAllocatorSession
16 : public cricket::HttpPortAllocatorSessionBase {
17 public:
18 FakePortAllocatorSession(
19 cricket::HttpPortAllocatorBase* allocator,
20 const std::string& content_name,
21 int component,
22 const std::string& ice_username_fragment,
23 const std::string& ice_password,
24 const std::vector<rtc::SocketAddress>& stun_hosts,
25 const std::vector<std::string>& relay_hosts,
26 const std::string& relay);
27 ~FakePortAllocatorSession() override;
29 // cricket::HttpPortAllocatorBase overrides.
30 void ConfigReady(cricket::PortConfiguration* config) override;
31 void SendSessionRequest(const std::string& host, int port) override;
33 private:
34 DISALLOW_COPY_AND_ASSIGN(FakePortAllocatorSession);
37 FakePortAllocatorSession::FakePortAllocatorSession(
38 cricket::HttpPortAllocatorBase* allocator,
39 const std::string& content_name,
40 int component,
41 const std::string& ice_username_fragment,
42 const std::string& ice_password,
43 const std::vector<rtc::SocketAddress>& stun_hosts,
44 const std::vector<std::string>& relay_hosts,
45 const std::string& relay)
46 : HttpPortAllocatorSessionBase(allocator,
47 content_name,
48 component,
49 ice_username_fragment,
50 ice_password,
51 stun_hosts,
52 relay_hosts,
53 relay,
54 std::string()) {
55 set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
56 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
57 cricket::PORTALLOCATOR_ENABLE_IPV6 |
58 cricket::PORTALLOCATOR_DISABLE_STUN |
59 cricket::PORTALLOCATOR_DISABLE_RELAY);
62 FakePortAllocatorSession::~FakePortAllocatorSession() {
65 void FakePortAllocatorSession::ConfigReady(
66 cricket::PortConfiguration* config) {
67 // Filter out non-UDP relay ports, so that we don't try using TCP.
68 for (cricket::PortConfiguration::RelayList::iterator relay =
69 config->relays.begin(); relay != config->relays.end(); ++relay) {
70 cricket::PortList filtered_ports;
71 for (cricket::PortList::iterator port =
72 relay->ports.begin(); port != relay->ports.end(); ++port) {
73 if (port->proto == cricket::PROTO_UDP) {
74 filtered_ports.push_back(*port);
77 relay->ports = filtered_ports;
79 cricket::BasicPortAllocatorSession::ConfigReady(config);
82 void FakePortAllocatorSession::SendSessionRequest(
83 const std::string& host,
84 int port) {
85 ReceiveSessionResponse(std::string());
88 } // namespace
90 // static
91 scoped_ptr<FakePortAllocator> FakePortAllocator::Create(
92 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher) {
93 scoped_ptr<FakePacketSocketFactory> socket_factory(
94 new FakePacketSocketFactory(fake_network_dispatcher.get()));
95 scoped_ptr<rtc::NetworkManager> network_manager(
96 new FakeNetworkManager(socket_factory->GetAddress()));
98 return make_scoped_ptr(
99 new FakePortAllocator(network_manager.Pass(), socket_factory.Pass()));
102 FakePortAllocator::FakePortAllocator(
103 scoped_ptr<rtc::NetworkManager> network_manager,
104 scoped_ptr<FakePacketSocketFactory> socket_factory)
105 : HttpPortAllocatorBase(network_manager.get(),
106 socket_factory.get(),
107 std::string()),
108 network_manager_(network_manager.Pass()),
109 socket_factory_(socket_factory.Pass()) {}
111 FakePortAllocator::~FakePortAllocator() {
114 cricket::PortAllocatorSession* FakePortAllocator::CreateSessionInternal(
115 const std::string& content_name,
116 int component,
117 const std::string& ice_username_fragment,
118 const std::string& ice_password) {
119 return new FakePortAllocatorSession(
120 this, content_name, component, ice_username_fragment, ice_password,
121 stun_hosts(), relay_hosts(), relay_token());
124 } // namespace remoting