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

Side by Side Diff: content/browser/memory/memory_coordinator_impl_unittest.cc

Issue 2448953002: Add MemoryCoordinatorProxy::SetCurrentMemoryStateForTesting (Closed)
Patch Set: Add tests Created 4 years, 1 month 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 | « content/browser/memory/memory_coordinator_impl.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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/memory/memory_coordinator_impl.h" 5 #include "content/browser/memory/memory_coordinator_impl.h"
6 6
7 #include "base/memory/memory_coordinator_proxy.h" 7 #include "base/memory/memory_coordinator_proxy.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "content/browser/memory/memory_monitor.h" 9 #include "content/browser/memory/memory_monitor.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void SetUp() override { 53 void SetUp() override {
54 MemoryCoordinator::EnableFeaturesForTesting(); 54 MemoryCoordinator::EnableFeaturesForTesting();
55 55
56 coordinator_.reset(new MemoryCoordinatorImpl( 56 coordinator_.reset(new MemoryCoordinatorImpl(
57 message_loop_.task_runner(), base::WrapUnique(new MockMemoryMonitor))); 57 message_loop_.task_runner(), base::WrapUnique(new MockMemoryMonitor)));
58 58
59 base::MemoryCoordinatorProxy::GetInstance()-> 59 base::MemoryCoordinatorProxy::GetInstance()->
60 SetGetCurrentMemoryStateCallback(base::Bind( 60 SetGetCurrentMemoryStateCallback(base::Bind(
61 &MemoryCoordinator::GetCurrentMemoryState, 61 &MemoryCoordinator::GetCurrentMemoryState,
62 base::Unretained(coordinator_.get()))); 62 base::Unretained(coordinator_.get())));
63 base::MemoryCoordinatorProxy::GetInstance()->
64 SetSetCurrentMemoryStateForTestingCallback(base::Bind(
65 &MemoryCoordinator::SetCurrentMemoryStateForTesting,
66 base::Unretained(coordinator_.get())));
63 } 67 }
64 68
65 MockMemoryMonitor* GetMockMemoryMonitor() { 69 MockMemoryMonitor* GetMockMemoryMonitor() {
66 return static_cast<MockMemoryMonitor*>(coordinator_->memory_monitor()); 70 return static_cast<MockMemoryMonitor*>(coordinator_->memory_monitor());
67 } 71 }
68 72
69 protected: 73 protected:
70 std::unique_ptr<MemoryCoordinatorImpl> coordinator_; 74 std::unique_ptr<MemoryCoordinatorImpl> coordinator_;
71 base::MessageLoop message_loop_; 75 base::MessageLoop message_loop_;
72 }; 76 };
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); 164 GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50);
161 coordinator_->UpdateState(); 165 coordinator_->UpdateState();
162 base::RunLoop loop; 166 base::RunLoop loop;
163 loop.RunUntilIdle(); 167 loop.RunUntilIdle();
164 EXPECT_FALSE(client.is_called()); 168 EXPECT_FALSE(client.is_called());
165 EXPECT_EQ(base::MemoryState::NORMAL, client.state()); 169 EXPECT_EQ(base::MemoryState::NORMAL, client.state());
166 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); 170 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client);
167 } 171 }
168 } 172 }
169 173
174 TEST_F(MemoryCoordinatorImplTest, SetMemoryStateForTesting) {
175 coordinator_->expected_renderer_size_ = 10;
176 coordinator_->new_renderers_until_throttled_ = 4;
177 coordinator_->new_renderers_until_suspended_ = 2;
178 coordinator_->new_renderers_back_to_normal_ = 5;
179 coordinator_->new_renderers_back_to_throttled_ = 3;
180 DCHECK(coordinator_->ValidateParameters());
181
182 MockMemoryCoordinatorClient client;
183 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(&client);
184 EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState());
185 EXPECT_EQ(base::MemoryState::NORMAL,
186 base::MemoryCoordinatorProxy::GetInstance()->
187 GetCurrentMemoryState());
188 EXPECT_EQ(base::MemoryState::NORMAL, client.state());
189
190 base::MemoryCoordinatorProxy::GetInstance()->SetCurrentMemoryStateForTesting(
191 base::MemoryState::THROTTLED);
192 EXPECT_EQ(base::MemoryState::THROTTLED,
193 coordinator_->GetCurrentMemoryState());
194 EXPECT_EQ(base::MemoryState::THROTTLED,
195 base::MemoryCoordinatorProxy::GetInstance()->
196 GetCurrentMemoryState());
197 base::RunLoop loop;
198 loop.RunUntilIdle();
199 EXPECT_TRUE(client.is_called());
200 EXPECT_EQ(base::MemoryState::THROTTLED, client.state());
201 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client);
202 }
203
170 } // namespace content 204 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698