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

Unified Diff: base/memory/memory_coordinator_client_registry_unittest.cc

Issue 2655083003: Add OnPurgeMemory() to MemoryCoordinatorClient (Closed)
Patch Set: comment Created 3 years, 11 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 | « base/memory/memory_coordinator_client_registry.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/memory_coordinator_client_registry_unittest.cc
diff --git a/base/memory/memory_coordinator_client_registry_unittest.cc b/base/memory/memory_coordinator_client_registry_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..37ed7673d9aab69009b49f479d409ddc907b54ea
--- /dev/null
+++ b/base/memory/memory_coordinator_client_registry_unittest.cc
@@ -0,0 +1,58 @@
+// 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 "base/memory/memory_coordinator_client_registry.h"
+
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+namespace {
+
+class TestMemoryCoordinatorClient : public MemoryCoordinatorClient {
+ public:
+ void OnMemoryStateChange(MemoryState state) override { state_ = state; }
+
+ void OnPurgeMemory() override { ++purge_count_; }
+
+ MemoryState state() const { return state_; }
+ size_t purge_count() const { return purge_count_; }
+
+ private:
+ MemoryState state_ = MemoryState::UNKNOWN;
+ size_t purge_count_ = 0;
+};
+
+void RunUntilIdle() {
+ base::RunLoop loop;
+ loop.RunUntilIdle();
+}
+
+TEST(MemoryCoordinatorClientRegistryTest, NotifyStateChange) {
+ MessageLoop loop;
+ auto* registry = MemoryCoordinatorClientRegistry::GetInstance();
+ TestMemoryCoordinatorClient client;
+ registry->Register(&client);
+ registry->Notify(MemoryState::THROTTLED);
+ RunUntilIdle();
+ ASSERT_EQ(MemoryState::THROTTLED, client.state());
+ registry->Unregister(&client);
+}
+
+TEST(MemoryCoordinatorClientRegistryTest, PurgeMemory) {
+ MessageLoop loop;
+ auto* registry = MemoryCoordinatorClientRegistry::GetInstance();
+ TestMemoryCoordinatorClient client;
+ registry->Register(&client);
+ registry->PurgeMemory();
+ RunUntilIdle();
+ ASSERT_EQ(1u, client.purge_count());
+ registry->Unregister(&client);
+}
+
+} // namespace
+
+} // namespace base
« no previous file with comments | « base/memory/memory_coordinator_client_registry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698