| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/api/socket/socket_api.h" | 9 #include "chrome/browser/extensions/api/socket/socket_api.h" |
| 10 #include "chrome/browser/extensions/api/socket/socket_api_controller.h" | 10 #include "chrome/browser/extensions/api/socket/socket_api_controller.h" |
| 11 | 11 |
| 12 namespace extensions { | 12 namespace extensions { |
| 13 | 13 |
| 14 class SocketApiControllerTest : public testing::Test { | 14 class SocketApiControllerTest : public testing::Test { |
| 15 }; | 15 }; |
| 16 | 16 |
| 17 TEST_F(SocketApiControllerTest, TestSocketControllerLifetime) { | 17 TEST_F(SocketApiControllerTest, TestSocketControllerLifetime) { |
| 18 // We want to make sure that killing the controller while a bunch of | 18 // We want to make sure that killing the controller while a bunch of |
| 19 // sockets are alive doesn't crash. | 19 // sockets are alive doesn't crash. |
| 20 scoped_ptr<SocketController> controller(new SocketController()); | 20 scoped_ptr<SocketController> controller(new SocketController()); |
| 21 | 21 |
| 22 // Create some sockets but don't do anything with them. | 22 // Create some sockets but don't do anything with them. |
| 23 Profile* profile = NULL; | 23 Profile* profile = NULL; |
| 24 const std::string extension_id("xxxxxxxxx"); | 24 const std::string extension_id("xxxxxxxxx"); |
| 25 const GURL url; | 25 const GURL url; |
| 26 for (int i = 0; i < 10; ++i) { | 26 for (int i = 0; i < 10; ++i) { |
| 27 int socket_id = controller->CreateUdp(profile, extension_id, url); | 27 int socket_id = controller->CreateUdp(profile, extension_id, -1, url); |
| 28 ASSERT_TRUE(socket_id != 0); | 28 ASSERT_TRUE(socket_id != 0); |
| 29 } | 29 } |
| 30 | 30 |
| 31 // Create some more sockets and connect them. Note that because this is | 31 // Create some more sockets and connect them. Note that because this is |
| 32 // UDP, we can happily "connect" a UDP socket without anyone listening. | 32 // UDP, we can happily "connect" a UDP socket without anyone listening. |
| 33 const int kPort = 38888; | 33 const int kPort = 38888; |
| 34 const std::string address("127.0.0.1"); | 34 const std::string address("127.0.0.1"); |
| 35 for (int i = 0; i < 10; ++i) { | 35 for (int i = 0; i < 10; ++i) { |
| 36 int socket_id = controller->CreateUdp(profile, extension_id, url); | 36 int socket_id = controller->CreateUdp(profile, extension_id, -1, url); |
| 37 ASSERT_TRUE(socket_id != 0); | 37 ASSERT_TRUE(socket_id != 0); |
| 38 ASSERT_TRUE(controller->ConnectUdp(socket_id, address, kPort)); | 38 ASSERT_TRUE(controller->ConnectUdp(socket_id, address, kPort)); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace extensions | 42 } // namespace extensions |
| OLD | NEW |