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

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

Issue 2950993003: [Chromoting] Use ProcessStatsSender in DaemonProcess (daemon process) (Closed)
Patch Set: Resolve review comments Created 3 years, 5 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 | « remoting/host/daemon_process.cc ('k') | remoting/host/desktop_session_win.h » ('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 "remoting/host/daemon_process.h" 5 #include "remoting/host/daemon_process.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 22 matching lines...) Expand all
33 namespace remoting { 33 namespace remoting {
34 34
35 namespace { 35 namespace {
36 36
37 enum Messages { 37 enum Messages {
38 kMessageCrash = ChromotingDaemonMsg_Crash::ID, 38 kMessageCrash = ChromotingDaemonMsg_Crash::ID,
39 kMessageConfiguration = ChromotingDaemonNetworkMsg_Configuration::ID, 39 kMessageConfiguration = ChromotingDaemonNetworkMsg_Configuration::ID,
40 kMessageConnectTerminal = ChromotingNetworkHostMsg_ConnectTerminal::ID, 40 kMessageConnectTerminal = ChromotingNetworkHostMsg_ConnectTerminal::ID,
41 kMessageDisconnectTerminal = ChromotingNetworkHostMsg_DisconnectTerminal::ID, 41 kMessageDisconnectTerminal = ChromotingNetworkHostMsg_DisconnectTerminal::ID,
42 kMessageTerminalDisconnected = 42 kMessageTerminalDisconnected =
43 ChromotingDaemonNetworkMsg_TerminalDisconnected::ID 43 ChromotingDaemonNetworkMsg_TerminalDisconnected::ID,
44 kMessageReportProcessStats = ChromotingAnyToNetworkMsg_ReportProcessStats::ID,
44 }; 45 };
45 46
46 // Provides a public constructor allowing the test to create instances of 47 // Provides a public constructor allowing the test to create instances of
47 // DesktopSession directly. 48 // DesktopSession directly.
48 class FakeDesktopSession : public DesktopSession { 49 class FakeDesktopSession : public DesktopSession {
49 public: 50 public:
50 FakeDesktopSession(DaemonProcess* daemon_process, int id); 51 FakeDesktopSession(DaemonProcess* daemon_process, int id);
51 ~FakeDesktopSession() override; 52 ~FakeDesktopSession() override;
52 53
53 void SetScreenResolution(const ScreenResolution& resolution) override {} 54 void SetScreenResolution(const ScreenResolution& resolution) override {}
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 ChromotingNetworkHostMsg_ConnectTerminal(id, resolution, false))); 341 ChromotingNetworkHostMsg_ConnectTerminal(id, resolution, false)));
341 EXPECT_EQ(1u, desktop_sessions().size()); 342 EXPECT_EQ(1u, desktop_sessions().size());
342 EXPECT_EQ(id, desktop_sessions().front()->id()); 343 EXPECT_EQ(id, desktop_sessions().front()->id());
343 344
344 EXPECT_TRUE(daemon_process_->OnMessageReceived( 345 EXPECT_TRUE(daemon_process_->OnMessageReceived(
345 ChromotingNetworkHostMsg_ConnectTerminal(id, resolution, false))); 346 ChromotingNetworkHostMsg_ConnectTerminal(id, resolution, false)));
346 EXPECT_TRUE(desktop_sessions().empty()); 347 EXPECT_TRUE(desktop_sessions().empty());
347 EXPECT_EQ(0, terminal_id_); 348 EXPECT_EQ(0, terminal_id_);
348 } 349 }
349 350
351 TEST_F(DaemonProcessTest, StartProcessStatsReport) {
352 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageReportProcessStats)));
353 daemon_process_->OnMessageReceived(
354 ChromotingNetworkToAnyMsg_StartProcessStatsReport(
355 base::TimeDelta::FromMilliseconds(1)));
356 base::RunLoop run_loop;
357 ON_CALL(*daemon_process_, Sent(Message(kMessageReportProcessStats)))
358 .WillByDefault(testing::Invoke(
359 [&run_loop](const IPC::Message& message) {
360 run_loop.Quit();
361 }));
362 run_loop.Run();
363 }
364
365 TEST_F(DaemonProcessTest, StartProcessStatsReportWithDifferentDelta) {
366 EXPECT_CALL(*daemon_process_, Sent(Message(kMessageReportProcessStats)))
367 .Times(AnyNumber());
368 int received = 0;
369 daemon_process_->OnMessageReceived(
370 ChromotingNetworkToAnyMsg_StartProcessStatsReport(
371 base::TimeDelta::FromHours(1)));
372 daemon_process_->OnMessageReceived(
373 ChromotingNetworkToAnyMsg_StartProcessStatsReport(
374 base::TimeDelta::FromMilliseconds(1)));
375 base::RunLoop run_loop;
376 ON_CALL(*daemon_process_, Sent(Message(kMessageReportProcessStats)))
377 .WillByDefault(testing::Invoke(
378 [&run_loop, &received](const IPC::Message& message) {
379 received++;
380 if (received == 5) {
381 run_loop.Quit();
382 }
383 }));
384 run_loop.Run();
385 }
386
387 TEST_F(DaemonProcessTest, StopProcessStatsReportWhenTheWorkerProcessDied) {
388 daemon_process_->OnMessageReceived(
389 ChromotingNetworkToAnyMsg_StartProcessStatsReport(
390 base::TimeDelta::FromMilliseconds(1)));
391 base::RunLoop run_loop;
392 ON_CALL(*daemon_process_, Sent(Message(kMessageReportProcessStats)))
393 .WillByDefault(testing::Invoke(
394 [](const IPC::Message& message) {
395 ASSERT_TRUE(false);
396 }));
397 static_cast<WorkerProcessIpcDelegate*>(daemon_process_.get())
398 ->OnWorkerProcessStopped();
399 message_loop_.task_runner()->PostDelayedTask(
400 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromMilliseconds(10));
401 run_loop.Run();
402 }
403
350 } // namespace remoting 404 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/daemon_process.cc ('k') | remoting/host/desktop_session_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698