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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 using extensions::ExtensionRegistryObserver; | 54 using extensions::ExtensionRegistryObserver; |
55 using extensions::ExtensionSystem; | 55 using extensions::ExtensionSystem; |
56 using extensions::Manifest; | 56 using extensions::Manifest; |
57 | 57 |
58 namespace { | 58 namespace { |
59 | 59 |
60 namespace alarms = extensions::api::alarms; | 60 namespace alarms = extensions::api::alarms; |
61 | 61 |
62 const char kPowerTestApp[] = "ephemeral_apps/power"; | 62 const char kPowerTestApp[] = "ephemeral_apps/power"; |
63 | 63 |
64 // Enabling sync causes these tests to be flaky on Windows. Disable sync so that | |
65 // everything else can be tested. See crbug.com/401028 | |
benwells
2014/08/26 03:09:54
This makes me a bit uneasy. Is there some underlyi
tmdiep
2014/08/26 03:44:45
Yes.
This patch is intended to be a temporary band
benwells
2014/08/26 03:58:12
OK. It is probably that someone else that should b
tmdiep
2014/08/26 04:29:39
I think it's sync related. There are other browser
| |
66 #if defined(OS_WIN) | |
67 const bool kEnableSync = false; | |
68 #else | |
69 const bool kEnableSync = true; | |
70 #endif | |
71 | |
64 typedef std::vector<message_center::Notifier*> NotifierList; | 72 typedef std::vector<message_center::Notifier*> NotifierList; |
65 | 73 |
66 bool IsNotifierInList(const message_center::NotifierId& notifier_id, | 74 bool IsNotifierInList(const message_center::NotifierId& notifier_id, |
67 const NotifierList& notifiers) { | 75 const NotifierList& notifiers) { |
68 for (NotifierList::const_iterator it = notifiers.begin(); | 76 for (NotifierList::const_iterator it = notifiers.begin(); |
69 it != notifiers.end(); ++it) { | 77 it != notifiers.end(); ++it) { |
70 const message_center::Notifier* notifier = *it; | 78 const message_center::Notifier* notifier = *it; |
71 if (notifier->notifier_id == notifier_id) | 79 if (notifier->notifier_id == notifier_id) |
72 return true; | 80 return true; |
73 } | 81 } |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 | 506 |
499 // The sort ordinals from sync should not be overridden. | 507 // The sort ordinals from sync should not be overridden. |
500 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 508 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
501 extensions::AppSorting* app_sorting = prefs->app_sorting(); | 509 extensions::AppSorting* app_sorting = prefs->app_sorting(); |
502 EXPECT_TRUE( | 510 EXPECT_TRUE( |
503 app_sorting->GetAppLaunchOrdinal(app_id).Equals(kAppLaunchOrdinal)); | 511 app_sorting->GetAppLaunchOrdinal(app_id).Equals(kAppLaunchOrdinal)); |
504 EXPECT_TRUE(app_sorting->GetPageOrdinal(app_id).Equals(kPageOrdinal)); | 512 EXPECT_TRUE(app_sorting->GetPageOrdinal(app_id).Equals(kPageOrdinal)); |
505 } | 513 } |
506 | 514 |
507 void InitSyncService() { | 515 void InitSyncService() { |
516 if (!kEnableSync) | |
517 return; | |
518 | |
508 ExtensionSyncService* sync_service = ExtensionSyncService::Get(profile()); | 519 ExtensionSyncService* sync_service = ExtensionSyncService::Get(profile()); |
509 sync_service->MergeDataAndStartSyncing( | 520 sync_service->MergeDataAndStartSyncing( |
510 syncer::APPS, | 521 syncer::APPS, |
511 syncer::SyncDataList(), | 522 syncer::SyncDataList(), |
512 scoped_ptr<syncer::SyncChangeProcessor>( | 523 scoped_ptr<syncer::SyncChangeProcessor>( |
513 new syncer::SyncChangeProcessorWrapperForTest( | 524 new syncer::SyncChangeProcessorWrapperForTest( |
514 &mock_sync_processor_)), | 525 &mock_sync_processor_)), |
515 scoped_ptr<syncer::SyncErrorFactory>( | 526 scoped_ptr<syncer::SyncErrorFactory>( |
516 new syncer::SyncErrorFactoryMock())); | 527 new syncer::SyncErrorFactoryMock())); |
517 } | 528 } |
518 | 529 |
519 scoped_ptr<AppSyncData> GetLastSyncChangeForApp(const std::string& id) { | 530 scoped_ptr<AppSyncData> GetLastSyncChangeForApp(const std::string& id) { |
520 scoped_ptr<AppSyncData> sync_data; | 531 scoped_ptr<AppSyncData> sync_data; |
521 for (syncer::SyncChangeList::iterator it = | 532 for (syncer::SyncChangeList::iterator it = |
522 mock_sync_processor_.changes().begin(); | 533 mock_sync_processor_.changes().begin(); |
523 it != mock_sync_processor_.changes().end(); ++it) { | 534 it != mock_sync_processor_.changes().end(); ++it) { |
524 scoped_ptr<AppSyncData> data(new AppSyncData(*it)); | 535 scoped_ptr<AppSyncData> data(new AppSyncData(*it)); |
525 if (data->id() == id) | 536 if (data->id() == id) |
526 sync_data.reset(data.release()); | 537 sync_data.reset(data.release()); |
527 } | 538 } |
528 | 539 |
529 return sync_data.Pass(); | 540 return sync_data.Pass(); |
530 } | 541 } |
531 | 542 |
532 void VerifySyncChange(const AppSyncData* sync_change, bool expect_enabled) { | 543 void VerifySyncChange(const AppSyncData* sync_change, bool expect_enabled) { |
544 if (!kEnableSync) | |
545 return; | |
546 | |
533 ASSERT_TRUE(sync_change); | 547 ASSERT_TRUE(sync_change); |
534 EXPECT_TRUE(sync_change->page_ordinal().IsValid()); | 548 EXPECT_TRUE(sync_change->page_ordinal().IsValid()); |
535 EXPECT_TRUE(sync_change->app_launch_ordinal().IsValid()); | 549 EXPECT_TRUE(sync_change->app_launch_ordinal().IsValid()); |
536 EXPECT_FALSE(sync_change->uninstalled()); | 550 EXPECT_FALSE(sync_change->uninstalled()); |
537 EXPECT_EQ(expect_enabled, sync_change->extension_sync_data().enabled()); | 551 EXPECT_EQ(expect_enabled, sync_change->extension_sync_data().enabled()); |
538 } | 552 } |
539 | 553 |
540 void TestInstallEvent(bool close_app) { | 554 void TestInstallEvent(bool close_app) { |
541 ExtensionTestMessageListener first_msg_listener(false); | 555 ExtensionTestMessageListener first_msg_listener(false); |
542 const Extension* app = InstallAndLaunchEphemeralApp(kDispatchEventTestApp); | 556 const Extension* app = InstallAndLaunchEphemeralApp(kDispatchEventTestApp); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 CloseAppWaitForUnload(app->id()); | 922 CloseAppWaitForUnload(app->id()); |
909 VerifyInactiveEphemeralApp(app->id()); | 923 VerifyInactiveEphemeralApp(app->id()); |
910 | 924 |
911 PromoteEphemeralAppFromSyncAndVerify(app, false, ExtensionRegistry::DISABLED); | 925 PromoteEphemeralAppFromSyncAndVerify(app, false, ExtensionRegistry::DISABLED); |
912 } | 926 } |
913 | 927 |
914 // In most cases, ExtensionService::PromoteEphemeralApp() will be called to | 928 // In most cases, ExtensionService::PromoteEphemeralApp() will be called to |
915 // permanently install an ephemeral app. However, there may be cases where an | 929 // permanently install an ephemeral app. However, there may be cases where an |
916 // install occurs through the usual route of installing from the Web Store (due | 930 // install occurs through the usual route of installing from the Web Store (due |
917 // to race conditions). Ensure that the app is still installed correctly. | 931 // to race conditions). Ensure that the app is still installed correctly. |
918 #if defined(OS_WIN) | |
919 // Disabled on Windows due to failures. See crbug.com/401028 | |
920 #define MAYBE_ReplaceEphemeralAppWithInstalledApp \ | |
921 DISABLED_ReplaceEphemeralAppWithInstalledApp | |
922 #else | |
923 #define MAYBE_ReplaceEphemeralAppWithInstalledApp \ | |
924 ReplaceEphemeralAppWithInstalledApp | |
925 #endif | |
926 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, | 932 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, |
927 MAYBE_ReplaceEphemeralAppWithInstalledApp) { | 933 ReplaceEphemeralAppWithInstalledApp) { |
928 InitSyncService(); | 934 InitSyncService(); |
929 | 935 |
930 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); | 936 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); |
931 ASSERT_TRUE(app); | 937 ASSERT_TRUE(app); |
932 CloseAppWaitForUnload(app->id()); | 938 CloseAppWaitForUnload(app->id()); |
933 std::string app_id = app->id(); | 939 std::string app_id = app->id(); |
934 app = NULL; | 940 app = NULL; |
935 | 941 |
936 InstallObserver installed_observer(profile()); | 942 InstallObserver installed_observer(profile()); |
937 ReplaceEphemeralApp(app_id, kNotificationsTestApp, 1); | 943 ReplaceEphemeralApp(app_id, kNotificationsTestApp, 1); |
938 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); | 944 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); |
939 | 945 |
940 // Check the notification parameters. | 946 // Check the notification parameters. |
941 const InstallObserver::InstallParameters& params = installed_observer.Last(); | 947 const InstallObserver::InstallParameters& params = installed_observer.Last(); |
942 EXPECT_EQ(app_id, params.id); | 948 EXPECT_EQ(app_id, params.id); |
943 EXPECT_TRUE(params.is_update); | 949 EXPECT_TRUE(params.is_update); |
944 EXPECT_TRUE(params.from_ephemeral); | 950 EXPECT_TRUE(params.from_ephemeral); |
945 } | 951 } |
946 | 952 |
947 // This is similar to ReplaceEphemeralAppWithInstalledApp, but installs will | 953 // This is similar to ReplaceEphemeralAppWithInstalledApp, but installs will |
948 // be delayed until the app is idle. | 954 // be delayed until the app is idle. |
949 #if defined(OS_WIN) | |
950 // Disabled on Windows due to failures. See crbug.com/401028 | |
951 #define MAYBE_ReplaceEphemeralAppWithDelayedInstalledApp \ | |
952 DISABLED_ReplaceEphemeralAppWithDelayedInstalledApp | |
953 #else | |
954 #define MAYBE_ReplaceEphemeralAppWithDelayedInstalledApp \ | |
955 ReplaceEphemeralAppWithDelayedInstalledApp | |
956 #endif | |
957 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, | 955 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, |
958 MAYBE_ReplaceEphemeralAppWithDelayedInstalledApp) { | 956 ReplaceEphemeralAppWithDelayedInstalledApp) { |
959 InitSyncService(); | 957 InitSyncService(); |
960 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); | 958 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); |
961 ASSERT_TRUE(app); | 959 ASSERT_TRUE(app); |
962 std::string app_id = app->id(); | 960 std::string app_id = app->id(); |
963 app = NULL; | 961 app = NULL; |
964 | 962 |
965 // Initiate install. | 963 // Initiate install. |
966 ReplaceEphemeralApp(app_id, kNotificationsTestApp, 0); | 964 ReplaceEphemeralApp(app_id, kNotificationsTestApp, 0); |
967 | 965 |
968 // The delayed installation will occur when the ephemeral app is closed. | 966 // The delayed installation will occur when the ephemeral app is closed. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1035 base::Bind(&PowerSaveBlockerStub::Create, &power_settings)); | 1033 base::Bind(&PowerSaveBlockerStub::Create, &power_settings)); |
1036 | 1034 |
1037 const Extension* app = InstallAndLaunchEphemeralApp(kPowerTestApp); | 1035 const Extension* app = InstallAndLaunchEphemeralApp(kPowerTestApp); |
1038 ASSERT_TRUE(app); | 1036 ASSERT_TRUE(app); |
1039 EXPECT_EQ(1, power_settings.keep_awake_count()); | 1037 EXPECT_EQ(1, power_settings.keep_awake_count()); |
1040 | 1038 |
1041 CloseAppWaitForUnload(app->id()); | 1039 CloseAppWaitForUnload(app->id()); |
1042 | 1040 |
1043 EXPECT_EQ(0, power_settings.keep_awake_count()); | 1041 EXPECT_EQ(0, power_settings.keep_awake_count()); |
1044 } | 1042 } |
OLD | NEW |