| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "ipc/ipc_test_base.h" | 7 #include "ipc/ipc_test_base.h" |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 return test_client_name + "__Channel"; | 22 return test_client_name + "__Channel"; |
| 23 } | 23 } |
| 24 | 24 |
| 25 IPCTestBase::IPCTestBase() | 25 IPCTestBase::IPCTestBase() |
| 26 : client_process_(base::kNullProcessHandle) { | 26 : client_process_(base::kNullProcessHandle) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 IPCTestBase::~IPCTestBase() { | 29 IPCTestBase::~IPCTestBase() { |
| 30 } | 30 } |
| 31 | 31 |
| 32 void IPCTestBase::SetUp() { | |
| 33 MultiProcessTest::SetUp(); | |
| 34 | |
| 35 // Construct a fresh Message loop for the duration of each test. | |
| 36 DCHECK(!message_loop_.get()); | |
| 37 message_loop_.reset(new base::MessageLoopForIO()); | |
| 38 } | |
| 39 | |
| 40 void IPCTestBase::TearDown() { | 32 void IPCTestBase::TearDown() { |
| 41 DCHECK(message_loop_.get()); | |
| 42 message_loop_.reset(); | 33 message_loop_.reset(); |
| 43 MultiProcessTest::TearDown(); | 34 MultiProcessTest::TearDown(); |
| 44 } | 35 } |
| 45 | 36 |
| 46 void IPCTestBase::Init(const std::string& test_client_name) { | 37 void IPCTestBase::Init(const std::string& test_client_name) { |
| 38 InitWithCustomMessageLoop( |
| 39 test_client_name, |
| 40 scoped_ptr<base::MessageLoop>(new base::MessageLoopForIO())); |
| 41 } |
| 42 |
| 43 void IPCTestBase::InitWithCustomMessageLoop( |
| 44 const std::string& test_client_name, |
| 45 scoped_ptr<base::MessageLoop> message_loop) { |
| 47 DCHECK(!test_client_name.empty()); | 46 DCHECK(!test_client_name.empty()); |
| 48 DCHECK(test_client_name_.empty()); | 47 DCHECK(test_client_name_.empty()); |
| 48 DCHECK(!message_loop_); |
| 49 |
| 49 test_client_name_ = test_client_name; | 50 test_client_name_ = test_client_name; |
| 51 message_loop_ = message_loop.Pass(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void IPCTestBase::CreateChannel(IPC::Listener* listener) { | 54 void IPCTestBase::CreateChannel(IPC::Listener* listener) { |
| 53 return CreateChannelFromChannelHandle(GetChannelName(test_client_name_), | 55 return CreateChannelFromChannelHandle(GetChannelName(test_client_name_), |
| 54 listener); | 56 listener); |
| 55 } | 57 } |
| 56 | 58 |
| 57 bool IPCTestBase::ConnectChannel() { | 59 bool IPCTestBase::ConnectChannel() { |
| 58 CHECK(channel_.get()); | 60 CHECK(channel_.get()); |
| 59 return channel_->Connect(); | 61 return channel_->Connect(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 bool rv = base::WaitForSingleProcess(client_process_, | 128 bool rv = base::WaitForSingleProcess(client_process_, |
| 127 base::TimeDelta::FromSeconds(5)); | 129 base::TimeDelta::FromSeconds(5)); |
| 128 base::CloseProcessHandle(client_process_); | 130 base::CloseProcessHandle(client_process_); |
| 129 client_process_ = base::kNullProcessHandle; | 131 client_process_ = base::kNullProcessHandle; |
| 130 return rv; | 132 return rv; |
| 131 } | 133 } |
| 132 | 134 |
| 133 scoped_refptr<base::TaskRunner> IPCTestBase::task_runner() { | 135 scoped_refptr<base::TaskRunner> IPCTestBase::task_runner() { |
| 134 return message_loop_->message_loop_proxy(); | 136 return message_loop_->message_loop_proxy(); |
| 135 } | 137 } |
| 136 | |
| 137 void IPCTestBase::set_message_loop(scoped_ptr<base::MessageLoop> loop) { | |
| 138 message_loop_ = loop.Pass(); | |
| 139 } | |
| OLD | NEW |