OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/lifetime/keep_alive_registry.h" | 18 #include "chrome/browser/lifetime/keep_alive_registry.h" |
18 #include "chrome/browser/lifetime/keep_alive_types.h" | 19 #include "chrome/browser/lifetime/keep_alive_types.h" |
19 #include "chrome/browser/notifications/message_center_notification_manager.h" | 20 #include "chrome/browser/notifications/message_center_notification_manager.h" |
20 #include "chrome/browser/notifications/notification.h" | 21 #include "chrome/browser/notifications/notification.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 133 |
133 return Notification( | 134 return Notification( |
134 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 135 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
135 base::ASCIIToUTF16("title"), base::ASCIIToUTF16("message"), | 136 base::ASCIIToUTF16("title"), base::ASCIIToUTF16("message"), |
136 gfx::Image(), | 137 gfx::Image(), |
137 message_center::NotifierId(message_center::NotifierId::APPLICATION, | 138 message_center::NotifierId(message_center::NotifierId::APPLICATION, |
138 "extension_id"), | 139 "extension_id"), |
139 base::UTF8ToUTF16("chrome-test://testing/"), | 140 base::UTF8ToUTF16("chrome-test://testing/"), |
140 GURL("chrome-test://testing/"), "REPLACE-ME", data, new_delegate); | 141 GURL("chrome-test://testing/"), "REPLACE-ME", data, new_delegate); |
141 } | 142 } |
| 143 |
| 144 void RunLoopUntilIdle() { |
| 145 base::RunLoop loop; |
| 146 loop.RunUntilIdle(); |
| 147 } |
142 }; | 148 }; |
143 | 149 |
144 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, RetrieveBaseParts) { | 150 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, RetrieveBaseParts) { |
145 EXPECT_TRUE(manager()); | 151 EXPECT_TRUE(manager()); |
146 EXPECT_TRUE(message_center()); | 152 EXPECT_TRUE(message_center()); |
147 } | 153 } |
148 | 154 |
149 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicAddCancel) { | 155 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicAddCancel) { |
150 // Someone may create system notifications like "you're in multi-profile | 156 // Someone may create system notifications like "you're in multi-profile |
151 // mode..." or something which may change the expectation. | 157 // mode..." or something which may change the expectation. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 delegate->Release(); | 200 delegate->Release(); |
195 delegate2->Release(); | 201 delegate2->Release(); |
196 } | 202 } |
197 | 203 |
198 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, VerifyKeepAlives) { | 204 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, VerifyKeepAlives) { |
199 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( | 205 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( |
200 KeepAliveOrigin::NOTIFICATION)); | 206 KeepAliveOrigin::NOTIFICATION)); |
201 | 207 |
202 TestDelegate* delegate; | 208 TestDelegate* delegate; |
203 manager()->Add(CreateTestNotification("a", &delegate), profile()); | 209 manager()->Add(CreateTestNotification("a", &delegate), profile()); |
| 210 RunLoopUntilIdle(); |
204 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( | 211 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( |
205 KeepAliveOrigin::NOTIFICATION)); | 212 KeepAliveOrigin::NOTIFICATION)); |
206 | 213 |
207 TestDelegate* delegate2; | 214 TestDelegate* delegate2; |
208 manager()->Add(CreateRichTestNotification("b", &delegate2), profile()); | 215 manager()->Add(CreateRichTestNotification("b", &delegate2), profile()); |
| 216 RunLoopUntilIdle(); |
209 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( | 217 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( |
210 KeepAliveOrigin::NOTIFICATION)); | 218 KeepAliveOrigin::NOTIFICATION)); |
211 | 219 |
212 manager()->CancelById("a", NotificationUIManager::GetProfileID(profile())); | 220 manager()->CancelById("a", NotificationUIManager::GetProfileID(profile())); |
| 221 RunLoopUntilIdle(); |
213 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( | 222 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( |
214 KeepAliveOrigin::NOTIFICATION)); | 223 KeepAliveOrigin::NOTIFICATION)); |
215 | 224 |
216 manager()->CancelById("b", NotificationUIManager::GetProfileID(profile())); | 225 manager()->CancelById("b", NotificationUIManager::GetProfileID(profile())); |
| 226 RunLoopUntilIdle(); |
217 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( | 227 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( |
218 KeepAliveOrigin::NOTIFICATION)); | 228 KeepAliveOrigin::NOTIFICATION)); |
219 | 229 |
220 delegate->Release(); | 230 delegate->Release(); |
221 delegate2->Release(); | 231 delegate2->Release(); |
222 } | 232 } |
223 | 233 |
224 // Notification center is only used on ChromeOS. | 234 // Notification center is only used on ChromeOS. |
225 #if defined(OS_CHROMEOS) | 235 #if defined(OS_CHROMEOS) |
226 | 236 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 EXPECT_EQ("", observer.log(notification_id)); | 443 EXPECT_EQ("", observer.log(notification_id)); |
434 | 444 |
435 message_center()->SetVisibility(message_center::VISIBILITY_TRANSIENT); | 445 message_center()->SetVisibility(message_center::VISIBILITY_TRANSIENT); |
436 EXPECT_EQ(base::StringPrintf("update-%s", notification_id.c_str()), | 446 EXPECT_EQ(base::StringPrintf("update-%s", notification_id.c_str()), |
437 observer.log(notification_id)); | 447 observer.log(notification_id)); |
438 | 448 |
439 delegate->Release(); | 449 delegate->Release(); |
440 } | 450 } |
441 | 451 |
442 #endif // defined(OS_CHROMEOS) | 452 #endif // defined(OS_CHROMEOS) |
OLD | NEW |