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" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 }; | 115 }; |
116 | 116 |
117 } // namespace | 117 } // namespace |
118 | 118 |
119 class NotificationsTest : public InProcessBrowserTest { | 119 class NotificationsTest : public InProcessBrowserTest { |
120 public: | 120 public: |
121 NotificationsTest() {} | 121 NotificationsTest() {} |
122 | 122 |
123 protected: | 123 protected: |
124 int GetNotificationCount(); | 124 int GetNotificationCount(); |
125 int GetNotificationPopupCount(); | |
126 | 125 |
127 void CloseBrowserWindow(Browser* browser); | 126 void CloseBrowserWindow(Browser* browser); |
128 void CrashTab(Browser* browser, int index); | 127 void CrashTab(Browser* browser, int index); |
129 | 128 |
130 void DenyOrigin(const GURL& origin); | 129 void DenyOrigin(const GURL& origin); |
131 void AllowOrigin(const GURL& origin); | 130 void AllowOrigin(const GURL& origin); |
132 void AllowAllOrigins(); | 131 void AllowAllOrigins(); |
133 void SetDefaultContentSetting(ContentSetting setting); | 132 void SetDefaultContentSetting(ContentSetting setting); |
134 | 133 |
135 void VerifyInfoBar(const Browser* browser, int index); | 134 void VerifyInfoBar(const Browser* browser, int index); |
(...skipping 22 matching lines...) Expand all Loading... |
158 } | 157 } |
159 | 158 |
160 private: | 159 private: |
161 void DropOriginPreference(const GURL& origin); | 160 void DropOriginPreference(const GURL& origin); |
162 }; | 161 }; |
163 | 162 |
164 int NotificationsTest::GetNotificationCount() { | 163 int NotificationsTest::GetNotificationCount() { |
165 return message_center::MessageCenter::Get()->NotificationCount(); | 164 return message_center::MessageCenter::Get()->NotificationCount(); |
166 } | 165 } |
167 | 166 |
168 int NotificationsTest::GetNotificationPopupCount() { | |
169 return message_center::MessageCenter::Get()->GetPopupNotifications().size(); | |
170 } | |
171 | |
172 void NotificationsTest::CloseBrowserWindow(Browser* browser) { | 167 void NotificationsTest::CloseBrowserWindow(Browser* browser) { |
173 content::WindowedNotificationObserver observer( | 168 content::WindowedNotificationObserver observer( |
174 chrome::NOTIFICATION_BROWSER_CLOSED, | 169 chrome::NOTIFICATION_BROWSER_CLOSED, |
175 content::Source<Browser>(browser)); | 170 content::Source<Browser>(browser)); |
176 browser->window()->Close(); | 171 browser->window()->Close(); |
177 observer.Wait(); | 172 observer.Wait(); |
178 } | 173 } |
179 | 174 |
180 void NotificationsTest::CrashTab(Browser* browser, int index) { | 175 void NotificationsTest::CrashTab(Browser* browser, int index) { |
181 content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index)); | 176 content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index)); |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 NEW_BACKGROUND_TAB, | 736 NEW_BACKGROUND_TAB, |
742 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 737 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
743 browser()->tab_strip_model()->ActivateTabAt(0, true); | 738 browser()->tab_strip_model()->ActivateTabAt(0, true); |
744 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 739 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
745 CreateSimpleNotification(browser(), true); | 740 CreateSimpleNotification(browser(), true); |
746 ASSERT_EQ(1, GetNotificationCount()); | 741 ASSERT_EQ(1, GetNotificationCount()); |
747 CrashTab(browser(), 0); | 742 CrashTab(browser(), 0); |
748 ASSERT_EQ(1, GetNotificationCount()); | 743 ASSERT_EQ(1, GetNotificationCount()); |
749 } | 744 } |
750 | 745 |
751 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) { | 746 // See http://crbug.com/366539 |
| 747 #if defined(OS_LINUX) |
| 748 #define MAYBE_TestNotificationReplacement DISABLED_TestNotificationReplacement |
| 749 #else |
| 750 #define MAYBE_TestNotificationReplacement TestNotificationReplacement |
| 751 #endif |
| 752 |
| 753 IN_PROC_BROWSER_TEST_F(NotificationsTest, MAYBE_TestNotificationReplacement) { |
752 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 754 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
753 | 755 |
754 // Test that we can replace a notification using the tag. | 756 // Test that we can replace a notification using the replaceId. |
755 AllowAllOrigins(); | 757 AllowAllOrigins(); |
756 | 758 |
757 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 759 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
758 | 760 |
759 std::string result = CreateNotification( | 761 std::string result = CreateNotification( |
760 browser(), true, "abc.png", "Title1", "Body1", "chat"); | 762 browser(), true, "abc.png", "Title1", "Body1", "chat"); |
761 EXPECT_NE("-1", result); | 763 EXPECT_NE("-1", result); |
762 | 764 |
763 ASSERT_EQ(1, GetNotificationCount()); | 765 ASSERT_EQ(1, GetNotificationCount()); |
764 | 766 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 | 802 |
801 result = CreateSimpleNotification(browser(), true); | 803 result = CreateSimpleNotification(browser(), true); |
802 EXPECT_NE("-1", result); | 804 EXPECT_NE("-1", result); |
803 | 805 |
804 EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(), | 806 EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(), |
805 GetTestPageURL().GetOrigin(), | 807 GetTestPageURL().GetOrigin(), |
806 CONTENT_SETTINGS_TYPE_NOTIFICATIONS) | 808 CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
807 .ToDoubleT(), | 809 .ToDoubleT(), |
808 13); | 810 13); |
809 } | 811 } |
810 | |
811 IN_PROC_BROWSER_TEST_F(NotificationsTest, | |
812 TestNotificationReplacementReappearance) { | |
813 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
814 | |
815 // Test that we can replace a notification using the tag, and that it will | |
816 // cause the notification to reappear as a popup again. | |
817 AllowAllOrigins(); | |
818 | |
819 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | |
820 | |
821 ASSERT_EQ(0, GetNotificationPopupCount()); | |
822 | |
823 std::string result = CreateNotification( | |
824 browser(), true, "abc.png", "Title1", "Body1", "chat"); | |
825 EXPECT_NE("-1", result); | |
826 | |
827 ASSERT_EQ(1, GetNotificationPopupCount()); | |
828 | |
829 message_center::NotificationList::Notifications notifications = | |
830 message_center::MessageCenter::Get()->GetVisibleNotifications(); | |
831 message_center::MessageCenter::Get()->ClickOnNotification( | |
832 (*notifications.rbegin())->id()); | |
833 | |
834 ASSERT_EQ(0, GetNotificationPopupCount()); | |
835 | |
836 result = CreateNotification( | |
837 browser(), true, "abc.png", "Title2", "Body2", "chat"); | |
838 EXPECT_NE("-1", result); | |
839 | |
840 ASSERT_EQ(1, GetNotificationPopupCount()); | |
841 } | |
OLD | NEW |