Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: chrome/browser/extensions/api/socket/socket_api_controller_unittest.cc

Issue 8857004: Delete UDPClientSocket on same thread as creation. Also refactor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to fix hunk failure. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/values.h" 8 #include "base/values.h"
8 #include "chrome/browser/extensions/api/socket/socket_api.h" 9 #include "chrome/browser/extensions/api/socket/socket_api.h"
9 #include "chrome/browser/extensions/api/socket/socket_api_controller.h" 10 #include "chrome/browser/extensions/api/socket/socket_api_controller.h"
10 11
11 namespace extensions { 12 namespace extensions {
12 13
13 class SocketApiControllerTest : public testing::Test { 14 class SocketApiControllerTest : public testing::Test {
14 }; 15 };
15 16
16 TEST_F(SocketApiControllerTest, TestSocketControllerLifetime) { 17 TEST_F(SocketApiControllerTest, TestSocketControllerLifetime) {
17 // 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
18 // sockets are alive doesn't crash. 19 // sockets are alive doesn't crash.
19 SocketController* controller = SocketController::GetInstance(); 20 scoped_ptr<SocketController> controller(new SocketController());
20 21
21 // Create some sockets but don't do anything with them. 22 // Create some sockets but don't do anything with them.
22 Profile* profile = NULL; 23 Profile* profile = NULL;
23 const std::string extension_id("xxxxxxxxx"); 24 const std::string extension_id("xxxxxxxxx");
24 const GURL url; 25 const GURL url;
25 for (int i = 0; i < 10; ++i) { 26 for (int i = 0; i < 10; ++i) {
26 int socket_id = controller->CreateUdp(profile, extension_id, url); 27 int socket_id = controller->CreateUdp(profile, extension_id, url);
27 ASSERT_TRUE(socket_id != 0); 28 ASSERT_TRUE(socket_id != 0);
28 } 29 }
29 30
30 // 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
31 // UDP, we can happily "connect" a UDP socket without anyone listening. 32 // UDP, we can happily "connect" a UDP socket without anyone listening.
32 const int kPort = 38888; 33 const int kPort = 38888;
33 const std::string address("127.0.0.1"); 34 const std::string address("127.0.0.1");
34 for (int i = 0; i < 10; ++i) { 35 for (int i = 0; i < 10; ++i) {
35 int socket_id = controller->CreateUdp(profile, extension_id, url); 36 int socket_id = controller->CreateUdp(profile, extension_id, url);
36 ASSERT_TRUE(socket_id != 0); 37 ASSERT_TRUE(socket_id != 0);
37 ASSERT_TRUE(controller->ConnectUdp(socket_id, address, kPort)); 38 ASSERT_TRUE(controller->ConnectUdp(socket_id, address, kPort));
38 } 39 }
39
40 // At this point, we're done, and we're relying on the RAE mechanism
41 // of the Singleton class to delete the controller at process exit.
42 // We'd have to jump through some icky hoops to turn off RAE and
43 // manually delete in this test method, so we'll instead take it on
44 // faith that the singleton will indeed delete itself, and that if
45 // we had any heap management problems in the controller, they'd
46 // show up later in this test process. I (miket) hereby confirm that
47 // I manually added a temporary double-free in the controller
48 // destructor and verified that the unit_tests process segfaulted.
49 } 40 }
50 41
51 } // namespace extensions 42 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/socket/socket_api_controller.cc ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698