1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/http/http_proxy_client_socket.h"
6
7 #include "build/build_config.h"
8 #include "net/base/address_list.h"
9 #include "net/base/host_port_pair.h"
10 #include "net/base/proxy_server.h"
11 #include "net/socket/next_proto.h"
12 #include "net/socket/socket_tag.h"
13 #include "net/socket/socket_test_util.h"
14 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace net {
18
19 namespace {
20
TEST(HttpProxyClientSocketTest,Tag)21 TEST(HttpProxyClientSocketTest, Tag) {
22 StaticSocketDataProvider data;
23 auto tagging_sock = std::make_unique<MockTaggingStreamSocket>(
24 std::make_unique<MockTCPClientSocket>(AddressList(),
25 nullptr /* net_log */, &data));
26 auto* tagging_sock_ptr = tagging_sock.get();
27
28 // |socket| takes ownership of |tagging_sock|, but the test keeps a non-owning
29 // pointer to it.
30 HttpProxyClientSocket socket(
31 std::move(tagging_sock), /*user_agent=*/"", HostPortPair(), ProxyServer(),
32 /*http_auth_controller=*/nullptr,
33 /*proxy_delegate=*/nullptr, TRAFFIC_ANNOTATION_FOR_TESTS);
34
35 EXPECT_EQ(tagging_sock_ptr->tag(), SocketTag());
36 #if BUILDFLAG(IS_ANDROID)
37 SocketTag tag(0x12345678, 0x87654321);
38 socket.ApplySocketTag(tag);
39 EXPECT_EQ(tagging_sock_ptr->tag(), tag);
40 #endif // BUILDFLAG(IS_ANDROID)
41 }
42
43 } // namespace
44
45 } // namespace net
46