OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "extensions/browser/api/dns/host_resolver_wrapper.h" | 7 #include "extensions/browser/api/dns/host_resolver_wrapper.h" |
8 #include "extensions/browser/api/dns/mock_host_resolver_creator.h" | 8 #include "extensions/browser/api/dns/mock_host_resolver_creator.h" |
9 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" | 9 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" |
10 #include "extensions/browser/api_test_utils.h" | 10 #include "extensions/browser/api_test_utils.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 base::DictionaryValue::From(result.Pass()); | 67 base::DictionaryValue::From(result.Pass()); |
68 int socketId = -1; | 68 int socketId = -1; |
69 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); | 69 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); |
70 ASSERT_TRUE(socketId > 0); | 70 ASSERT_TRUE(socketId > 0); |
71 } | 71 } |
72 | 72 |
73 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtension) { | 73 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtension) { |
74 scoped_ptr<net::SpawnedTestServer> test_server(new net::SpawnedTestServer( | 74 scoped_ptr<net::SpawnedTestServer> test_server(new net::SpawnedTestServer( |
75 net::SpawnedTestServer::TYPE_TCP_ECHO, net::SpawnedTestServer::kLocalhost, | 75 net::SpawnedTestServer::TYPE_TCP_ECHO, net::SpawnedTestServer::kLocalhost, |
76 base::FilePath(FILE_PATH_LITERAL("net/data")))); | 76 base::FilePath(FILE_PATH_LITERAL("net/data")))); |
| 77 |
77 EXPECT_TRUE(test_server->Start()); | 78 EXPECT_TRUE(test_server->Start()); |
78 | 79 |
79 net::HostPortPair host_port_pair = test_server->host_port_pair(); | 80 net::HostPortPair host_port_pair = test_server->host_port_pair(); |
80 int port = host_port_pair.port(); | 81 int port = host_port_pair.port(); |
81 ASSERT_TRUE(port > 0); | 82 ASSERT_TRUE(port > 0); |
82 | 83 |
83 // Test that connect() is properly resolving hostnames. | 84 // Test that connect() is properly resolving hostnames. |
84 host_port_pair.set_host("lOcAlHoSt"); | 85 host_port_pair.set_host("lOcAlHoSt"); |
85 | 86 |
86 ResultCatcher catcher; | 87 ResultCatcher catcher; |
87 catcher.RestrictToBrowserContext(browser_context()); | 88 catcher.RestrictToBrowserContext(browser_context()); |
88 | 89 |
89 ExtensionTestMessageListener listener("info_please", true); | 90 ExtensionTestMessageListener listener("info_please", true); |
90 | 91 |
91 ASSERT_TRUE(LoadApp("sockets_tcp/api")); | 92 ASSERT_TRUE(LoadApp("sockets_tcp/api")); |
92 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 93 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
93 listener.Reply( | 94 listener.Reply( |
94 base::StringPrintf("tcp:%s:%d", host_port_pair.host().c_str(), port)); | 95 base::StringPrintf("tcp:%s:%d", host_port_pair.host().c_str(), port)); |
95 | 96 |
96 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 97 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
97 } | 98 } |
98 | 99 |
99 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtensionTLS) { | 100 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtensionTLS) { |
100 scoped_ptr<net::SpawnedTestServer> test_https_server( | 101 scoped_ptr<net::SpawnedTestServer> test_https_server( |
101 new net::SpawnedTestServer( | 102 new net::SpawnedTestServer( |
102 net::SpawnedTestServer::TYPE_HTTPS, net::BaseTestServer::SSLOptions(), | 103 net::SpawnedTestServer::TYPE_HTTPS, net::BaseTestServer::SSLOptions(), |
103 base::FilePath(FILE_PATH_LITERAL("net/data")))); | 104 base::FilePath(FILE_PATH_LITERAL("net/data")))); |
| 105 |
104 EXPECT_TRUE(test_https_server->Start()); | 106 EXPECT_TRUE(test_https_server->Start()); |
105 | 107 |
106 net::HostPortPair https_host_port_pair = test_https_server->host_port_pair(); | 108 net::HostPortPair https_host_port_pair = test_https_server->host_port_pair(); |
107 int https_port = https_host_port_pair.port(); | 109 int https_port = https_host_port_pair.port(); |
108 ASSERT_GT(https_port, 0); | 110 ASSERT_GT(https_port, 0); |
109 | 111 |
110 ResultCatcher catcher; | 112 ResultCatcher catcher; |
111 catcher.RestrictToBrowserContext(browser_context()); | 113 catcher.RestrictToBrowserContext(browser_context()); |
112 | 114 |
113 ExtensionTestMessageListener listener("info_please", true); | 115 ExtensionTestMessageListener listener("info_please", true); |
114 | 116 |
115 ASSERT_TRUE(LoadApp("sockets_tcp/api")); | 117 ASSERT_TRUE(LoadApp("sockets_tcp/api")); |
116 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 118 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
117 listener.Reply(base::StringPrintf( | 119 listener.Reply(base::StringPrintf( |
118 "https:%s:%d", https_host_port_pair.host().c_str(), https_port)); | 120 "https:%s:%d", https_host_port_pair.host().c_str(), https_port)); |
119 | 121 |
120 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 122 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
121 } | 123 } |
122 | 124 |
123 } // namespace extensions | 125 } // namespace extensions |
OLD | NEW |