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

Side by Side Diff: athena/content/app_activity_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: Added a few more unittests 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
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_factory.h" 5 #include "athena/activity/public/activity_factory.h"
6 #include "athena/activity/public/activity_manager.h" 6 #include "athena/activity/public/activity_manager.h"
7 #include "athena/content/app_activity.h" 7 #include "athena/content/app_activity.h"
8 #include "athena/content/app_activity_registry.h" 8 #include "athena/content/app_activity_registry.h"
9 #include "athena/content/public/app_registry.h" 9 #include "athena/content/public/app_registry.h"
10 #include "athena/extensions/public/extensions_delegate.h" 10 #include "athena/extensions/public/extensions_delegate.h"
11 #include "athena/resource_manager/public/resource_manager.h"
11 #include "athena/test/athena_test_base.h" 12 #include "athena/test/athena_test_base.h"
12 #include "extensions/common/extension_set.h" 13 #include "extensions/common/extension_set.h"
13 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
14 #include "ui/views/view.h" 15 #include "ui/views/view.h"
15 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
16 17
17 namespace content { 18 namespace content {
18 class BrowserContext; 19 class BrowserContext;
19 } 20 }
20 21
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 149 }
149 150
150 // A function to create an Activity. 151 // A function to create an Activity.
151 TestAppActivity* CreateAppActivity(const std::string& app_id) { 152 TestAppActivity* CreateAppActivity(const std::string& app_id) {
152 TestAppActivity* activity = new TestAppActivity(app_id); 153 TestAppActivity* activity = new TestAppActivity(app_id);
153 ActivityManager::Get()->AddActivity(activity); 154 ActivityManager::Get()->AddActivity(activity);
154 return activity; 155 return activity;
155 } 156 }
156 157
157 void CloseActivity(Activity* activity) { 158 void CloseActivity(Activity* activity) {
158 delete activity; 159 Activity::CloseActivity(activity);
159 RunAllPendingInMessageLoop(); 160 RunAllPendingInMessageLoop();
160 } 161 }
161 162
162 // Get the position of the activity in the navigation history. 163 // Get the position of the activity in the navigation history.
163 int GetActivityPosition(Activity* activity) { 164 int GetActivityPosition(Activity* activity) {
164 aura::Window* window = activity->GetActivityViewModel()->GetContentsView() 165 aura::Window* window = activity->GetActivityViewModel()->GetContentsView()
165 ->GetWidget()->GetNativeWindow(); 166 ->GetWidget()->GetNativeWindow();
166 aura::Window::Windows windows = activity->GetWindow()->parent()->children(); 167 aura::Window::Windows windows = activity->GetWindow()->parent()->children();
167 for (size_t i = 0; i < windows.size(); i++) { 168 for (size_t i = 0; i < windows.size(); i++) {
168 if (windows[i] == window) 169 if (windows[i] == window)
169 return i; 170 return i;
170 } 171 }
171 return -1; 172 return -1;
172 } 173 }
173 174
175 // To avoid interference of the ResourceManager in these AppActivity
176 // framework tests, we disable the ResourceManager for some tests.
177 // Every use/interference of this function gets explained.
178 void DisableResourceManager() {
179 ResourceManager::Get()->Pause(true);
180 }
181
174 protected: 182 protected:
175 TestExtensionsDelegate* test_extensions_delegate() { 183 TestExtensionsDelegate* test_extensions_delegate() {
176 return test_extensions_delegate_; 184 return test_extensions_delegate_;
177 } 185 }
178 186
179 private: 187 private:
180 TestExtensionsDelegate* test_extensions_delegate_; 188 TestExtensionsDelegate* test_extensions_delegate_;
181 189
182 DISALLOW_COPY_AND_ASSIGN(AppActivityTest); 190 DISALLOW_COPY_AND_ASSIGN(AppActivityTest);
183 }; 191 };
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 EXPECT_EQ(1, app_activity1->app_activity_registry()->NumberOfActivities()); 253 EXPECT_EQ(1, app_activity1->app_activity_registry()->NumberOfActivities());
246 CloseActivity(app_activity1); 254 CloseActivity(app_activity1);
247 } 255 }
248 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); 256 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
249 EXPECT_EQ(0, test_extensions_delegate()->unload_called()); 257 EXPECT_EQ(0, test_extensions_delegate()->unload_called());
250 EXPECT_EQ(0, test_extensions_delegate()->restart_called()); 258 EXPECT_EQ(0, test_extensions_delegate()->restart_called());
251 } 259 }
252 260
253 // Test unload and the creation of the proxy, then "closing the activity". 261 // Test unload and the creation of the proxy, then "closing the activity".
254 TEST_F(AppActivityTest, TestUnloadFollowedByClose) { 262 TEST_F(AppActivityTest, TestUnloadFollowedByClose) {
263 // We do not want the ResourceManager to interfere with this test. In this
264 // case it would (dependent on its current internal implementation)
265 // automatically re-load the unloaded activity if it is in an "active"
266 // position.
267 DisableResourceManager();
255 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); 268 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
256 269
257 TestAppActivity* app_activity = CreateAppActivity(kDummyApp1); 270 TestAppActivity* app_activity = CreateAppActivity(kDummyApp1);
258 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); 271 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications());
259 AppActivityRegistry* app_activity_registry = 272 AppActivityRegistry* app_activity_registry =
260 app_activity->app_activity_registry(); 273 app_activity->app_activity_registry();
261 EXPECT_EQ(1, app_activity_registry->NumberOfActivities()); 274 EXPECT_EQ(1, app_activity_registry->NumberOfActivities());
262 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app_activity->GetCurrentState()); 275 EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app_activity->GetCurrentState());
263 276
264 // Calling Unload now should not do anything since at least one activity in 277 // Calling Unload now should not do anything since at least one activity in
265 // the registry is still visible. 278 // the registry is still visible.
266 app_activity_registry->Unload(); 279 app_activity_registry->Unload();
267 EXPECT_EQ(0, test_extensions_delegate()->unload_called()); 280 EXPECT_EQ(0, test_extensions_delegate()->unload_called());
268 281
269 // After setting our activity to unloaded however the application should get 282 // After setting our activity to unloaded however the application should get
270 // unloaded as requested. 283 // unloaded as requested.
271 app_activity->SetCurrentState(Activity::ACTIVITY_UNLOADED); 284 app_activity->SetCurrentState(Activity::ACTIVITY_UNLOADED);
272 app_activity_registry->Unload(); 285 app_activity_registry->Unload();
273 EXPECT_EQ(1, test_extensions_delegate()->unload_called()); 286 EXPECT_EQ(1, test_extensions_delegate()->unload_called());
274 287
275 // Check that our created application is gone, and instead a proxy got 288 // Check that our created application is gone, and instead a proxy got
276 // created. 289 // created.
277 ASSERT_EQ(1, AppRegistry::Get()->NumberOfApplications()); 290 ASSERT_EQ(1, AppRegistry::Get()->NumberOfApplications());
278 ASSERT_EQ(app_activity_registry, 291 ASSERT_EQ(app_activity_registry,
279 AppRegistry::Get()->GetAppActivityRegistry(kDummyApp1, NULL)); 292 AppRegistry::Get()->GetAppActivityRegistry(kDummyApp1, NULL));
280 EXPECT_EQ(0, app_activity_registry->NumberOfActivities()); 293 EXPECT_EQ(0, app_activity_registry->NumberOfActivities());
281 Activity* activity_proxy = 294 Activity* activity_proxy = app_activity_registry->unloaded_activity_proxy();
282 app_activity_registry->unloaded_activity_proxy_for_test();
283 ASSERT_TRUE(activity_proxy); 295 ASSERT_TRUE(activity_proxy);
284 EXPECT_NE(app_activity, activity_proxy); 296 EXPECT_NE(app_activity, activity_proxy);
285 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, activity_proxy->GetCurrentState()); 297 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, activity_proxy->GetCurrentState());
298 EXPECT_EQ(0, test_extensions_delegate()->restart_called());
286 299
287 // Close the proxy object and make sure that nothing bad happens. 300 // Close the proxy object and make sure that nothing bad happens.
288 CloseActivity(activity_proxy); 301 CloseActivity(activity_proxy);
289 302
290 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); 303 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
291 EXPECT_EQ(1, test_extensions_delegate()->unload_called()); 304 EXPECT_EQ(1, test_extensions_delegate()->unload_called());
292 EXPECT_EQ(0, test_extensions_delegate()->restart_called()); 305 EXPECT_EQ(0, test_extensions_delegate()->restart_called());
293 } 306 }
294 307
295 // Test that when unloading an app while multiple apps / activities are present, 308 // Test that when unloading an app while multiple apps / activities are present,
296 // the proxy gets created in the correct location. 309 // the proxy gets created in the correct location.
297 TEST_F(AppActivityTest, TestUnloadProxyLocation) { 310 TEST_F(AppActivityTest, TestUnloadProxyLocation) {
298 // Set up some activities for some applications. 311 // Set up some activities for some applications.
299 TestAppActivity* app_activity1a = CreateAppActivity(kDummyApp1); 312 TestAppActivity* app_activity1a = CreateAppActivity(kDummyApp1);
300 TestAppActivity* app_activity2a = CreateAppActivity(kDummyApp2); 313 TestAppActivity* app_activity2a = CreateAppActivity(kDummyApp2);
301 TestAppActivity* app_activity2b = CreateAppActivity(kDummyApp2); 314 TestAppActivity* app_activity2b = CreateAppActivity(kDummyApp2);
302 TestAppActivity* app_activity1b = CreateAppActivity(kDummyApp1); 315 TestAppActivity* app_activity1b = CreateAppActivity(kDummyApp1);
303 EXPECT_EQ(3, GetActivityPosition(app_activity1b)); 316 EXPECT_EQ(3, GetActivityPosition(app_activity1b));
304 EXPECT_EQ(2, GetActivityPosition(app_activity2b)); 317 EXPECT_EQ(2, GetActivityPosition(app_activity2b));
305 EXPECT_EQ(1, GetActivityPosition(app_activity2a)); 318 EXPECT_EQ(1, GetActivityPosition(app_activity2a));
306 EXPECT_EQ(0, GetActivityPosition(app_activity1a)); 319 EXPECT_EQ(0, GetActivityPosition(app_activity1a));
307 320
308 // Unload an app and make sure that the proxy is in the newest activity slot. 321 // Unload an app and make sure that the proxy is in the newest activity slot.
309 AppActivityRegistry* app_activity_registry = 322 AppActivityRegistry* app_activity_registry =
310 app_activity2a->app_activity_registry(); 323 app_activity2a->app_activity_registry();
311 app_activity2a->SetCurrentState(Activity::ACTIVITY_UNLOADED); 324 app_activity2a->SetCurrentState(Activity::ACTIVITY_UNLOADED);
312 app_activity2b->SetCurrentState(Activity::ACTIVITY_UNLOADED); 325 app_activity2b->SetCurrentState(Activity::ACTIVITY_UNLOADED);
313 app_activity2a->app_activity_registry()->Unload(); 326 app_activity2a->app_activity_registry()->Unload();
314 EXPECT_EQ(0, app_activity_registry->NumberOfActivities()); 327 EXPECT_EQ(0, app_activity_registry->NumberOfActivities());
315 Activity* activity_proxy = 328 Activity* activity_proxy = app_activity_registry->unloaded_activity_proxy();
316 app_activity_registry->unloaded_activity_proxy_for_test();
317 RunAllPendingInMessageLoop(); 329 RunAllPendingInMessageLoop();
318 330
319 EXPECT_EQ(2, GetActivityPosition(app_activity1b)); 331 EXPECT_EQ(2, GetActivityPosition(app_activity1b));
320 EXPECT_EQ(1, GetActivityPosition(activity_proxy)); 332 EXPECT_EQ(1, GetActivityPosition(activity_proxy));
321 EXPECT_EQ(0, GetActivityPosition(app_activity1a)); 333 EXPECT_EQ(0, GetActivityPosition(app_activity1a));
334 EXPECT_EQ(0, test_extensions_delegate()->restart_called());
322 335
323 CloseActivity(activity_proxy); 336 CloseActivity(activity_proxy);
324 CloseActivity(app_activity1b); 337 CloseActivity(app_activity1b);
325 CloseActivity(app_activity1a); 338 CloseActivity(app_activity1a);
326 } 339 }
327 340
328 // Test that an unload with multiple activities of the same app will only unload 341 // Test that an unload with multiple activities of the same app will only unload
329 // when all activities were marked for unloading. 342 // when all activities were marked for unloading.
330 TEST_F(AppActivityTest, TestMultipleActivityUnloadLock) { 343 TEST_F(AppActivityTest, TestMultipleActivityUnloadLock) {
331 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); 344 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
(...skipping 22 matching lines...) Expand all
354 EXPECT_EQ(0, test_extensions_delegate()->unload_called()); 367 EXPECT_EQ(0, test_extensions_delegate()->unload_called());
355 app_activity3->SetCurrentState(Activity::ACTIVITY_UNLOADED); 368 app_activity3->SetCurrentState(Activity::ACTIVITY_UNLOADED);
356 app_activity3->app_activity_registry()->Unload(); 369 app_activity3->app_activity_registry()->Unload();
357 EXPECT_EQ(1, test_extensions_delegate()->unload_called()); 370 EXPECT_EQ(1, test_extensions_delegate()->unload_called());
358 371
359 // Now there should only be the proxy activity left. 372 // Now there should only be the proxy activity left.
360 ASSERT_EQ(1, AppRegistry::Get()->NumberOfApplications()); 373 ASSERT_EQ(1, AppRegistry::Get()->NumberOfApplications());
361 ASSERT_EQ(app_activity_registry, 374 ASSERT_EQ(app_activity_registry,
362 AppRegistry::Get()->GetAppActivityRegistry(kDummyApp1, NULL)); 375 AppRegistry::Get()->GetAppActivityRegistry(kDummyApp1, NULL));
363 EXPECT_EQ(0, app_activity_registry->NumberOfActivities()); 376 EXPECT_EQ(0, app_activity_registry->NumberOfActivities());
364 Activity* activity_proxy = 377 Activity* activity_proxy = app_activity_registry->unloaded_activity_proxy();
365 app_activity_registry->unloaded_activity_proxy_for_test();
366 ASSERT_TRUE(activity_proxy); 378 ASSERT_TRUE(activity_proxy);
367 EXPECT_NE(app_activity1, activity_proxy); 379 EXPECT_NE(app_activity1, activity_proxy);
368 EXPECT_NE(app_activity2, activity_proxy); 380 EXPECT_NE(app_activity2, activity_proxy);
369 EXPECT_NE(app_activity3, activity_proxy); 381 EXPECT_NE(app_activity3, activity_proxy);
370 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, activity_proxy->GetCurrentState()); 382 EXPECT_EQ(Activity::ACTIVITY_UNLOADED, activity_proxy->GetCurrentState());
371 383
372 // Close the proxy object and make sure that nothing bad happens. 384 // Close the proxy object and make sure that nothing bad happens.
373 CloseActivity(activity_proxy); 385 CloseActivity(activity_proxy);
374 386
375 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); 387 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
376 EXPECT_EQ(1, test_extensions_delegate()->unload_called()); 388 EXPECT_EQ(1, test_extensions_delegate()->unload_called());
377 EXPECT_EQ(0, test_extensions_delegate()->restart_called()); 389 EXPECT_EQ(0, test_extensions_delegate()->restart_called());
378 } 390 }
379 391
380 // Test that activating the proxy will reload the application. 392 // Test that activating the proxy will reload the application.
381 TEST_F(AppActivityTest, TestUnloadWithReload) { 393 TEST_F(AppActivityTest, TestUnloadWithReload) {
394 // We do not want the ResourceManager to interfere with this test. In this
395 // case it would (dependent on its current internal implementation)
396 // automatically re-load the unloaded activity if it is in an "active"
397 // position.
398 DisableResourceManager();
382 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); 399 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
383 400
384 TestAppActivity* app_activity = CreateAppActivity(kDummyApp1); 401 TestAppActivity* app_activity = CreateAppActivity(kDummyApp1);
385 AppActivityRegistry* app_activity_registry = 402 AppActivityRegistry* app_activity_registry =
386 app_activity->app_activity_registry(); 403 app_activity->app_activity_registry();
387 404
388 // Unload the activity. 405 // Unload the activity.
389 app_activity->SetCurrentState(Activity::ACTIVITY_UNLOADED); 406 app_activity->SetCurrentState(Activity::ACTIVITY_UNLOADED);
390 app_activity_registry->Unload(); 407 app_activity_registry->Unload();
391 EXPECT_EQ(1, test_extensions_delegate()->unload_called()); 408 EXPECT_EQ(1, test_extensions_delegate()->unload_called());
392 409
393 // Try to activate the activity again. This will force the application to 410 // Try to activate the activity again. This will force the application to
394 // reload. 411 // reload.
395 Activity* activity_proxy = 412 Activity* activity_proxy = app_activity_registry->unloaded_activity_proxy();
396 app_activity_registry->unloaded_activity_proxy_for_test();
397 activity_proxy->SetCurrentState(Activity::ACTIVITY_VISIBLE); 413 activity_proxy->SetCurrentState(Activity::ACTIVITY_VISIBLE);
398 EXPECT_EQ(1, test_extensions_delegate()->restart_called()); 414 EXPECT_EQ(1, test_extensions_delegate()->restart_called());
399 415
400 // However - the restart in this test framework does not really restart and 416 // However - the restart in this test framework does not really restart and
401 // all objects should be gone now. 417 // all objects should be still there..
418 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications());
419 EXPECT_TRUE(app_activity_registry->unloaded_activity_proxy());
420 Activity::CloseActivity(app_activity_registry->unloaded_activity_proxy());
402 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); 421 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
403 } 422 }
404 423
405 } // namespace test 424 } // namespace test
406 } // namespace athena 425 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698