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

Side by Side Diff: chrome/service/service_ipc_server_unittest.cc

Issue 1899083002: Convert //chrome from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months 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
« no previous file with comments | « chrome/service/service_ipc_server.cc ('k') | chrome/service/service_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/service/service_ipc_server.h" 5 #include "chrome/service/service_ipc_server.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "chrome/common/service_messages.h" 16 #include "chrome/common/service_messages.h"
16 #include "ipc/ipc_channel.h" 17 #include "ipc/ipc_channel.h"
17 #include "ipc/ipc_channel_handle.h" 18 #include "ipc/ipc_channel_handle.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 IPC::SyncChannel* GetServerChannel() { 101 IPC::SyncChannel* GetServerChannel() {
101 return server_->channel_.get(); 102 return server_->channel_.get();
102 } 103 }
103 104
104 protected: 105 protected:
105 FakeServiceIPCServerClient service_process_client_; 106 FakeServiceIPCServerClient service_process_client_;
106 IPC::ChannelHandle channel_handle_; 107 IPC::ChannelHandle channel_handle_;
107 base::MessageLoopForUI main_message_loop_; 108 base::MessageLoopForUI main_message_loop_;
108 base::Thread io_thread_; 109 base::Thread io_thread_;
109 base::WaitableEvent shutdown_event_; 110 base::WaitableEvent shutdown_event_;
110 scoped_ptr<ServiceIPCServer> server_; 111 std::unique_ptr<ServiceIPCServer> server_;
111 FakeChannelListener client_process_channel_listener_; 112 FakeChannelListener client_process_channel_listener_;
112 scoped_ptr<IPC::SyncChannel> client_process_channel_; 113 std::unique_ptr<IPC::SyncChannel> client_process_channel_;
113 }; 114 };
114 115
115 ServiceIPCServerTest::ServiceIPCServerTest() 116 ServiceIPCServerTest::ServiceIPCServerTest()
116 : channel_handle_(IPC::Channel::GenerateUniqueRandomChannelID()), 117 : channel_handle_(IPC::Channel::GenerateUniqueRandomChannelID()),
117 io_thread_("ServiceIPCServerTest IO"), 118 io_thread_("ServiceIPCServerTest IO"),
118 shutdown_event_(true /* manual_reset */, false /* initially_signaled */) { 119 shutdown_event_(true /* manual_reset */, false /* initially_signaled */) {
119 } 120 }
120 121
121 void ServiceIPCServerTest::SetUp() { 122 void ServiceIPCServerTest::SetUp() {
122 base::Thread::Options options; 123 base::Thread::Options options;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 231 }
231 232
232 TEST_F(ServiceIPCServerTest, SingleMessageHandler) { 233 TEST_F(ServiceIPCServerTest, SingleMessageHandler) {
233 ConnectClientChannel(); 234 ConnectClientChannel();
234 ASSERT_TRUE(server_->is_ipc_client_connected()); 235 ASSERT_TRUE(server_->is_ipc_client_connected());
235 236
236 // Verify that a message handler is offered messages not handled by the server 237 // Verify that a message handler is offered messages not handled by the server
237 // itself. 238 // itself.
238 FakeMessageHandler* handler = 239 FakeMessageHandler* handler =
239 new FakeMessageHandler(true /* should_handle */); 240 new FakeMessageHandler(true /* should_handle */);
240 server_->AddMessageHandler(make_scoped_ptr(handler)); 241 server_->AddMessageHandler(base::WrapUnique(handler));
241 SendToServiceProcess(new ServiceMsg_DisableCloudPrintProxy()); 242 SendToServiceProcess(new ServiceMsg_DisableCloudPrintProxy());
242 ASSERT_EQ(1, handler->handle_message_calls_); 243 ASSERT_EQ(1, handler->handle_message_calls_);
243 } 244 }
244 245
245 TEST_F(ServiceIPCServerTest, MultipleMessageHandlers) { 246 TEST_F(ServiceIPCServerTest, MultipleMessageHandlers) {
246 ConnectClientChannel(); 247 ConnectClientChannel();
247 ASSERT_TRUE(server_->is_ipc_client_connected()); 248 ASSERT_TRUE(server_->is_ipc_client_connected());
248 249
249 // If there are multiple handlers they are offered the message in order of 250 // If there are multiple handlers they are offered the message in order of
250 // being added until it is handled. 251 // being added until it is handled.
251 FakeMessageHandler* handler1 = 252 FakeMessageHandler* handler1 =
252 new FakeMessageHandler(false /* should_handle */); 253 new FakeMessageHandler(false /* should_handle */);
253 server_->AddMessageHandler(make_scoped_ptr(handler1)); 254 server_->AddMessageHandler(base::WrapUnique(handler1));
254 FakeMessageHandler* handler2 = 255 FakeMessageHandler* handler2 =
255 new FakeMessageHandler(true /* should_handle */); 256 new FakeMessageHandler(true /* should_handle */);
256 server_->AddMessageHandler(make_scoped_ptr(handler2)); 257 server_->AddMessageHandler(base::WrapUnique(handler2));
257 FakeMessageHandler* handler3 = 258 FakeMessageHandler* handler3 =
258 new FakeMessageHandler(true /* should_handle */); 259 new FakeMessageHandler(true /* should_handle */);
259 server_->AddMessageHandler(make_scoped_ptr(handler3)); 260 server_->AddMessageHandler(base::WrapUnique(handler3));
260 SendToServiceProcess(new ServiceMsg_DisableCloudPrintProxy()); 261 SendToServiceProcess(new ServiceMsg_DisableCloudPrintProxy());
261 ASSERT_EQ(1, handler1->handle_message_calls_); 262 ASSERT_EQ(1, handler1->handle_message_calls_);
262 ASSERT_EQ(1, handler2->handle_message_calls_); 263 ASSERT_EQ(1, handler2->handle_message_calls_);
263 ASSERT_EQ(0, handler3->handle_message_calls_); 264 ASSERT_EQ(0, handler3->handle_message_calls_);
264 } 265 }
OLDNEW
« no previous file with comments | « chrome/service/service_ipc_server.cc ('k') | chrome/service/service_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698