| 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 <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" | 
|   11 #include "base/compiler_specific.h" |   11 #include "base/compiler_specific.h" | 
|   12 #include "base/macros.h" |   12 #include "base/macros.h" | 
|   13 #include "base/memory/ref_counted.h" |   13 #include "base/memory/ref_counted.h" | 
|   14 #include "base/run_loop.h" |   14 #include "base/run_loop.h" | 
|   15 #include "base/strings/stringprintf.h" |   15 #include "base/strings/stringprintf.h" | 
|   16 #include "base/strings/utf_string_conversions.h" |   16 #include "base/strings/utf_string_conversions.h" | 
|   17 #include "base/test/simple_test_clock.h" |   17 #include "base/test/simple_test_clock.h" | 
|   18 #include "base/time/clock.h" |   18 #include "base/time/clock.h" | 
|   19 #include "build/build_config.h" |   19 #include "build/build_config.h" | 
|   20 #include "chrome/browser/browser_process.h" |   20 #include "chrome/browser/browser_process.h" | 
|   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/notifications/notification_test_util.h" | 
|   26 #include "chrome/browser/permissions/permission_request_manager.h" |   27 #include "chrome/browser/permissions/permission_request_manager.h" | 
|   27 #include "chrome/browser/profiles/profile.h" |   28 #include "chrome/browser/profiles/profile.h" | 
|   28 #include "chrome/browser/ui/browser.h" |   29 #include "chrome/browser/ui/browser.h" | 
|   29 #include "chrome/browser/ui/browser_tabstrip.h" |   30 #include "chrome/browser/ui/browser_tabstrip.h" | 
|   30 #include "chrome/browser/ui/browser_window.h" |   31 #include "chrome/browser/ui/browser_window.h" | 
 |   32 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" | 
|   31 #include "chrome/browser/ui/tabs/tab_strip_model.h" |   33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 
|   32 #include "chrome/test/base/in_process_browser_test.h" |   34 #include "chrome/test/base/in_process_browser_test.h" | 
 |   35 #include "chrome/test/base/interactive_test_utils.h" | 
|   33 #include "chrome/test/base/ui_test_utils.h" |   36 #include "chrome/test/base/ui_test_utils.h" | 
|   34 #include "components/content_settings/core/browser/host_content_settings_map.h" |   37 #include "components/content_settings/core/browser/host_content_settings_map.h" | 
|   35 #include "components/content_settings/core/common/content_settings.h" |   38 #include "components/content_settings/core/common/content_settings.h" | 
|   36 #include "components/content_settings/core/common/content_settings_pattern.h" |   39 #include "components/content_settings/core/common/content_settings_pattern.h" | 
|   37 #include "content/public/browser/notification_service.h" |   40 #include "content/public/browser/notification_service.h" | 
|   38 #include "content/public/browser/notification_source.h" |   41 #include "content/public/browser/notification_source.h" | 
|   39 #include "content/public/browser/notification_types.h" |   42 #include "content/public/browser/notification_types.h" | 
|   40 #include "content/public/browser/render_view_host.h" |   43 #include "content/public/browser/render_view_host.h" | 
|   41 #include "content/public/browser/web_contents.h" |   44 #include "content/public/browser/web_contents.h" | 
|   42 #include "content/public/test/browser_test_utils.h" |   45 #include "content/public/test/browser_test_utils.h" | 
|   43 #include "content/public/test/test_utils.h" |   46 #include "content/public/test/test_utils.h" | 
|   44 #include "net/test/embedded_test_server/embedded_test_server.h" |   47 #include "net/test/embedded_test_server/embedded_test_server.h" | 
|   45 #include "testing/gtest/include/gtest/gtest.h" |   48 #include "testing/gtest/include/gtest/gtest.h" | 
|   46 #include "ui/base/window_open_disposition.h" |   49 #include "ui/base/window_open_disposition.h" | 
|   47 #include "ui/message_center/message_center.h" |   50 #include "ui/message_center/message_center.h" | 
|   48 #include "ui/message_center/message_center_observer.h" |   51 #include "ui/message_center/message_center_observer.h" | 
|   49 #include "ui/message_center/message_center_style.h" |   52 #include "ui/message_center/message_center_style.h" | 
|   50 #include "ui/message_center/notification_blocker.h" |   53 #include "ui/message_center/notification_blocker.h" | 
|   51 #include "url/gurl.h" |   54 #include "url/gurl.h" | 
|   52  |   55  | 
 |   56 #if defined(OS_MACOSX) | 
 |   57 #include "base/mac/mac_util.h" | 
 |   58 #include "ui/base/test/scoped_fake_nswindow_fullscreen.h" | 
 |   59 #endif | 
 |   60  | 
|   53 namespace { |   61 namespace { | 
|   54  |   62  | 
|   55 class ToggledNotificationBlocker : public message_center::NotificationBlocker { |   63 class ToggledNotificationBlocker : public message_center::NotificationBlocker { | 
|   56  public: |   64  public: | 
|   57   ToggledNotificationBlocker() |   65   ToggledNotificationBlocker() | 
|   58       : message_center::NotificationBlocker( |   66       : message_center::NotificationBlocker( | 
|   59             message_center::MessageCenter::Get()), |   67             message_center::MessageCenter::Get()), | 
|   60         notifications_enabled_(true) {} |   68         notifications_enabled_(true) {} | 
|   61   ~ToggledNotificationBlocker() override {} |   69   ~ToggledNotificationBlocker() override {} | 
|   62  |   70  | 
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  874       true);  // by_user |  882       true);  // by_user | 
|  875  |  883  | 
|  876   ASSERT_EQ(0, GetNotificationCount()); |  884   ASSERT_EQ(0, GetNotificationCount()); | 
|  877  |  885  | 
|  878   // Calling WebContents::IsCrashed() will return FALSE here, even if the WC did |  886   // Calling WebContents::IsCrashed() will return FALSE here, even if the WC did | 
|  879   // crash. Work around this timing issue by creating another notification, |  887   // crash. Work around this timing issue by creating another notification, | 
|  880   // which requires interaction with the renderer process. |  888   // which requires interaction with the renderer process. | 
|  881   result = CreateNotification(browser(), true, "", "Title1", "Body1", "chat"); |  889   result = CreateNotification(browser(), true, "", "Title1", "Body1", "chat"); | 
|  882   EXPECT_NE("-1", result); |  890   EXPECT_NE("-1", result); | 
|  883 } |  891 } | 
 |  892  | 
 |  893 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestShouldDisplayNormal) { | 
 |  894   ASSERT_TRUE(embedded_test_server()->Start()); | 
 |  895  | 
 |  896   // Creates a simple notification. | 
 |  897   AllowAllOrigins(); | 
 |  898   ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 
 |  899  | 
 |  900   std::string result = CreateSimpleNotification(browser(), true); | 
 |  901   EXPECT_NE("-1", result); | 
 |  902  | 
 |  903   ASSERT_EQ(1, GetNotificationCount()); | 
 |  904   message_center::NotificationList::Notifications notifications = | 
 |  905       message_center::MessageCenter::Get()->GetVisibleNotifications(); | 
 |  906  | 
 |  907   // Because the webpage is not fullscreen, ShouldDisplayOverFullscreen will be | 
 |  908   // false. | 
 |  909   EXPECT_FALSE( | 
 |  910       (*notifications.rbegin())->delegate()->ShouldDisplayOverFullscreen()); | 
 |  911 } | 
 |  912  | 
 |  913 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestShouldDisplayFullscreen) { | 
 |  914 #if defined(OS_MACOSX) | 
 |  915   ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; | 
 |  916 #endif | 
 |  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   // Set the page fullscreen | 
 |  927   browser()->exclusive_access_manager()->fullscreen_controller()-> | 
 |  928       ToggleBrowserFullscreenMode(); | 
 |  929  | 
 |  930   { | 
 |  931     FullscreenStateWaiter fs_state(browser(), true); | 
 |  932     fs_state.Wait(); | 
 |  933   } | 
 |  934  | 
 |  935   ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 
 |  936       browser()->window()->GetNativeWindow())); | 
 |  937  | 
 |  938   ASSERT_TRUE(browser()->window()->IsActive()); | 
 |  939  | 
 |  940   ASSERT_EQ(1, GetNotificationCount()); | 
 |  941   message_center::NotificationList::Notifications notifications = | 
 |  942       message_center::MessageCenter::Get()->GetVisibleNotifications(); | 
 |  943  | 
 |  944   // Because the webpage is fullscreen, ShouldDisplayOverFullscreen will be true | 
 |  945   EXPECT_TRUE( | 
 |  946       (*notifications.rbegin())->delegate()->ShouldDisplayOverFullscreen()); | 
 |  947 } | 
 |  948  | 
 |  949 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen | 
 |  950 // window when another is visible. | 
 |  951 #if !defined(OS_MACOSX) | 
 |  952 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestShouldDisplayMultiFullscreen) { | 
 |  953   ASSERT_TRUE(embedded_test_server()->Start()); | 
 |  954   AllowAllOrigins(); | 
 |  955  | 
 |  956   ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 
 |  957  | 
 |  958   Browser* other_browser = CreateBrowser(browser()->profile()); | 
 |  959   ui_test_utils::NavigateToURL(other_browser, GURL("about:blank")); | 
 |  960  | 
 |  961   std::string result = CreateSimpleNotification(browser(), true); | 
 |  962   EXPECT_NE("-1", result); | 
 |  963  | 
 |  964   // Set the notifcation page fullscreen | 
 |  965   browser()->exclusive_access_manager()->fullscreen_controller()-> | 
 |  966       ToggleBrowserFullscreenMode(); | 
 |  967   { | 
 |  968     FullscreenStateWaiter fs_state(browser(), true); | 
 |  969     fs_state.Wait(); | 
 |  970   } | 
 |  971  | 
 |  972   // Set the other browser fullscreen | 
 |  973   other_browser->exclusive_access_manager()->fullscreen_controller()-> | 
 |  974       ToggleBrowserFullscreenMode(); | 
 |  975   { | 
 |  976     FullscreenStateWaiter fs_state(other_browser, true); | 
 |  977     fs_state.Wait(); | 
 |  978   } | 
 |  979  | 
 |  980   ASSERT_TRUE(browser()->exclusive_access_manager()->context()->IsFullscreen()); | 
 |  981   ASSERT_TRUE( | 
 |  982       other_browser->exclusive_access_manager()->context()->IsFullscreen()); | 
 |  983  | 
 |  984   ASSERT_FALSE(browser()->window()->IsActive()); | 
 |  985   ASSERT_TRUE(other_browser->window()->IsActive()); | 
 |  986  | 
 |  987   ASSERT_EQ(1, GetNotificationCount()); | 
 |  988   message_center::NotificationList::Notifications notifications = | 
 |  989       message_center::MessageCenter::Get()->GetVisibleNotifications(); | 
 |  990   // Because the second page is the top-most fullscreen, | 
 |  991   // ShouldDisplayOverFullscreen will be false | 
 |  992   EXPECT_FALSE( | 
 |  993       (*notifications.rbegin())->delegate()->ShouldDisplayOverFullscreen()); | 
 |  994 } | 
 |  995 #endif | 
| OLD | NEW |