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

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

Issue 536013002: Decoupling visibility states from webcontent, adding visibility management in ResourceManager (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/wm/public/window_manager.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"
11 #include "athena/wm/public/window_manager.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "ui/gfx/image/image_skia.h" 13 #include "ui/gfx/image/image_skia.h"
13 #include "ui/views/view.h" 14 #include "ui/views/view.h"
14 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
15 16
16 namespace athena { 17 namespace athena {
17 namespace test { 18 namespace test {
18 19
19 namespace { 20 namespace {
20 21
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } // namespace 79 } // namespace
79 80
80 // Our testing base. 81 // Our testing base.
81 class ResourceManagerTest : public AthenaTestBase { 82 class ResourceManagerTest : public AthenaTestBase {
82 public: 83 public:
83 ResourceManagerTest() {} 84 ResourceManagerTest() {}
84 virtual ~ResourceManagerTest() {} 85 virtual ~ResourceManagerTest() {}
85 86
86 virtual void TearDown() OVERRIDE { 87 virtual void TearDown() OVERRIDE {
87 while (!activity_list_.empty()) 88 while (!activity_list_.empty())
88 CloseActivity(activity_list_[0]); 89 DeleteActivity(activity_list_[0]);
89 AthenaTestBase::TearDown(); 90 AthenaTestBase::TearDown();
90 } 91 }
91 92
92 TestActivity* CreateActivity(const std::string& title) { 93 TestActivity* CreateActivity(const std::string& title) {
93 TestActivity* activity = new TestActivity(title); 94 TestActivity* activity = new TestActivity(title);
94 ActivityManager::Get()->AddActivity(activity); 95 ActivityManager::Get()->AddActivity(activity);
95 activity->SetCurrentState(Activity::ACTIVITY_INVISIBLE); 96 activity->SetCurrentState(Activity::ACTIVITY_INVISIBLE);
96 activity_list_.push_back(activity); 97 activity_list_.push_back(activity);
97 return activity; 98 return activity;
98 } 99 }
99 100
100 void CloseActivity(Activity* activity) { 101 void DeleteActivity(Activity* activity) {
101 delete activity; 102 Activity::Delete(activity);
102 RunAllPendingInMessageLoop(); 103 RunAllPendingInMessageLoop();
103 std::vector<TestActivity*>::iterator it = std::find(activity_list_.begin(), 104 std::vector<TestActivity*>::iterator it = std::find(activity_list_.begin(),
104 activity_list_.end(), 105 activity_list_.end(),
105 activity); 106 activity);
106 DCHECK(it != activity_list_.end()); 107 DCHECK(it != activity_list_.end());
107 activity_list_.erase(it); 108 activity_list_.erase(it);
108 } 109 }
109 110
110 private: 111 private:
111 std::vector<TestActivity*> activity_list_; 112 std::vector<TestActivity*> activity_list_;
112 113
113 DISALLOW_COPY_AND_ASSIGN(ResourceManagerTest); 114 DISALLOW_COPY_AND_ASSIGN(ResourceManagerTest);
114 }; 115 };
115 116
116 // Only creates and destroys it to see that the system gets properly shut down. 117 // Only creates and destroys it to see that the system gets properly shut down.
117 TEST_F(ResourceManagerTest, SimpleTest) { 118 TEST_F(ResourceManagerTest, SimpleTest) {
118 } 119 }
119 120
120 // Test that we release an activity when the memory pressure goes critical. 121 // Test that we release an activity when the memory pressure goes critical.
121 TEST_F(ResourceManagerTest, OnCriticalWillUnloadOneActivity) { 122 TEST_F(ResourceManagerTest, OnCriticalWillUnloadOneActivity) {
122 // create a few dummy activities. 123 // Create a few dummy activities in the reverse order as we need them.
124 TestActivity* app_unloadable2 = CreateActivity("unloadable2");
125 TestActivity* app_unloadable1 = CreateActivity("unloadable1");
123 TestActivity* app_visible = CreateActivity("visible"); 126 TestActivity* app_visible = CreateActivity("visible");
124 TestActivity* app_unloadable1 = CreateActivity("unloadable1");
125 TestActivity* app_unloadable2 = CreateActivity("unloadable2");
126 app_visible->set_visible(true); 127 app_visible->set_visible(true);
127 app_unloadable1->set_visible(false); 128 app_unloadable1->set_visible(false);
128 app_unloadable2->set_visible(false); 129 app_unloadable2->set_visible(false);
129 130
130 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState()); 131 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
131 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState()); 132 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState());
132 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState()); 133 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState());
133 134
134 // Call the resource manager and say we are in a critical memory condition. 135 // Call the resource manager and say we are in a critical memory condition.
135 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 136 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
(...skipping 13 matching lines...) Expand all
149 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 150 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
150 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL); 151 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
151 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState()); 152 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
152 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState()); 153 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState());
153 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState()); 154 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState());
154 } 155 }
155 156
156 // Test that media playing activities only get unloaded if there is no other 157 // Test that media playing activities only get unloaded if there is no other
157 // way. 158 // way.
158 TEST_F(ResourceManagerTest, OnCriticalMediaHandling) { 159 TEST_F(ResourceManagerTest, OnCriticalMediaHandling) {
159 // create a few dummy activities. 160 // Create a few dummy activities in the reverse order as we need them.
161 TestActivity* app_media_locked2 = CreateActivity("medialocked2");
162 TestActivity* app_unloadable = CreateActivity("unloadable2");
163 TestActivity* app_media_locked1 = CreateActivity("medialocked1");
160 TestActivity* app_visible = CreateActivity("visible"); 164 TestActivity* app_visible = CreateActivity("visible");
161 TestActivity* app_media_locked1 = CreateActivity("medialocked1");
162 TestActivity* app_unloadable = CreateActivity("unloadable2");
163 TestActivity* app_media_locked2 = CreateActivity("medialocked2");
164 app_visible->set_visible(true); 165 app_visible->set_visible(true);
165 app_unloadable->set_visible(false); 166 app_unloadable->set_visible(false);
166 app_media_locked1->set_visible(false); 167 app_media_locked1->set_visible(false);
167 app_media_locked2->set_visible(false); 168 app_media_locked2->set_visible(false);
168 169
169 app_media_locked1->set_media_state( 170 app_media_locked1->set_media_state(
170 Activity::ACTIVITY_MEDIA_STATE_AUDIO_PLAYING); 171 Activity::ACTIVITY_MEDIA_STATE_AUDIO_PLAYING);
171 app_media_locked2->set_media_state(Activity::ACTIVITY_MEDIA_STATE_RECORDING); 172 app_media_locked2->set_media_state(Activity::ACTIVITY_MEDIA_STATE_RECORDING);
172 173
173 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState()); 174 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
(...skipping 22 matching lines...) Expand all
196 // Calling it the third time, the oldest media playing activity will get 197 // Calling it the third time, the oldest media playing activity will get
197 // unloaded. 198 // unloaded.
198 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring( 199 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
199 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL); 200 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
200 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState()); 201 DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
201 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_media_locked1->GetCurrentState()); 202 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_media_locked1->GetCurrentState());
202 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable->GetCurrentState()); 203 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable->GetCurrentState());
203 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_media_locked2->GetCurrentState()); 204 DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_media_locked2->GetCurrentState());
204 } 205 }
205 206
207 // Test the visibility of items.
208 TEST_F(ResourceManagerTest, VisibilityChanges) {
209 // Create a few dummy activities in the reverse order as we need them.
210 TestActivity* app4 = CreateActivity("app4");
211 TestActivity* app3 = CreateActivity("app3");
212 TestActivity* app2 = CreateActivity("app2");
213 TestActivity* app1 = CreateActivity("app1");
214 app1->SetCurrentState(Activity::ACTIVITY_VISIBLE);
215 app2->SetCurrentState(Activity::ACTIVITY_VISIBLE);
216 app3->SetCurrentState(Activity::ACTIVITY_VISIBLE);
217 app4->SetCurrentState(Activity::ACTIVITY_VISIBLE);
218
219 // Applying low resource pressure should keep everything as is.
220 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
221 MemoryPressureObserver::MEMORY_PRESSURE_LOW);
222 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
223 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
224 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState());
225 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app4->GetCurrentState());
226
227 // Applying moderate resource pressure we should see 3 visible activities.
228 // This is testing an internal algorithm constant, but for the time being
229 // this should suffice.
230 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
231 MemoryPressureObserver::MEMORY_PRESSURE_MODERATE);
232 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
233 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
234 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState());
235 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app4->GetCurrentState());
236
237 // Applying higher pressure should get rid of everything unneeded.
238 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
239 MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
240 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
241 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
242 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app3->GetCurrentState());
243 // Note: This might very well be unloaded with this memory pressure.
244 EXPECT_NE(Activity::ACTIVITY_VISIBLE, app4->GetCurrentState());
245
246 // Once the split view mode gets turned on, more windows should become
247 // visible.
248 WindowManager::GetInstance()->ToggleSplitViewForTest();
249 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
250 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
251 EXPECT_NE(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState());
252 EXPECT_NE(Activity::ACTIVITY_VISIBLE, app4->GetCurrentState());
253
254 // Going back to a relaxed memory pressure should reload the old activities.
255 ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
256 MemoryPressureObserver::MEMORY_PRESSURE_LOW);
257 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
258 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
259 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState());
260 EXPECT_NE(Activity::ACTIVITY_INVISIBLE, app4->GetCurrentState());
261 }
262
206 } // namespace test 263 } // namespace test
207 } // namespace athena 264 } // namespace athena
OLDNEW
« no previous file with comments | « athena/resource_manager/resource_manager_impl.cc ('k') | athena/wm/public/window_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698