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

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

Issue 11234034: Crash the network process when a fatal daemon-to-network protocol error encountered. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 2 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/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "ipc/ipc_message.h" 9 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_message_macros.h" 10 #include "ipc/ipc_message_macros.h"
11 #include "remoting/base/auto_thread_task_runner.h" 11 #include "remoting/base/auto_thread_task_runner.h"
12 #include "remoting/host/chromoting_messages.h" 12 #include "remoting/host/chromoting_messages.h"
13 #include "remoting/host/daemon_process.h" 13 #include "remoting/host/daemon_process.h"
14 #include "remoting/host/desktop_session.h" 14 #include "remoting/host/desktop_session.h"
15 #include "testing/gmock_mutant.h" 15 #include "testing/gmock_mutant.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 using testing::_; 19 using testing::_;
20 using testing::AnyNumber; 20 using testing::AnyNumber;
21 using testing::InSequence; 21 using testing::InSequence;
22 22
23 namespace remoting { 23 namespace remoting {
24 24
25 namespace { 25 namespace {
26 26
27 enum Messages { 27 enum Messages {
28 kMessageCrash = ChromotingDaemonNetworkMsg_Crash::ID,
28 kMessageConfiguration = ChromotingDaemonNetworkMsg_Configuration::ID, 29 kMessageConfiguration = ChromotingDaemonNetworkMsg_Configuration::ID,
29 kMessageConnectTerminal = ChromotingNetworkHostMsg_ConnectTerminal::ID, 30 kMessageConnectTerminal = ChromotingNetworkHostMsg_ConnectTerminal::ID,
30 kMessageDisconnectTerminal = ChromotingNetworkHostMsg_DisconnectTerminal::ID, 31 kMessageDisconnectTerminal = ChromotingNetworkHostMsg_DisconnectTerminal::ID,
31 kMessageTerminalDisconnected = 32 kMessageTerminalDisconnected =
32 ChromotingDaemonNetworkMsg_TerminalDisconnected::ID 33 ChromotingDaemonNetworkMsg_TerminalDisconnected::ID
33 }; 34 };
34 35
35 // Provides a public constructor allowing the test to create instances of 36 // Provides a public constructor allowing the test to create instances of
36 // DesktopSession directly. 37 // DesktopSession directly.
37 class FakeDesktopSession : public DesktopSession { 38 class FakeDesktopSession : public DesktopSession {
(...skipping 16 matching lines...) Expand all
54 virtual scoped_ptr<DesktopSession> DoCreateDesktopSession( 55 virtual scoped_ptr<DesktopSession> DoCreateDesktopSession(
55 int terminal_id) OVERRIDE; 56 int terminal_id) OVERRIDE;
56 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
57 virtual void SendToNetwork(IPC::Message* message) OVERRIDE; 58 virtual void SendToNetwork(IPC::Message* message) OVERRIDE;
58 59
59 MOCK_METHOD1(Received, void(const IPC::Message&)); 60 MOCK_METHOD1(Received, void(const IPC::Message&));
60 MOCK_METHOD1(Sent, void(const IPC::Message&)); 61 MOCK_METHOD1(Sent, void(const IPC::Message&));
61 62
62 MOCK_METHOD1(DoCreateDesktopSessionPtr, DesktopSession*(int)); 63 MOCK_METHOD1(DoCreateDesktopSessionPtr, DesktopSession*(int));
63 MOCK_METHOD0(LaunchNetworkProcess, void()); 64 MOCK_METHOD0(LaunchNetworkProcess, void());
64 MOCK_METHOD0(RestartNetworkProcess, void());
65 65
66 private: 66 private:
67 DISALLOW_COPY_AND_ASSIGN(MockDaemonProcess); 67 DISALLOW_COPY_AND_ASSIGN(MockDaemonProcess);
68 }; 68 };
69 69
70 FakeDesktopSession::FakeDesktopSession(DaemonProcess* daemon_process, int id) 70 FakeDesktopSession::FakeDesktopSession(DaemonProcess* daemon_process, int id)
71 : DesktopSession(daemon_process, id) { 71 : DesktopSession(daemon_process, id) {
72 } 72 }
73 73
74 FakeDesktopSession::~FakeDesktopSession() { 74 FakeDesktopSession::~FakeDesktopSession() {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 ChromotingNetworkHostMsg_DisconnectTerminal(id))); 263 ChromotingNetworkHostMsg_DisconnectTerminal(id)));
264 EXPECT_TRUE(desktop_sessions().empty()); 264 EXPECT_TRUE(desktop_sessions().empty());
265 } 265 }
266 266
267 // Tries to close an invalid terminal ID and expects the network process to be 267 // Tries to close an invalid terminal ID and expects the network process to be
268 // restarted. 268 // restarted.
269 TEST_F(DaemonProcessTest, InvalidDisconnectTerminal) { 269 TEST_F(DaemonProcessTest, InvalidDisconnectTerminal) {
270 InSequence s; 270 InSequence s;
271 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageConfiguration))); 271 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageConfiguration)));
272 EXPECT_CALL(*daemon_process_, Received(Message(kMessageDisconnectTerminal))); 272 EXPECT_CALL(*daemon_process_, Received(Message(kMessageDisconnectTerminal)));
273 EXPECT_CALL(*daemon_process_, RestartNetworkProcess()) 273 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageCrash)))
274 .WillRepeatedly(Invoke(this, &DaemonProcessTest::LaunchNetworkProcess)); 274 .WillOnce(InvokeWithoutArgs(this,
275 &DaemonProcessTest::LaunchNetworkProcess));
275 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageConfiguration))); 276 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageConfiguration)));
276 277
277 StartDaemonProcess(); 278 StartDaemonProcess();
278 279
279 int id = terminal_id_++; 280 int id = terminal_id_++;
280 281
281 EXPECT_TRUE(daemon_process_->OnMessageReceived( 282 EXPECT_TRUE(daemon_process_->OnMessageReceived(
282 ChromotingNetworkHostMsg_DisconnectTerminal(id))); 283 ChromotingNetworkHostMsg_DisconnectTerminal(id)));
283 EXPECT_TRUE(desktop_sessions().empty()); 284 EXPECT_TRUE(desktop_sessions().empty());
284 EXPECT_EQ(0, terminal_id_); 285 EXPECT_EQ(0, terminal_id_);
285 } 286 }
286 287
287 // Tries to open an invalid terminal ID and expects the network process to be 288 // Tries to open an invalid terminal ID and expects the network process to be
288 // restarted. 289 // restarted.
289 TEST_F(DaemonProcessTest, InvalidConnectTerminal) { 290 TEST_F(DaemonProcessTest, InvalidConnectTerminal) {
290 InSequence s; 291 InSequence s;
291 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageConfiguration))); 292 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageConfiguration)));
292 EXPECT_CALL(*daemon_process_, Received(Message(kMessageConnectTerminal))); 293 EXPECT_CALL(*daemon_process_, Received(Message(kMessageConnectTerminal)));
293 EXPECT_CALL(*daemon_process_, Received(Message(kMessageConnectTerminal))); 294 EXPECT_CALL(*daemon_process_, Received(Message(kMessageConnectTerminal)));
294 EXPECT_CALL(*daemon_process_, RestartNetworkProcess()) 295 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageCrash)))
295 .WillRepeatedly(Invoke(this, &DaemonProcessTest::LaunchNetworkProcess)); 296 .WillOnce(InvokeWithoutArgs(this,
297 &DaemonProcessTest::LaunchNetworkProcess));
296 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageConfiguration))); 298 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageConfiguration)));
297 299
298 StartDaemonProcess(); 300 StartDaemonProcess();
299 301
300 int id = terminal_id_++; 302 int id = terminal_id_++;
301 303
302 EXPECT_TRUE(daemon_process_->OnMessageReceived( 304 EXPECT_TRUE(daemon_process_->OnMessageReceived(
303 ChromotingNetworkHostMsg_ConnectTerminal(id))); 305 ChromotingNetworkHostMsg_ConnectTerminal(id)));
304 EXPECT_EQ(1u, desktop_sessions().size()); 306 EXPECT_EQ(1u, desktop_sessions().size());
305 EXPECT_EQ(id, desktop_sessions().front()->id()); 307 EXPECT_EQ(id, desktop_sessions().front()->id());
306 308
307 EXPECT_TRUE(daemon_process_->OnMessageReceived( 309 EXPECT_TRUE(daemon_process_->OnMessageReceived(
308 ChromotingNetworkHostMsg_ConnectTerminal(id))); 310 ChromotingNetworkHostMsg_ConnectTerminal(id)));
309 EXPECT_TRUE(desktop_sessions().empty()); 311 EXPECT_TRUE(desktop_sessions().empty());
310 EXPECT_EQ(0, terminal_id_); 312 EXPECT_EQ(0, terminal_id_);
311 } 313 }
312 314
313 } // namespace remoting 315 } // 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