Chromium Code Reviews| 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..8b0c7fa4a07e1eeb48d60eecc9dd0015c10cb1e0 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" |
| @@ -81,9 +85,18 @@ class UserGestureCatcher : public content::NotificationObserver { |
| bool waiting_; |
| }; |
| +enum class WindowState { |
| + FULLSCREEN, |
| + NORMAL |
| +}; |
| +static const char* const kWindowStateStrings[] = { |
| + "fullscreen", |
| + "normal" |
| +}; |
| + |
| class NotificationsApiTest : public ExtensionApiTest { |
| public: |
| - const extensions::Extension* LoadExtensionAndWait( |
| + const Extension* LoadExtensionAndWait( |
| const std::string& test_name) { |
| base::FilePath extdir = test_data_dir_.AppendASCII(test_name); |
| content::WindowedNotificationObserver page_created( |
| @@ -96,6 +109,23 @@ class NotificationsApiTest : public ExtensionApiTest { |
| return extension; |
| } |
| + const Extension* LoadAppWithWindowState( |
| + const std::string& test_name, WindowState window_state) { |
| + const std::string& create_window_options = base::StringPrintf( |
| + "{\"state\":\"%s\"}", |
| + kWindowStateStrings[static_cast<int>(window_state)]); |
|
dewittj
2016/09/14 23:09:47
Sorry to be picky here, but since there's only 2 l
bmalcolm
2016/09/15 16:25:52
Done.
|
| + base::FilePath extdir = test_data_dir_.AppendASCII(test_name); |
| + const extensions::Extension* extension = LoadExtension(extdir); |
| + EXPECT_TRUE(extension); |
| + |
| + ExtensionTestMessageListener launched_listener("launched", true); |
| + LaunchPlatformApp(extension); |
| + EXPECT_TRUE(launched_listener.WaitUntilSatisfied()); |
| + launched_listener.Reply(create_window_options); |
| + |
| + return extension; |
| + } |
| + |
| protected: |
| std::string GetNotificationIdFromDelegateId(const std::string& delegate_id) { |
| return g_browser_process->notification_ui_manager() |
| @@ -105,6 +135,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 +338,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 Extension* extension = LoadAppWithWindowState( |
| + "notifications/api/basic_app", WindowState::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 Extension* extension = LoadAppWithWindowState( |
| + "notifications/api/basic_app", WindowState::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 Extension* extension1 = LoadAppWithWindowState( |
| + "notifications/api/basic_app", WindowState::FULLSCREEN); |
| + ASSERT_TRUE(extension1) << message_; |
| + |
| + ExtensionTestMessageListener window_visible_listener("visible", false); |
| + const Extension* extension2 = LoadAppWithWindowState( |
| + "notifications/api/other_app", WindowState::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()); |
| +} |