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

Side by Side Diff: chrome/browser/notifications/notification_interactive_uitest.cc

Issue 2377553003: Add ShouldDisplayOverFullscreen support to web notifications. (Closed)
Patch Set: Fix Android/OSX unit test breakages Created 4 years, 2 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
OLDNEW
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 <deque> 5 #include <deque>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
23 #include "chrome/browser/infobars/infobar_service.h" 23 #include "chrome/browser/infobars/infobar_service.h"
24 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 24 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
25 #include "chrome/browser/notifications/notification.h" 25 #include "chrome/browser/notifications/notification.h"
26 #include "chrome/browser/permissions/permission_request_manager.h" 26 #include "chrome/browser/permissions/permission_request_manager.h"
27 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
29 #include "chrome/browser/ui/browser_tabstrip.h" 29 #include "chrome/browser/ui/browser_tabstrip.h"
30 #include "chrome/browser/ui/browser_window.h" 30 #include "chrome/browser/ui/browser_window.h"
31 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" 32 #include "chrome/browser/ui/tabs/tab_strip_model.h"
32 #include "chrome/test/base/in_process_browser_test.h" 33 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/ui_test_utils.h" 34 #include "chrome/test/base/ui_test_utils.h"
34 #include "components/content_settings/core/browser/host_content_settings_map.h" 35 #include "components/content_settings/core/browser/host_content_settings_map.h"
35 #include "components/content_settings/core/common/content_settings.h" 36 #include "components/content_settings/core/common/content_settings.h"
36 #include "components/content_settings/core/common/content_settings_pattern.h" 37 #include "components/content_settings/core/common/content_settings_pattern.h"
37 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/notification_source.h" 39 #include "content/public/browser/notification_source.h"
39 #include "content/public/browser/notification_types.h" 40 #include "content/public/browser/notification_types.h"
40 #include "content/public/browser/render_view_host.h" 41 #include "content/public/browser/render_view_host.h"
41 #include "content/public/browser/web_contents.h" 42 #include "content/public/browser/web_contents.h"
42 #include "content/public/test/browser_test_utils.h" 43 #include "content/public/test/browser_test_utils.h"
43 #include "content/public/test/test_utils.h" 44 #include "content/public/test/test_utils.h"
44 #include "net/test/embedded_test_server/embedded_test_server.h" 45 #include "net/test/embedded_test_server/embedded_test_server.h"
45 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
46 #include "ui/base/window_open_disposition.h" 47 #include "ui/base/window_open_disposition.h"
47 #include "ui/message_center/message_center.h" 48 #include "ui/message_center/message_center.h"
48 #include "ui/message_center/message_center_observer.h" 49 #include "ui/message_center/message_center_observer.h"
49 #include "ui/message_center/message_center_style.h" 50 #include "ui/message_center/message_center_style.h"
50 #include "ui/message_center/notification_blocker.h" 51 #include "ui/message_center/notification_blocker.h"
51 #include "url/gurl.h" 52 #include "url/gurl.h"
52 53
54 #if defined(OS_MACOSX)
55 #include "base/mac/mac_util.h"
56 #include "ui/base/test/scoped_fake_nswindow_fullscreen.h"
57 #endif
58
53 namespace { 59 namespace {
54 60
55 class ToggledNotificationBlocker : public message_center::NotificationBlocker { 61 class ToggledNotificationBlocker : public message_center::NotificationBlocker {
56 public: 62 public:
57 ToggledNotificationBlocker() 63 ToggledNotificationBlocker()
58 : message_center::NotificationBlocker( 64 : message_center::NotificationBlocker(
59 message_center::MessageCenter::Get()), 65 message_center::MessageCenter::Get()),
60 notifications_enabled_(true) {} 66 notifications_enabled_(true) {}
61 ~ToggledNotificationBlocker() override {} 67 ~ToggledNotificationBlocker() override {}
62 68
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 175
170 PermissionRequestManager* request_manager_; 176 PermissionRequestManager* request_manager_;
171 bool request_shown_; 177 bool request_shown_;
172 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 178 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
173 179
174 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); 180 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver);
175 }; 181 };
176 182
177 } // namespace 183 } // namespace
178 184
185 namespace {
186
187 // Helper class that has to be created in the stack to check if the fullscreen
188 // setting of a browser is in the desired state.
189 class FullscreenStateWaiter {
190 public:
191 explicit FullscreenStateWaiter(Browser* browser, bool desired_state)
192 : browser_(browser),
193 desired_state_(desired_state) {}
194
195 void Wait() {
196 while (desired_state_ !=
197 browser_->exclusive_access_manager()->context()->IsFullscreen())
198 content::RunAllPendingInMessageLoop();
199 }
200
201 private:
202 Browser* browser_;
203 bool desired_state_;
204
205 DISALLOW_COPY_AND_ASSIGN(FullscreenStateWaiter);
206 };
207
208 } // namespace
209
179 class NotificationsTest : public InProcessBrowserTest { 210 class NotificationsTest : public InProcessBrowserTest {
180 public: 211 public:
181 NotificationsTest() {} 212 NotificationsTest() {}
182 213
183 protected: 214 protected:
184 int GetNotificationCount(); 215 int GetNotificationCount();
185 int GetNotificationPopupCount(); 216 int GetNotificationPopupCount();
186 217
187 void CloseBrowserWindow(Browser* browser); 218 void CloseBrowserWindow(Browser* browser);
188 void CrashTab(Browser* browser, int index); 219 void CrashTab(Browser* browser, int index);
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 true); // by_user 905 true); // by_user
875 906
876 ASSERT_EQ(0, GetNotificationCount()); 907 ASSERT_EQ(0, GetNotificationCount());
877 908
878 // Calling WebContents::IsCrashed() will return FALSE here, even if the WC did 909 // Calling WebContents::IsCrashed() will return FALSE here, even if the WC did
879 // crash. Work around this timing issue by creating another notification, 910 // crash. Work around this timing issue by creating another notification,
880 // which requires interaction with the renderer process. 911 // which requires interaction with the renderer process.
881 result = CreateNotification(browser(), true, "", "Title1", "Body1", "chat"); 912 result = CreateNotification(browser(), true, "", "Title1", "Body1", "chat");
882 EXPECT_NE("-1", result); 913 EXPECT_NE("-1", result);
883 } 914 }
915
916 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestShouldDisplayNormal) {
917 ASSERT_TRUE(embedded_test_server()->Start());
918
919 // Creates a simple notification.
920 AllowAllOrigins();
921 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
922
923 std::string result = CreateSimpleNotification(browser(), true);
924 EXPECT_NE("-1", result);
925
926 ASSERT_EQ(1, GetNotificationCount());
927 message_center::NotificationList::Notifications notifications =
928 message_center::MessageCenter::Get()->GetVisibleNotifications();
929
930 // Because the webpage is not fullscreen, ShouldDisplayOverFullscreen will be
931 // false.
932 EXPECT_FALSE(
933 (*notifications.rbegin())->delegate()->ShouldDisplayOverFullscreen());
934 }
935
936 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestShouldDisplayFullscreen) {
937 #if defined(OS_MACOSX)
938 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
939 #endif
940 ASSERT_TRUE(embedded_test_server()->Start());
941
942 // Creates a simple notification.
943 AllowAllOrigins();
944 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
945
946 std::string result = CreateSimpleNotification(browser(), true);
947 EXPECT_NE("-1", result);
948
949 // Set the page fullscreen
950 browser()->exclusive_access_manager()->fullscreen_controller()->
951 ToggleBrowserFullscreenMode();
952
953 {
954 FullscreenStateWaiter fs_state(browser(), true);
955 fs_state.Wait();
956 }
957
958 ASSERT_EQ(1, GetNotificationCount());
959 message_center::NotificationList::Notifications notifications =
960 message_center::MessageCenter::Get()->GetVisibleNotifications();
961
962 // Because the webpage is fullscreen, ShouldDisplayOverFullscreen will be true
963 EXPECT_TRUE(
964 (*notifications.rbegin())->delegate()->ShouldDisplayOverFullscreen());
965 }
966
967 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen
968 // window when another is visible.
969 #if !defined(OS_MACOSX)
970 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestShouldDisplayMultiFullscreen) {
971 ASSERT_TRUE(embedded_test_server()->Start());
972 AllowAllOrigins();
973
974 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
975
976 Browser* other_browser = CreateBrowser(browser()->profile());
977 ui_test_utils::NavigateToURL(other_browser, GURL("about:blank"));
978
979 std::string result = CreateSimpleNotification(browser(), true);
980 EXPECT_NE("-1", result);
981
982 // Set the notifcation page fullscreen
983 browser()->exclusive_access_manager()->fullscreen_controller()->
984 ToggleBrowserFullscreenMode();
985 {
986 FullscreenStateWaiter fs_state(browser(), true);
987 fs_state.Wait();
988 }
989
990 // Set the other browser fullscreen
991 other_browser->exclusive_access_manager()->fullscreen_controller()->
992 ToggleBrowserFullscreenMode();
993 {
994 FullscreenStateWaiter fs_state(other_browser, true);
995 fs_state.Wait();
996 }
997
998 ASSERT_TRUE(browser()->exclusive_access_manager()->context()->IsFullscreen());
999 ASSERT_TRUE(
1000 other_browser->exclusive_access_manager()->context()->IsFullscreen());
1001
1002 ASSERT_FALSE(browser()->window()->IsActive());
1003 ASSERT_TRUE(other_browser->window()->IsActive());
1004
1005 ASSERT_EQ(1, GetNotificationCount());
1006 message_center::NotificationList::Notifications notifications =
1007 message_center::MessageCenter::Get()->GetVisibleNotifications();
1008 // Because the second page is the top-most fullscreen,
1009 // ShouldDisplayOverFullscreen will be false
1010 EXPECT_FALSE(
1011 (*notifications.rbegin())->delegate()->ShouldDisplayOverFullscreen());
1012 }
1013 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698