Index: chrome/browser/notifications/notification_interactive_uitest.cc |
diff --git a/chrome/browser/notifications/notification_interactive_uitest.cc b/chrome/browser/notifications/notification_interactive_uitest.cc |
index f1b87e8b8a9719391685b23fbfb188a50397bc24..472e95defb50f8af6b893f35316934c84490eaea 100644 |
--- a/chrome/browser/notifications/notification_interactive_uitest.cc |
+++ b/chrome/browser/notifications/notification_interactive_uitest.cc |
@@ -28,6 +28,7 @@ |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_tabstrip.h" |
#include "chrome/browser/ui/browser_window.h" |
+#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/test/base/in_process_browser_test.h" |
#include "chrome/test/base/ui_test_utils.h" |
@@ -50,6 +51,11 @@ |
#include "ui/message_center/notification_blocker.h" |
#include "url/gurl.h" |
+#if defined(OS_MACOSX) |
+#include "base/mac/mac_util.h" |
+#include "ui/base/test/scoped_fake_nswindow_fullscreen.h" |
+#endif |
+ |
namespace { |
class ToggledNotificationBlocker : public message_center::NotificationBlocker { |
@@ -176,6 +182,31 @@ class PermissionRequestObserver : public PermissionRequestManager::Observer { |
} // namespace |
+namespace { |
+ |
+// Helper class that has to be created in the stack to check if the fullscreen |
+// setting of a browser is in the desired state. |
+class FullscreenStateWaiter { |
+ public: |
+ explicit FullscreenStateWaiter(Browser* browser, bool desired_state) |
+ : browser_(browser), |
+ desired_state_(desired_state) {} |
+ |
+ void Wait() { |
+ while (desired_state_ != |
+ browser_->exclusive_access_manager()->context()->IsFullscreen()) |
+ content::RunAllPendingInMessageLoop(); |
+ } |
+ |
+ private: |
+ Browser* browser_; |
+ bool desired_state_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FullscreenStateWaiter); |
+}; |
+ |
+} // namespace |
+ |
class NotificationsTest : public InProcessBrowserTest { |
public: |
NotificationsTest() {} |
@@ -881,3 +912,102 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationDoubleClose) { |
result = CreateNotification(browser(), true, "", "Title1", "Body1", "chat"); |
EXPECT_NE("-1", result); |
} |
+ |
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestShouldDisplayNormal) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ // Creates a simple notification. |
+ AllowAllOrigins(); |
+ ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
+ |
+ std::string result = CreateSimpleNotification(browser(), true); |
+ EXPECT_NE("-1", result); |
+ |
+ ASSERT_EQ(1, GetNotificationCount()); |
+ message_center::NotificationList::Notifications notifications = |
+ message_center::MessageCenter::Get()->GetVisibleNotifications(); |
+ |
+ // Because the webpage is not fullscreen, ShouldDisplayOverFullscreen will be |
+ // false. |
+ EXPECT_FALSE( |
+ (*notifications.rbegin())->delegate()->ShouldDisplayOverFullscreen()); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestShouldDisplayFullscreen) { |
+#if defined(OS_MACOSX) |
+ ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; |
+#endif |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ // Creates a simple notification. |
+ AllowAllOrigins(); |
+ ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
+ |
+ std::string result = CreateSimpleNotification(browser(), true); |
+ EXPECT_NE("-1", result); |
+ |
+ // Set the page fullscreen |
+ browser()->exclusive_access_manager()->fullscreen_controller()-> |
+ ToggleBrowserFullscreenMode(); |
+ |
+ { |
+ FullscreenStateWaiter fs_state(browser(), true); |
+ fs_state.Wait(); |
+ } |
+ |
+ ASSERT_EQ(1, GetNotificationCount()); |
+ message_center::NotificationList::Notifications notifications = |
+ message_center::MessageCenter::Get()->GetVisibleNotifications(); |
+ |
+ // Because the webpage is fullscreen, ShouldDisplayOverFullscreen will be true |
+ EXPECT_TRUE( |
+ (*notifications.rbegin())->delegate()->ShouldDisplayOverFullscreen()); |
+} |
+ |
+// The Fake OSX fullscreen window doesn't like drawing a second fullscreen |
+// window when another is visible. |
+#if !defined(OS_MACOSX) |
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestShouldDisplayMultiFullscreen) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ AllowAllOrigins(); |
+ |
+ ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
+ |
+ Browser* other_browser = CreateBrowser(browser()->profile()); |
+ ui_test_utils::NavigateToURL(other_browser, GURL("about:blank")); |
+ |
+ std::string result = CreateSimpleNotification(browser(), true); |
+ EXPECT_NE("-1", result); |
+ |
+ // Set the notifcation page fullscreen |
+ browser()->exclusive_access_manager()->fullscreen_controller()-> |
+ ToggleBrowserFullscreenMode(); |
+ { |
+ FullscreenStateWaiter fs_state(browser(), true); |
+ fs_state.Wait(); |
+ } |
+ |
+ // Set the other browser fullscreen |
+ other_browser->exclusive_access_manager()->fullscreen_controller()-> |
+ ToggleBrowserFullscreenMode(); |
+ { |
+ FullscreenStateWaiter fs_state(other_browser, true); |
+ fs_state.Wait(); |
+ } |
+ |
+ ASSERT_TRUE(browser()->exclusive_access_manager()->context()->IsFullscreen()); |
+ ASSERT_TRUE( |
+ other_browser->exclusive_access_manager()->context()->IsFullscreen()); |
+ |
+ ASSERT_FALSE(browser()->window()->IsActive()); |
+ ASSERT_TRUE(other_browser->window()->IsActive()); |
+ |
+ ASSERT_EQ(1, GetNotificationCount()); |
+ message_center::NotificationList::Notifications notifications = |
+ message_center::MessageCenter::Get()->GetVisibleNotifications(); |
+ // Because the second page is the top-most fullscreen, |
+ // ShouldDisplayOverFullscreen will be false |
+ EXPECT_FALSE( |
+ (*notifications.rbegin())->delegate()->ShouldDisplayOverFullscreen()); |
+} |
+#endif |