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

Unified Diff: components/memory_coordinator/child/child_memory_coordinator_impl_unittest.cc

Issue 2094583002: Add MemoryCoordinator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 side-by-side diff with in-line comments
Download patch
Index: components/memory_coordinator/child/child_memory_coordinator_impl_unittest.cc
diff --git a/components/memory_coordinator/child/child_memory_coordinator_impl_unittest.cc b/components/memory_coordinator/child/child_memory_coordinator_impl_unittest.cc
index 3b7db4037d659d2e5ba8a0a230244ee5f46a772d..7486d864952214040ea510c6fbb1eea0f14b4215 100644
--- a/components/memory_coordinator/child/child_memory_coordinator_impl_unittest.cc
+++ b/components/memory_coordinator/child/child_memory_coordinator_impl_unittest.cc
@@ -13,21 +13,20 @@
namespace memory_coordinator {
-namespace {
-
class ChildMemoryCoordinatorImplTest : public testing::Test {
public:
ChildMemoryCoordinatorImplTest()
- : clients_(new ChildMemoryCoordinatorImpl::ClientList),
- message_loop_(new base::MessageLoop),
- coordinator_impl_(mojo::GetProxy(&coordinator_), clients_) {}
+ : message_loop_(new base::MessageLoop),
+ coordinator_impl_(nullptr) {
+ coordinator_ = coordinator_impl_.binding_.CreateInterfacePtrAndBind();
+ }
void RegisterClient(MemoryCoordinatorClient* client) {
- clients_->AddObserver(client);
+ coordinator_impl_.RegisterClient(client);
}
void UnregisterClient(MemoryCoordinatorClient* client) {
- clients_->RemoveObserver(client);
+ coordinator_impl_.UnregisterClient(client);
}
mojom::ChildMemoryCoordinatorPtr& coordinator() { return coordinator_; }
@@ -39,17 +38,16 @@ class ChildMemoryCoordinatorImplTest : public testing::Test {
loop.RunUntilIdle();
}
- protected:
- scoped_refptr<ChildMemoryCoordinatorImpl::ClientList> clients_;
-
private:
std::unique_ptr<base::MessageLoop> message_loop_;
- mojom::ChildMemoryCoordinatorPtr coordinator_ = nullptr;
ChildMemoryCoordinatorImpl coordinator_impl_;
+ mojom::ChildMemoryCoordinatorPtr coordinator_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(ChildMemoryCoordinatorImplTest);
};
+namespace {
+
class MockMemoryCoordinatorClient final : public MemoryCoordinatorClient {
public:
void OnMemoryStateChange(mojom::MemoryState state) override {
@@ -67,12 +65,12 @@ class MemoryCoordinatorTestThread : public base::Thread,
public:
MemoryCoordinatorTestThread(
const std::string& name,
- scoped_refptr<ChildMemoryCoordinatorImpl::ClientList> clients)
- : Thread(name), clients_(clients) {}
+ ChildMemoryCoordinatorImpl& coordinator)
+ : Thread(name), coordinator_(coordinator) {}
~MemoryCoordinatorTestThread() override { Stop(); }
void Init() override {
- clients_->AddObserver(this);
+ coordinator_.RegisterClient(this);
}
void OnMemoryStateChange(mojom::MemoryState state) override {
@@ -94,7 +92,7 @@ class MemoryCoordinatorTestThread : public base::Thread,
EXPECT_EQ(state, last_state_);
}
- scoped_refptr<ChildMemoryCoordinatorImpl::ClientList> clients_;
+ ChildMemoryCoordinatorImpl& coordinator_;
mojom::MemoryState last_state_ = mojom::MemoryState::UNKNOWN;
};
@@ -114,8 +112,8 @@ TEST_F(ChildMemoryCoordinatorImplTest, SingleClient) {
}
TEST_F(ChildMemoryCoordinatorImplTest, MultipleClients) {
- MemoryCoordinatorTestThread t1("thread 1", clients_);
- MemoryCoordinatorTestThread t2("thread 2", clients_);
+ MemoryCoordinatorTestThread t1("thread 1", coordinator_impl());
+ MemoryCoordinatorTestThread t2("thread 2", coordinator_impl());
t1.StartAndWaitForTesting();
t2.StartAndWaitForTesting();
« no previous file with comments | « components/memory_coordinator/child/child_memory_coordinator_impl.cc ('k') | components/memory_coordinator/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698