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

Unified Diff: chrome/browser/task_manager/sampling/task_group_unittest.cc

Issue 2646623004: Query NaCl processes' GDB debug port on the correct thread. (Closed)
Patch Set: Add TaskGroup unit-tests Created 3 years, 10 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
Index: chrome/browser/task_manager/sampling/task_group_unittest.cc
diff --git a/chrome/browser/task_manager/sampling/task_group_unittest.cc b/chrome/browser/task_manager/sampling/task_group_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f10cfd6df8a6b423b51e1e7b27e83ace5155470e
--- /dev/null
+++ b/chrome/browser/task_manager/sampling/task_group_unittest.cc
@@ -0,0 +1,154 @@
+// Copyright 2016 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 "chrome/browser/task_manager/sampling/task_group.h"
+
+#include <memory>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/memory/ref_counted.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/strings/string16.h"
+#include "chrome/browser/task_manager/sampling/shared_sampler.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "gpu/ipc/common/memory_stats.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace task_manager {
+
+namespace {
+
+class FakeTask : public Task {
+ public:
+ FakeTask(base::ProcessId process_id,
+ Type type)
+ : Task(base::string16(),
+ "FakeTask",
+ nullptr,
+ base::kNullProcessHandle,
+ process_id),
+ type_(type) {
+ }
+
+ Type GetType() const override { return type_; }
+
+ int GetChildProcessUniqueID() const override { return 0; }
+
+ const Task* GetParentTask() const override { return nullptr; }
+
+ int GetTabId() const override { return 0; }
+
+ private:
+ Type type_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeTask);
+};
+
+} // namespace
+
+class TaskGroupTest : public testing::Test {
+ public:
+ TaskGroupTest()
+ : io_task_runner_(content::BrowserThread::GetTaskRunnerForThread(
+ content::BrowserThread::IO)),
+ run_loop_(base::MakeUnique<base::RunLoop>()),
+ task_group_(process_handle(),
+ process_id(),
afakhry 2017/02/10 20:08:52 I think you should make the above two accessors st
Wez 2017/02/13 01:22:19 Removed them in favour of calling the base::Proces
afakhry 2017/02/15 02:58:19 Acknowledged.
+ base::Bind(&TaskGroupTest::OnBackgroundCalculationsDone,
+ base::Unretained(this)),
+ new SharedSampler(io_task_runner_),
+ io_task_runner_) {}
+
+ protected:
+ void OnBackgroundCalculationsDone() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ background_refresh_complete_ = true;
+ run_loop_->QuitWhenIdle();
+ }
+
+ base::ProcessHandle process_handle() const {
+ return base::Process::Current().Handle();
+ }
+ base::ProcessId process_id() const { return base::Process::Current().Pid(); }
+
+ content::TestBrowserThreadBundle browser_threads_;
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
+ std::unique_ptr<base::RunLoop> run_loop_;
+ TaskGroup task_group_;
+ bool background_refresh_complete_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskGroupTest);
+};
+
+TEST_F(TaskGroupTest, NullRefresh) {
afakhry 2017/02/10 20:08:52 It would be really nice to add a comment above eac
Wez 2017/02/13 01:22:19 Done.
+ task_group_.Refresh(gpu::VideoMemoryUsageStats(), base::TimeDelta(), 0);
+ EXPECT_TRUE(task_group_.AreBackgroundCalculationsDone());
+ EXPECT_FALSE(background_refresh_complete_);
+}
+
+TEST_F(TaskGroupTest, SyncRefresh) {
+ task_group_.Refresh(gpu::VideoMemoryUsageStats(), base::TimeDelta(),
+ REFRESH_TYPE_NETWORK_USAGE);
+ EXPECT_TRUE(task_group_.AreBackgroundCalculationsDone());
+ EXPECT_FALSE(background_refresh_complete_);
+}
+
+TEST_F(TaskGroupTest, AsyncRefresh) {
+ // Memory is measured asynchronously, but not via SharedSampler (see below).
+ task_group_.Refresh(gpu::VideoMemoryUsageStats(), base::TimeDelta(),
+ REFRESH_TYPE_MEMORY);
+ EXPECT_FALSE(task_group_.AreBackgroundCalculationsDone());
+
+ ASSERT_FALSE(background_refresh_complete_);
+ run_loop_->Run();
+
+ EXPECT_TRUE(task_group_.AreBackgroundCalculationsDone());
+ EXPECT_TRUE(background_refresh_complete_);
+}
+
+TEST_F(TaskGroupTest, SharedAsyncRefresh) {
+ // Idle wakeups are measured via SharedSampler under Windows.
+ task_group_.Refresh(gpu::VideoMemoryUsageStats(), base::TimeDelta(),
+ REFRESH_TYPE_IDLE_WAKEUPS);
afakhry 2017/02/10 20:08:52 IDLE_WAKEUPS is a background-calculated value and
Wez 2017/02/13 01:22:19 I've reworked the comment; I'd prefer to keep the
afakhry 2017/02/15 02:58:19 Acknowledged.
+ EXPECT_FALSE(task_group_.AreBackgroundCalculationsDone());
+
+ ASSERT_FALSE(background_refresh_complete_);
+ run_loop_->Run();
+
+ EXPECT_TRUE(background_refresh_complete_);
+
+ EXPECT_TRUE(task_group_.AreBackgroundCalculationsDone());
+}
+
+TEST_F(TaskGroupTest, NaclRefreshZeroTasks) {
+ task_group_.Refresh(gpu::VideoMemoryUsageStats(), base::TimeDelta(),
+ REFRESH_TYPE_NACL);
+ EXPECT_TRUE(task_group_.AreBackgroundCalculationsDone());
+ EXPECT_FALSE(background_refresh_complete_);
+}
+
+TEST_F(TaskGroupTest, NaclRefreshWithTask) {
+ FakeTask fake_task(process_id(), Task::NACL);
+ task_group_.AddTask(&fake_task);
+
+ task_group_.Refresh(gpu::VideoMemoryUsageStats(), base::TimeDelta(),
+ REFRESH_TYPE_NACL);
+#if !defined(DISABLE_NACL)
+ EXPECT_FALSE(task_group_.AreBackgroundCalculationsDone());
+
+ ASSERT_FALSE(background_refresh_complete_);
+ run_loop_->Run();
+
+ EXPECT_TRUE(background_refresh_complete_);
+#endif // !defined(DISABLE_NACL)
+
+ EXPECT_TRUE(task_group_.AreBackgroundCalculationsDone());
+}
+
+} // namespace task_manager

Powered by Google App Engine
This is Rietveld 408576698