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

Side by Side Diff: chrome/browser/extensions/api/sockets_tcp/sockets_tcp_apitest.cc

Issue 76403004: An implementation of chrome.socket.secure(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: An un-DCHECK-ification, a new test, a test clarification, and a lot of nit-double-spaces. Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/path_service.h" 6 #include "base/path_service.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h" 8 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h"
9 #include "chrome/browser/extensions/api/dns/mock_host_resolver_creator.h" 9 #include "chrome/browser/extensions/api/dns/mock_host_resolver_creator.h"
10 #include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h" 10 #include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); 81 EXPECT_TRUE(value->GetInteger("socketId", &socketId));
82 ASSERT_TRUE(socketId > 0); 82 ASSERT_TRUE(socketId > 0);
83 } 83 }
84 84
85 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtension) { 85 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtension) {
86 scoped_ptr<net::SpawnedTestServer> test_server( 86 scoped_ptr<net::SpawnedTestServer> test_server(
87 new net::SpawnedTestServer( 87 new net::SpawnedTestServer(
88 net::SpawnedTestServer::TYPE_TCP_ECHO, 88 net::SpawnedTestServer::TYPE_TCP_ECHO,
89 net::SpawnedTestServer::kLocalhost, 89 net::SpawnedTestServer::kLocalhost,
90 base::FilePath(FILE_PATH_LITERAL("net/data")))); 90 base::FilePath(FILE_PATH_LITERAL("net/data"))));
91 EXPECT_TRUE(test_server->Start()); 91
92 // Start them in parallel.
93 EXPECT_TRUE(test_server->StartInBackground());
94 EXPECT_TRUE(test_server->BlockUntilStarted());
92 95
93 net::HostPortPair host_port_pair = test_server->host_port_pair(); 96 net::HostPortPair host_port_pair = test_server->host_port_pair();
94 int port = host_port_pair.port(); 97 int port = host_port_pair.port();
95 ASSERT_TRUE(port > 0); 98 ASSERT_TRUE(port > 0);
96 99
97 // Test that connect() is properly resolving hostnames. 100 // Test that connect() is properly resolving hostnames.
98 host_port_pair.set_host("lOcAlHoSt"); 101 host_port_pair.set_host("lOcAlHoSt");
99 102
100 ResultCatcher catcher; 103 ResultCatcher catcher;
101 catcher.RestrictToProfile(browser()->profile()); 104 catcher.RestrictToProfile(browser()->profile());
102 105
103 ExtensionTestMessageListener listener("info_please", true); 106 ExtensionTestMessageListener listener("info_please", true);
104 107
105 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("sockets_tcp/api"))); 108 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("sockets_tcp/api")));
106 EXPECT_TRUE(listener.WaitUntilSatisfied()); 109 EXPECT_TRUE(listener.WaitUntilSatisfied());
107 listener.Reply( 110 listener.Reply(
108 base::StringPrintf("tcp:%s:%d", host_port_pair.host().c_str(), port)); 111 base::StringPrintf("tcp:%s:%d", host_port_pair.host().c_str(), port));
109 112
110 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 113 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
111 } 114 }
115
116 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtensionTLS) {
117 scoped_ptr<net::SpawnedTestServer> test_tcp_server(new net::SpawnedTestServer(
118 net::SpawnedTestServer::TYPE_TCP_ECHO,
119 net::SpawnedTestServer::kLocalhost,
120 base::FilePath(FILE_PATH_LITERAL("net/data"))));
121 scoped_ptr<net::SpawnedTestServer> test_https_server(
122 new net::SpawnedTestServer(
123 net::SpawnedTestServer::TYPE_HTTPS,
124 net::BaseTestServer::SSLOptions(),
125 base::FilePath(FILE_PATH_LITERAL("net/data"))));
126 // Start the servers in parallel.
127 EXPECT_TRUE(test_tcp_server->StartInBackground());
128 EXPECT_TRUE(test_https_server->StartInBackground());
129 EXPECT_TRUE(test_tcp_server->BlockUntilStarted());
130 EXPECT_TRUE(test_https_server->BlockUntilStarted());
131
132 net::HostPortPair tcp_host_port_pair = test_tcp_server->host_port_pair();
133 int tcp_port = tcp_host_port_pair.port();
134 ASSERT_TRUE(tcp_port > 0);
135
136 net::HostPortPair https_host_port_pair = test_https_server->host_port_pair();
137 int https_port = https_host_port_pair.port();
138 ASSERT_TRUE(https_port > 0);
139
140 // Test that connect() is properly resolving hostnames.
141 tcp_host_port_pair.set_host("lOcAlHoSt");
142
143 ResultCatcher catcher;
144 catcher.RestrictToProfile(browser()->profile());
145
146 ExtensionTestMessageListener listener("info_please", true);
147
148 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("sockets_tcp/api")));
149 EXPECT_TRUE(listener.WaitUntilSatisfied());
150 listener.Reply(base::StringPrintf("tcp:%s:%d,https:%s:%d",
151 tcp_host_port_pair.host().c_str(),
152 tcp_port,
153 https_host_port_pair.host().c_str(),
154 https_port));
155
156 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698