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

Side by Side Diff: athena/resource_manager/resource_manager_unittest.cc

Issue 588823002: A visibile to invisible state change will also release memory and should therefore wait as an unloa… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 6 years, 3 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 | « athena/resource_manager/resource_manager_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 2014 The Chromium Authors. All rights reserved. 1 /// Copyright 2014 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 "athena/activity/public/activity.h" 5 #include "athena/activity/public/activity.h"
6 #include "athena/activity/public/activity_manager.h" 6 #include "athena/activity/public/activity_manager.h"
7 #include "athena/activity/public/activity_view_model.h" 7 #include "athena/activity/public/activity_view_model.h"
8 #include "athena/resource_manager/memory_pressure_notifier.h" 8 #include "athena/resource_manager/memory_pressure_notifier.h"
9 #include "athena/resource_manager/public/resource_manager.h" 9 #include "athena/resource_manager/public/resource_manager.h"
10 #include "athena/test/athena_test_base.h" 10 #include "athena/test/athena_test_base.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 // Going back to a relaxed memory pressure should reload the old activities. 238 // Going back to a relaxed memory pressure should reload the old activities.
239 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 239 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
240 MemoryPressureObserver::MEMORY_PRESSURE_LOW); 240 MemoryPressureObserver::MEMORY_PRESSURE_LOW);
241 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState()); 241 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
242 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState()); 242 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
243 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState()); 243 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState());
244 EXPECT_NE(Activity::ACTIVITY_INVISIBLE, app4->GetCurrentState()); 244 EXPECT_NE(Activity::ACTIVITY_INVISIBLE, app4->GetCurrentState());
245 } 245 }
246 246
247 // Make sure that an activity which got just demoted from visible to invisible, 247 // Make sure that an activity which got just reduced from visible to invisible,
248 // does not get thrown out of memory in the same step. 248 // does not get thrown out of memory in the same step.
249 TEST_F(ResourceManagerTest, NoUnloadFromVisible) { 249 TEST_F(ResourceManagerTest, NoUnloadFromVisible) {
250 // The timeout override in milliseconds.
251 const int kTimeoutOverrideInMs = 20;
252 // Tell the resource manager to wait for 20ms between calls.
253 ResourceManager::Get()->SetWaitTimeBetweenResourceManageCalls(
254 kTimeoutOverrideInMs);
255
250 // Create a few dummy activities in the reverse order as we need them. 256 // Create a few dummy activities in the reverse order as we need them.
251 TestActivity* app2 = CreateActivity("app2"); 257 TestActivity* app2 = CreateActivity("app2");
252 TestActivity* app1 = CreateActivity("app1"); 258 TestActivity* app1 = CreateActivity("app1");
253 app1->SetCurrentState(Activity::ACTIVITY_VISIBLE); 259 app1->SetCurrentState(Activity::ACTIVITY_VISIBLE);
254 app2->SetCurrentState(Activity::ACTIVITY_VISIBLE); 260 app2->SetCurrentState(Activity::ACTIVITY_VISIBLE);
255 261
256 // Applying low resource pressure should turn one item ivisible. 262 // Applying low resource pressure should turn one item invisible.
257 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 263 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
258 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL); 264 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
259 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState()); 265 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
260 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState()); 266 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
261 267
262 // Applying low resource pressure again will unload it. 268 // Trying to apply the memory pressure again does not do anything.
263 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 269 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
264 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL); 270 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
265 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState()); 271 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
272 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
273
274 // Waiting and applying the pressure again should unload it.
275 usleep(kTimeoutOverrideInMs * 1000);
276 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
277 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
278 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
266 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, app2->GetCurrentState()); 279 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, app2->GetCurrentState());
267 } 280 }
268 281
269 // Make sure that ActivityVisibility changes will be updated instantaneously 282 // Make sure that ActivityVisibility changes will be updated instantaneously
270 // when the ResourceManager is called for operation. 283 // when the ResourceManager is called for operation.
271 TEST_F(ResourceManagerTest, VisibilityChangeIsInstantaneous) { 284 TEST_F(ResourceManagerTest, VisibilityChangeIsInstantaneous) {
272 // Create a few dummy activities in the reverse order as we need them. 285 // Create a few dummy activities in the reverse order as we need them.
273 TestActivity* app3 = CreateActivity("app3"); 286 TestActivity* app3 = CreateActivity("app3");
274 TestActivity* app2 = CreateActivity("app2"); 287 TestActivity* app2 = CreateActivity("app2");
275 TestActivity* app1 = CreateActivity("app1"); 288 TestActivity* app1 = CreateActivity("app1");
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 353 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
341 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL); 354 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
342 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState()); 355 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
343 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState()); 356 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
344 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, app3->GetCurrentState()); 357 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, app3->GetCurrentState());
345 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, app4->GetCurrentState()); 358 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, app4->GetCurrentState());
346 } 359 }
347 360
348 } // namespace test 361 } // namespace test
349 } // namespace athena 362 } // namespace athena
OLDNEW
« no previous file with comments | « athena/resource_manager/resource_manager_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698