Ensure that media requests from Chrome Extension/WebUI pages can be auto-granted
[chromium-blink-merge.git] / remoting / test / fake_port_allocator.cc
blobd63243f980b3f58694e99b7ed9adfd56be212cde
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()) {
57 FakePortAllocatorSession::~FakePortAllocatorSession() {
60 void FakePortAllocatorSession::ConfigReady(
61 cricket::PortConfiguration* config) {
62 // Filter out non-UDP relay ports, so that we don't try using TCP.
63 for (cricket::PortConfiguration::RelayList::iterator relay =
64 config->relays.begin(); relay != config->relays.end(); ++relay) {
65 cricket::PortList filtered_ports;
66 for (cricket::PortList::iterator port =
67 relay->ports.begin(); port != relay->ports.end(); ++port) {
68 if (port->proto == cricket::PROTO_UDP) {
69 filtered_ports.push_back(*port);
72 relay->ports = filtered_ports;
74 cricket::BasicPortAllocatorSession::ConfigReady(config);
77 void FakePortAllocatorSession::SendSessionRequest(
78 const std::string& host,
79 int port) {
80 ReceiveSessionResponse(std::string());
83 } // namespace
85 // static
86 scoped_ptr<FakePortAllocator> FakePortAllocator::Create(
87 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher) {
88 scoped_ptr<FakePacketSocketFactory> socket_factory(
89 new FakePacketSocketFactory(fake_network_dispatcher.get()));
90 scoped_ptr<rtc::NetworkManager> network_manager(
91 new FakeNetworkManager(socket_factory->GetAddress()));
93 return make_scoped_ptr(
94 new FakePortAllocator(network_manager.Pass(), socket_factory.Pass()));
97 FakePortAllocator::FakePortAllocator(
98 scoped_ptr<rtc::NetworkManager> network_manager,
99 scoped_ptr<FakePacketSocketFactory> socket_factory)
100 : HttpPortAllocatorBase(network_manager.get(),
101 socket_factory.get(),
102 std::string()),
103 network_manager_(network_manager.Pass()),
104 socket_factory_(socket_factory.Pass()) {
105 set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
106 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
107 cricket::PORTALLOCATOR_ENABLE_IPV6 |
108 cricket::PORTALLOCATOR_DISABLE_STUN |
109 cricket::PORTALLOCATOR_DISABLE_RELAY);
112 FakePortAllocator::~FakePortAllocator() {
115 cricket::PortAllocatorSession* FakePortAllocator::CreateSessionInternal(
116 const std::string& content_name,
117 int component,
118 const std::string& ice_username_fragment,
119 const std::string& ice_password) {
120 return new FakePortAllocatorSession(
121 this, content_name, component, ice_username_fragment, ice_password,
122 stun_hosts(), relay_hosts(), relay_token());
125 } // namespace remoting