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

Side by Side Diff: chrome/browser/extensions/api/socket/socket_apitest.cc

Issue 13811036: Add Pepper API tests for chrome.socket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/stringprintf.h" 7 #include "base/stringprintf.h"
7 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h" 8 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h"
8 #include "chrome/browser/extensions/api/dns/mock_host_resolver_creator.h" 9 #include "chrome/browser/extensions/api/dns/mock_host_resolver_creator.h"
9 #include "chrome/browser/extensions/api/socket/socket_api.h" 10 #include "chrome/browser/extensions/api/socket/socket_api.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_function_test_utils.h" 12 #include "chrome/browser/extensions/extension_function_test_utils.h"
12 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_test_message_listener.h" 14 #include "chrome/browser/extensions/extension_test_message_listener.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/extensions/application_launch.h"
17 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
18 #include "net/dns/mock_host_resolver.h" 21 #include "net/dns/mock_host_resolver.h"
19 #include "net/test/test_server.h" 22 #include "net/test/test_server.h"
20 23
21 using extensions::Extension; 24 using extensions::Extension;
22 25
23 namespace utils = extension_function_test_utils; 26 namespace utils = extension_function_test_utils;
24 27
(...skipping 30 matching lines...) Expand all
55 58
56 private: 59 private:
57 base::WaitableEvent resolver_event_; 60 base::WaitableEvent resolver_event_;
58 61
59 // The MockHostResolver asserts that it's used on the same thread on which 62 // The MockHostResolver asserts that it's used on the same thread on which
60 // it's created, which is actually a stronger rule than its real counterpart. 63 // it's created, which is actually a stronger rule than its real counterpart.
61 // But that's fine; it's good practice. 64 // But that's fine; it's good practice.
62 scoped_refptr<extensions::MockHostResolverCreator> resolver_creator_; 65 scoped_refptr<extensions::MockHostResolverCreator> resolver_creator_;
63 }; 66 };
64 67
68 #if !defined(DISABLE_NACL)
69 // TODO(yzshen): Build testing framework for all extensions APIs in Pepper. And
70 // move these Pepper API tests there.
71 class SocketPpapiTest : public SocketApiTest {
72 public:
73 SocketPpapiTest() {
74 }
75 virtual ~SocketPpapiTest() {
76 }
77
78 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
79 SocketApiTest::SetUpCommandLine(command_line);
80 // TODO(yzshen): It is better to use switches::kEnablePepperTesting.
81 // However, that requires adding a new DEPS entry. Considering that we are
82 // going to move the Pepper API tests to a new place, use a string literal
83 // for now.
84 command_line->AppendSwitch("enable-pepper-testing");
85
86 PathService::Get(chrome::DIR_GEN_TEST_DATA, &app_dir_);
87 app_dir_ = app_dir_.AppendASCII(
88 "chrome/test/data/extensions/api_test/socket/ppapi/newlib");
89 }
90
91 protected:
92 void LaunchTestingApp() {
93 const Extension* extension = LoadExtension(app_dir_);
94 ASSERT_TRUE(extension);
95
96 chrome::AppLaunchParams params(browser()->profile(), extension,
97 extension_misc::LAUNCH_NONE,
98 NEW_WINDOW);
99 params.command_line = CommandLine::ForCurrentProcess();
100 chrome::OpenApplication(params);
101 }
102
103 private:
104 base::FilePath app_dir_;
105 };
106 #endif
107
65 } // namespace 108 } // namespace
66 109
67 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketUDPCreateGood) { 110 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketUDPCreateGood) {
68 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( 111 scoped_refptr<extensions::SocketCreateFunction> socket_create_function(
69 new extensions::SocketCreateFunction()); 112 new extensions::SocketCreateFunction());
70 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); 113 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
71 114
72 socket_create_function->set_extension(empty_extension.get()); 115 socket_create_function->set_extension(empty_extension.get());
73 socket_create_function->set_has_callback(true); 116 socket_create_function->set_has_callback(true);
74 117
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 LoadExtension(test_data_dir_.AppendASCII("socket/unload")); 235 LoadExtension(test_data_dir_.AppendASCII("socket/unload"));
193 ASSERT_TRUE(extension); 236 ASSERT_TRUE(extension);
194 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 237 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
195 238
196 UnloadExtension(extension->id()); 239 UnloadExtension(extension->id());
197 240
198 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("socket/unload"))) 241 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("socket/unload")))
199 << message_; 242 << message_;
200 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 243 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
201 } 244 }
245
246 #if !defined(DISABLE_NACL)
247 IN_PROC_BROWSER_TEST_F(SocketPpapiTest, UDP) {
248 scoped_ptr<net::TestServer> test_server(
249 new net::TestServer(net::TestServer::TYPE_UDP_ECHO,
250 net::TestServer::kLocalhost,
251 base::FilePath(FILE_PATH_LITERAL("net/data"))));
252 EXPECT_TRUE(test_server->Start());
253
254 net::HostPortPair host_port_pair = test_server->host_port_pair();
255 int port = host_port_pair.port();
256 ASSERT_TRUE(port > 0);
257
258 // Test that sendTo() is properly resolving hostnames.
259 host_port_pair.set_host("LOCALhost");
260
261 ResultCatcher catcher;
262 catcher.RestrictToProfile(browser()->profile());
263
264 ExtensionTestMessageListener listener("info_please", true);
265
266 LaunchTestingApp();
267
268 EXPECT_TRUE(listener.WaitUntilSatisfied());
269 listener.Reply(
270 base::StringPrintf("udp:%s:%d", host_port_pair.host().c_str(), port));
271
272 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
273 }
274
275 IN_PROC_BROWSER_TEST_F(SocketPpapiTest, TCP) {
276 scoped_ptr<net::TestServer> test_server(
277 new net::TestServer(net::TestServer::TYPE_TCP_ECHO,
278 net::TestServer::kLocalhost,
279 base::FilePath(FILE_PATH_LITERAL("net/data"))));
280 EXPECT_TRUE(test_server->Start());
281
282 net::HostPortPair host_port_pair = test_server->host_port_pair();
283 int port = host_port_pair.port();
284 ASSERT_TRUE(port > 0);
285
286 // Test that connect() is properly resolving hostnames.
287 host_port_pair.set_host("lOcAlHoSt");
288
289 ResultCatcher catcher;
290 catcher.RestrictToProfile(browser()->profile());
291
292 ExtensionTestMessageListener listener("info_please", true);
293
294 LaunchTestingApp();
295
296 EXPECT_TRUE(listener.WaitUntilSatisfied());
297 listener.Reply(
298 base::StringPrintf("tcp:%s:%d", host_port_pair.host().c_str(), port));
299
300 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
301 }
302
303 IN_PROC_BROWSER_TEST_F(SocketPpapiTest, TCPServer) {
304 ResultCatcher catcher;
305 catcher.RestrictToProfile(browser()->profile());
306 ExtensionTestMessageListener listener("info_please", true);
307
308 LaunchTestingApp();
309
310 EXPECT_TRUE(listener.WaitUntilSatisfied());
311 listener.Reply(
312 base::StringPrintf("tcp_server:%s:%d", kHostname.c_str(), kPort));
313
314 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
315 }
316 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698