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 13 matching lines...) Expand all Loading... |
24 #include "content/public/test/browser_test.h" | 24 #include "content/public/test/browser_test.h" |
25 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
26 #include "extensions/browser/api/power/power_api.h" | 26 #include "extensions/browser/api/power/power_api.h" |
27 #include "extensions/browser/app_sorting.h" | 27 #include "extensions/browser/app_sorting.h" |
28 #include "extensions/browser/event_router.h" | 28 #include "extensions/browser/event_router.h" |
29 #include "extensions/browser/extension_prefs.h" | 29 #include "extensions/browser/extension_prefs.h" |
30 #include "extensions/browser/extension_registry.h" | 30 #include "extensions/browser/extension_registry.h" |
31 #include "extensions/browser/extension_registry_observer.h" | 31 #include "extensions/browser/extension_registry_observer.h" |
32 #include "extensions/browser/extension_system.h" | 32 #include "extensions/browser/extension_system.h" |
33 #include "extensions/browser/extension_util.h" | 33 #include "extensions/browser/extension_util.h" |
34 #include "extensions/browser/notification_types.h" | |
35 #include "extensions/browser/process_manager.h" | 34 #include "extensions/browser/process_manager.h" |
| 35 #include "extensions/browser/test_extension_registry_observer.h" |
36 #include "extensions/browser/uninstall_reason.h" | 36 #include "extensions/browser/uninstall_reason.h" |
37 #include "extensions/common/api/alarms.h" | 37 #include "extensions/common/api/alarms.h" |
38 #include "extensions/common/extension.h" | 38 #include "extensions/common/extension.h" |
39 #include "extensions/test/extension_test_message_listener.h" | 39 #include "extensions/test/extension_test_message_listener.h" |
40 #include "extensions/test/result_catcher.h" | 40 #include "extensions/test/result_catcher.h" |
41 #include "sync/api/fake_sync_change_processor.h" | 41 #include "sync/api/fake_sync_change_processor.h" |
42 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 42 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
43 #include "sync/api/sync_error_factory_mock.h" | 43 #include "sync/api/sync_error_factory_mock.h" |
44 #include "ui/app_list/app_list_switches.h" | 44 #include "ui/app_list/app_list_switches.h" |
45 #include "ui/message_center/message_center.h" | 45 #include "ui/message_center/message_center.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 309 |
310 void EphemeralAppTestBase::CloseApp(const std::string& app_id) { | 310 void EphemeralAppTestBase::CloseApp(const std::string& app_id) { |
311 EXPECT_EQ(1U, GetAppWindowCountForApp(app_id)); | 311 EXPECT_EQ(1U, GetAppWindowCountForApp(app_id)); |
312 extensions::AppWindow* app_window = GetFirstAppWindowForApp(app_id); | 312 extensions::AppWindow* app_window = GetFirstAppWindowForApp(app_id); |
313 ASSERT_TRUE(app_window); | 313 ASSERT_TRUE(app_window); |
314 CloseAppWindow(app_window); | 314 CloseAppWindow(app_window); |
315 } | 315 } |
316 | 316 |
317 void EphemeralAppTestBase::CloseAppWaitForUnload(const std::string& app_id) { | 317 void EphemeralAppTestBase::CloseAppWaitForUnload(const std::string& app_id) { |
318 // Ephemeral apps are unloaded from extension system after they stop running. | 318 // Ephemeral apps are unloaded from extension system after they stop running. |
319 content::WindowedNotificationObserver unloaded_signal( | 319 extensions::TestExtensionRegistryObserver observer( |
320 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 320 ExtensionRegistry::Get(profile()), app_id); |
321 content::Source<Profile>(profile())); | |
322 CloseApp(app_id); | 321 CloseApp(app_id); |
323 unloaded_signal.Wait(); | 322 observer.WaitForExtensionUnloaded(); |
324 } | 323 } |
325 | 324 |
326 void EphemeralAppTestBase::EvictApp(const std::string& app_id) { | 325 void EphemeralAppTestBase::EvictApp(const std::string& app_id) { |
327 // Uninstall the app, which is what happens when ephemeral apps get evicted | 326 // Uninstall the app, which is what happens when ephemeral apps get evicted |
328 // from the cache. | 327 // from the cache. |
329 content::WindowedNotificationObserver uninstalled_signal( | 328 extensions::TestExtensionRegistryObserver observer( |
330 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, | 329 ExtensionRegistry::Get(profile()), app_id); |
331 content::Source<Profile>(profile())); | |
332 | 330 |
333 ExtensionService* service = | 331 ExtensionService* service = |
334 ExtensionSystem::Get(profile())->extension_service(); | 332 ExtensionSystem::Get(profile())->extension_service(); |
335 ASSERT_TRUE(service); | 333 ASSERT_TRUE(service); |
336 service->UninstallExtension( | 334 service->UninstallExtension( |
337 app_id, | 335 app_id, |
338 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, | 336 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, |
339 base::Bind(&base::DoNothing), | 337 base::Bind(&base::DoNothing), |
340 NULL); | 338 NULL); |
341 | 339 |
342 uninstalled_signal.Wait(); | 340 observer.WaitForExtensionUninstalled(); |
343 } | 341 } |
344 | 342 |
345 // EphemeralAppBrowserTest: | 343 // EphemeralAppBrowserTest: |
346 | 344 |
347 class EphemeralAppBrowserTest : public EphemeralAppTestBase { | 345 class EphemeralAppBrowserTest : public EphemeralAppTestBase { |
348 protected: | 346 protected: |
349 bool LaunchAppAndRunTest(const Extension* app, const char* test_name) { | 347 bool LaunchAppAndRunTest(const Extension* app, const char* test_name) { |
350 // Ephemeral apps are unloaded after they are closed. Ensure they are | 348 // Ephemeral apps are unloaded after they are closed. Ensure they are |
351 // enabled before launch. | 349 // enabled before launch. |
352 ExtensionService* service = | 350 ExtensionService* service = |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 InitSyncService(); | 956 InitSyncService(); |
959 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); | 957 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); |
960 ASSERT_TRUE(app); | 958 ASSERT_TRUE(app); |
961 std::string app_id = app->id(); | 959 std::string app_id = app->id(); |
962 app = NULL; | 960 app = NULL; |
963 | 961 |
964 // Initiate install. | 962 // Initiate install. |
965 ReplaceEphemeralApp(app_id, kNotificationsTestApp, 0); | 963 ReplaceEphemeralApp(app_id, kNotificationsTestApp, 0); |
966 | 964 |
967 // The delayed installation will occur when the ephemeral app is closed. | 965 // The delayed installation will occur when the ephemeral app is closed. |
968 content::WindowedNotificationObserver installed_signal( | 966 extensions::TestExtensionRegistryObserver observer( |
969 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 967 ExtensionRegistry::Get(profile()), app_id); |
970 content::Source<Profile>(profile())); | |
971 InstallObserver installed_observer(profile()); | 968 InstallObserver installed_observer(profile()); |
972 CloseAppWaitForUnload(app_id); | 969 CloseAppWaitForUnload(app_id); |
973 installed_signal.Wait(); | 970 observer.WaitForExtensionWillBeInstalled(); |
974 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); | 971 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); |
975 | 972 |
976 // Check the notification parameters. | 973 // Check the notification parameters. |
977 const InstallObserver::InstallParameters& params = installed_observer.Last(); | 974 const InstallObserver::InstallParameters& params = installed_observer.Last(); |
978 EXPECT_EQ(app_id, params.id); | 975 EXPECT_EQ(app_id, params.id); |
979 EXPECT_TRUE(params.is_update); | 976 EXPECT_TRUE(params.is_update); |
980 EXPECT_TRUE(params.from_ephemeral); | 977 EXPECT_TRUE(params.from_ephemeral); |
981 } | 978 } |
982 | 979 |
983 // Verifies that an installed app cannot turn into an ephemeral app as result of | 980 // Verifies that an installed app cannot turn into an ephemeral app as result of |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 base::Bind(&PowerSaveBlockerStub::Create, &power_settings)); | 1029 base::Bind(&PowerSaveBlockerStub::Create, &power_settings)); |
1033 | 1030 |
1034 const Extension* app = InstallAndLaunchEphemeralApp(kPowerTestApp); | 1031 const Extension* app = InstallAndLaunchEphemeralApp(kPowerTestApp); |
1035 ASSERT_TRUE(app); | 1032 ASSERT_TRUE(app); |
1036 EXPECT_EQ(1, power_settings.keep_awake_count()); | 1033 EXPECT_EQ(1, power_settings.keep_awake_count()); |
1037 | 1034 |
1038 CloseAppWaitForUnload(app->id()); | 1035 CloseAppWaitForUnload(app->id()); |
1039 | 1036 |
1040 EXPECT_EQ(0, power_settings.keep_awake_count()); | 1037 EXPECT_EQ(0, power_settings.keep_awake_count()); |
1041 } | 1038 } |
OLD | NEW |