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_chain.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(), ProxyChain(),
32 /*proxy_chain_index=*/0,
33 /*http_auth_controller=*/nullptr,
34 /*proxy_delegate=*/nullptr, TRAFFIC_ANNOTATION_FOR_TESTS);
35
36 EXPECT_EQ(tagging_sock_ptr->tag(), SocketTag());
37 #if BUILDFLAG(IS_ANDROID)
38 SocketTag tag(0x12345678, 0x87654321);
39 socket.ApplySocketTag(tag);
40 EXPECT_EQ(tagging_sock_ptr->tag(), tag);
41 #endif // BUILDFLAG(IS_ANDROID)
42 }
43
44 } // namespace
45
46 } // namespace net
47