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

Unified Diff: remoting/host/process_stats_sender_unittest.cc

Issue 2847743004: Revert of [Chromoting] Retrieve process resource usage (ProcessStats) and its tests (Closed)
Patch Set: Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/process_stats_sender.cc ('k') | remoting/host/process_stats_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/process_stats_sender_unittest.cc
diff --git a/remoting/host/process_stats_sender_unittest.cc b/remoting/host/process_stats_sender_unittest.cc
deleted file mode 100644
index 6d08818c5343271c10557df58b0c051dd8bf6661..0000000000000000000000000000000000000000
--- a/remoting/host/process_stats_sender_unittest.cc
+++ /dev/null
@@ -1,180 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/host/process_stats_sender.h"
-
-#include <stdint.h>
-
-#include <utility>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/location.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/time/time.h"
-#include "remoting/host/process_stats_agent.h"
-#include "remoting/proto/process_stats.pb.h"
-#include "remoting/protocol/process_stats_stub.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace remoting {
-
-namespace {
-
-class FakeProcessStatsStub : public protocol::ProcessStatsStub {
- public:
- FakeProcessStatsStub() = default;
- ~FakeProcessStatsStub() override = default;
-
- void OnProcessStats(
- const protocol::AggregatedProcessResourceUsage& usage) override {
- received_.push_back(usage);
- DCHECK_LE(received_.size(), expected_usage_count_);
- DCHECK(!quit_closure_.is_null());
- if (received_.size() == expected_usage_count_) {
- quit_closure_.Run();
- }
- }
-
- const std::vector<protocol::AggregatedProcessResourceUsage>& received()
- const {
- return received_;
- }
-
- void set_quit_closure(base::Closure quit_closure) {
- quit_closure_ = quit_closure;
- }
-
- void set_expected_usage_count(size_t expected_usage_count) {
- expected_usage_count_ = expected_usage_count;
- }
-
- private:
- std::vector<protocol::AggregatedProcessResourceUsage> received_;
- size_t expected_usage_count_ = 0;
- base::Closure quit_closure_;
-};
-
-class FakeProcessStatsAgent : public ProcessStatsAgent {
- public:
- FakeProcessStatsAgent() = default;
- ~FakeProcessStatsAgent() override = default;
-
- protocol::ProcessResourceUsage GetResourceUsage() override {
- protocol::ProcessResourceUsage usage;
- usage.set_process_name("FakeProcessStatsAgent");
- usage.set_processor_usage(index_);
- usage.set_working_set_size(index_);
- usage.set_pagefile_size(index_);
- index_++;
- return usage;
- }
-
- // Checks the expected usage based on index.
- static void AssertExpected(
- const protocol::AggregatedProcessResourceUsage& usage,
- size_t index) {
- ASSERT_EQ(usage.processor_usage(), index);
- ASSERT_EQ(usage.working_set_size(), index);
- ASSERT_EQ(usage.pagefile_size(), index);
- }
-
- static void AssertExpected(const protocol::ProcessResourceUsage& usage,
- size_t index) {
- ASSERT_EQ(usage.processor_usage(), index);
- ASSERT_EQ(usage.working_set_size(), index);
- ASSERT_EQ(usage.pagefile_size(), index);
- }
-
- size_t issued_times() const { return index_; }
-
- private:
- size_t index_ = 0;
-};
-
-} // namespace
-
-TEST(ProcessStatsSenderTest, ReportUsage) {
- base::MessageLoop message_loop;
- base::RunLoop run_loop;
- FakeProcessStatsStub stub;
- std::unique_ptr<ProcessStatsSender> stats;
- FakeProcessStatsAgent agent;
-
- stub.set_expected_usage_count(10);
- stub.set_quit_closure(base::Bind(
- [](std::unique_ptr<ProcessStatsSender>* stats,
- const FakeProcessStatsStub& stub, const FakeProcessStatsAgent& agent,
- base::RunLoop* run_loop) -> void {
- ASSERT_EQ(stub.received().size(), agent.issued_times());
- stats->reset();
- run_loop->Quit();
- },
- base::Unretained(&stats), base::ConstRef(stub), base::ConstRef(agent),
- base::Unretained(&run_loop)));
- message_loop.task_runner()->PostTask(
- FROM_HERE,
- base::Bind(
- [](std::unique_ptr<ProcessStatsSender>* stats,
- FakeProcessStatsStub* stub, FakeProcessStatsAgent* agent) -> void {
- stats->reset(new ProcessStatsSender(
- stub, base::TimeDelta::FromMilliseconds(1), { agent }));
- },
- base::Unretained(&stats), base::Unretained(&stub),
- base::Unretained(&agent)));
- run_loop.Run();
-
- ASSERT_EQ(stub.received().size(), 10U);
- for (size_t i = 0; i < stub.received().size(); i++) {
- FakeProcessStatsAgent::AssertExpected(stub.received()[i], i);
- }
-}
-
-TEST(ProcessStatsSenderTest, MergeUsage) {
- base::MessageLoop message_loop;
- base::RunLoop run_loop;
- FakeProcessStatsStub stub;
- std::unique_ptr<ProcessStatsSender> stats;
- // Owned by |stats|.
- FakeProcessStatsAgent agent1;
- FakeProcessStatsAgent agent2;
-
- stub.set_expected_usage_count(10);
- stub.set_quit_closure(base::Bind(
- [](std::unique_ptr<ProcessStatsSender>* stats,
- const FakeProcessStatsStub& stub, const FakeProcessStatsAgent& agent1,
- const FakeProcessStatsAgent& agent2, base::RunLoop* run_loop) -> void {
- ASSERT_EQ(stub.received().size(), agent1.issued_times());
- ASSERT_EQ(stub.received().size(), agent2.issued_times());
- stats->reset();
- run_loop->Quit();
- },
- base::Unretained(&stats), base::ConstRef(stub), base::ConstRef(agent1),
- base::ConstRef(agent2), base::Unretained(&run_loop)));
- message_loop.task_runner()->PostTask(
- FROM_HERE,
- base::Bind(
- [](std::unique_ptr<ProcessStatsSender>* stats,
- FakeProcessStatsStub* stub, FakeProcessStatsAgent* agent1,
- FakeProcessStatsAgent* agent2) -> void {
- stats->reset(new ProcessStatsSender(
- stub, base::TimeDelta::FromMilliseconds(1),
- { agent1, agent2 } ));
- },
- base::Unretained(&stats), base::Unretained(&stub),
- base::Unretained(&agent1), base::Unretained(&agent2)));
- run_loop.Run();
-
- ASSERT_EQ(stub.received().size(), 10U);
- for (size_t i = 0; i < stub.received().size(); i++) {
- FakeProcessStatsAgent::AssertExpected(stub.received()[i], i * 2);
- for (int j = 0; j < stub.received()[i].usages_size(); j++) {
- FakeProcessStatsAgent::AssertExpected(
- stub.received()[i].usages().Get(j), i);
- }
- }
-}
-
-} // namespace remoting
« no previous file with comments | « remoting/host/process_stats_sender.cc ('k') | remoting/host/process_stats_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698