Commit 87b30cd3 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

[PM] Add a test for worker node properties.

Also exposed accessors for the dev tools token and renamed
WorkerNode::GetType() to GetWorkerType() to better differentiate
with the graph node type.

Bug: 993029
Change-Id: I951c222dc107fb0337712c3c202e6876b68a17d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769177Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690066}
parent 8c11ec66
...@@ -101,6 +101,11 @@ ProcessNodeImpl* WorkerNodeImpl::process_node() const { ...@@ -101,6 +101,11 @@ ProcessNodeImpl* WorkerNodeImpl::process_node() const {
return process_node_; return process_node_;
} }
const base::UnguessableToken& WorkerNodeImpl::dev_tools_token() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return dev_tools_token_;
}
const base::flat_set<FrameNodeImpl*>& WorkerNodeImpl::client_frames() const { const base::flat_set<FrameNodeImpl*>& WorkerNodeImpl::client_frames() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return client_frames_; return client_frames_;
...@@ -131,7 +136,7 @@ void WorkerNodeImpl::LeaveGraph() { ...@@ -131,7 +136,7 @@ void WorkerNodeImpl::LeaveGraph() {
process_node_->RemoveWorker(this); process_node_->RemoveWorker(this);
} }
WorkerNode::WorkerType WorkerNodeImpl::GetType() const { WorkerNode::WorkerType WorkerNodeImpl::GetWorkerType() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return worker_type(); return worker_type();
} }
...@@ -141,6 +146,11 @@ const ProcessNode* WorkerNodeImpl::GetProcessNode() const { ...@@ -141,6 +146,11 @@ const ProcessNode* WorkerNodeImpl::GetProcessNode() const {
return process_node(); return process_node();
} }
const base::UnguessableToken& WorkerNodeImpl::GetDevToolsToken() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return dev_tools_token();
}
const base::flat_set<const FrameNode*> WorkerNodeImpl::GetClientFrames() const { const base::flat_set<const FrameNode*> WorkerNodeImpl::GetClientFrames() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::flat_set<const FrameNode*> client_frames; base::flat_set<const FrameNode*> client_frames;
......
...@@ -43,6 +43,7 @@ class WorkerNodeImpl : public PublicNodeImpl<WorkerNodeImpl, WorkerNode>, ...@@ -43,6 +43,7 @@ class WorkerNodeImpl : public PublicNodeImpl<WorkerNodeImpl, WorkerNode>,
// Getters for const properties. These can be called from any thread. // Getters for const properties. These can be called from any thread.
WorkerType worker_type() const; WorkerType worker_type() const;
ProcessNodeImpl* process_node() const; ProcessNodeImpl* process_node() const;
const base::UnguessableToken& dev_tools_token() const;
// Getters for non-const properties. These are not thread safe. // Getters for non-const properties. These are not thread safe.
const base::flat_set<FrameNodeImpl*>& client_frames() const; const base::flat_set<FrameNodeImpl*>& client_frames() const;
...@@ -55,8 +56,9 @@ class WorkerNodeImpl : public PublicNodeImpl<WorkerNodeImpl, WorkerNode>, ...@@ -55,8 +56,9 @@ class WorkerNodeImpl : public PublicNodeImpl<WorkerNodeImpl, WorkerNode>,
// WorkerNode: These are private so that users of the // WorkerNode: These are private so that users of the
// impl use the private getters rather than the public interface. // impl use the private getters rather than the public interface.
WorkerType GetType() const override; WorkerType GetWorkerType() const override;
const ProcessNode* GetProcessNode() const override; const ProcessNode* GetProcessNode() const override;
const base::UnguessableToken& GetDevToolsToken() const override;
const base::flat_set<const FrameNode*> GetClientFrames() const override; const base::flat_set<const FrameNode*> GetClientFrames() const override;
const base::flat_set<const WorkerNode*> GetClientWorkers() const override; const base::flat_set<const WorkerNode*> GetClientWorkers() const override;
const base::flat_set<const WorkerNode*> GetChildWorkers() const override; const base::flat_set<const WorkerNode*> GetChildWorkers() const override;
......
...@@ -44,6 +44,28 @@ TEST_F(WorkerNodeImplDeathTest, SafeDowncast) { ...@@ -44,6 +44,28 @@ TEST_F(WorkerNodeImplDeathTest, SafeDowncast) {
ASSERT_DEATH_IF_SUPPORTED(FrameNodeImpl::FromNodeBase(worker.get()), ""); ASSERT_DEATH_IF_SUPPORTED(FrameNodeImpl::FromNodeBase(worker.get()), "");
} }
TEST_F(WorkerNodeImplTest, ConstProperties) {
const WorkerNode::WorkerType kWorkerType = WorkerNode::WorkerType::kShared;
auto process = CreateNode<ProcessNodeImpl>();
static const base::UnguessableToken kTestDevToolsToken =
base::UnguessableToken::Create();
auto worker_impl = CreateNode<WorkerNodeImpl>(kWorkerType, process.get(),
kTestDevToolsToken);
// Test private interface.
EXPECT_EQ(worker_impl->worker_type(), kWorkerType);
EXPECT_EQ(worker_impl->process_node(), process.get());
EXPECT_EQ(worker_impl->dev_tools_token(), kTestDevToolsToken);
// Test public interface.
const WorkerNode* worker = worker_impl.get();
EXPECT_EQ(worker->GetWorkerType(), kWorkerType);
EXPECT_EQ(worker->GetProcessNode(), process.get());
EXPECT_EQ(worker->GetDevToolsToken(), kTestDevToolsToken);
}
// Create a worker of each type and register the frame as a client of each. // Create a worker of each type and register the frame as a client of each.
TEST_F(WorkerNodeImplTest, AddWorkerNodes) { TEST_F(WorkerNodeImplTest, AddWorkerNodes) {
auto process = CreateNode<ProcessNodeImpl>(); auto process = CreateNode<ProcessNodeImpl>();
......
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/performance_manager/public/graph/node.h" #include "chrome/browser/performance_manager/public/graph/node.h"
namespace base {
class UnguessableToken;
}
namespace performance_manager { namespace performance_manager {
class WorkerNodeObserver; class WorkerNodeObserver;
...@@ -52,13 +56,16 @@ class WorkerNode : public Node { ...@@ -52,13 +56,16 @@ class WorkerNode : public Node {
WorkerNode(); WorkerNode();
~WorkerNode() override; ~WorkerNode() override;
// Returns the type. // Returns the worker type. Note that this is different from the NodeTypeEnum.
virtual WorkerType GetType() const = 0; virtual WorkerType GetWorkerType() const = 0;
// Returns the process node to which this worker belongs. This is a constant // Returns the process node to which this worker belongs. This is a constant
// over the lifetime of the frame. // over the lifetime of the frame.
virtual const ProcessNode* GetProcessNode() const = 0; virtual const ProcessNode* GetProcessNode() const = 0;
// Returns the dev tools token for this worker.
virtual const base::UnguessableToken& GetDevToolsToken() const = 0;
// Returns the frames that are clients of this worker. // Returns the frames that are clients of this worker.
virtual const base::flat_set<const FrameNode*> GetClientFrames() const = 0; virtual const base::flat_set<const FrameNode*> GetClientFrames() const = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment