Index: chrome/browser/extensions/api/notifications/notifications_apitest.cc |
diff --git a/chrome/browser/extensions/api/notifications/notifications_apitest.cc b/chrome/browser/extensions/api/notifications/notifications_apitest.cc |
index 426eea9aa2ed4f1af50186fc70c0f2c2ba1fa3a4..60f63ebb9e4810900d9347f2e3552d87585c077c 100644 |
--- a/chrome/browser/extensions/api/notifications/notifications_apitest.cc |
+++ b/chrome/browser/extensions/api/notifications/notifications_apitest.cc |
@@ -5,6 +5,7 @@ |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/apps/app_browsertest_util.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/extensions/api/notifications/notifications_api.h" |
#include "chrome/browser/extensions/extension_apitest.h" |
@@ -12,12 +13,15 @@ |
#include "chrome/browser/notifications/notification.h" |
#include "chrome/browser/notifications/notification_ui_manager.h" |
#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/ui/extensions/app_launch_params.h" |
+#include "chrome/browser/ui/extensions/application_launch.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/test/test_utils.h" |
#include "extensions/browser/api/test/test_api.h" |
#include "extensions/browser/notification_types.h" |
#include "extensions/common/features/feature.h" |
#include "extensions/common/test_util.h" |
+#include "extensions/test/extension_test_message_listener.h" |
#include "extensions/test/result_catcher.h" |
#include "ui/message_center/message_center.h" |
#include "ui/message_center/notification_list.h" |
@@ -96,6 +100,20 @@ class NotificationsApiTest : public ExtensionApiTest { |
return extension; |
} |
+ const extensions::Extension* LoadAppWithWindowState( |
+ 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.
|
+ base::FilePath extdir = test_data_dir_.AppendASCII(test_name); |
+ 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.
|
+ EXPECT_TRUE(extension); |
+ |
+ ExtensionTestMessageListener launched_listener("launched", true); |
+ LaunchPlatformApp(extension); |
+ EXPECT_TRUE(launched_listener.WaitUntilSatisfied()); |
+ launched_listener.Reply(window_state); |
+ |
+ return extension; |
+ } |
+ |
protected: |
std::string GetNotificationIdFromDelegateId(const std::string& delegate_id) { |
return g_browser_process->notification_ui_manager() |
@@ -105,6 +123,12 @@ class NotificationsApiTest : public ExtensionApiTest { |
g_browser_process->profile_manager()->GetLastUsedProfile())) |
->id(); |
} |
+ |
+ void LaunchPlatformApp(const Extension* extension) { |
+ OpenApplication(AppLaunchParams( |
+ browser()->profile(), extension, extensions::LAUNCH_CONTAINER_NONE, |
+ WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); |
+ } |
}; |
} // namespace |
@@ -302,3 +326,61 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestRequireInteraction) { |
EXPECT_TRUE(notification->never_timeout()); |
} |
+ |
+IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayNormal) { |
+ ExtensionTestMessageListener notification_created_listener("created", false); |
+ const extensions::Extension* extension = LoadAppWithWindowState( |
+ "notifications/api/basic_app", "{\"state\":\"normal\"}"); |
+ ASSERT_TRUE(extension) << message_; |
+ ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); |
+ |
+ const message_center::NotificationList::Notifications& notifications = |
+ g_browser_process->message_center()->GetVisibleNotifications(); |
+ ASSERT_EQ(1u, notifications.size()); |
+ message_center::Notification* notification = *(notifications.begin()); |
+ // If the app hasn't created a fullscreen window, then its notifications |
+ // shouldn't be displayed when a window is fullscreen. |
+ ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreen) { |
+ ExtensionTestMessageListener notification_created_listener("created", false); |
+ const extensions::Extension* extension = LoadAppWithWindowState( |
+ "notifications/api/basic_app", "{\"state\":\"fullscreen\"}"); |
+ ASSERT_TRUE(extension) << message_; |
+ ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); |
+ |
+ const message_center::NotificationList::Notifications& notifications = |
+ g_browser_process->message_center()->GetVisibleNotifications(); |
+ ASSERT_EQ(1u, notifications.size()); |
+ message_center::Notification* notification = *(notifications.begin()); |
+ // If the app has created a fullscreen window, then its notifications should |
+ // be displayed when a window is fullscreen. |
+ ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen()); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayMultiFullscreen) { |
+ // Start a fullscreen app, and then start another fullscreen app on top of the |
+ // first. Notifications from the first should not be displayed because it is |
+ // not the app actually displaying on the screen. |
+ ExtensionTestMessageListener notification_created_listener("created", false); |
+ const extensions::Extension* extension1 = LoadAppWithWindowState( |
+ "notifications/api/basic_app", "{\"state\":\"fullscreen\"}"); |
+ ASSERT_TRUE(extension1) << message_; |
+ |
+ ExtensionTestMessageListener window_visible_listener("visible", false); |
+ const extensions::Extension* extension2 = LoadAppWithWindowState( |
+ "notifications/api/other_app", "{\"state\":\"fullscreen\"}"); |
+ ASSERT_TRUE(extension2) << message_; |
+ |
+ ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); |
+ ASSERT_TRUE(window_visible_listener.WaitUntilSatisfied()); |
+ |
+ const message_center::NotificationList::Notifications& notifications = |
+ g_browser_process->message_center()->GetVisibleNotifications(); |
+ ASSERT_EQ(1u, notifications.size()); |
+ message_center::Notification* notification = *(notifications.begin()); |
+ // The first app window is superseded by the second window, so its |
+ // notification shouldn't be displayed. |
+ ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); |
+} |