| OLD | NEW |
| 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/path_service.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/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/socket/socket_api.h" | 10 #include "chrome/browser/extensions/api/socket/socket_api.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketUDPCreateGood) { | 117 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketUDPCreateGood) { |
| 118 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( | 118 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( |
| 119 new extensions::SocketCreateFunction()); | 119 new extensions::SocketCreateFunction()); |
| 120 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 120 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
| 121 | 121 |
| 122 socket_create_function->set_extension(empty_extension.get()); | 122 socket_create_function->set_extension(empty_extension.get()); |
| 123 socket_create_function->set_has_callback(true); | 123 socket_create_function->set_has_callback(true); |
| 124 | 124 |
| 125 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 125 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 126 socket_create_function, | 126 socket_create_function.get(), "[\"udp\"]", browser(), utils::NONE)); |
| 127 "[\"udp\"]", | |
| 128 browser(), utils::NONE)); | |
| 129 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); | 127 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); |
| 130 DictionaryValue *value = static_cast<DictionaryValue*>(result.get()); | 128 DictionaryValue *value = static_cast<DictionaryValue*>(result.get()); |
| 131 int socketId = -1; | 129 int socketId = -1; |
| 132 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); | 130 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); |
| 133 EXPECT_TRUE(socketId > 0); | 131 EXPECT_TRUE(socketId > 0); |
| 134 } | 132 } |
| 135 | 133 |
| 136 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketTCPCreateGood) { | 134 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketTCPCreateGood) { |
| 137 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( | 135 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( |
| 138 new extensions::SocketCreateFunction()); | 136 new extensions::SocketCreateFunction()); |
| 139 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 137 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
| 140 | 138 |
| 141 socket_create_function->set_extension(empty_extension.get()); | 139 socket_create_function->set_extension(empty_extension.get()); |
| 142 socket_create_function->set_has_callback(true); | 140 socket_create_function->set_has_callback(true); |
| 143 | 141 |
| 144 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 142 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 145 socket_create_function, | 143 socket_create_function.get(), "[\"tcp\"]", browser(), utils::NONE)); |
| 146 "[\"tcp\"]", | |
| 147 browser(), utils::NONE)); | |
| 148 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); | 144 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); |
| 149 DictionaryValue *value = static_cast<DictionaryValue*>(result.get()); | 145 DictionaryValue *value = static_cast<DictionaryValue*>(result.get()); |
| 150 int socketId = -1; | 146 int socketId = -1; |
| 151 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); | 147 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); |
| 152 ASSERT_TRUE(socketId > 0); | 148 ASSERT_TRUE(socketId > 0); |
| 153 } | 149 } |
| 154 | 150 |
| 155 IN_PROC_BROWSER_TEST_F(SocketApiTest, GetNetworkList) { | 151 IN_PROC_BROWSER_TEST_F(SocketApiTest, GetNetworkList) { |
| 156 scoped_refptr<extensions::SocketGetNetworkListFunction> socket_function( | 152 scoped_refptr<extensions::SocketGetNetworkListFunction> socket_function( |
| 157 new extensions::SocketGetNetworkListFunction()); | 153 new extensions::SocketGetNetworkListFunction()); |
| 158 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 154 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
| 159 | 155 |
| 160 socket_function->set_extension(empty_extension.get()); | 156 socket_function->set_extension(empty_extension.get()); |
| 161 socket_function->set_has_callback(true); | 157 socket_function->set_has_callback(true); |
| 162 | 158 |
| 163 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 159 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 164 socket_function, "[]", browser(), utils::NONE)); | 160 socket_function.get(), "[]", browser(), utils::NONE)); |
| 165 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); | 161 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); |
| 166 | 162 |
| 167 // If we're invoking socket tests, all we can confirm is that we have at | 163 // If we're invoking socket tests, all we can confirm is that we have at |
| 168 // least one address, but not what it is. | 164 // least one address, but not what it is. |
| 169 ListValue *value = static_cast<ListValue*>(result.get()); | 165 ListValue *value = static_cast<ListValue*>(result.get()); |
| 170 ASSERT_TRUE(value->GetSize() > 0); | 166 ASSERT_TRUE(value->GetSize() > 0); |
| 171 } | 167 } |
| 172 | 168 |
| 173 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketUDPExtension) { | 169 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketUDPExtension) { |
| 174 scoped_ptr<net::SpawnedTestServer> test_server( | 170 scoped_ptr<net::SpawnedTestServer> test_server( |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 340 |
| 345 LaunchTestingApp(); | 341 LaunchTestingApp(); |
| 346 | 342 |
| 347 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 343 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 348 listener.Reply( | 344 listener.Reply( |
| 349 base::StringPrintf("multicast:%s:%d", kHostname.c_str(), kPort)); | 345 base::StringPrintf("multicast:%s:%d", kHostname.c_str(), kPort)); |
| 350 | 346 |
| 351 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 347 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 352 } | 348 } |
| 353 #endif | 349 #endif |
| OLD | NEW |