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

Side by Side Diff: base/memory/memory_coordinator_client_registry_unittest.cc

Issue 2655083003: Add OnPurgeMemory() to MemoryCoordinatorClient (Closed)
Patch Set: comment 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 unified diff | Download patch
« no previous file with comments | « base/memory/memory_coordinator_client_registry.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/memory_coordinator_client_registry.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace base {
12
13 namespace {
14
15 class TestMemoryCoordinatorClient : public MemoryCoordinatorClient {
16 public:
17 void OnMemoryStateChange(MemoryState state) override { state_ = state; }
18
19 void OnPurgeMemory() override { ++purge_count_; }
20
21 MemoryState state() const { return state_; }
22 size_t purge_count() const { return purge_count_; }
23
24 private:
25 MemoryState state_ = MemoryState::UNKNOWN;
26 size_t purge_count_ = 0;
27 };
28
29 void RunUntilIdle() {
30 base::RunLoop loop;
31 loop.RunUntilIdle();
32 }
33
34 TEST(MemoryCoordinatorClientRegistryTest, NotifyStateChange) {
35 MessageLoop loop;
36 auto* registry = MemoryCoordinatorClientRegistry::GetInstance();
37 TestMemoryCoordinatorClient client;
38 registry->Register(&client);
39 registry->Notify(MemoryState::THROTTLED);
40 RunUntilIdle();
41 ASSERT_EQ(MemoryState::THROTTLED, client.state());
42 registry->Unregister(&client);
43 }
44
45 TEST(MemoryCoordinatorClientRegistryTest, PurgeMemory) {
46 MessageLoop loop;
47 auto* registry = MemoryCoordinatorClientRegistry::GetInstance();
48 TestMemoryCoordinatorClient client;
49 registry->Register(&client);
50 registry->PurgeMemory();
51 RunUntilIdle();
52 ASSERT_EQ(1u, client.purge_count());
53 registry->Unregister(&client);
54 }
55
56 } // namespace
57
58 } // namespace base
OLDNEW
« 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