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

Side by Side Diff: chrome/browser/apps/ephemeral_app_browsertest.cc

Issue 163953012: Notification settings for ephemeral apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Abort test for linux gtk Created 6 years, 10 months 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
« no previous file with comments | « no previous file | chrome/browser/notifications/desktop_notification_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/apps/app_browsertest_util.h" 5 #include "chrome/browser/apps/app_browsertest_util.h"
6 #include "chrome/browser/extensions/extension_service.h" 6 #include "chrome/browser/extensions/extension_service.h"
7 #include "chrome/browser/extensions/extension_test_message_listener.h" 7 #include "chrome/browser/extensions/extension_test_message_listener.h"
8 #include "chrome/browser/notifications/desktop_notification_service.h"
9 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
8 #include "chrome/common/extensions/api/alarms.h" 10 #include "chrome/common/extensions/api/alarms.h"
9 #include "content/public/test/browser_test.h" 11 #include "content/public/test/browser_test.h"
10 #include "content/public/test/test_utils.h" 12 #include "content/public/test/test_utils.h"
11 #include "extensions/browser/event_router.h" 13 #include "extensions/browser/event_router.h"
12 #include "extensions/browser/extension_system.h" 14 #include "extensions/browser/extension_system.h"
13 #include "extensions/browser/process_manager.h" 15 #include "extensions/browser/process_manager.h"
14 #include "extensions/common/switches.h" 16 #include "extensions/common/switches.h"
17 #include "ui/message_center/message_center.h"
18 #include "ui/message_center/notifier_settings.h"
15 19
16 using extensions::Event; 20 using extensions::Event;
17 using extensions::EventRouter; 21 using extensions::EventRouter;
18 using extensions::Extension; 22 using extensions::Extension;
19 using extensions::ExtensionSystem; 23 using extensions::ExtensionSystem;
20 using extensions::PlatformAppBrowserTest; 24 using extensions::PlatformAppBrowserTest;
21 25
22 namespace { 26 namespace {
23 27
24 namespace alarms = extensions::api::alarms; 28 namespace alarms = extensions::api::alarms;
25 29
26 const char kDispatchEventTestApp[] = 30 const char kDispatchEventTestApp[] =
27 "platform_apps/ephemeral_apps/dispatch_event"; 31 "platform_apps/ephemeral_apps/dispatch_event";
28 32
29 const char kMessagingReceiverApp[] = 33 const char kMessagingReceiverApp[] =
30 "platform_apps/ephemeral_apps/messaging_receiver"; 34 "platform_apps/ephemeral_apps/messaging_receiver";
31 35
32 const char kMessagingReceiverAppV2[] = 36 const char kMessagingReceiverAppV2[] =
33 "platform_apps/ephemeral_apps/messaging_receiver2"; 37 "platform_apps/ephemeral_apps/messaging_receiver2";
34 38
39 const char kNotificationsTestApp[] =
40 "platform_apps/ephemeral_apps/notification_settings";
41
42 typedef std::vector<message_center::Notifier*> NotifierList;
43
44 bool IsNotifierInList(const message_center::NotifierId& notifier_id,
45 const NotifierList& notifiers) {
46 for (NotifierList::const_iterator it = notifiers.begin();
47 it != notifiers.end(); ++it) {
48 const message_center::Notifier* notifier = *it;
49 if (notifier->notifier_id == notifier_id)
50 return true;
51 }
52
53 return false;
54 }
55
35 class EphemeralAppBrowserTest : public PlatformAppBrowserTest { 56 class EphemeralAppBrowserTest : public PlatformAppBrowserTest {
36 protected: 57 protected:
37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 58 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
38 // Skip PlatformAppBrowserTest, which sets different values for the switches 59 // Skip PlatformAppBrowserTest, which sets different values for the switches
39 // below. 60 // below.
40 ExtensionBrowserTest::SetUpCommandLine(command_line); 61 ExtensionBrowserTest::SetUpCommandLine(command_line);
41 62
42 // Make event pages get suspended immediately. 63 // Make event pages get suspended immediately.
43 command_line->AppendSwitchASCII( 64 command_line->AppendSwitchASCII(
44 extensions::switches::kEventPageIdleTime, "10"); 65 extensions::switches::kEventPageIdleTime, "10");
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 ExtensionSystem::Get(browser()->profile())->extension_service(); 214 ExtensionSystem::Get(browser()->profile())->extension_service();
194 EXPECT_TRUE(service->UpdateExtension(app_id, app_v2_path, true, GURL(), 215 EXPECT_TRUE(service->UpdateExtension(app_id, app_v2_path, true, GURL(),
195 &crx_installer)); 216 &crx_installer));
196 windowed_observer.Wait(); 217 windowed_observer.Wait();
197 218
198 const Extension* app_v2 = service->GetExtensionById(app_id, false); 219 const Extension* app_v2 = service->GetExtensionById(app_id, false);
199 ASSERT_TRUE(app_v2); 220 ASSERT_TRUE(app_v2);
200 EXPECT_TRUE(app_v2->version()->CompareTo(app_original_version) > 0); 221 EXPECT_TRUE(app_v2->version()->CompareTo(app_original_version) > 0);
201 EXPECT_TRUE(app_v2->is_ephemeral()); 222 EXPECT_TRUE(app_v2->is_ephemeral());
202 } 223 }
224
225 // Verify that if notifications have been disabled for an ephemeral app, it will
226 // remain disabled even after being evicted from the cache.
227 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, StickyNotificationSettings) {
228 const Extension* app = InstallEphemeralApp(kNotificationsTestApp);
229 ASSERT_TRUE(app);
230
231 // Disable notifications for this app.
232 DesktopNotificationService* notification_service =
233 DesktopNotificationServiceFactory::GetForProfile(browser()->profile());
234 ASSERT_TRUE(notification_service);
235
236 message_center::NotifierId notifier_id(
237 message_center::NotifierId::APPLICATION, app->id());
238 EXPECT_TRUE(notification_service->IsNotifierEnabled(notifier_id));
239 notification_service->SetNotifierEnabled(notifier_id, false);
240 EXPECT_FALSE(notification_service->IsNotifierEnabled(notifier_id));
241
242 // Uninstall the app, which is what happens when ephemeral apps get evicted
243 // from the cache.
244 content::WindowedNotificationObserver uninstalled_signal(
245 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
246 content::Source<Profile>(browser()->profile()));
247
248 ExtensionService* service =
249 ExtensionSystem::Get(browser()->profile())->extension_service();
250 ASSERT_TRUE(service);
251 service->UninstallExtension(app->id(), false, NULL);
252
253 uninstalled_signal.Wait();
254
255 // Reinstall the ephemeral app and verify that notifications remain disabled.
256 app = InstallEphemeralApp(kNotificationsTestApp);
257 ASSERT_TRUE(app);
258 message_center::NotifierId reinstalled_notifier_id(
259 message_center::NotifierId::APPLICATION, app->id());
260 EXPECT_FALSE(notification_service->IsNotifierEnabled(
261 reinstalled_notifier_id));
262 }
263
264 // Verify that only running ephemeral apps will appear in the Notification
265 // Settings UI. Inactive, cached ephemeral apps should not appear.
266 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest,
267 IncludeRunningEphmeralAppsInNotifiers) {
268 message_center::NotifierSettingsProvider* settings_provider =
269 message_center::MessageCenter::Get()->GetNotifierSettingsProvider();
270 // TODO(tmdiep): Remove once notifications settings are supported across
271 // all platforms. This test will fail for Linux GTK.
272 if (!settings_provider)
273 return;
274
275 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp);
276 ASSERT_TRUE(app);
277 message_center::NotifierId notifier_id(
278 message_center::NotifierId::APPLICATION, app->id());
279
280 // Since the ephemeral app is running, it should be included in the list
281 // of notifiers to show in the UI.
282 NotifierList notifiers;
283 settings_provider->GetNotifierList(&notifiers);
284 EXPECT_TRUE(IsNotifierInList(notifier_id, notifiers));
285
286 // Close the ephemeral app.
287 CloseApp(app->id());
288
289 // Inactive ephemeral apps should not be included in the list of notifiers to
290 // show in the UI.
291 notifiers.clear();
292 settings_provider->GetNotifierList(&notifiers);
293 EXPECT_FALSE(IsNotifierInList(notifier_id, notifiers));
294 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/notifications/desktop_notification_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698