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

Side by Side Diff: remoting/host/daemon_process_unittest.cc

Issue 12545006: The worker process launcher can now ask the worker to crash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/daemon_process.cc ('k') | remoting/host/daemon_process_win.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 (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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/location.h"
7 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
8 #include "base/process.h" 9 #include "base/process.h"
9 #include "ipc/ipc_message.h" 10 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_message_macros.h" 11 #include "ipc/ipc_message_macros.h"
11 #include "ipc/ipc_platform_file.h" 12 #include "ipc/ipc_platform_file.h"
12 #include "remoting/base/auto_thread_task_runner.h" 13 #include "remoting/base/auto_thread_task_runner.h"
13 #include "remoting/host/chromoting_messages.h" 14 #include "remoting/host/chromoting_messages.h"
14 #include "remoting/host/daemon_process.h" 15 #include "remoting/host/daemon_process.h"
15 #include "remoting/host/desktop_session.h" 16 #include "remoting/host/desktop_session.h"
16 #include "testing/gmock_mutant.h" 17 #include "testing/gmock_mutant.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 using testing::_; 21 using testing::_;
21 using testing::AnyNumber; 22 using testing::AnyNumber;
22 using testing::InSequence; 23 using testing::InSequence;
23 24
24 namespace remoting { 25 namespace remoting {
25 26
26 namespace { 27 namespace {
27 28
28 enum Messages { 29 enum Messages {
29 kMessageCrash = ChromotingDaemonNetworkMsg_Crash::ID, 30 kMessageCrash = ChromotingDaemonMsg_Crash::ID,
30 kMessageConfiguration = ChromotingDaemonNetworkMsg_Configuration::ID, 31 kMessageConfiguration = ChromotingDaemonNetworkMsg_Configuration::ID,
31 kMessageConnectTerminal = ChromotingNetworkHostMsg_ConnectTerminal::ID, 32 kMessageConnectTerminal = ChromotingNetworkHostMsg_ConnectTerminal::ID,
32 kMessageDisconnectTerminal = ChromotingNetworkHostMsg_DisconnectTerminal::ID, 33 kMessageDisconnectTerminal = ChromotingNetworkHostMsg_DisconnectTerminal::ID,
33 kMessageTerminalDisconnected = 34 kMessageTerminalDisconnected =
34 ChromotingDaemonNetworkMsg_TerminalDisconnected::ID 35 ChromotingDaemonNetworkMsg_TerminalDisconnected::ID
35 }; 36 };
36 37
37 // Provides a public constructor allowing the test to create instances of 38 // Provides a public constructor allowing the test to create instances of
38 // DesktopSession directly. 39 // DesktopSession directly.
39 class FakeDesktopSession : public DesktopSession { 40 class FakeDesktopSession : public DesktopSession {
(...skipping 21 matching lines...) Expand all
61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 62 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
62 virtual void SendToNetwork(IPC::Message* message) OVERRIDE; 63 virtual void SendToNetwork(IPC::Message* message) OVERRIDE;
63 64
64 MOCK_METHOD1(Received, void(const IPC::Message&)); 65 MOCK_METHOD1(Received, void(const IPC::Message&));
65 MOCK_METHOD1(Sent, void(const IPC::Message&)); 66 MOCK_METHOD1(Sent, void(const IPC::Message&));
66 67
67 MOCK_METHOD3(OnDesktopSessionAgentAttached, 68 MOCK_METHOD3(OnDesktopSessionAgentAttached,
68 bool(int, base::ProcessHandle, IPC::PlatformFileForTransit)); 69 bool(int, base::ProcessHandle, IPC::PlatformFileForTransit));
69 70
70 MOCK_METHOD1(DoCreateDesktopSessionPtr, DesktopSession*(int)); 71 MOCK_METHOD1(DoCreateDesktopSessionPtr, DesktopSession*(int));
72 MOCK_METHOD1(DoCrashNetworkProcess, void(const tracked_objects::Location&));
71 MOCK_METHOD0(LaunchNetworkProcess, void()); 73 MOCK_METHOD0(LaunchNetworkProcess, void());
72 74
73 private: 75 private:
74 DISALLOW_COPY_AND_ASSIGN(MockDaemonProcess); 76 DISALLOW_COPY_AND_ASSIGN(MockDaemonProcess);
75 }; 77 };
76 78
77 FakeDesktopSession::FakeDesktopSession(DaemonProcess* daemon_process, int id) 79 FakeDesktopSession::FakeDesktopSession(DaemonProcess* daemon_process, int id)
78 : DesktopSession(daemon_process, id) { 80 : DesktopSession(daemon_process, id) {
79 } 81 }
80 82
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 class DaemonProcessTest : public testing::Test { 119 class DaemonProcessTest : public testing::Test {
118 public: 120 public:
119 DaemonProcessTest(); 121 DaemonProcessTest();
120 virtual ~DaemonProcessTest(); 122 virtual ~DaemonProcessTest();
121 123
122 virtual void SetUp() OVERRIDE; 124 virtual void SetUp() OVERRIDE;
123 virtual void TearDown() OVERRIDE; 125 virtual void TearDown() OVERRIDE;
124 126
125 // DaemonProcess mocks 127 // DaemonProcess mocks
126 DesktopSession* DoCreateDesktopSession(int terminal_id); 128 DesktopSession* DoCreateDesktopSession(int terminal_id);
129 void DoCrashNetworkProcess(const tracked_objects::Location& location);
127 void LaunchNetworkProcess(); 130 void LaunchNetworkProcess();
128 131
129 // Deletes |daemon_process_|. 132 // Deletes |daemon_process_|.
130 void DeleteDaemonProcess(); 133 void DeleteDaemonProcess();
131 134
132 // Quits |message_loop_|. 135 // Quits |message_loop_|.
133 void QuitMessageLoop(); 136 void QuitMessageLoop();
134 137
135 void StartDaemonProcess(); 138 void StartDaemonProcess();
136 139
(...skipping 24 matching lines...) Expand all
161 base::Unretained(this))); 164 base::Unretained(this)));
162 daemon_process_.reset( 165 daemon_process_.reset(
163 new MockDaemonProcess(task_runner, task_runner, 166 new MockDaemonProcess(task_runner, task_runner,
164 base::Bind(&DaemonProcessTest::DeleteDaemonProcess, 167 base::Bind(&DaemonProcessTest::DeleteDaemonProcess,
165 base::Unretained(this)))); 168 base::Unretained(this))));
166 169
167 // Set up daemon process mocks. 170 // Set up daemon process mocks.
168 EXPECT_CALL(*daemon_process_, DoCreateDesktopSessionPtr(_)) 171 EXPECT_CALL(*daemon_process_, DoCreateDesktopSessionPtr(_))
169 .Times(AnyNumber()) 172 .Times(AnyNumber())
170 .WillRepeatedly(Invoke(this, &DaemonProcessTest::DoCreateDesktopSession)); 173 .WillRepeatedly(Invoke(this, &DaemonProcessTest::DoCreateDesktopSession));
174 EXPECT_CALL(*daemon_process_, DoCrashNetworkProcess(_))
175 .Times(AnyNumber())
176 .WillRepeatedly(Invoke(this, &DaemonProcessTest::DoCrashNetworkProcess));
171 EXPECT_CALL(*daemon_process_, LaunchNetworkProcess()) 177 EXPECT_CALL(*daemon_process_, LaunchNetworkProcess())
172 .Times(AnyNumber()) 178 .Times(AnyNumber())
173 .WillRepeatedly(Invoke(this, &DaemonProcessTest::LaunchNetworkProcess)); 179 .WillRepeatedly(Invoke(this, &DaemonProcessTest::LaunchNetworkProcess));
174 } 180 }
175 181
176 void DaemonProcessTest::TearDown() { 182 void DaemonProcessTest::TearDown() {
177 daemon_process_->Stop(); 183 daemon_process_->Stop();
178 message_loop_.Run(); 184 message_loop_.Run();
179 } 185 }
180 186
181 DesktopSession* DaemonProcessTest::DoCreateDesktopSession(int terminal_id) { 187 DesktopSession* DaemonProcessTest::DoCreateDesktopSession(int terminal_id) {
182 return new FakeDesktopSession(daemon_process_.get(), terminal_id); 188 return new FakeDesktopSession(daemon_process_.get(), terminal_id);
183 } 189 }
184 190
191 void DaemonProcessTest::DoCrashNetworkProcess(
192 const tracked_objects::Location& location) {
193 daemon_process_->SendToNetwork(
194 new ChromotingDaemonMsg_Crash(location.function_name(),
195 location.file_name(),
196 location.line_number()));
197 }
198
185 void DaemonProcessTest::LaunchNetworkProcess() { 199 void DaemonProcessTest::LaunchNetworkProcess() {
186 terminal_id_ = 0; 200 terminal_id_ = 0;
187 daemon_process_->OnChannelConnected(0); 201 daemon_process_->OnChannelConnected(0);
188 } 202 }
189 203
190 void DaemonProcessTest::DeleteDaemonProcess() { 204 void DaemonProcessTest::DeleteDaemonProcess() {
191 daemon_process_.reset(); 205 daemon_process_.reset();
192 } 206 }
193 207
194 void DaemonProcessTest::QuitMessageLoop() { 208 void DaemonProcessTest::QuitMessageLoop() {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 EXPECT_EQ(1u, desktop_sessions().size()); 333 EXPECT_EQ(1u, desktop_sessions().size());
320 EXPECT_EQ(id, desktop_sessions().front()->id()); 334 EXPECT_EQ(id, desktop_sessions().front()->id());
321 335
322 EXPECT_TRUE(daemon_process_->OnMessageReceived( 336 EXPECT_TRUE(daemon_process_->OnMessageReceived(
323 ChromotingNetworkHostMsg_ConnectTerminal(id, params, false))); 337 ChromotingNetworkHostMsg_ConnectTerminal(id, params, false)));
324 EXPECT_TRUE(desktop_sessions().empty()); 338 EXPECT_TRUE(desktop_sessions().empty());
325 EXPECT_EQ(0, terminal_id_); 339 EXPECT_EQ(0, terminal_id_);
326 } 340 }
327 341
328 } // namespace remoting 342 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/daemon_process.cc ('k') | remoting/host/daemon_process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698