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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 | Annotate | Revision Log
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 "chrome/browser/notifications/desktop_notifications_unittest.h" 5 #include "chrome/browser/notifications/desktop_notifications_unittest.h"
6 6
7 #include "base/prefs/testing_pref_service.h" 7 #include "base/prefs/testing_pref_service.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" 10 #include "chrome/browser/notifications/balloon_notification_ui_manager.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return params; 159 return params;
160 } 160 }
161 161
162 TEST_F(DesktopNotificationsTest, TestShow) { 162 TEST_F(DesktopNotificationsTest, TestShow) {
163 content::ShowDesktopNotificationHostMsgParams params = 163 content::ShowDesktopNotificationHostMsgParams params =
164 StandardTestNotification(); 164 StandardTestNotification();
165 params.notification_id = 1; 165 params.notification_id = 1;
166 166
167 EXPECT_TRUE(service_->ShowDesktopNotification( 167 EXPECT_TRUE(service_->ShowDesktopNotification(
168 params, 0, 0, DesktopNotificationService::PageNotification)); 168 params, 0, 0, DesktopNotificationService::PageNotification));
169 MessageLoopForUI::current()->RunUntilIdle(); 169 base::MessageLoopForUI::current()->RunUntilIdle();
170 EXPECT_EQ(1, balloon_collection_->count()); 170 EXPECT_EQ(1, balloon_collection_->count());
171 171
172 content::ShowDesktopNotificationHostMsgParams params2; 172 content::ShowDesktopNotificationHostMsgParams params2;
173 params2.origin = GURL("http://www.google.com"); 173 params2.origin = GURL("http://www.google.com");
174 params2.is_html = true; 174 params2.is_html = true;
175 params2.contents_url = GURL("http://www.google.com/notification.html"); 175 params2.contents_url = GURL("http://www.google.com/notification.html");
176 params2.notification_id = 2; 176 params2.notification_id = 2;
177 177
178 EXPECT_TRUE(service_->ShowDesktopNotification( 178 EXPECT_TRUE(service_->ShowDesktopNotification(
179 params2, 0, 0, DesktopNotificationService::PageNotification)); 179 params2, 0, 0, DesktopNotificationService::PageNotification));
180 MessageLoopForUI::current()->RunUntilIdle(); 180 base::MessageLoopForUI::current()->RunUntilIdle();
181 EXPECT_EQ(2, balloon_collection_->count()); 181 EXPECT_EQ(2, balloon_collection_->count());
182 182
183 EXPECT_EQ("notification displayed\n" 183 EXPECT_EQ("notification displayed\n"
184 "notification displayed\n", 184 "notification displayed\n",
185 log_output_); 185 log_output_);
186 } 186 }
187 187
188 TEST_F(DesktopNotificationsTest, TestClose) { 188 TEST_F(DesktopNotificationsTest, TestClose) {
189 content::ShowDesktopNotificationHostMsgParams params = 189 content::ShowDesktopNotificationHostMsgParams params =
190 StandardTestNotification(); 190 StandardTestNotification();
191 params.notification_id = 1; 191 params.notification_id = 1;
192 192
193 // Request a notification; should open a balloon. 193 // Request a notification; should open a balloon.
194 EXPECT_TRUE(service_->ShowDesktopNotification( 194 EXPECT_TRUE(service_->ShowDesktopNotification(
195 params, 0, 0, DesktopNotificationService::PageNotification)); 195 params, 0, 0, DesktopNotificationService::PageNotification));
196 MessageLoopForUI::current()->RunUntilIdle(); 196 base::MessageLoopForUI::current()->RunUntilIdle();
197 EXPECT_EQ(1, balloon_collection_->count()); 197 EXPECT_EQ(1, balloon_collection_->count());
198 198
199 // Close all the open balloons. 199 // Close all the open balloons.
200 while (balloon_collection_->count() > 0) { 200 while (balloon_collection_->count() > 0) {
201 (*(balloon_collection_->GetActiveBalloons().begin()))->OnClose(true); 201 (*(balloon_collection_->GetActiveBalloons().begin()))->OnClose(true);
202 } 202 }
203 203
204 EXPECT_EQ("notification displayed\n" 204 EXPECT_EQ("notification displayed\n"
205 "notification closed by user\n", 205 "notification closed by user\n",
206 log_output_); 206 log_output_);
207 } 207 }
208 208
209 TEST_F(DesktopNotificationsTest, TestCancel) { 209 TEST_F(DesktopNotificationsTest, TestCancel) {
210 int process_id = 0; 210 int process_id = 0;
211 int route_id = 0; 211 int route_id = 0;
212 int notification_id = 1; 212 int notification_id = 1;
213 213
214 content::ShowDesktopNotificationHostMsgParams params = 214 content::ShowDesktopNotificationHostMsgParams params =
215 StandardTestNotification(); 215 StandardTestNotification();
216 params.notification_id = notification_id; 216 params.notification_id = notification_id;
217 217
218 // Request a notification; should open a balloon. 218 // Request a notification; should open a balloon.
219 EXPECT_TRUE(service_->ShowDesktopNotification( 219 EXPECT_TRUE(service_->ShowDesktopNotification(
220 params, process_id, route_id, 220 params, process_id, route_id,
221 DesktopNotificationService::PageNotification)); 221 DesktopNotificationService::PageNotification));
222 MessageLoopForUI::current()->RunUntilIdle(); 222 base::MessageLoopForUI::current()->RunUntilIdle();
223 EXPECT_EQ(1, balloon_collection_->count()); 223 EXPECT_EQ(1, balloon_collection_->count());
224 224
225 // Cancel the same notification 225 // Cancel the same notification
226 service_->CancelDesktopNotification(process_id, 226 service_->CancelDesktopNotification(process_id,
227 route_id, 227 route_id,
228 notification_id); 228 notification_id);
229 MessageLoopForUI::current()->RunUntilIdle(); 229 base::MessageLoopForUI::current()->RunUntilIdle();
230 // Verify that the balloon collection is now empty. 230 // Verify that the balloon collection is now empty.
231 EXPECT_EQ(0, balloon_collection_->count()); 231 EXPECT_EQ(0, balloon_collection_->count());
232 232
233 EXPECT_EQ("notification displayed\n" 233 EXPECT_EQ("notification displayed\n"
234 "notification closed by script\n", 234 "notification closed by script\n",
235 log_output_); 235 log_output_);
236 } 236 }
237 237
238 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 238 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
239 TEST_F(DesktopNotificationsTest, TestPositioning) { 239 TEST_F(DesktopNotificationsTest, TestPositioning) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 327
328 // |kLotsOfToasts| must be large enough to trigger a resize of the underlying 328 // |kLotsOfToasts| must be large enough to trigger a resize of the underlying
329 // std::deque while we're clearing it. 329 // std::deque while we're clearing it.
330 const int kLotsOfToasts = 20; 330 const int kLotsOfToasts = 20;
331 for (int id = 2; id <= kLotsOfToasts; ++id) { 331 for (int id = 2; id <= kLotsOfToasts; ++id) {
332 params.notification_id = id; 332 params.notification_id = id;
333 EXPECT_TRUE(second_service->ShowDesktopNotification( 333 EXPECT_TRUE(second_service->ShowDesktopNotification(
334 params, process_id, route_id, 334 params, process_id, route_id,
335 DesktopNotificationService::PageNotification)); 335 DesktopNotificationService::PageNotification));
336 } 336 }
337 MessageLoopForUI::current()->RunUntilIdle(); 337 base::MessageLoopForUI::current()->RunUntilIdle();
338 338
339 ui_manager_->CancelAllByProfile(second_profile); 339 ui_manager_->CancelAllByProfile(second_profile);
340 340
341 // Verify that the balloon collection only contains the single 341 // Verify that the balloon collection only contains the single
342 // notification from the first profile. 342 // notification from the first profile.
343 EXPECT_EQ(1, balloon_collection_->count()); 343 EXPECT_EQ(1, balloon_collection_->count());
344 } 344 }
345 345
346 TEST_F(DesktopNotificationsTest, TestCancelBySourceOrigin) { 346 TEST_F(DesktopNotificationsTest, TestCancelBySourceOrigin) {
347 int process_id = 0; 347 int process_id = 0;
(...skipping 16 matching lines...) Expand all
364 364
365 // |kLotsOfToasts| must be large enough to trigger a resize of the underlying 365 // |kLotsOfToasts| must be large enough to trigger a resize of the underlying
366 // std::deque while we're clearing it. 366 // std::deque while we're clearing it.
367 const int kLotsOfToasts = 20; 367 const int kLotsOfToasts = 20;
368 for (int id = 2; id <= kLotsOfToasts; ++id) { 368 for (int id = 2; id <= kLotsOfToasts; ++id) {
369 odd_params.notification_id = id; 369 odd_params.notification_id = id;
370 EXPECT_TRUE(service_->ShowDesktopNotification( 370 EXPECT_TRUE(service_->ShowDesktopNotification(
371 odd_params, process_id, route_id, 371 odd_params, process_id, route_id,
372 DesktopNotificationService::PageNotification)); 372 DesktopNotificationService::PageNotification));
373 } 373 }
374 MessageLoopForUI::current()->RunUntilIdle(); 374 base::MessageLoopForUI::current()->RunUntilIdle();
375 375
376 ui_manager_->CancelAllBySourceOrigin(odd_params.origin); 376 ui_manager_->CancelAllBySourceOrigin(odd_params.origin);
377 377
378 // Verify that the balloon collection only contains the single 378 // Verify that the balloon collection only contains the single
379 // notification which is not from the canceled origin. 379 // notification which is not from the canceled origin.
380 EXPECT_EQ(1, balloon_collection_->count()); 380 EXPECT_EQ(1, balloon_collection_->count());
381 } 381 }
382 382
383 TEST_F(DesktopNotificationsTest, TestQueueing) { 383 TEST_F(DesktopNotificationsTest, TestQueueing) {
384 int process_id = 0; 384 int process_id = 0;
385 int route_id = 0; 385 int route_id = 0;
386 386
387 // Request lots of identical notifications. 387 // Request lots of identical notifications.
388 content::ShowDesktopNotificationHostMsgParams params = 388 content::ShowDesktopNotificationHostMsgParams params =
389 StandardTestNotification(); 389 StandardTestNotification();
390 const int kLotsOfToasts = 20; 390 const int kLotsOfToasts = 20;
391 for (int id = 1; id <= kLotsOfToasts; ++id) { 391 for (int id = 1; id <= kLotsOfToasts; ++id) {
392 params.notification_id = id; 392 params.notification_id = id;
393 EXPECT_TRUE(service_->ShowDesktopNotification( 393 EXPECT_TRUE(service_->ShowDesktopNotification(
394 params, process_id, route_id, 394 params, process_id, route_id,
395 DesktopNotificationService::PageNotification)); 395 DesktopNotificationService::PageNotification));
396 } 396 }
397 MessageLoopForUI::current()->RunUntilIdle(); 397 base::MessageLoopForUI::current()->RunUntilIdle();
398 398
399 // Build up an expected log of what should be happening. 399 // Build up an expected log of what should be happening.
400 std::string expected_log; 400 std::string expected_log;
401 for (int i = 0; i < balloon_collection_->max_balloon_count(); ++i) { 401 for (int i = 0; i < balloon_collection_->max_balloon_count(); ++i) {
402 expected_log.append("notification displayed\n"); 402 expected_log.append("notification displayed\n");
403 } 403 }
404 404
405 // The max number that our balloon collection can hold should be 405 // The max number that our balloon collection can hold should be
406 // shown. 406 // shown.
407 EXPECT_EQ(balloon_collection_->max_balloon_count(), 407 EXPECT_EQ(balloon_collection_->max_balloon_count(),
408 balloon_collection_->count()); 408 balloon_collection_->count());
409 EXPECT_EQ(expected_log, log_output_); 409 EXPECT_EQ(expected_log, log_output_);
410 410
411 // Cancel the notifications from the start; the balloon space should 411 // Cancel the notifications from the start; the balloon space should
412 // remain full. 412 // remain full.
413 { 413 {
414 int id; 414 int id;
415 for (id = 1; 415 for (id = 1;
416 id <= kLotsOfToasts - balloon_collection_->max_balloon_count(); 416 id <= kLotsOfToasts - balloon_collection_->max_balloon_count();
417 ++id) { 417 ++id) {
418 service_->CancelDesktopNotification(process_id, route_id, id); 418 service_->CancelDesktopNotification(process_id, route_id, id);
419 MessageLoopForUI::current()->RunUntilIdle(); 419 base::MessageLoopForUI::current()->RunUntilIdle();
420 expected_log.append("notification closed by script\n"); 420 expected_log.append("notification closed by script\n");
421 expected_log.append("notification displayed\n"); 421 expected_log.append("notification displayed\n");
422 EXPECT_EQ(balloon_collection_->max_balloon_count(), 422 EXPECT_EQ(balloon_collection_->max_balloon_count(),
423 balloon_collection_->count()); 423 balloon_collection_->count());
424 EXPECT_EQ(expected_log, log_output_); 424 EXPECT_EQ(expected_log, log_output_);
425 } 425 }
426 426
427 // Now cancel the rest. It should empty the balloon space. 427 // Now cancel the rest. It should empty the balloon space.
428 for (; id <= kLotsOfToasts; ++id) { 428 for (; id <= kLotsOfToasts; ++id) {
429 service_->CancelDesktopNotification(process_id, route_id, id); 429 service_->CancelDesktopNotification(process_id, route_id, id);
430 expected_log.append("notification closed by script\n"); 430 expected_log.append("notification closed by script\n");
431 MessageLoopForUI::current()->RunUntilIdle(); 431 base::MessageLoopForUI::current()->RunUntilIdle();
432 EXPECT_EQ(expected_log, log_output_); 432 EXPECT_EQ(expected_log, log_output_);
433 } 433 }
434 } 434 }
435 435
436 // Verify that the balloon collection is now empty. 436 // Verify that the balloon collection is now empty.
437 EXPECT_EQ(0, balloon_collection_->count()); 437 EXPECT_EQ(0, balloon_collection_->count());
438 } 438 }
439 439
440 TEST_F(DesktopNotificationsTest, TestEarlyDestruction) { 440 TEST_F(DesktopNotificationsTest, TestEarlyDestruction) {
441 // Create some toasts and then prematurely delete the notification service, 441 // Create some toasts and then prematurely delete the notification service,
(...skipping 12 matching lines...) Expand all
454 // Create a test script with some HTML; assert that it doesn't get into the 454 // Create a test script with some HTML; assert that it doesn't get into the
455 // data:// URL that's produced for the balloon. 455 // data:// URL that's produced for the balloon.
456 content::ShowDesktopNotificationHostMsgParams params = 456 content::ShowDesktopNotificationHostMsgParams params =
457 StandardTestNotification(); 457 StandardTestNotification();
458 params.title = ASCIIToUTF16("<script>window.alert('uh oh');</script>"); 458 params.title = ASCIIToUTF16("<script>window.alert('uh oh');</script>");
459 params.body = ASCIIToUTF16("<i>this text is in italics</i>"); 459 params.body = ASCIIToUTF16("<i>this text is in italics</i>");
460 params.notification_id = 1; 460 params.notification_id = 1;
461 EXPECT_TRUE(service_->ShowDesktopNotification( 461 EXPECT_TRUE(service_->ShowDesktopNotification(
462 params, 0, 0, DesktopNotificationService::PageNotification)); 462 params, 0, 0, DesktopNotificationService::PageNotification));
463 463
464 MessageLoopForUI::current()->RunUntilIdle(); 464 base::MessageLoopForUI::current()->RunUntilIdle();
465 EXPECT_EQ(1, balloon_collection_->count()); 465 EXPECT_EQ(1, balloon_collection_->count());
466 Balloon* balloon = (*balloon_collection_->balloons().begin()); 466 Balloon* balloon = (*balloon_collection_->balloons().begin());
467 GURL data_url = balloon->notification().content_url(); 467 GURL data_url = balloon->notification().content_url();
468 EXPECT_EQ(std::string::npos, data_url.spec().find("<script>")); 468 EXPECT_EQ(std::string::npos, data_url.spec().find("<script>"));
469 EXPECT_EQ(std::string::npos, data_url.spec().find("<i>")); 469 EXPECT_EQ(std::string::npos, data_url.spec().find("<i>"));
470 // URL-encoded versions of tags should also not be found. 470 // URL-encoded versions of tags should also not be found.
471 EXPECT_EQ(std::string::npos, data_url.spec().find("%3cscript%3e")); 471 EXPECT_EQ(std::string::npos, data_url.spec().find("%3cscript%3e"));
472 EXPECT_EQ(std::string::npos, data_url.spec().find("%3ci%3e")); 472 EXPECT_EQ(std::string::npos, data_url.spec().find("%3ci%3e"));
473 } 473 }
474 474
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } 573 }
574 574
575 // Now change the position to upper left. Confirm that the X value for the 575 // Now change the position to upper left. Confirm that the X value for the
576 // balloons gets smaller. 576 // balloons gets smaller.
577 local_state_.SetInteger(prefs::kDesktopNotificationPosition, 577 local_state_.SetInteger(prefs::kDesktopNotificationPosition,
578 BalloonCollection::UPPER_LEFT); 578 BalloonCollection::UPPER_LEFT);
579 579
580 int current_x = (*balloons.begin())->GetPosition().x(); 580 int current_x = (*balloons.begin())->GetPosition().x();
581 EXPECT_LT(current_x, last_x); 581 EXPECT_LT(current_x, last_x);
582 } 582 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/desktop_notifications_unittest.h ('k') | chrome/browser/omnibox_search_hint.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698