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/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
18 #include "extensions/browser/api/dns/host_resolver_wrapper.h" | 17 #include "extensions/browser/api/dns/host_resolver_wrapper.h" |
19 #include "extensions/browser/api/dns/mock_host_resolver_creator.h" | 18 #include "extensions/browser/api/dns/mock_host_resolver_creator.h" |
20 #include "extensions/browser/api/sockets_udp/sockets_udp_api.h" | 19 #include "extensions/browser/api/sockets_udp/sockets_udp_api.h" |
21 #include "net/dns/mock_host_resolver.h" | 20 #include "net/dns/mock_host_resolver.h" |
22 #include "net/test/spawned_test_server/spawned_test_server.h" | 21 #include "net/test/spawned_test_server/spawned_test_server.h" |
23 | 22 |
24 using extensions::Extension; | 23 using extensions::Extension; |
25 | 24 |
26 namespace utils = extension_function_test_utils; | |
27 | |
28 namespace { | 25 namespace { |
29 | 26 |
30 // TODO(jschuh): Hanging plugin tests. crbug.com/244653 | 27 // TODO(jschuh): Hanging plugin tests. crbug.com/244653 |
31 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | 28 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) |
32 #define MAYBE(x) DISABLED_##x | 29 #define MAYBE(x) DISABLED_##x |
33 #else | 30 #else |
34 #define MAYBE(x) x | 31 #define MAYBE(x) x |
35 #endif | 32 #endif |
36 | 33 |
37 const std::string kHostname = "127.0.0.1"; | 34 const std::string kHostname = "127.0.0.1"; |
(...skipping 21 matching lines...) Expand all Loading... |
59 base::WaitableEvent resolver_event_; | 56 base::WaitableEvent resolver_event_; |
60 | 57 |
61 // The MockHostResolver asserts that it's used on the same thread on which | 58 // The MockHostResolver asserts that it's used on the same thread on which |
62 // it's created, which is actually a stronger rule than its real counterpart. | 59 // it's created, which is actually a stronger rule than its real counterpart. |
63 // But that's fine; it's good practice. | 60 // But that's fine; it's good practice. |
64 scoped_refptr<extensions::MockHostResolverCreator> resolver_creator_; | 61 scoped_refptr<extensions::MockHostResolverCreator> resolver_creator_; |
65 }; | 62 }; |
66 | 63 |
67 } // namespace | 64 } // namespace |
68 | 65 |
69 IN_PROC_BROWSER_TEST_F(SocketsUdpApiTest, SocketsUdpCreateGood) { | |
70 scoped_refptr<extensions::core_api::SocketsUdpCreateFunction> | |
71 socket_create_function( | |
72 new extensions::core_api::SocketsUdpCreateFunction()); | |
73 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | |
74 | |
75 socket_create_function->set_extension(empty_extension.get()); | |
76 socket_create_function->set_has_callback(true); | |
77 | |
78 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | |
79 socket_create_function.get(), "[]", browser(), utils::NONE)); | |
80 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); | |
81 base::DictionaryValue *value = | |
82 static_cast<base::DictionaryValue*>(result.get()); | |
83 int socketId = -1; | |
84 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); | |
85 EXPECT_TRUE(socketId > 0); | |
86 } | |
87 | |
88 IN_PROC_BROWSER_TEST_F(SocketsUdpApiTest, SocketsUdpExtension) { | 66 IN_PROC_BROWSER_TEST_F(SocketsUdpApiTest, SocketsUdpExtension) { |
89 scoped_ptr<net::SpawnedTestServer> test_server( | 67 scoped_ptr<net::SpawnedTestServer> test_server( |
90 new net::SpawnedTestServer( | 68 new net::SpawnedTestServer( |
91 net::SpawnedTestServer::TYPE_UDP_ECHO, | 69 net::SpawnedTestServer::TYPE_UDP_ECHO, |
92 net::SpawnedTestServer::kLocalhost, | 70 net::SpawnedTestServer::kLocalhost, |
93 base::FilePath(FILE_PATH_LITERAL("net/data")))); | 71 base::FilePath(FILE_PATH_LITERAL("net/data")))); |
94 EXPECT_TRUE(test_server->Start()); | 72 EXPECT_TRUE(test_server->Start()); |
95 | 73 |
96 net::HostPortPair host_port_pair = test_server->host_port_pair(); | 74 net::HostPortPair host_port_pair = test_server->host_port_pair(); |
97 int port = host_port_pair.port(); | 75 int port = host_port_pair.port(); |
(...skipping 19 matching lines...) Expand all Loading... |
117 ResultCatcher catcher; | 95 ResultCatcher catcher; |
118 catcher.RestrictToProfile(browser()->profile()); | 96 catcher.RestrictToProfile(browser()->profile()); |
119 ExtensionTestMessageListener listener("info_please", true); | 97 ExtensionTestMessageListener listener("info_please", true); |
120 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("sockets_udp/api"))); | 98 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("sockets_udp/api"))); |
121 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 99 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
122 listener.Reply( | 100 listener.Reply( |
123 base::StringPrintf("multicast:%s:%d", kHostname.c_str(), kPort)); | 101 base::StringPrintf("multicast:%s:%d", kHostname.c_str(), kPort)); |
124 | 102 |
125 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 103 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
126 } | 104 } |
OLD | NEW |