Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Side by Side Diff: remoting/protocol/http_ice_config_request_unittest.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/protocol/http_ice_config_request.h" 5 #include "remoting/protocol/http_ice_config_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ptr_util.h"
9 #include "remoting/base/url_request.h" 10 #include "remoting/base/url_request.h"
10 #include "remoting/protocol/ice_config.h" 11 #include "remoting/protocol/ice_config.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 namespace protocol { 15 namespace protocol {
15 16
16 namespace { 17 namespace {
17 18
18 class FakeUrlRequest : public UrlRequest { 19 class FakeUrlRequest : public UrlRequest {
(...skipping 21 matching lines...) Expand all
40 class FakeUrlRequestFactory : public UrlRequestFactory { 41 class FakeUrlRequestFactory : public UrlRequestFactory {
41 public: 42 public:
42 FakeUrlRequestFactory() {} 43 FakeUrlRequestFactory() {}
43 ~FakeUrlRequestFactory() override {} 44 ~FakeUrlRequestFactory() override {}
44 45
45 void SetResult(const std::string& url, const UrlRequest::Result& result) { 46 void SetResult(const std::string& url, const UrlRequest::Result& result) {
46 results_[url] = result; 47 results_[url] = result;
47 } 48 }
48 49
49 // UrlRequestFactory interface. 50 // UrlRequestFactory interface.
50 scoped_ptr<UrlRequest> CreateUrlRequest(UrlRequest::Type type, 51 std::unique_ptr<UrlRequest> CreateUrlRequest(
51 const std::string& url) override { 52 UrlRequest::Type type,
53 const std::string& url) override {
52 EXPECT_EQ(UrlRequest::Type::POST, type); 54 EXPECT_EQ(UrlRequest::Type::POST, type);
53 CHECK(results_.count(url)); 55 CHECK(results_.count(url));
54 return make_scoped_ptr(new FakeUrlRequest(results_[url])); 56 return base::WrapUnique(new FakeUrlRequest(results_[url]));
55 } 57 }
56 58
57 std::map<std::string, UrlRequest::Result> results_; 59 std::map<std::string, UrlRequest::Result> results_;
58 }; 60 };
59 61
60 bool operator==(const cricket::ProtocolAddress& a, 62 bool operator==(const cricket::ProtocolAddress& a,
61 const cricket::ProtocolAddress& b) { 63 const cricket::ProtocolAddress& b) {
62 return a.address == b.address && a.proto == b.proto && a.secure == b.secure; 64 return a.address == b.address && a.proto == b.proto && a.secure == b.secure;
63 } 65 }
64 bool operator==(const cricket::RelayServerConfig& a, 66 bool operator==(const cricket::RelayServerConfig& a,
65 const cricket::RelayServerConfig& b) { 67 const cricket::RelayServerConfig& b) {
66 if (a.ports.size() != b.ports.size()) 68 if (a.ports.size() != b.ports.size())
67 return false; 69 return false;
68 for (size_t i = 0; i < a.ports.size(); ++i) { 70 for (size_t i = 0; i < a.ports.size(); ++i) {
69 if (!(a.ports[i] == b.ports[i])) 71 if (!(a.ports[i] == b.ports[i]))
70 return false; 72 return false;
71 } 73 }
72 return a.type == b.type && 74 return a.type == b.type &&
73 a.credentials.username == b.credentials.username && 75 a.credentials.username == b.credentials.username &&
74 a.credentials.password == b.credentials.password; 76 a.credentials.password == b.credentials.password;
75 } 77 }
76 78
77 } // namespace 79 } // namespace
78 80
79 static const char kTestUrl[] = "http://host/ice_config"; 81 static const char kTestUrl[] = "http://host/ice_config";
80 82
81 class HttpIceConfigRequestTest : public testing::Test { 83 class HttpIceConfigRequestTest : public testing::Test {
82 public: 84 public:
83 void OnResult(const IceConfig& config) { 85 void OnResult(const IceConfig& config) {
84 received_config_ = make_scoped_ptr(new IceConfig(config)); 86 received_config_ = base::WrapUnique(new IceConfig(config));
85 } 87 }
86 88
87 protected: 89 protected:
88 FakeUrlRequestFactory url_request_factory_; 90 FakeUrlRequestFactory url_request_factory_;
89 scoped_ptr<HttpIceConfigRequest> request_; 91 std::unique_ptr<HttpIceConfigRequest> request_;
90 scoped_ptr<IceConfig> received_config_; 92 std::unique_ptr<IceConfig> received_config_;
91 }; 93 };
92 94
93 TEST_F(HttpIceConfigRequestTest, Parse) { 95 TEST_F(HttpIceConfigRequestTest, Parse) {
94 const char kTestResponse[] = 96 const char kTestResponse[] =
95 "{" 97 "{"
96 " \"lifetimeDuration\": \"43200.000s\"," 98 " \"lifetimeDuration\": \"43200.000s\","
97 " \"iceServers\": [" 99 " \"iceServers\": ["
98 " {" 100 " {"
99 " \"urls\": [" 101 " \"urls\": ["
100 " \"turn:8.8.8.8:19234\"," 102 " \"turn:8.8.8.8:19234\","
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 TEST_F(HttpIceConfigRequestTest, FailedRequest) { 204 TEST_F(HttpIceConfigRequestTest, FailedRequest) {
203 url_request_factory_.SetResult(kTestUrl, UrlRequest::Result::Failed()); 205 url_request_factory_.SetResult(kTestUrl, UrlRequest::Result::Failed());
204 request_.reset(new HttpIceConfigRequest(&url_request_factory_, kTestUrl)); 206 request_.reset(new HttpIceConfigRequest(&url_request_factory_, kTestUrl));
205 request_->Send( 207 request_->Send(
206 base::Bind(&HttpIceConfigRequestTest::OnResult, base::Unretained(this))); 208 base::Bind(&HttpIceConfigRequestTest::OnResult, base::Unretained(this)));
207 EXPECT_TRUE(received_config_->is_null()); 209 EXPECT_TRUE(received_config_->is_null());
208 } 210 }
209 211
210 } // namespace protocol 212 } // namespace protocol
211 } // namespace remoting 213 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/http_ice_config_request.cc ('k') | remoting/protocol/ice_connection_to_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698