OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/strings/string_number_conversions.h" | 5 #include "base/strings/string_number_conversions.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/apps/app_browsertest_util.h" | |
8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | 10 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
11 #include "chrome/browser/extensions/extension_function_test_utils.h" | 12 #include "chrome/browser/extensions/extension_function_test_utils.h" |
12 #include "chrome/browser/notifications/notification.h" | 13 #include "chrome/browser/notifications/notification.h" |
13 #include "chrome/browser/notifications/notification_ui_manager.h" | 14 #include "chrome/browser/notifications/notification_ui_manager.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
16 #include "chrome/browser/ui/extensions/app_launch_params.h" | |
17 #include "chrome/browser/ui/extensions/application_launch.h" | |
15 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
16 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
17 #include "extensions/browser/api/test/test_api.h" | 20 #include "extensions/browser/api/test/test_api.h" |
18 #include "extensions/browser/notification_types.h" | 21 #include "extensions/browser/notification_types.h" |
19 #include "extensions/common/features/feature.h" | 22 #include "extensions/common/features/feature.h" |
20 #include "extensions/common/test_util.h" | 23 #include "extensions/common/test_util.h" |
24 #include "extensions/test/extension_test_message_listener.h" | |
21 #include "extensions/test/result_catcher.h" | 25 #include "extensions/test/result_catcher.h" |
22 #include "ui/message_center/message_center.h" | 26 #include "ui/message_center/message_center.h" |
23 #include "ui/message_center/notification_list.h" | 27 #include "ui/message_center/notification_list.h" |
24 #include "ui/message_center/notifier_settings.h" | 28 #include "ui/message_center/notifier_settings.h" |
25 | 29 |
26 using extensions::Extension; | 30 using extensions::Extension; |
27 using extensions::ResultCatcher; | 31 using extensions::ResultCatcher; |
28 | 32 |
29 namespace utils = extension_function_test_utils; | 33 namespace utils = extension_function_test_utils; |
30 | 34 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 content::WindowedNotificationObserver page_created( | 93 content::WindowedNotificationObserver page_created( |
90 extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, | 94 extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
91 content::NotificationService::AllSources()); | 95 content::NotificationService::AllSources()); |
92 const extensions::Extension* extension = LoadExtension(extdir); | 96 const extensions::Extension* extension = LoadExtension(extdir); |
93 if (extension) { | 97 if (extension) { |
94 page_created.Wait(); | 98 page_created.Wait(); |
95 } | 99 } |
96 return extension; | 100 return extension; |
97 } | 101 } |
98 | 102 |
103 const extensions::Extension* LoadAppWithWindowState( | |
104 const std::string& test_name, const std::string& window_state) { | |
dewittj
2016/09/14 21:06:51
instead of |window_state| could we have an enum cl
bmalcolm
2016/09/14 21:56:24
Done.
| |
105 base::FilePath extdir = test_data_dir_.AppendASCII(test_name); | |
106 const extensions::Extension* extension = LoadExtension(extdir); | |
dewittj
2016/09/14 21:06:51
lose the "extensions::", there's a using statement
bmalcolm
2016/09/14 21:56:25
Done.
| |
107 EXPECT_TRUE(extension); | |
108 | |
109 ExtensionTestMessageListener launched_listener("launched", true); | |
110 LaunchPlatformApp(extension); | |
111 EXPECT_TRUE(launched_listener.WaitUntilSatisfied()); | |
112 launched_listener.Reply(window_state); | |
113 | |
114 return extension; | |
115 } | |
116 | |
99 protected: | 117 protected: |
100 std::string GetNotificationIdFromDelegateId(const std::string& delegate_id) { | 118 std::string GetNotificationIdFromDelegateId(const std::string& delegate_id) { |
101 return g_browser_process->notification_ui_manager() | 119 return g_browser_process->notification_ui_manager() |
102 ->FindById( | 120 ->FindById( |
103 delegate_id, | 121 delegate_id, |
104 NotificationUIManager::GetProfileID( | 122 NotificationUIManager::GetProfileID( |
105 g_browser_process->profile_manager()->GetLastUsedProfile())) | 123 g_browser_process->profile_manager()->GetLastUsedProfile())) |
106 ->id(); | 124 ->id(); |
107 } | 125 } |
126 | |
127 void LaunchPlatformApp(const Extension* extension) { | |
128 OpenApplication(AppLaunchParams( | |
129 browser()->profile(), extension, extensions::LAUNCH_CONTAINER_NONE, | |
130 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); | |
131 } | |
108 }; | 132 }; |
109 | 133 |
110 } // namespace | 134 } // namespace |
111 | 135 |
112 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestBasicUsage) { | 136 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestBasicUsage) { |
113 ASSERT_TRUE(RunExtensionTest("notifications/api/basic_usage")) << message_; | 137 ASSERT_TRUE(RunExtensionTest("notifications/api/basic_usage")) << message_; |
114 } | 138 } |
115 | 139 |
116 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { | 140 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { |
117 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; | 141 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 ASSERT_TRUE(extension) << message_; | 319 ASSERT_TRUE(extension) << message_; |
296 | 320 |
297 const message_center::NotificationList::Notifications& notifications = | 321 const message_center::NotificationList::Notifications& notifications = |
298 g_browser_process->message_center()->GetVisibleNotifications(); | 322 g_browser_process->message_center()->GetVisibleNotifications(); |
299 ASSERT_EQ(1u, notifications.size()); | 323 ASSERT_EQ(1u, notifications.size()); |
300 message_center::Notification* notification = *(notifications.begin()); | 324 message_center::Notification* notification = *(notifications.begin()); |
301 ASSERT_EQ(extension->url(), notification->origin_url()); | 325 ASSERT_EQ(extension->url(), notification->origin_url()); |
302 | 326 |
303 EXPECT_TRUE(notification->never_timeout()); | 327 EXPECT_TRUE(notification->never_timeout()); |
304 } | 328 } |
329 | |
330 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayNormal) { | |
331 ExtensionTestMessageListener notification_created_listener("created", false); | |
332 const extensions::Extension* extension = LoadAppWithWindowState( | |
333 "notifications/api/basic_app", "{\"state\":\"normal\"}"); | |
334 ASSERT_TRUE(extension) << message_; | |
335 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); | |
336 | |
337 const message_center::NotificationList::Notifications& notifications = | |
338 g_browser_process->message_center()->GetVisibleNotifications(); | |
339 ASSERT_EQ(1u, notifications.size()); | |
340 message_center::Notification* notification = *(notifications.begin()); | |
341 // If the app hasn't created a fullscreen window, then its notifications | |
342 // shouldn't be displayed when a window is fullscreen. | |
343 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); | |
344 } | |
345 | |
346 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreen) { | |
347 ExtensionTestMessageListener notification_created_listener("created", false); | |
348 const extensions::Extension* extension = LoadAppWithWindowState( | |
349 "notifications/api/basic_app", "{\"state\":\"fullscreen\"}"); | |
350 ASSERT_TRUE(extension) << message_; | |
351 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); | |
352 | |
353 const message_center::NotificationList::Notifications& notifications = | |
354 g_browser_process->message_center()->GetVisibleNotifications(); | |
355 ASSERT_EQ(1u, notifications.size()); | |
356 message_center::Notification* notification = *(notifications.begin()); | |
357 // If the app has created a fullscreen window, then its notifications should | |
358 // be displayed when a window is fullscreen. | |
359 ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen()); | |
360 } | |
361 | |
362 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayMultiFullscreen) { | |
363 // Start a fullscreen app, and then start another fullscreen app on top of the | |
364 // first. Notifications from the first should not be displayed because it is | |
365 // not the app actually displaying on the screen. | |
366 ExtensionTestMessageListener notification_created_listener("created", false); | |
367 const extensions::Extension* extension1 = LoadAppWithWindowState( | |
368 "notifications/api/basic_app", "{\"state\":\"fullscreen\"}"); | |
369 ASSERT_TRUE(extension1) << message_; | |
370 | |
371 ExtensionTestMessageListener window_visible_listener("visible", false); | |
372 const extensions::Extension* extension2 = LoadAppWithWindowState( | |
373 "notifications/api/other_app", "{\"state\":\"fullscreen\"}"); | |
374 ASSERT_TRUE(extension2) << message_; | |
375 | |
376 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); | |
377 ASSERT_TRUE(window_visible_listener.WaitUntilSatisfied()); | |
378 | |
379 const message_center::NotificationList::Notifications& notifications = | |
380 g_browser_process->message_center()->GetVisibleNotifications(); | |
381 ASSERT_EQ(1u, notifications.size()); | |
382 message_center::Notification* notification = *(notifications.begin()); | |
383 // The first app window is superseded by the second window, so its | |
384 // notification shouldn't be displayed. | |
385 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); | |
386 } | |
OLD | NEW |