OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "chrome/browser/apps/ephemeral_app_browsertest.h" | 7 #include "chrome/browser/apps/ephemeral_app_browsertest.h" |
8 #include "chrome/browser/apps/ephemeral_app_service.h" | 8 #include "chrome/browser/apps/ephemeral_app_service.h" |
9 #include "chrome/browser/extensions/extension_service.h" | |
10 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
11 #include "content/public/test/test_utils.h" | 10 #include "content/public/test/test_utils.h" |
12 #include "extensions/browser/extension_prefs.h" | 11 #include "extensions/browser/extension_prefs.h" |
13 #include "extensions/browser/extension_system.h" | 12 #include "extensions/browser/extension_registry.h" |
14 #include "extensions/common/manifest.h" | 13 #include "extensions/common/manifest.h" |
15 | 14 |
16 using extensions::Extension; | 15 using extensions::Extension; |
17 using extensions::ExtensionPrefs; | 16 using extensions::ExtensionPrefs; |
18 using extensions::ExtensionSystem; | 17 using extensions::ExtensionRegistry; |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 const int kNumTestApps = 2; | 21 const int kNumTestApps = 2; |
23 const char* kTestApps[] = { | 22 const char* kTestApps[] = { |
24 "app_window/generic", | 23 "app_window/generic", |
25 "minimal" | 24 "minimal" |
26 }; | 25 }; |
27 | 26 |
28 } // namespace | 27 } // namespace |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 base::TimeDelta::FromDays(EphemeralAppService::kAppKeepThreshold); | 81 base::TimeDelta::FromDays(EphemeralAppService::kAppKeepThreshold); |
83 prefs->SetLastLaunchTime(active_app_id, active_launch); | 82 prefs->SetLastLaunchTime(active_app_id, active_launch); |
84 | 83 |
85 // Perform garbage collection. | 84 // Perform garbage collection. |
86 content::WindowedNotificationObserver uninstall_signal( | 85 content::WindowedNotificationObserver uninstall_signal( |
87 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, | 86 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, |
88 content::Source<Profile>(browser()->profile())); | 87 content::Source<Profile>(browser()->profile())); |
89 GarbageCollectEphemeralApps(); | 88 GarbageCollectEphemeralApps(); |
90 uninstall_signal.Wait(); | 89 uninstall_signal.Wait(); |
91 | 90 |
92 ExtensionService* service = ExtensionSystem::Get(browser()->profile()) | 91 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
93 ->extension_service(); | 92 ASSERT_TRUE(registry); |
94 ASSERT_TRUE(service); | 93 EXPECT_FALSE(registry->GetExtensionById(inactive_app_id, |
95 EXPECT_FALSE(service->GetInstalledExtension(inactive_app_id)); | 94 ExtensionRegistry::EVERYTHING)); |
96 EXPECT_TRUE(service->GetInstalledExtension(active_app_id)); | 95 EXPECT_TRUE( |
| 96 registry->GetExtensionById(active_app_id, ExtensionRegistry::EVERYTHING)); |
97 | 97 |
98 EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); | 98 EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); |
99 } | 99 } |
100 | 100 |
101 // Verify that the count of ephemeral apps is maintained correctly. | 101 // Verify that the count of ephemeral apps is maintained correctly. |
102 IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, | 102 IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, EphemeralAppCount) { |
103 EphemeralAppCount) { | |
104 EphemeralAppService* ephemeral_service = | 103 EphemeralAppService* ephemeral_service = |
105 EphemeralAppService::Get(browser()->profile()); | 104 EphemeralAppService::Get(browser()->profile()); |
106 ASSERT_TRUE(ephemeral_service); | 105 ASSERT_TRUE(ephemeral_service); |
107 InitEphemeralAppCount(ephemeral_service); | 106 InitEphemeralAppCount(ephemeral_service); |
108 | 107 |
109 // The count should not increase for regular installed apps. | 108 // The count should not increase for regular installed apps. |
110 EXPECT_TRUE(InstallPlatformApp("minimal")); | 109 EXPECT_TRUE(InstallPlatformApp("minimal")); |
111 EXPECT_EQ(0, ephemeral_service->ephemeral_app_count()); | 110 EXPECT_EQ(0, ephemeral_service->ephemeral_app_count()); |
112 | 111 |
113 // The count should increase when an ephemeral app is added. | 112 // The count should increase when an ephemeral app is added. |
114 const Extension* app = InstallEphemeralApp(kMessagingReceiverApp); | 113 const Extension* app = InstallEphemeralApp(kMessagingReceiverApp); |
115 ASSERT_TRUE(app); | 114 ASSERT_TRUE(app); |
116 EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); | 115 EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); |
117 | 116 |
118 // The count should remain constant if the ephemeral app is updated. | 117 // The count should remain constant if the ephemeral app is updated. |
119 const std::string app_id = app->id(); | 118 const std::string app_id = app->id(); |
120 app = UpdateEphemeralApp( | 119 app = UpdateEphemeralApp( |
121 app_id, GetTestPath(kMessagingReceiverAppV2), | 120 app_id, GetTestPath(kMessagingReceiverAppV2), |
122 GetTestPath(kMessagingReceiverApp).ReplaceExtension( | 121 GetTestPath(kMessagingReceiverApp).ReplaceExtension( |
123 FILE_PATH_LITERAL(".pem"))); | 122 FILE_PATH_LITERAL(".pem"))); |
124 ASSERT_TRUE(app); | 123 ASSERT_TRUE(app); |
125 EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); | 124 EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); |
126 | 125 |
127 // The count should decrease when an ephemeral app is promoted to a regular | 126 // The count should decrease when an ephemeral app is promoted to a regular |
128 // installed app. | 127 // installed app. |
129 PromoteEphemeralApp(app); | 128 PromoteEphemeralApp(app); |
130 EXPECT_EQ(0, ephemeral_service->ephemeral_app_count()); | 129 EXPECT_EQ(0, ephemeral_service->ephemeral_app_count()); |
131 } | 130 } |
| 131 |
| 132 // Verify that the cache of ephemeral apps is correctly cleared. Running apps |
| 133 // should not be removed. |
| 134 IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, ClearCachedApps) { |
| 135 const Extension* running_app = |
| 136 InstallAndLaunchEphemeralApp(kMessagingReceiverApp); |
| 137 const Extension* inactive_app = |
| 138 InstallAndLaunchEphemeralApp(kDispatchEventTestApp); |
| 139 std::string inactive_app_id = inactive_app->id(); |
| 140 std::string running_app_id = running_app->id(); |
| 141 CloseApp(inactive_app_id); |
| 142 |
| 143 EphemeralAppService* ephemeral_service = |
| 144 EphemeralAppService::Get(browser()->profile()); |
| 145 ASSERT_TRUE(ephemeral_service); |
| 146 EXPECT_EQ(2, ephemeral_service->ephemeral_app_count()); |
| 147 |
| 148 ephemeral_service->ClearCachedApps(); |
| 149 |
| 150 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 151 ASSERT_TRUE(registry); |
| 152 EXPECT_FALSE(registry->GetExtensionById(inactive_app_id, |
| 153 ExtensionRegistry::EVERYTHING)); |
| 154 EXPECT_TRUE(registry->GetExtensionById(running_app_id, |
| 155 ExtensionRegistry::EVERYTHING)); |
| 156 |
| 157 EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); |
| 158 } |
OLD | NEW |