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

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

Issue 548633005: Adding overview / layer framework to Activities so that unloaded / sleeping activities can be shown… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed 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') | athena/test/sample_activity.h » ('j') | 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 // ActivityViewModel overrides: 50 // ActivityViewModel overrides:
51 virtual void Init() OVERRIDE {} 51 virtual void Init() OVERRIDE {}
52 virtual SkColor GetRepresentativeColor() const OVERRIDE { return 0; } 52 virtual SkColor GetRepresentativeColor() const OVERRIDE { return 0; }
53 virtual base::string16 GetTitle() const OVERRIDE { return title_; } 53 virtual base::string16 GetTitle() const OVERRIDE { return title_; }
54 virtual gfx::ImageSkia GetIcon() const OVERRIDE { return gfx::ImageSkia(); } 54 virtual gfx::ImageSkia GetIcon() const OVERRIDE { return gfx::ImageSkia(); }
55 virtual bool UsesFrame() const OVERRIDE { return true; } 55 virtual bool UsesFrame() const OVERRIDE { return true; }
56 virtual views::View* GetContentsView() OVERRIDE { return view_; } 56 virtual views::View* GetContentsView() OVERRIDE { return view_; }
57 virtual views::Widget* CreateWidget() OVERRIDE { return NULL; } 57 virtual views::Widget* CreateWidget() OVERRIDE { return NULL; }
58 virtual void CreateOverviewModeImage() OVERRIDE {} 58 virtual gfx::ImageSkia GetOverviewModeImage() OVERRIDE {
59 virtual gfx::ImageSkia GetOverviewModeImage() OVERRIDE { return image_; } 59 return gfx::ImageSkia();
60 }
60 virtual void PrepareContentsForOverview() OVERRIDE {} 61 virtual void PrepareContentsForOverview() OVERRIDE {}
61 virtual void ResetContentsView() OVERRIDE {} 62 virtual void ResetContentsView() OVERRIDE {}
62 63
63 private: 64 private:
64 // The presentation values. 65 // The presentation values.
65 const base::string16 title_; 66 const base::string16 title_;
66 gfx::ImageSkia image_; 67 gfx::ImageSkia image_;
67 68
68 // The associated view. 69 // The associated view.
69 views::View* view_; 70 views::View* view_;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // Test that we release an activity when the memory pressure goes critical. 126 // Test that we release an activity when the memory pressure goes critical.
126 TEST_F(ResourceManagerTest, OnCriticalWillUnloadOneActivity) { 127 TEST_F(ResourceManagerTest, OnCriticalWillUnloadOneActivity) {
127 // Create a few dummy activities in the reverse order as we need them. 128 // Create a few dummy activities in the reverse order as we need them.
128 TestActivity* app_unloadable2 = CreateActivity("unloadable2"); 129 TestActivity* app_unloadable2 = CreateActivity("unloadable2");
129 TestActivity* app_unloadable1 = CreateActivity("unloadable1"); 130 TestActivity* app_unloadable1 = CreateActivity("unloadable1");
130 TestActivity* app_visible = CreateActivity("visible"); 131 TestActivity* app_visible = CreateActivity("visible");
131 app_visible->set_visible(true); 132 app_visible->set_visible(true);
132 app_unloadable1->set_visible(false); 133 app_unloadable1->set_visible(false);
133 app_unloadable2->set_visible(false); 134 app_unloadable2->set_visible(false);
134 135
135 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState()); 136 // Set the initial visibility states.
136 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState()); 137 app_visible->SetCurrentState(Activity::ACTIVITY_VISIBLE);
137 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState()); 138 app_unloadable1->SetCurrentState(Activity::ACTIVITY_INVISIBLE);
139 app_unloadable2->SetCurrentState(Activity::ACTIVITY_INVISIBLE);
138 140
139 // Call the resource manager and say we are in a critical memory condition. 141 // Call the resource manager and say we are in a critical memory condition.
140 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 142 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
141 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL); 143 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
142 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState()); 144 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
143 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState()); 145 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState());
144 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState()); 146 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState());
145 147
146 // Calling it a second time will release the second app. 148 // Calling it a second time will release the second app.
147 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 149 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
(...skipping 20 matching lines...) Expand all
168 TestActivity* app_visible = CreateActivity("visible"); 170 TestActivity* app_visible = CreateActivity("visible");
169 app_visible->set_visible(true); 171 app_visible->set_visible(true);
170 app_unloadable->set_visible(false); 172 app_unloadable->set_visible(false);
171 app_media_locked1->set_visible(false); 173 app_media_locked1->set_visible(false);
172 app_media_locked2->set_visible(false); 174 app_media_locked2->set_visible(false);
173 175
174 app_media_locked1->set_media_state( 176 app_media_locked1->set_media_state(
175 Activity::ACTIVITY_MEDIA_STATE_AUDIO_PLAYING); 177 Activity::ACTIVITY_MEDIA_STATE_AUDIO_PLAYING);
176 app_media_locked2->set_media_state(Activity::ACTIVITY_MEDIA_STATE_RECORDING); 178 app_media_locked2->set_media_state(Activity::ACTIVITY_MEDIA_STATE_RECORDING);
177 179
180 // Set the initial visibility states.
181 app_visible->SetCurrentState(Activity::ACTIVITY_VISIBLE);
182 app_media_locked1->SetCurrentState(Activity::ACTIVITY_INVISIBLE);
183 app_unloadable->SetCurrentState(Activity::ACTIVITY_INVISIBLE);
184 app_media_locked2->SetCurrentState(Activity::ACTIVITY_INVISIBLE);
185
178 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState()); 186 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
179 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_media_locked1->GetCurrentState()); 187 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_media_locked1->GetCurrentState());
180 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable->GetCurrentState()); 188 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable->GetCurrentState());
181 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_media_locked2->GetCurrentState()); 189 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_media_locked2->GetCurrentState());
182 190
183 // Calling it with a critical situation first, it will release the non media 191 // Calling it with a critical situation first, it will release the non media
184 // locked app. 192 // locked app.
185 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 193 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
186 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL); 194 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
187 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState()); 195 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 265
258 // Going back to a relaxed memory pressure should reload the old activities. 266 // Going back to a relaxed memory pressure should reload the old activities.
259 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 267 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
260 MemoryPressureObserver::MEMORY_PRESSURE_LOW); 268 MemoryPressureObserver::MEMORY_PRESSURE_LOW);
261 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState()); 269 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
262 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState()); 270 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
263 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState()); 271 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState());
264 EXPECT_NE(Activity::ACTIVITY_INVISIBLE, app4->GetCurrentState()); 272 EXPECT_NE(Activity::ACTIVITY_INVISIBLE, app4->GetCurrentState());
265 } 273 }
266 274
275 // Make sure that an activity which got just demoted from visible to invisible,
276 // does not get thrown out of memory in the same step.
277 TEST_F(ResourceManagerTest, NoUnloadFromVisible) {
278 // Create a few dummy activities in the reverse order as we need them.
279 TestActivity* app2 = CreateActivity("app2");
280 TestActivity* app1 = CreateActivity("app1");
281 app1->SetCurrentState(Activity::ACTIVITY_VISIBLE);
282 app2->SetCurrentState(Activity::ACTIVITY_VISIBLE);
283
284 // Applying low resource pressure should turn one item ivisible.
285 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
286 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
287 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
288 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
289
290 // Applying low resource pressure again will unload it.
291 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
292 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
293 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
294 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, app2->GetCurrentState());
295 }
296
267 } // namespace test 297 } // namespace test
268 } // namespace athena 298 } // namespace athena
OLDNEW
« no previous file with comments | « athena/resource_manager/resource_manager_impl.cc ('k') | athena/test/sample_activity.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698