| 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/saved_files_service.h" | 9 #include "apps/saved_files_service.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 270 |
| 271 CloseApp(app->id()); | 271 CloseApp(app->id()); |
| 272 return result; | 272 return result; |
| 273 } | 273 } |
| 274 | 274 |
| 275 void VerifyAppNotLoaded(const std::string& app_id) { | 275 void VerifyAppNotLoaded(const std::string& app_id) { |
| 276 EXPECT_FALSE(ExtensionSystem::Get(profile())-> | 276 EXPECT_FALSE(ExtensionSystem::Get(profile())-> |
| 277 process_manager()->GetBackgroundHostForExtension(app_id)); | 277 process_manager()->GetBackgroundHostForExtension(app_id)); |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Verify properties of ephemeral apps. |
| 281 void VerifyEphemeralApp(const std::string& app_id) { |
| 282 EXPECT_TRUE(extensions::util::IsEphemeralApp(app_id, profile())); |
| 283 |
| 284 // Ephemeral apps should not be synced. |
| 285 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app_id); |
| 286 EXPECT_FALSE(sync_change.get()); |
| 287 |
| 288 // Ephemeral apps should not be assigned ordinals. |
| 289 extensions::AppSorting* app_sorting = |
| 290 ExtensionPrefs::Get(profile())->app_sorting(); |
| 291 EXPECT_FALSE(app_sorting->GetAppLaunchOrdinal(app_id).IsValid()); |
| 292 EXPECT_FALSE(app_sorting->GetPageOrdinal(app_id).IsValid()); |
| 293 } |
| 294 |
| 295 // Dispatch a fake alarm event to the app. |
| 280 void DispatchAlarmEvent(EventRouter* event_router, | 296 void DispatchAlarmEvent(EventRouter* event_router, |
| 281 const std::string& app_id) { | 297 const std::string& app_id) { |
| 282 alarms::Alarm dummy_alarm; | 298 alarms::Alarm dummy_alarm; |
| 283 dummy_alarm.name = "test_alarm"; | 299 dummy_alarm.name = "test_alarm"; |
| 284 | 300 |
| 285 scoped_ptr<base::ListValue> args(new base::ListValue()); | 301 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 286 args->Append(dummy_alarm.ToValue().release()); | 302 args->Append(dummy_alarm.ToValue().release()); |
| 287 scoped_ptr<Event> event(new Event(alarms::OnAlarm::kEventName, | 303 scoped_ptr<Event> event(new Event(alarms::OnAlarm::kEventName, |
| 288 args.Pass())); | 304 args.Pass())); |
| 289 | 305 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 317 sync_service->MergeDataAndStartSyncing( | 333 sync_service->MergeDataAndStartSyncing( |
| 318 syncer::APPS, | 334 syncer::APPS, |
| 319 syncer::SyncDataList(), | 335 syncer::SyncDataList(), |
| 320 scoped_ptr<syncer::SyncChangeProcessor>( | 336 scoped_ptr<syncer::SyncChangeProcessor>( |
| 321 new syncer::SyncChangeProcessorWrapperForTest( | 337 new syncer::SyncChangeProcessorWrapperForTest( |
| 322 &mock_sync_processor_)), | 338 &mock_sync_processor_)), |
| 323 scoped_ptr<syncer::SyncErrorFactory>( | 339 scoped_ptr<syncer::SyncErrorFactory>( |
| 324 new syncer::SyncErrorFactoryMock())); | 340 new syncer::SyncErrorFactoryMock())); |
| 325 } | 341 } |
| 326 | 342 |
| 327 scoped_ptr<AppSyncData> GetFirstSyncChangeForApp(const std::string& id) { | 343 scoped_ptr<AppSyncData> GetLastSyncChangeForApp(const std::string& id) { |
| 328 scoped_ptr<AppSyncData> sync_data; | 344 scoped_ptr<AppSyncData> sync_data; |
| 329 for (syncer::SyncChangeList::iterator it = | 345 for (syncer::SyncChangeList::iterator it = |
| 330 mock_sync_processor_.changes().begin(); | 346 mock_sync_processor_.changes().begin(); |
| 331 it != mock_sync_processor_.changes().end(); ++it) { | 347 it != mock_sync_processor_.changes().end(); ++it) { |
| 332 sync_data.reset(new AppSyncData(*it)); | 348 scoped_ptr<AppSyncData> data(new AppSyncData(*it)); |
| 333 if (sync_data->id() == id) | 349 if (data->id() == id) |
| 334 return sync_data.Pass(); | 350 sync_data.reset(data.release()); |
| 335 } | 351 } |
| 336 | 352 |
| 337 return scoped_ptr<AppSyncData>(); | 353 return sync_data.Pass(); |
| 338 } | 354 } |
| 339 | 355 |
| 340 void VerifySyncChange(const AppSyncData* sync_change, bool expect_enabled) { | 356 void VerifySyncChange(const AppSyncData* sync_change, bool expect_enabled) { |
| 341 ASSERT_TRUE(sync_change); | 357 ASSERT_TRUE(sync_change); |
| 342 EXPECT_TRUE(sync_change->page_ordinal().IsValid()); | 358 EXPECT_TRUE(sync_change->page_ordinal().IsValid()); |
| 343 EXPECT_TRUE(sync_change->app_launch_ordinal().IsValid()); | 359 EXPECT_TRUE(sync_change->app_launch_ordinal().IsValid()); |
| 344 EXPECT_FALSE(sync_change->uninstalled()); | 360 EXPECT_FALSE(sync_change->uninstalled()); |
| 345 EXPECT_EQ(expect_enabled, sync_change->extension_sync_data().enabled()); | 361 EXPECT_EQ(expect_enabled, sync_change->extension_sync_data().enabled()); |
| 346 } | 362 } |
| 347 | 363 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 CloseApp(receiver->id()); | 411 CloseApp(receiver->id()); |
| 396 | 412 |
| 397 // Verify that messages are not received while the app is inactive. | 413 // Verify that messages are not received while the app is inactive. |
| 398 LoadAndLaunchPlatformApp("ephemeral_apps/messaging_sender_fail", "Launched"); | 414 LoadAndLaunchPlatformApp("ephemeral_apps/messaging_sender_fail", "Launched"); |
| 399 EXPECT_TRUE(result_catcher.GetNextResult()); | 415 EXPECT_TRUE(result_catcher.GetNextResult()); |
| 400 } | 416 } |
| 401 | 417 |
| 402 // Verify that an updated ephemeral app will still have its ephemeral flag | 418 // Verify that an updated ephemeral app will still have its ephemeral flag |
| 403 // enabled. | 419 // enabled. |
| 404 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, UpdateEphemeralApp) { | 420 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, UpdateEphemeralApp) { |
| 405 const Extension* app_v1 = InstallEphemeralApp(kMessagingReceiverApp); | 421 InitSyncService(); |
| 422 |
| 423 const Extension* app_v1 = InstallAndLaunchEphemeralApp(kMessagingReceiverApp); |
| 406 ASSERT_TRUE(app_v1); | 424 ASSERT_TRUE(app_v1); |
| 407 std::string app_id = app_v1->id(); | 425 std::string app_id = app_v1->id(); |
| 408 base::Version app_original_version = *app_v1->version(); | 426 base::Version app_original_version = *app_v1->version(); |
| 409 app_v1 = NULL; // The extension object will be destroyed during update. | 427 |
| 428 VerifyEphemeralApp(app_id); |
| 429 CloseApp(app_id); |
| 410 | 430 |
| 411 // Update to version 2 of the app. | 431 // Update to version 2 of the app. |
| 432 app_v1 = NULL; // The extension object will be destroyed during update. |
| 412 InstallObserver installed_observer(profile()); | 433 InstallObserver installed_observer(profile()); |
| 413 const Extension* app_v2 = UpdateEphemeralApp( | 434 const Extension* app_v2 = UpdateEphemeralApp( |
| 414 app_id, GetTestPath(kMessagingReceiverAppV2), | 435 app_id, GetTestPath(kMessagingReceiverAppV2), |
| 415 GetTestPath(kMessagingReceiverApp).ReplaceExtension( | 436 GetTestPath(kMessagingReceiverApp).ReplaceExtension( |
| 416 FILE_PATH_LITERAL(".pem"))); | 437 FILE_PATH_LITERAL(".pem"))); |
| 417 | 438 |
| 418 // Check the notification parameters. | 439 // Check the notification parameters. |
| 419 const InstallObserver::InstallParameters& params = installed_observer.Last(); | 440 const InstallObserver::InstallParameters& params = installed_observer.Last(); |
| 420 EXPECT_EQ(app_id, params.id); | 441 EXPECT_EQ(app_id, params.id); |
| 421 EXPECT_TRUE(params.is_update); | 442 EXPECT_TRUE(params.is_update); |
| 422 EXPECT_FALSE(params.from_ephemeral); | 443 EXPECT_FALSE(params.from_ephemeral); |
| 423 | 444 |
| 424 // The ephemeral flag should still be enabled. | 445 // The ephemeral flag should still be enabled. |
| 425 ASSERT_TRUE(app_v2); | 446 ASSERT_TRUE(app_v2); |
| 426 EXPECT_TRUE(app_v2->version()->CompareTo(app_original_version) > 0); | 447 EXPECT_GT(app_v2->version()->CompareTo(app_original_version), 0); |
| 427 EXPECT_TRUE(extensions::util::IsEphemeralApp(app_v2->id(), profile())); | 448 VerifyEphemeralApp(app_id); |
| 428 } | 449 } |
| 429 | 450 |
| 430 // Verify that if notifications have been disabled for an ephemeral app, it will | 451 // Verify that if notifications have been disabled for an ephemeral app, it will |
| 431 // remain disabled even after being evicted from the cache. | 452 // remain disabled even after being evicted from the cache. |
| 432 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, StickyNotificationSettings) { | 453 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, StickyNotificationSettings) { |
| 433 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); | 454 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 434 ASSERT_TRUE(app); | 455 ASSERT_TRUE(app); |
| 435 | 456 |
| 436 // Disable notifications for this app. | 457 // Disable notifications for this app. |
| 437 DesktopNotificationService* notification_service = | 458 DesktopNotificationService* notification_service = |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 547 } |
| 527 | 548 |
| 528 // Checks the process of installing and then promoting an ephemeral app. | 549 // Checks the process of installing and then promoting an ephemeral app. |
| 529 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralApp) { | 550 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralApp) { |
| 530 InitSyncService(); | 551 InitSyncService(); |
| 531 | 552 |
| 532 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); | 553 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 533 ASSERT_TRUE(app); | 554 ASSERT_TRUE(app); |
| 534 | 555 |
| 535 // Ephemeral apps should not be synced. | 556 // Ephemeral apps should not be synced. |
| 536 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | 557 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app->id()); |
| 537 EXPECT_FALSE(sync_change.get()); | 558 EXPECT_FALSE(sync_change.get()); |
| 538 | 559 |
| 539 // Promote the app to a regular installed app. | 560 // Promote the app to a regular installed app. |
| 540 InstallObserver installed_observer(profile()); | 561 InstallObserver installed_observer(profile()); |
| 541 PromoteEphemeralApp(app); | 562 PromoteEphemeralApp(app); |
| 542 VerifyPromotedApp(app->id(), ExtensionRegistry::ENABLED); | 563 VerifyPromotedApp(app->id(), ExtensionRegistry::ENABLED); |
| 543 | 564 |
| 544 // Check the notification parameters. | 565 // Check the notification parameters. |
| 545 const InstallObserver::InstallParameters& params = installed_observer.Last(); | 566 const InstallObserver::InstallParameters& params = installed_observer.Last(); |
| 546 EXPECT_EQ(app->id(), params.id); | 567 EXPECT_EQ(app->id(), params.id); |
| 547 EXPECT_TRUE(params.is_update); | 568 EXPECT_TRUE(params.is_update); |
| 548 EXPECT_TRUE(params.from_ephemeral); | 569 EXPECT_TRUE(params.from_ephemeral); |
| 549 | 570 |
| 550 // The installation should now be synced. | 571 // The installation should now be synced. |
| 551 sync_change = GetFirstSyncChangeForApp(app->id()); | 572 sync_change = GetLastSyncChangeForApp(app->id()); |
| 552 VerifySyncChange(sync_change.get(), true); | 573 VerifySyncChange(sync_change.get(), true); |
| 553 } | 574 } |
| 554 | 575 |
| 555 // Verifies that promoting an ephemeral app will enable it. | 576 // Verifies that promoting an ephemeral app will enable it. |
| 556 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralAppAndEnable) { | 577 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralAppAndEnable) { |
| 557 InitSyncService(); | 578 InitSyncService(); |
| 558 | 579 |
| 559 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); | 580 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 560 ASSERT_TRUE(app); | 581 ASSERT_TRUE(app); |
| 561 | 582 |
| 562 // Disable the ephemeral app due to a permissions increase. This also involves | 583 // Disable the ephemeral app due to a permissions increase. This also involves |
| 563 // setting the DidExtensionEscalatePermissions flag. | 584 // setting the DidExtensionEscalatePermissions flag. |
| 564 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 585 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 565 prefs->SetDidExtensionEscalatePermissions(app, true); | 586 prefs->SetDidExtensionEscalatePermissions(app, true); |
| 566 ExtensionService* service = | 587 ExtensionService* service = |
| 567 ExtensionSystem::Get(profile())->extension_service(); | 588 ExtensionSystem::Get(profile())->extension_service(); |
| 568 service->DisableExtension(app->id(), Extension::DISABLE_PERMISSIONS_INCREASE); | 589 service->DisableExtension(app->id(), Extension::DISABLE_PERMISSIONS_INCREASE); |
| 569 ASSERT_TRUE(ExtensionRegistry::Get(profile())-> | 590 ASSERT_TRUE(ExtensionRegistry::Get(profile())-> |
| 570 GetExtensionById(app->id(), ExtensionRegistry::DISABLED)); | 591 GetExtensionById(app->id(), ExtensionRegistry::DISABLED)); |
| 571 | 592 |
| 572 // Promote to a regular installed app. It should be enabled. | 593 // Promote to a regular installed app. It should be enabled. |
| 573 PromoteEphemeralApp(app); | 594 PromoteEphemeralApp(app); |
| 574 VerifyPromotedApp(app->id(), ExtensionRegistry::ENABLED); | 595 VerifyPromotedApp(app->id(), ExtensionRegistry::ENABLED); |
| 575 EXPECT_FALSE(prefs->DidExtensionEscalatePermissions(app->id())); | 596 EXPECT_FALSE(prefs->DidExtensionEscalatePermissions(app->id())); |
| 576 | 597 |
| 577 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | 598 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app->id()); |
| 578 VerifySyncChange(sync_change.get(), true); | 599 VerifySyncChange(sync_change.get(), true); |
| 579 } | 600 } |
| 580 | 601 |
| 581 // Verifies that promoting an ephemeral app that has unsupported requirements | 602 // Verifies that promoting an ephemeral app that has unsupported requirements |
| 582 // will not enable it. | 603 // will not enable it. |
| 583 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, | 604 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, |
| 584 PromoteUnsupportedEphemeralApp) { | 605 PromoteUnsupportedEphemeralApp) { |
| 585 InitSyncService(); | 606 InitSyncService(); |
| 586 | 607 |
| 587 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); | 608 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 588 ASSERT_TRUE(app); | 609 ASSERT_TRUE(app); |
| 589 | 610 |
| 590 // Disable the ephemeral app. | 611 // Disable the ephemeral app. |
| 591 ExtensionService* service = | 612 ExtensionService* service = |
| 592 ExtensionSystem::Get(profile())->extension_service(); | 613 ExtensionSystem::Get(profile())->extension_service(); |
| 593 service->DisableExtension( | 614 service->DisableExtension( |
| 594 app->id(), Extension::DISABLE_UNSUPPORTED_REQUIREMENT); | 615 app->id(), Extension::DISABLE_UNSUPPORTED_REQUIREMENT); |
| 595 ASSERT_TRUE(ExtensionRegistry::Get(profile())-> | 616 ASSERT_TRUE(ExtensionRegistry::Get(profile())-> |
| 596 GetExtensionById(app->id(), ExtensionRegistry::DISABLED)); | 617 GetExtensionById(app->id(), ExtensionRegistry::DISABLED)); |
| 597 | 618 |
| 598 // Promote to a regular installed app. It should remain disabled. | 619 // Promote to a regular installed app. It should remain disabled. |
| 599 PromoteEphemeralApp(app); | 620 PromoteEphemeralApp(app); |
| 600 VerifyPromotedApp(app->id(), ExtensionRegistry::DISABLED); | 621 VerifyPromotedApp(app->id(), ExtensionRegistry::DISABLED); |
| 601 | 622 |
| 602 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | 623 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app->id()); |
| 603 VerifySyncChange(sync_change.get(), false); | 624 VerifySyncChange(sync_change.get(), false); |
| 604 } | 625 } |
| 605 | 626 |
| 606 // Checks the process of promoting an ephemeral app from sync. | 627 // Checks the process of promoting an ephemeral app from sync. |
| 607 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralAppFromSync) { | 628 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralAppFromSync) { |
| 608 InitSyncService(); | 629 InitSyncService(); |
| 609 | 630 |
| 610 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); | 631 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 611 ASSERT_TRUE(app); | 632 ASSERT_TRUE(app); |
| 612 std::string app_id = app->id(); | 633 std::string app_id = app->id(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 | 724 |
| 704 // Ensure that when the app is promoted to an installed app, the bit in the | 725 // Ensure that when the app is promoted to an installed app, the bit in the |
| 705 // creation flags is cleared. | 726 // creation flags is cleared. |
| 706 PromoteEphemeralApp(app); | 727 PromoteEphemeralApp(app); |
| 707 EXPECT_FALSE(extensions::util::IsEphemeralApp(app->id(), profile())); | 728 EXPECT_FALSE(extensions::util::IsEphemeralApp(app->id(), profile())); |
| 708 | 729 |
| 709 int creation_flags = | 730 int creation_flags = |
| 710 ExtensionPrefs::Get(profile())->GetCreationFlags(app->id()); | 731 ExtensionPrefs::Get(profile())->GetCreationFlags(app->id()); |
| 711 EXPECT_EQ(0, creation_flags & Extension::IS_EPHEMERAL); | 732 EXPECT_EQ(0, creation_flags & Extension::IS_EPHEMERAL); |
| 712 } | 733 } |
| OLD | NEW |