Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/browser/extensions/extension_storage_monitor_browsertest.cc

Issue 1497193002: Remove all the ephemeral apps code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review, Devlin review. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <set> 5 #include <set>
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 ExtensionStorageMonitor* monitor() { 90 ExtensionStorageMonitor* monitor() {
91 CHECK(storage_monitor_); 91 CHECK(storage_monitor_);
92 return storage_monitor_; 92 return storage_monitor_;
93 } 93 }
94 94
95 int64 GetInitialExtensionThreshold() { 95 int64 GetInitialExtensionThreshold() {
96 CHECK(storage_monitor_); 96 CHECK(storage_monitor_);
97 return storage_monitor_->initial_extension_threshold_; 97 return storage_monitor_->initial_extension_threshold_;
98 } 98 }
99 99
100 int64 GetInitialEphemeralThreshold() {
101 CHECK(storage_monitor_);
102 return storage_monitor_->initial_ephemeral_threshold_;
103 }
104
105 void DisableForInstalledExtensions() { 100 void DisableForInstalledExtensions() {
106 CHECK(storage_monitor_); 101 CHECK(storage_monitor_);
107 storage_monitor_->enable_for_all_extensions_ = false; 102 storage_monitor_->enable_for_all_extensions_ = false;
108 } 103 }
109 104
110 const Extension* InitWriteDataApp() { 105 const Extension* InitWriteDataApp() {
111 base::FilePath path = test_data_dir_.AppendASCII(kWriteDataApp); 106 base::FilePath path = test_data_dir_.AppendASCII(kWriteDataApp);
112 const Extension* extension = InstallExtension(path, 1); 107 const Extension* extension = InstallExtension(path, 1);
113 EXPECT_TRUE(extension); 108 EXPECT_TRUE(extension);
114 return extension; 109 return extension;
115 } 110 }
116 111
117 const Extension* InitWriteDataEphemeralApp() {
118 // The threshold for installed extensions should be higher than ephemeral
119 // apps.
120 storage_monitor_->initial_extension_threshold_ =
121 storage_monitor_->initial_ephemeral_threshold_ * 4;
122
123 base::FilePath path = test_data_dir_.AppendASCII(kWriteDataApp);
124 const Extension* extension = InstallEphemeralAppWithSourceAndFlags(
125 path, 1, Manifest::INTERNAL, Extension::NO_FLAGS);
126 EXPECT_TRUE(extension);
127 return extension;
128 }
129
130 std::string GetNotificationId(const std::string& extension_id) { 112 std::string GetNotificationId(const std::string& extension_id) {
131 return monitor()->GetNotificationId(extension_id); 113 return monitor()->GetNotificationId(extension_id);
132 } 114 }
133 115
134 bool IsStorageNotificationEnabled(const std::string& extension_id) { 116 bool IsStorageNotificationEnabled(const std::string& extension_id) {
135 return monitor()->IsStorageNotificationEnabled(extension_id); 117 return monitor()->IsStorageNotificationEnabled(extension_id);
136 } 118 }
137 119
138 int64 GetNextStorageThreshold(const std::string& extension_id) { 120 int64 GetNextStorageThreshold(const std::string& extension_id) {
139 return monitor()->GetNextStorageThreshold(extension_id); 121 return monitor()->GetNextStorageThreshold(extension_id);
(...skipping 13 matching lines...) Expand all
153 135
154 private: 136 private:
155 void InitStorageMonitor() { 137 void InitStorageMonitor() {
156 storage_monitor_ = ExtensionStorageMonitor::Get(profile()); 138 storage_monitor_ = ExtensionStorageMonitor::Get(profile());
157 ASSERT_TRUE(storage_monitor_); 139 ASSERT_TRUE(storage_monitor_);
158 140
159 // Override thresholds so that we don't have to write a huge amount of data 141 // Override thresholds so that we don't have to write a huge amount of data
160 // to trigger notifications in these tests. 142 // to trigger notifications in these tests.
161 storage_monitor_->enable_for_all_extensions_ = true; 143 storage_monitor_->enable_for_all_extensions_ = true;
162 storage_monitor_->initial_extension_threshold_ = kInitialUsageThreshold; 144 storage_monitor_->initial_extension_threshold_ = kInitialUsageThreshold;
163 storage_monitor_->initial_ephemeral_threshold_ = kInitialUsageThreshold;
164 145
165 // To ensure storage events are dispatched from QuotaManager immediately. 146 // To ensure storage events are dispatched from QuotaManager immediately.
166 storage_monitor_->observer_rate_ = base::TimeDelta(); 147 storage_monitor_->observer_rate_ = base::TimeDelta();
167 } 148 }
168 149
169 // Write a number of bytes to persistent storage. 150 // Write a number of bytes to persistent storage.
170 void WriteBytes(const Extension* extension, 151 void WriteBytes(const Extension* extension,
171 int num_bytes, 152 int num_bytes,
172 bool expected_notification) { 153 bool expected_notification) {
173 ExtensionTestMessageListener launched_listener("launched", true); 154 ExtensionTestMessageListener launched_listener("launched", true);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 231
251 // Expect to receive no further notifications when usage continues to 232 // Expect to receive no further notifications when usage continues to
252 // increase. 233 // increase.
253 int64 next_threshold = GetNextStorageThreshold(extension->id()); 234 int64 next_threshold = GetNextStorageThreshold(extension->id());
254 int64 next_data_size = next_threshold - GetInitialExtensionThreshold(); 235 int64 next_data_size = next_threshold - GetInitialExtensionThreshold();
255 ASSERT_GT(next_data_size, 0); 236 ASSERT_GT(next_data_size, 0);
256 237
257 WriteBytesNotExpectingNotification(extension, next_data_size); 238 WriteBytesNotExpectingNotification(extension, next_data_size);
258 } 239 }
259 240
260 // Verify that thresholds for ephemeral apps are reset when they are
261 // promoted to regular installed apps.
262 IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest, EphemeralAppLowUsage) {
263 const Extension* extension = InitWriteDataEphemeralApp();
264 ASSERT_TRUE(extension);
265 WriteBytesExpectingNotification(extension, GetInitialEphemeralThreshold());
266
267 // Store the number of bytes until the next threshold is reached.
268 int64 next_threshold = GetNextStorageThreshold(extension->id());
269 int64 next_data_size = next_threshold - GetInitialEphemeralThreshold();
270 ASSERT_GT(next_data_size, 0);
271 EXPECT_GE(GetInitialExtensionThreshold(), next_threshold);
272
273 // Promote the ephemeral app.
274 ExtensionService* service =
275 ExtensionSystem::Get(profile())->extension_service();
276 service->PromoteEphemeralApp(extension, false);
277
278 // The next threshold should now be equal to the initial threshold for
279 // extensions (which is higher than the initial threshold for ephemeral apps).
280 EXPECT_EQ(GetInitialExtensionThreshold(),
281 GetNextStorageThreshold(extension->id()));
282
283 // Since the threshold was increased, a notification should not be
284 // triggered.
285 WriteBytesNotExpectingNotification(extension, next_data_size);
286 }
287
288 // Verify that thresholds for ephemeral apps are not reset when they are
289 // promoted to regular installed apps if their usage is higher than the initial
290 // threshold for installed extensions.
291 IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest, EphemeralAppWithHighUsage) {
292 const Extension* extension = InitWriteDataEphemeralApp();
293 ASSERT_TRUE(extension);
294 WriteBytesExpectingNotification(extension, GetInitialExtensionThreshold());
295 int64 saved_next_threshold = GetNextStorageThreshold(extension->id());
296
297 // Promote the ephemeral app.
298 ExtensionService* service =
299 ExtensionSystem::Get(profile())->extension_service();
300 service->PromoteEphemeralApp(extension, false);
301
302 // The next threshold should not have changed.
303 EXPECT_EQ(saved_next_threshold, GetNextStorageThreshold(extension->id()));
304 }
305
306 // Ensure that monitoring is disabled for installed extensions if 241 // Ensure that monitoring is disabled for installed extensions if
307 // |enable_for_all_extensions_| is false. This test can be removed if monitoring 242 // |enable_for_all_extensions_| is false. This test can be removed if monitoring
308 // is eventually enabled for all extensions. 243 // is eventually enabled for all extensions.
309 IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest, 244 IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest,
310 DisableForInstalledExtensions) { 245 DisableForInstalledExtensions) {
311 DisableForInstalledExtensions(); 246 DisableForInstalledExtensions();
312 247
313 const Extension* extension = InitWriteDataApp(); 248 const Extension* extension = InitWriteDataApp();
314 ASSERT_TRUE(extension); 249 ASSERT_TRUE(extension);
315 WriteBytesNotExpectingNotification(extension, GetInitialExtensionThreshold()); 250 WriteBytesNotExpectingNotification(extension, GetInitialExtensionThreshold());
(...skipping 12 matching lines...) Expand all
328 ScopedTestDialogAutoConfirm::ACCEPT); 263 ScopedTestDialogAutoConfirm::ACCEPT);
329 TestExtensionRegistryObserver observer(ExtensionRegistry::Get(profile()), 264 TestExtensionRegistryObserver observer(ExtensionRegistry::Get(profile()),
330 extension->id()); 265 extension->id());
331 message_center::MessageCenter::Get()->ClickOnNotificationButton( 266 message_center::MessageCenter::Get()->ClickOnNotificationButton(
332 GetNotificationId(extension->id()), 267 GetNotificationId(extension->id()),
333 ExtensionStorageMonitor::BUTTON_UNINSTALL); 268 ExtensionStorageMonitor::BUTTON_UNINSTALL);
334 observer.WaitForExtensionUninstalled(); 269 observer.WaitForExtensionUninstalled();
335 } 270 }
336 271
337 } // namespace extensions 272 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_storage_monitor.cc ('k') | chrome/browser/extensions/extension_sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698