OLD | NEW |
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 "chrome/browser/apps/ephemeral_app_browsertest.h" | 5 #include "chrome/browser/apps/ephemeral_app_browsertest.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "apps/app_restore_service.h" | 9 #include "apps/app_restore_service.h" |
10 #include "apps/saved_files_service.h" | 10 #include "apps/saved_files_service.h" |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 CloseAppWaitForUnload(app->id()); | 292 CloseAppWaitForUnload(app->id()); |
293 return result; | 293 return result; |
294 } | 294 } |
295 | 295 |
296 // Verify that the event page of the app has not been loaded. | 296 // Verify that the event page of the app has not been loaded. |
297 void VerifyAppNotLoaded(const std::string& app_id) { | 297 void VerifyAppNotLoaded(const std::string& app_id) { |
298 EXPECT_FALSE(ExtensionSystem::Get(profile())-> | 298 EXPECT_FALSE(ExtensionSystem::Get(profile())-> |
299 process_manager()->GetBackgroundHostForExtension(app_id)); | 299 process_manager()->GetBackgroundHostForExtension(app_id)); |
300 } | 300 } |
301 | 301 |
| 302 // Verify properties of ephemeral apps. |
| 303 void VerifyEphemeralApp(const std::string& app_id) { |
| 304 // Ephemeral apps should not be synced. |
| 305 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app_id); |
| 306 EXPECT_FALSE(sync_change.get()); |
| 307 |
| 308 // Ephemeral apps should not be assigned ordinals. |
| 309 extensions::AppSorting* app_sorting = |
| 310 ExtensionPrefs::Get(profile())->app_sorting(); |
| 311 EXPECT_FALSE(app_sorting->GetAppLaunchOrdinal(app_id).IsValid()); |
| 312 EXPECT_FALSE(app_sorting->GetPageOrdinal(app_id).IsValid()); |
| 313 } |
| 314 |
302 // Verify that after ephemeral apps stop running, they reside in extension | 315 // Verify that after ephemeral apps stop running, they reside in extension |
303 // system in a disabled and unloaded state. | 316 // system in a disabled and unloaded state. |
304 void VerifyInactiveEphemeralApp(const std::string& app_id) { | 317 void VerifyInactiveEphemeralApp(const std::string& app_id) { |
305 EXPECT_TRUE( | 318 EXPECT_TRUE( |
306 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( | 319 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( |
307 app_id)); | 320 app_id)); |
308 | 321 |
309 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 322 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
310 EXPECT_TRUE(prefs->IsExtensionDisabled(app_id)); | 323 EXPECT_TRUE(prefs->IsExtensionDisabled(app_id)); |
311 EXPECT_NE(0, | 324 EXPECT_NE(0, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 386 |
374 ASSERT_TRUE( | 387 ASSERT_TRUE( |
375 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( | 388 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( |
376 app->id())); | 389 app->id())); |
377 } | 390 } |
378 | 391 |
379 void PromoteEphemeralAppAndVerify( | 392 void PromoteEphemeralAppAndVerify( |
380 const Extension* app, | 393 const Extension* app, |
381 ExtensionRegistry::IncludeFlag expected_set) { | 394 ExtensionRegistry::IncludeFlag expected_set) { |
382 ASSERT_TRUE(app); | 395 ASSERT_TRUE(app); |
383 | 396 VerifyEphemeralApp(app->id()); |
384 // Ephemeral apps should not be synced. | |
385 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | |
386 EXPECT_FALSE(sync_change.get()); | |
387 | 397 |
388 // Promote the app to a regular installed app. | 398 // Promote the app to a regular installed app. |
389 InstallObserver installed_observer(profile()); | 399 InstallObserver installed_observer(profile()); |
390 PromoteEphemeralApp(app); | 400 PromoteEphemeralApp(app); |
391 VerifyPromotedApp(app->id(), expected_set); | 401 VerifyPromotedApp(app->id(), expected_set); |
392 | 402 |
393 // Check the notification parameters. | 403 // Check the notification parameters. |
394 const InstallObserver::InstallParameters& params = | 404 const InstallObserver::InstallParameters& params = |
395 installed_observer.Last(); | 405 installed_observer.Last(); |
396 EXPECT_EQ(app->id(), params.id); | 406 EXPECT_EQ(app->id(), params.id); |
397 EXPECT_TRUE(params.is_update); | 407 EXPECT_TRUE(params.is_update); |
398 EXPECT_TRUE(params.from_ephemeral); | 408 EXPECT_TRUE(params.from_ephemeral); |
399 | 409 |
400 // The installation should now be synced. | 410 // The installation should now be synced. |
401 sync_change = GetFirstSyncChangeForApp(app->id()); | 411 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app->id()); |
402 VerifySyncChange(sync_change.get(), | 412 VerifySyncChange(sync_change.get(), |
403 expected_set == ExtensionRegistry::ENABLED); | 413 expected_set == ExtensionRegistry::ENABLED); |
404 } | 414 } |
405 | 415 |
406 void PromoteEphemeralAppFromSyncAndVerify( | 416 void PromoteEphemeralAppFromSyncAndVerify( |
407 const Extension* app, | 417 const Extension* app, |
408 bool enable_from_sync, | 418 bool enable_from_sync, |
409 ExtensionRegistry::IncludeFlag expected_set) { | 419 ExtensionRegistry::IncludeFlag expected_set) { |
410 ASSERT_TRUE(app); | 420 ASSERT_TRUE(app); |
| 421 VerifyEphemeralApp(app->id()); |
411 | 422 |
412 // Simulate an install from sync. | 423 // Simulate an install from sync. |
413 const syncer::StringOrdinal kAppLaunchOrdinal("x"); | 424 const syncer::StringOrdinal kAppLaunchOrdinal("x"); |
414 const syncer::StringOrdinal kPageOrdinal("y"); | 425 const syncer::StringOrdinal kPageOrdinal("y"); |
415 AppSyncData app_sync_data(*app, | 426 AppSyncData app_sync_data(*app, |
416 enable_from_sync, | 427 enable_from_sync, |
417 false /* incognito enabled */, | 428 false /* incognito enabled */, |
418 false /* remote install */, | 429 false /* remote install */, |
419 kAppLaunchOrdinal, | 430 kAppLaunchOrdinal, |
420 kPageOrdinal, | 431 kPageOrdinal, |
(...skipping 21 matching lines...) Expand all Loading... |
442 sync_service->MergeDataAndStartSyncing( | 453 sync_service->MergeDataAndStartSyncing( |
443 syncer::APPS, | 454 syncer::APPS, |
444 syncer::SyncDataList(), | 455 syncer::SyncDataList(), |
445 scoped_ptr<syncer::SyncChangeProcessor>( | 456 scoped_ptr<syncer::SyncChangeProcessor>( |
446 new syncer::SyncChangeProcessorWrapperForTest( | 457 new syncer::SyncChangeProcessorWrapperForTest( |
447 &mock_sync_processor_)), | 458 &mock_sync_processor_)), |
448 scoped_ptr<syncer::SyncErrorFactory>( | 459 scoped_ptr<syncer::SyncErrorFactory>( |
449 new syncer::SyncErrorFactoryMock())); | 460 new syncer::SyncErrorFactoryMock())); |
450 } | 461 } |
451 | 462 |
452 scoped_ptr<AppSyncData> GetFirstSyncChangeForApp(const std::string& id) { | 463 scoped_ptr<AppSyncData> GetLastSyncChangeForApp(const std::string& id) { |
453 scoped_ptr<AppSyncData> sync_data; | 464 scoped_ptr<AppSyncData> sync_data; |
454 for (syncer::SyncChangeList::iterator it = | 465 for (syncer::SyncChangeList::iterator it = |
455 mock_sync_processor_.changes().begin(); | 466 mock_sync_processor_.changes().begin(); |
456 it != mock_sync_processor_.changes().end(); ++it) { | 467 it != mock_sync_processor_.changes().end(); ++it) { |
457 sync_data.reset(new AppSyncData(*it)); | 468 scoped_ptr<AppSyncData> data(new AppSyncData(*it)); |
458 if (sync_data->id() == id) | 469 if (data->id() == id) |
459 return sync_data.Pass(); | 470 sync_data.reset(data.release()); |
460 } | 471 } |
461 | 472 |
462 return scoped_ptr<AppSyncData>(); | 473 return sync_data.Pass(); |
463 } | 474 } |
464 | 475 |
465 void VerifySyncChange(const AppSyncData* sync_change, bool expect_enabled) { | 476 void VerifySyncChange(const AppSyncData* sync_change, bool expect_enabled) { |
466 ASSERT_TRUE(sync_change); | 477 ASSERT_TRUE(sync_change); |
467 EXPECT_TRUE(sync_change->page_ordinal().IsValid()); | 478 EXPECT_TRUE(sync_change->page_ordinal().IsValid()); |
468 EXPECT_TRUE(sync_change->app_launch_ordinal().IsValid()); | 479 EXPECT_TRUE(sync_change->app_launch_ordinal().IsValid()); |
469 EXPECT_FALSE(sync_change->uninstalled()); | 480 EXPECT_FALSE(sync_change->uninstalled()); |
470 EXPECT_EQ(expect_enabled, sync_change->extension_sync_data().enabled()); | 481 EXPECT_EQ(expect_enabled, sync_change->extension_sync_data().enabled()); |
471 } | 482 } |
472 | 483 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 ExtensionSystem::Get(profile())->extension_service(); | 784 ExtensionSystem::Get(profile())->extension_service(); |
774 service->BlacklistExtensionForTest(app->id()); | 785 service->BlacklistExtensionForTest(app->id()); |
775 ASSERT_TRUE( | 786 ASSERT_TRUE( |
776 ExtensionRegistry::Get(profile())->blacklisted_extensions().Contains( | 787 ExtensionRegistry::Get(profile())->blacklisted_extensions().Contains( |
777 app->id())); | 788 app->id())); |
778 | 789 |
779 // When promoted to a regular installed app, it should remain blacklisted. | 790 // When promoted to a regular installed app, it should remain blacklisted. |
780 PromoteEphemeralAppAndVerify(app, ExtensionRegistry::BLACKLISTED); | 791 PromoteEphemeralAppAndVerify(app, ExtensionRegistry::BLACKLISTED); |
781 | 792 |
782 // The app should be synced, but disabled. | 793 // The app should be synced, but disabled. |
783 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | 794 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app->id()); |
784 VerifySyncChange(sync_change.get(), false); | 795 VerifySyncChange(sync_change.get(), false); |
785 } | 796 } |
786 | 797 |
787 // Checks the process of promoting an ephemeral app from sync while the app is | 798 // Checks the process of promoting an ephemeral app from sync while the app is |
788 // running. | 799 // running. |
789 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, | 800 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, |
790 PromoteAppFromSyncWhileRunning) { | 801 PromoteAppFromSyncWhileRunning) { |
791 InitSyncService(); | 802 InitSyncService(); |
792 | 803 |
793 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); | 804 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 | 940 |
930 // Ensure that when the app is promoted to an installed app, the bit in the | 941 // Ensure that when the app is promoted to an installed app, the bit in the |
931 // creation flags is cleared. | 942 // creation flags is cleared. |
932 PromoteEphemeralApp(app); | 943 PromoteEphemeralApp(app); |
933 EXPECT_FALSE(extensions::util::IsEphemeralApp(app->id(), profile())); | 944 EXPECT_FALSE(extensions::util::IsEphemeralApp(app->id(), profile())); |
934 | 945 |
935 int creation_flags = | 946 int creation_flags = |
936 ExtensionPrefs::Get(profile())->GetCreationFlags(app->id()); | 947 ExtensionPrefs::Get(profile())->GetCreationFlags(app->id()); |
937 EXPECT_EQ(0, creation_flags & Extension::IS_EPHEMERAL); | 948 EXPECT_EQ(0, creation_flags & Extension::IS_EPHEMERAL); |
938 } | 949 } |
OLD | NEW |