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 12 matching lines...) Expand all Loading... |
23 #include "chrome/common/extensions/api/alarms.h" | 23 #include "chrome/common/extensions/api/alarms.h" |
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/app_sorting.h" | 26 #include "extensions/browser/app_sorting.h" |
27 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
28 #include "extensions/browser/extension_prefs.h" | 28 #include "extensions/browser/extension_prefs.h" |
29 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
30 #include "extensions/browser/extension_registry_observer.h" | 30 #include "extensions/browser/extension_registry_observer.h" |
31 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
32 #include "extensions/browser/extension_util.h" | 32 #include "extensions/browser/extension_util.h" |
| 33 #include "extensions/browser/notification_types.h" |
33 #include "extensions/browser/process_manager.h" | 34 #include "extensions/browser/process_manager.h" |
34 #include "extensions/browser/uninstall_reason.h" | 35 #include "extensions/browser/uninstall_reason.h" |
35 #include "extensions/common/extension.h" | 36 #include "extensions/common/extension.h" |
36 #include "extensions/common/switches.h" | 37 #include "extensions/common/switches.h" |
37 #include "sync/api/fake_sync_change_processor.h" | 38 #include "sync/api/fake_sync_change_processor.h" |
38 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 39 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
39 #include "sync/api/sync_error_factory_mock.h" | 40 #include "sync/api/sync_error_factory_mock.h" |
40 #include "ui/message_center/message_center.h" | 41 #include "ui/message_center/message_center.h" |
41 #include "ui/message_center/notifier_settings.h" | 42 #include "ui/message_center/notifier_settings.h" |
42 | 43 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return NULL; | 196 return NULL; |
196 } | 197 } |
197 | 198 |
198 base::FilePath app_v2_path = PackExtensionWithOptions( | 199 base::FilePath app_v2_path = PackExtensionWithOptions( |
199 test_dir, crx_path, pem_path, base::FilePath()); | 200 test_dir, crx_path, pem_path, base::FilePath()); |
200 EXPECT_FALSE(app_v2_path.empty()); | 201 EXPECT_FALSE(app_v2_path.empty()); |
201 | 202 |
202 // Update the ephemeral app and wait for the update to finish. | 203 // Update the ephemeral app and wait for the update to finish. |
203 extensions::CrxInstaller* crx_installer = NULL; | 204 extensions::CrxInstaller* crx_installer = NULL; |
204 content::WindowedNotificationObserver windowed_observer( | 205 content::WindowedNotificationObserver windowed_observer( |
205 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 206 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
206 content::Source<extensions::CrxInstaller>(crx_installer)); | 207 content::Source<extensions::CrxInstaller>(crx_installer)); |
207 ExtensionService* service = | 208 ExtensionService* service = |
208 ExtensionSystem::Get(profile())->extension_service(); | 209 ExtensionSystem::Get(profile())->extension_service(); |
209 EXPECT_TRUE(service->UpdateExtension(app_id, app_v2_path, true, | 210 EXPECT_TRUE(service->UpdateExtension(app_id, app_v2_path, true, |
210 &crx_installer)); | 211 &crx_installer)); |
211 windowed_observer.Wait(); | 212 windowed_observer.Wait(); |
212 | 213 |
213 return service->GetExtensionById(app_id, false); | 214 return service->GetExtensionById(app_id, false); |
214 } | 215 } |
215 | 216 |
216 void EphemeralAppTestBase::PromoteEphemeralApp( | 217 void EphemeralAppTestBase::PromoteEphemeralApp( |
217 const extensions::Extension* app) { | 218 const extensions::Extension* app) { |
218 ExtensionService* extension_service = | 219 ExtensionService* extension_service = |
219 ExtensionSystem::Get(profile())->extension_service(); | 220 ExtensionSystem::Get(profile())->extension_service(); |
220 ASSERT_TRUE(extension_service); | 221 ASSERT_TRUE(extension_service); |
221 extension_service->PromoteEphemeralApp(app, false); | 222 extension_service->PromoteEphemeralApp(app, false); |
222 } | 223 } |
223 | 224 |
224 void EphemeralAppTestBase::CloseApp(const std::string& app_id) { | 225 void EphemeralAppTestBase::CloseApp(const std::string& app_id) { |
225 content::WindowedNotificationObserver event_page_destroyed_signal( | 226 content::WindowedNotificationObserver event_page_destroyed_signal( |
226 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 227 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
227 content::Source<Profile>(profile())); | 228 content::Source<Profile>(profile())); |
228 | 229 |
229 EXPECT_EQ(1U, GetAppWindowCountForApp(app_id)); | 230 EXPECT_EQ(1U, GetAppWindowCountForApp(app_id)); |
230 apps::AppWindow* app_window = GetFirstAppWindowForApp(app_id); | 231 apps::AppWindow* app_window = GetFirstAppWindowForApp(app_id); |
231 ASSERT_TRUE(app_window); | 232 ASSERT_TRUE(app_window); |
232 CloseAppWindow(app_window); | 233 CloseAppWindow(app_window); |
233 | 234 |
234 event_page_destroyed_signal.Wait(); | 235 event_page_destroyed_signal.Wait(); |
235 } | 236 } |
236 | 237 |
237 void EphemeralAppTestBase::EvictApp(const std::string& app_id) { | 238 void EphemeralAppTestBase::EvictApp(const std::string& app_id) { |
238 // Uninstall the app, which is what happens when ephemeral apps get evicted | 239 // Uninstall the app, which is what happens when ephemeral apps get evicted |
239 // from the cache. | 240 // from the cache. |
240 content::WindowedNotificationObserver uninstalled_signal( | 241 content::WindowedNotificationObserver uninstalled_signal( |
241 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, | 242 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, |
242 content::Source<Profile>(profile())); | 243 content::Source<Profile>(profile())); |
243 | 244 |
244 ExtensionService* service = | 245 ExtensionService* service = |
245 ExtensionSystem::Get(profile())->extension_service(); | 246 ExtensionSystem::Get(profile())->extension_service(); |
246 ASSERT_TRUE(service); | 247 ASSERT_TRUE(service); |
247 service->UninstallExtension( | 248 service->UninstallExtension( |
248 app_id, | 249 app_id, |
249 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, | 250 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, |
250 base::Bind(&base::DoNothing), | 251 base::Bind(&base::DoNothing), |
251 NULL); | 252 NULL); |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); | 691 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); |
691 ASSERT_TRUE(app); | 692 ASSERT_TRUE(app); |
692 std::string app_id = app->id(); | 693 std::string app_id = app->id(); |
693 app = NULL; | 694 app = NULL; |
694 | 695 |
695 // Initiate install. | 696 // Initiate install. |
696 ReplaceEphemeralApp(app_id, kNotificationsTestApp); | 697 ReplaceEphemeralApp(app_id, kNotificationsTestApp); |
697 | 698 |
698 // The delayed installation will occur when the ephemeral app is closed. | 699 // The delayed installation will occur when the ephemeral app is closed. |
699 content::WindowedNotificationObserver installed_signal( | 700 content::WindowedNotificationObserver installed_signal( |
700 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 701 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
701 content::Source<Profile>(profile())); | 702 content::Source<Profile>(profile())); |
702 InstallObserver installed_observer(profile()); | 703 InstallObserver installed_observer(profile()); |
703 CloseApp(app_id); | 704 CloseApp(app_id); |
704 installed_signal.Wait(); | 705 installed_signal.Wait(); |
705 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); | 706 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); |
706 | 707 |
707 // Check the notification parameters. | 708 // Check the notification parameters. |
708 const InstallObserver::InstallParameters& params = installed_observer.Last(); | 709 const InstallObserver::InstallParameters& params = installed_observer.Last(); |
709 EXPECT_EQ(app_id, params.id); | 710 EXPECT_EQ(app_id, params.id); |
710 EXPECT_TRUE(params.is_update); | 711 EXPECT_TRUE(params.is_update); |
(...skipping 16 matching lines...) Expand all Loading... |
727 | 728 |
728 // Ensure that when the app is promoted to an installed app, the bit in the | 729 // Ensure that when the app is promoted to an installed app, the bit in the |
729 // creation flags is cleared. | 730 // creation flags is cleared. |
730 PromoteEphemeralApp(app); | 731 PromoteEphemeralApp(app); |
731 EXPECT_FALSE(extensions::util::IsEphemeralApp(app->id(), profile())); | 732 EXPECT_FALSE(extensions::util::IsEphemeralApp(app->id(), profile())); |
732 | 733 |
733 int creation_flags = | 734 int creation_flags = |
734 ExtensionPrefs::Get(profile())->GetCreationFlags(app->id()); | 735 ExtensionPrefs::Get(profile())->GetCreationFlags(app->id()); |
735 EXPECT_EQ(0, creation_flags & Extension::IS_EPHEMERAL); | 736 EXPECT_EQ(0, creation_flags & Extension::IS_EPHEMERAL); |
736 } | 737 } |
OLD | NEW |