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 <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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 int64 previous_threshold = GetNextStorageThreshold(extension->id()); | 142 int64 previous_threshold = GetNextStorageThreshold(extension->id()); |
143 WriteBytes(extension, num_bytes, true); | 143 WriteBytes(extension, num_bytes, true); |
144 EXPECT_GT(GetNextStorageThreshold(extension->id()), previous_threshold); | 144 EXPECT_GT(GetNextStorageThreshold(extension->id()), previous_threshold); |
145 } | 145 } |
146 | 146 |
147 void WriteBytesNotExpectingNotification(const Extension* extension, | 147 void WriteBytesNotExpectingNotification(const Extension* extension, |
148 int num_bytes) { | 148 int num_bytes) { |
149 WriteBytes(extension, num_bytes, false); | 149 WriteBytes(extension, num_bytes, false); |
150 } | 150 } |
151 | 151 |
| 152 void SimulateUninstallDialogAccept() { |
| 153 // Ensure the uninstall dialog was shown and fake an accept. |
| 154 ASSERT_TRUE(monitor()->uninstall_dialog_.get()); |
| 155 monitor()->ExtensionUninstallAccepted(); |
| 156 } |
| 157 |
152 private: | 158 private: |
153 void InitStorageMonitor() { | 159 void InitStorageMonitor() { |
154 storage_monitor_ = ExtensionStorageMonitor::Get(profile()); | 160 storage_monitor_ = ExtensionStorageMonitor::Get(profile()); |
155 ASSERT_TRUE(storage_monitor_); | 161 ASSERT_TRUE(storage_monitor_); |
156 | 162 |
157 // Override thresholds so that we don't have to write a huge amount of data | 163 // Override thresholds so that we don't have to write a huge amount of data |
158 // to trigger notifications in these tests. | 164 // to trigger notifications in these tests. |
159 storage_monitor_->enable_for_all_extensions_ = true; | 165 storage_monitor_->enable_for_all_extensions_ = true; |
160 storage_monitor_->initial_extension_threshold_ = kInitialUsageThreshold; | 166 storage_monitor_->initial_extension_threshold_ = kInitialUsageThreshold; |
161 storage_monitor_->initial_ephemeral_threshold_ = kInitialUsageThreshold; | 167 storage_monitor_->initial_ephemeral_threshold_ = kInitialUsageThreshold; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 238 |
233 // Verify that notifications are disabled when the user clicks the action button | 239 // Verify that notifications are disabled when the user clicks the action button |
234 // in the notification. | 240 // in the notification. |
235 IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest, UserDisabledNotifications) { | 241 IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest, UserDisabledNotifications) { |
236 const Extension* extension = InitWriteDataApp(); | 242 const Extension* extension = InitWriteDataApp(); |
237 ASSERT_TRUE(extension); | 243 ASSERT_TRUE(extension); |
238 WriteBytesExpectingNotification(extension, GetInitialExtensionThreshold()); | 244 WriteBytesExpectingNotification(extension, GetInitialExtensionThreshold()); |
239 | 245 |
240 EXPECT_TRUE(IsStorageNotificationEnabled(extension->id())); | 246 EXPECT_TRUE(IsStorageNotificationEnabled(extension->id())); |
241 | 247 |
242 // Fake clicking the notification button. | 248 // Fake clicking the notification button to disable notifications. |
243 message_center::MessageCenter::Get()->ClickOnNotificationButton( | 249 message_center::MessageCenter::Get()->ClickOnNotificationButton( |
244 GetNotificationId(extension->id()), | 250 GetNotificationId(extension->id()), |
245 ExtensionStorageMonitor::BUTTON_DISABLE_NOTIFICATION); | 251 ExtensionStorageMonitor::BUTTON_DISABLE_NOTIFICATION); |
246 | 252 |
247 EXPECT_FALSE(IsStorageNotificationEnabled(extension->id())); | 253 EXPECT_FALSE(IsStorageNotificationEnabled(extension->id())); |
248 | 254 |
249 // Expect to receive no further notifications when usage continues to | 255 // Expect to receive no further notifications when usage continues to |
250 // increase. | 256 // increase. |
251 int64 next_threshold = GetNextStorageThreshold(extension->id()); | 257 int64 next_threshold = GetNextStorageThreshold(extension->id()); |
252 int64 next_data_size = next_threshold - GetInitialExtensionThreshold(); | 258 int64 next_data_size = next_threshold - GetInitialExtensionThreshold(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // |enable_for_all_extensions_| is false. This test can be removed if monitoring | 311 // |enable_for_all_extensions_| is false. This test can be removed if monitoring |
306 // is eventually enabled for all extensions. | 312 // is eventually enabled for all extensions. |
307 IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest, | 313 IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest, |
308 DisableForInstalledExtensions) { | 314 DisableForInstalledExtensions) { |
309 DisableForInstalledExtensions(); | 315 DisableForInstalledExtensions(); |
310 | 316 |
311 const Extension* extension = InitWriteDataApp(); | 317 const Extension* extension = InitWriteDataApp(); |
312 ASSERT_TRUE(extension); | 318 ASSERT_TRUE(extension); |
313 WriteBytesNotExpectingNotification(extension, GetInitialExtensionThreshold()); | 319 WriteBytesNotExpectingNotification(extension, GetInitialExtensionThreshold()); |
314 } | 320 } |
| 321 |
| 322 // Verify that notifications are disabled when the user clicks the action button |
| 323 // in the notification. |
| 324 IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest, UninstallExtension) { |
| 325 const Extension* extension = InitWriteDataApp(); |
| 326 ASSERT_TRUE(extension); |
| 327 WriteBytesExpectingNotification(extension, GetInitialExtensionThreshold()); |
| 328 |
| 329 // Fake clicking the notification button to uninstall. |
| 330 message_center::MessageCenter::Get()->ClickOnNotificationButton( |
| 331 GetNotificationId(extension->id()), |
| 332 ExtensionStorageMonitor::BUTTON_UNINSTALL); |
| 333 |
| 334 // Also fake accepting the uninstall. |
| 335 content::WindowedNotificationObserver uninstalled_signal( |
| 336 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, |
| 337 content::Source<Profile>(profile())); |
| 338 SimulateUninstallDialogAccept(); |
| 339 uninstalled_signal.Wait(); |
| 340 } |
| 341 |
315 } // namespace extensions | 342 } // namespace extensions |
OLD | NEW |