OLD | NEW |
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/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_function_test_utils.h" | |
10 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
12 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/extensions/application_launch.h" | 12 #include "chrome/browser/ui/extensions/application_launch.h" |
14 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
17 #include "extensions/browser/api/dns/host_resolver_wrapper.h" | 16 #include "extensions/browser/api/dns/host_resolver_wrapper.h" |
18 #include "extensions/browser/api/dns/mock_host_resolver_creator.h" | 17 #include "extensions/browser/api/dns/mock_host_resolver_creator.h" |
19 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" | 18 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" |
20 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
21 #include "net/test/spawned_test_server/spawned_test_server.h" | 20 #include "net/test/spawned_test_server/spawned_test_server.h" |
22 | 21 |
23 using extensions::Extension; | |
24 | |
25 namespace utils = extension_function_test_utils; | |
26 | |
27 namespace { | 22 namespace { |
28 | 23 |
29 // TODO(jschuh): Hanging plugin tests. crbug.com/244653 | 24 // TODO(jschuh): Hanging plugin tests. crbug.com/244653 |
30 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | 25 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) |
31 #define MAYBE(x) DISABLED_##x | 26 #define MAYBE(x) DISABLED_##x |
32 #else | 27 #else |
33 #define MAYBE(x) x | 28 #define MAYBE(x) x |
34 #endif | 29 #endif |
35 | 30 |
36 const std::string kHostname = "127.0.0.1"; | 31 const std::string kHostname = "127.0.0.1"; |
(...skipping 20 matching lines...) Expand all Loading... |
57 base::WaitableEvent resolver_event_; | 52 base::WaitableEvent resolver_event_; |
58 | 53 |
59 // The MockHostResolver asserts that it's used on the same thread on which | 54 // 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. | 55 // it's created, which is actually a stronger rule than its real counterpart. |
61 // But that's fine; it's good practice. | 56 // But that's fine; it's good practice. |
62 scoped_refptr<extensions::MockHostResolverCreator> resolver_creator_; | 57 scoped_refptr<extensions::MockHostResolverCreator> resolver_creator_; |
63 }; | 58 }; |
64 | 59 |
65 } // namespace | 60 } // namespace |
66 | 61 |
67 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketsTcpCreateGood) { | |
68 scoped_refptr<extensions::core_api::SocketsTcpCreateFunction> | |
69 socket_create_function( | |
70 new extensions::core_api::SocketsTcpCreateFunction()); | |
71 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | |
72 | |
73 socket_create_function->set_extension(empty_extension.get()); | |
74 socket_create_function->set_has_callback(true); | |
75 | |
76 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | |
77 socket_create_function.get(), "[]", browser(), utils::NONE)); | |
78 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); | |
79 base::DictionaryValue *value = | |
80 static_cast<base::DictionaryValue*>(result.get()); | |
81 int socketId = -1; | |
82 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); | |
83 ASSERT_TRUE(socketId > 0); | |
84 } | |
85 | |
86 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtension) { | 62 IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtension) { |
87 scoped_ptr<net::SpawnedTestServer> test_server( | 63 scoped_ptr<net::SpawnedTestServer> test_server( |
88 new net::SpawnedTestServer( | 64 new net::SpawnedTestServer( |
89 net::SpawnedTestServer::TYPE_TCP_ECHO, | 65 net::SpawnedTestServer::TYPE_TCP_ECHO, |
90 net::SpawnedTestServer::kLocalhost, | 66 net::SpawnedTestServer::kLocalhost, |
91 base::FilePath(FILE_PATH_LITERAL("net/data")))); | 67 base::FilePath(FILE_PATH_LITERAL("net/data")))); |
92 EXPECT_TRUE(test_server->Start()); | 68 EXPECT_TRUE(test_server->Start()); |
93 | 69 |
94 net::HostPortPair host_port_pair = test_server->host_port_pair(); | 70 net::HostPortPair host_port_pair = test_server->host_port_pair(); |
95 int port = host_port_pair.port(); | 71 int port = host_port_pair.port(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 104 |
129 ExtensionTestMessageListener listener("info_please", true); | 105 ExtensionTestMessageListener listener("info_please", true); |
130 | 106 |
131 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("sockets_tcp/api"))); | 107 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("sockets_tcp/api"))); |
132 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 108 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
133 listener.Reply(base::StringPrintf( | 109 listener.Reply(base::StringPrintf( |
134 "https:%s:%d", https_host_port_pair.host().c_str(), https_port)); | 110 "https:%s:%d", https_host_port_pair.host().c_str(), https_port)); |
135 | 111 |
136 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 112 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
137 } | 113 } |
OLD | NEW |