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 "extensions/browser/api/dns/host_resolver_wrapper.h" | 5 #include "extensions/browser/api/dns/host_resolver_wrapper.h" |
6 #include "extensions/browser/api/dns/mock_host_resolver_creator.h" | 6 #include "extensions/browser/api/dns/mock_host_resolver_creator.h" |
7 #include "extensions/browser/api/socket/socket_api.h" | 7 #include "extensions/browser/api/socket/socket_api.h" |
8 #include "extensions/browser/api_test_utils.h" | 8 #include "extensions/browser/api_test_utils.h" |
9 #include "extensions/common/extension.h" | 9 #include "extensions/common/extension.h" |
10 #include "extensions/common/test_util.h" | 10 #include "extensions/common/test_util.h" |
11 #include "extensions/shell/test/shell_test.h" | 11 #include "extensions/shell/test/shell_test.h" |
12 | 12 |
13 using extensions::api_test_utils::RunFunctionAndReturnSingleResult; | 13 using extensions::api_test_utils::RunFunctionAndReturnSingleResult; |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 class SocketApiTest : public AppShellTest {}; | 17 class SocketApiTest : public AppShellTest {}; |
18 | 18 |
19 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketUDPCreateGood) { | 19 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketUDPCreateGood) { |
20 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( | 20 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( |
21 new extensions::SocketCreateFunction()); | 21 new extensions::SocketCreateFunction()); |
22 scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); | 22 scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); |
23 | 23 |
24 socket_create_function->set_extension(empty_extension.get()); | 24 socket_create_function->set_extension(empty_extension.get()); |
25 socket_create_function->set_has_callback(true); | 25 socket_create_function->set_has_callback(true); |
26 | 26 |
27 scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( | 27 scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( |
28 socket_create_function.get(), "[\"udp\"]", browser_context())); | 28 socket_create_function.get(), "[\"udp\"]", browser_context())); |
29 base::DictionaryValue* value = NULL; | 29 base::DictionaryValue* value = nullptr; |
30 ASSERT_TRUE(result->GetAsDictionary(&value)); | 30 ASSERT_TRUE(result->GetAsDictionary(&value)); |
31 int socket_id = -1; | 31 int socket_id = -1; |
32 EXPECT_TRUE(value->GetInteger("socketId", &socket_id)); | 32 EXPECT_TRUE(value->GetInteger("socketId", &socket_id)); |
33 EXPECT_GT(socket_id, 0); | 33 EXPECT_GT(socket_id, 0); |
34 } | 34 } |
35 | 35 |
36 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketTCPCreateGood) { | 36 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketTCPCreateGood) { |
37 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( | 37 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( |
38 new extensions::SocketCreateFunction()); | 38 new extensions::SocketCreateFunction()); |
39 scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); | 39 scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); |
40 | 40 |
41 socket_create_function->set_extension(empty_extension.get()); | 41 socket_create_function->set_extension(empty_extension.get()); |
42 socket_create_function->set_has_callback(true); | 42 socket_create_function->set_has_callback(true); |
43 | 43 |
44 scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( | 44 scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( |
45 socket_create_function.get(), "[\"tcp\"]", browser_context())); | 45 socket_create_function.get(), "[\"tcp\"]", browser_context())); |
46 base::DictionaryValue* value = NULL; | 46 base::DictionaryValue* value = nullptr; |
47 ASSERT_TRUE(result->GetAsDictionary(&value)); | 47 ASSERT_TRUE(result->GetAsDictionary(&value)); |
48 int socket_id = -1; | 48 int socket_id = -1; |
49 EXPECT_TRUE(value->GetInteger("socketId", &socket_id)); | 49 EXPECT_TRUE(value->GetInteger("socketId", &socket_id)); |
50 ASSERT_GT(socket_id, 0); | 50 ASSERT_GT(socket_id, 0); |
51 } | 51 } |
52 | 52 |
53 IN_PROC_BROWSER_TEST_F(SocketApiTest, GetNetworkList) { | 53 IN_PROC_BROWSER_TEST_F(SocketApiTest, GetNetworkList) { |
54 scoped_refptr<extensions::SocketGetNetworkListFunction> socket_function( | 54 scoped_refptr<extensions::SocketGetNetworkListFunction> socket_function( |
55 new extensions::SocketGetNetworkListFunction()); | 55 new extensions::SocketGetNetworkListFunction()); |
56 scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); | 56 scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); |
57 | 57 |
58 socket_function->set_extension(empty_extension.get()); | 58 socket_function->set_extension(empty_extension.get()); |
59 socket_function->set_has_callback(true); | 59 socket_function->set_has_callback(true); |
60 | 60 |
61 scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( | 61 scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( |
62 socket_function.get(), "[]", browser_context())); | 62 socket_function.get(), "[]", browser_context())); |
63 | 63 |
64 // If we're invoking socket tests, all we can confirm is that we have at | 64 // If we're invoking socket tests, all we can confirm is that we have at |
65 // least one address, but not what it is. | 65 // least one address, but not what it is. |
66 base::ListValue* value = NULL; | 66 base::ListValue* value = nullptr; |
67 ASSERT_TRUE(result->GetAsList(&value)); | 67 ASSERT_TRUE(result->GetAsList(&value)); |
68 ASSERT_GT(value->GetSize(), 0U); | 68 ASSERT_GT(value->GetSize(), 0U); |
69 } | 69 } |
70 | 70 |
71 } // namespace extensions | 71 } // namespace extensions |
OLD | NEW |