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 "apps/saved_files_service.h" | 5 #include "apps/saved_files_service.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "chrome/browser/apps/app_browsertest_util.h" | 8 #include "chrome/browser/apps/app_browsertest_util.h" |
9 #include "chrome/browser/apps/ephemeral_app_service.h" | 9 #include "chrome/browser/apps/ephemeral_app_service.h" |
10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
13 #include "chrome/browser/extensions/extension_util.h" | 13 #include "chrome/browser/extensions/extension_util.h" |
14 #include "chrome/browser/notifications/desktop_notification_service.h" | 14 #include "chrome/browser/notifications/desktop_notification_service.h" |
15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
16 #include "chrome/common/extensions/api/alarms.h" | 16 #include "chrome/common/extensions/api/alarms.h" |
17 #include "content/public/test/browser_test.h" | 17 #include "content/public/test/browser_test.h" |
18 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
19 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
20 #include "extensions/browser/extension_prefs.h" | 20 #include "extensions/browser/extension_prefs.h" |
21 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
| 22 #include "extensions/browser/extension_util.h" |
22 #include "extensions/browser/process_manager.h" | 23 #include "extensions/browser/process_manager.h" |
23 #include "extensions/common/switches.h" | 24 #include "extensions/common/switches.h" |
24 #include "ui/message_center/message_center.h" | 25 #include "ui/message_center/message_center.h" |
25 #include "ui/message_center/notifier_settings.h" | 26 #include "ui/message_center/notifier_settings.h" |
26 | 27 |
27 using extensions::Event; | 28 using extensions::Event; |
28 using extensions::EventRouter; | 29 using extensions::EventRouter; |
29 using extensions::Extension; | 30 using extensions::Extension; |
30 using extensions::ExtensionInfo; | 31 using extensions::ExtensionInfo; |
31 using extensions::ExtensionPrefs; | 32 using extensions::ExtensionPrefs; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 extensions::switches::kEventPageSuspendingTime, "10"); | 86 extensions::switches::kEventPageSuspendingTime, "10"); |
86 } | 87 } |
87 | 88 |
88 base::FilePath GetTestPath(const char* test_path) { | 89 base::FilePath GetTestPath(const char* test_path) { |
89 return test_data_dir_.AppendASCII("platform_apps").AppendASCII(test_path); | 90 return test_data_dir_.AppendASCII("platform_apps").AppendASCII(test_path); |
90 } | 91 } |
91 | 92 |
92 const Extension* InstallEphemeralApp(const char* test_path, | 93 const Extension* InstallEphemeralApp(const char* test_path, |
93 Manifest::Location manifest_location) { | 94 Manifest::Location manifest_location) { |
94 const Extension* extension = | 95 const Extension* extension = |
95 InstallExtensionWithSourceAndFlags( | 96 InstallEphemeralAppWithSourceAndFlags( |
96 GetTestPath(test_path), | 97 GetTestPath(test_path), |
97 1, | 98 1, |
98 manifest_location, | 99 manifest_location, |
99 Extension::IS_EPHEMERAL); | 100 Extension::NO_FLAGS); |
100 return extension; | 101 return extension; |
101 } | 102 } |
102 | 103 |
103 const Extension* InstallEphemeralApp(const char* test_path) { | 104 const Extension* InstallEphemeralApp(const char* test_path) { |
104 return InstallEphemeralApp(test_path, Manifest::INTERNAL); | 105 return InstallEphemeralApp(test_path, Manifest::INTERNAL); |
105 } | 106 } |
106 | 107 |
107 const Extension* InstallAndLaunchEphemeralApp(const char* test_path) { | 108 const Extension* InstallAndLaunchEphemeralApp(const char* test_path) { |
108 ExtensionTestMessageListener launched_listener("launched", false); | 109 ExtensionTestMessageListener launched_listener("launched", false); |
109 const Extension* extension = InstallEphemeralApp(test_path); | 110 const Extension* extension = InstallEphemeralApp(test_path); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // Verify that messages are not received while the app is inactive. | 241 // Verify that messages are not received while the app is inactive. |
241 LoadAndLaunchPlatformApp("ephemeral_apps/messaging_sender_fail"); | 242 LoadAndLaunchPlatformApp("ephemeral_apps/messaging_sender_fail"); |
242 EXPECT_TRUE(result_catcher.GetNextResult()); | 243 EXPECT_TRUE(result_catcher.GetNextResult()); |
243 } | 244 } |
244 | 245 |
245 // Verify that an updated ephemeral app will still have its ephemeral flag | 246 // Verify that an updated ephemeral app will still have its ephemeral flag |
246 // enabled. | 247 // enabled. |
247 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, UpdateEphemeralApp) { | 248 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, UpdateEphemeralApp) { |
248 const Extension* app_v1 = InstallEphemeralApp(kMessagingReceiverApp); | 249 const Extension* app_v1 = InstallEphemeralApp(kMessagingReceiverApp); |
249 ASSERT_TRUE(app_v1); | 250 ASSERT_TRUE(app_v1); |
250 ASSERT_TRUE(app_v1->is_ephemeral()); | 251 ASSERT_TRUE(extensions::util::IsEphemeralApp(app_v1->id(), profile())); |
251 std::string app_id = app_v1->id(); | 252 std::string app_id = app_v1->id(); |
252 base::Version app_original_version = *app_v1->version(); | 253 base::Version app_original_version = *app_v1->version(); |
253 app_v1 = NULL; // The extension object will be destroyed during update. | 254 app_v1 = NULL; // The extension object will be destroyed during update. |
254 | 255 |
255 // Pack version 2 of the app. | 256 // Pack version 2 of the app. |
256 base::ScopedTempDir temp_dir; | 257 base::ScopedTempDir temp_dir; |
257 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 258 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
258 | 259 |
259 base::FilePath crx_path = temp_dir.path().AppendASCII("temp.crx"); | 260 base::FilePath crx_path = temp_dir.path().AppendASCII("temp.crx"); |
260 if (!base::DeleteFile(crx_path, false)) { | 261 if (!base::DeleteFile(crx_path, false)) { |
(...skipping 16 matching lines...) Expand all Loading... |
277 content::Source<extensions::CrxInstaller>(crx_installer)); | 278 content::Source<extensions::CrxInstaller>(crx_installer)); |
278 ExtensionService* service = | 279 ExtensionService* service = |
279 ExtensionSystem::Get(browser()->profile())->extension_service(); | 280 ExtensionSystem::Get(browser()->profile())->extension_service(); |
280 EXPECT_TRUE(service->UpdateExtension(app_id, app_v2_path, true, | 281 EXPECT_TRUE(service->UpdateExtension(app_id, app_v2_path, true, |
281 &crx_installer)); | 282 &crx_installer)); |
282 windowed_observer.Wait(); | 283 windowed_observer.Wait(); |
283 | 284 |
284 const Extension* app_v2 = service->GetExtensionById(app_id, false); | 285 const Extension* app_v2 = service->GetExtensionById(app_id, false); |
285 ASSERT_TRUE(app_v2); | 286 ASSERT_TRUE(app_v2); |
286 EXPECT_TRUE(app_v2->version()->CompareTo(app_original_version) > 0); | 287 EXPECT_TRUE(app_v2->version()->CompareTo(app_original_version) > 0); |
287 EXPECT_TRUE(app_v2->is_ephemeral()); | 288 EXPECT_TRUE(extensions::util::IsEphemeralApp(app_v2->id(), profile())); |
288 } | 289 } |
289 | 290 |
290 // Verify that if notifications have been disabled for an ephemeral app, it will | 291 // Verify that if notifications have been disabled for an ephemeral app, it will |
291 // remain disabled even after being evicted from the cache. | 292 // remain disabled even after being evicted from the cache. |
292 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, StickyNotificationSettings) { | 293 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, StickyNotificationSettings) { |
293 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); | 294 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
294 ASSERT_TRUE(app); | 295 ASSERT_TRUE(app); |
295 | 296 |
296 // Disable notifications for this app. | 297 // Disable notifications for this app. |
297 DesktopNotificationService* notification_service = | 298 DesktopNotificationService* notification_service = |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 const std::string app_id = app->id(); | 402 const std::string app_id = app->id(); |
402 EvictApp(app->id()); | 403 EvictApp(app->id()); |
403 app = NULL; | 404 app = NULL; |
404 | 405 |
405 // The app should be in the list of evicted apps. | 406 // The app should be in the list of evicted apps. |
406 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser()->profile()); | 407 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser()->profile()); |
407 ASSERT_TRUE(prefs); | 408 ASSERT_TRUE(prefs); |
408 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( | 409 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
409 prefs->GetEvictedEphemeralAppsInfo()); | 410 prefs->GetEvictedEphemeralAppsInfo()); |
410 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, app_id)); | 411 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, app_id)); |
| 412 scoped_ptr<ExtensionInfo> single_extension_info( |
| 413 prefs->GetEvictedEphemeralAppInfo(app_id)); |
| 414 EXPECT_TRUE(single_extension_info.get()); |
411 | 415 |
412 // The app should not be in the list of installed extensions. | 416 // The app should not be in the list of installed extensions. |
413 extensions_info = prefs->GetInstalledExtensionsInfo(); | 417 extensions_info = prefs->GetInstalledExtensionsInfo(); |
414 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app_id)); | 418 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app_id)); |
415 | 419 |
416 // Ensure the evicted app is considered to have isolated storage. This will | 420 // Ensure the evicted app is considered to have isolated storage. This will |
417 // prevent its data from getting garbage collected by | 421 // prevent its data from getting garbage collected by |
418 // ExtensionService::GarbageCollectIsolatedStorage(). | 422 // ExtensionService::GarbageCollectIsolatedStorage(). |
419 GURL site_url = extensions::util::GetSiteForExtensionId( | 423 GURL site_url = extensions::util::GetSiteForExtensionId( |
420 app_id, browser()->profile()); | 424 app_id, browser()->profile()); |
421 EXPECT_TRUE(extensions::util::SiteHasIsolatedStorage( | 425 EXPECT_TRUE(extensions::util::SiteHasIsolatedStorage( |
422 site_url, browser()->profile())); | 426 site_url, browser()->profile())); |
423 | 427 |
424 // Phase 2 - Reinstall the ephemeral app and verify that data still exists | 428 // Phase 2 - Reinstall the ephemeral app and verify that data still exists |
425 // in the storage. | 429 // in the storage. |
426 app = InstallEphemeralApp(kRetainDataApp); | 430 app = InstallEphemeralApp(kRetainDataApp); |
427 ASSERT_TRUE(app); | 431 ASSERT_TRUE(app); |
428 EXPECT_TRUE(LaunchAppAndRunTest(app, "ReadData")) << message_; | 432 EXPECT_TRUE(LaunchAppAndRunTest(app, "ReadData")) << message_; |
429 | 433 |
430 // The app should now be in the list of installed extensions, but not in the | 434 // The app should now be in the list of installed extensions, but not in the |
431 // list of evicted apps. | 435 // list of evicted apps. |
432 extensions_info = prefs->GetInstalledExtensionsInfo(); | 436 extensions_info = prefs->GetInstalledExtensionsInfo(); |
433 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, app_id)); | 437 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, app_id)); |
434 extensions_info = prefs->GetEvictedEphemeralAppsInfo(); | 438 extensions_info = prefs->GetEvictedEphemeralAppsInfo(); |
435 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app_id)); | 439 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app_id)); |
| 440 single_extension_info = prefs->GetEvictedEphemeralAppInfo(app_id); |
| 441 EXPECT_FALSE(single_extension_info.get()); |
| 442 } |
| 443 |
| 444 // Verify that preferences are updated correctly when an evicted ephemeral app |
| 445 // is re-installed permanently. |
| 446 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, InstallEvictedEphemeralApp) { |
| 447 const Extension* app = InstallEphemeralApp(kRetainDataApp); |
| 448 ASSERT_TRUE(app); |
| 449 |
| 450 // Remove the app. |
| 451 EvictApp(app->id()); |
| 452 app = NULL; |
| 453 |
| 454 // Install the app permanently. |
| 455 app = InstallPlatformApp(kRetainDataApp); |
| 456 ASSERT_TRUE(app); |
| 457 |
| 458 // Verify that preferences are correct. |
| 459 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser()->profile()); |
| 460 ASSERT_TRUE(prefs); |
| 461 EXPECT_FALSE(prefs->IsEphemeralApp(app->id())); |
| 462 |
| 463 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
| 464 prefs->GetEvictedEphemeralAppsInfo()); |
| 465 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app->id())); |
| 466 extensions_info = prefs->GetInstalledExtensionsInfo(); |
| 467 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, app->id())); |
436 } | 468 } |
437 | 469 |
438 // Verify that the data of regular installed apps are deleted on uninstall. | 470 // Verify that the data of regular installed apps are deleted on uninstall. |
439 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, RemoveInstalledData) { | 471 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, RemoveInstalledData) { |
440 // Install the ephemeral app and write data to various storage. | 472 // Install the ephemeral app and write data to various storage. |
441 const Extension* app = InstallPlatformApp(kRetainDataApp); | 473 const Extension* app = InstallPlatformApp(kRetainDataApp); |
442 ASSERT_TRUE(app); | 474 ASSERT_TRUE(app); |
443 ASSERT_TRUE(LaunchAppAndRunTest(app, "WriteData")) << message_; | 475 ASSERT_TRUE(LaunchAppAndRunTest(app, "WriteData")) << message_; |
444 | 476 |
445 // Remove the app. | 477 // Remove the app. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 534 |
503 // The garbage collected app should no longer be in the preferences. | 535 // The garbage collected app should no longer be in the preferences. |
504 extensions_info = prefs->GetEvictedEphemeralAppsInfo(); | 536 extensions_info = prefs->GetEvictedEphemeralAppsInfo(); |
505 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, retain_app_id)); | 537 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, retain_app_id)); |
506 ASSERT_FALSE(IsAppInExtensionsInfo(*extensions_info, evict_app_id)); | 538 ASSERT_FALSE(IsAppInExtensionsInfo(*extensions_info, evict_app_id)); |
507 | 539 |
508 // Reinstall the app and verify that all data has been reset. | 540 // Reinstall the app and verify that all data has been reset. |
509 evict_app = InstallEphemeralApp(kRetainDataApp); | 541 evict_app = InstallEphemeralApp(kRetainDataApp); |
510 ASSERT_TRUE(LaunchAppAndRunTest(evict_app, "DataReset")) << message_; | 542 ASSERT_TRUE(LaunchAppAndRunTest(evict_app, "DataReset")) << message_; |
511 } | 543 } |
OLD | NEW |