OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 : ui_thread_(BrowserThread::UI, &message_loop_) { | 78 : ui_thread_(BrowserThread::UI, &message_loop_) { |
79 } | 79 } |
80 | 80 |
81 DesktopNotificationsTest::~DesktopNotificationsTest() { | 81 DesktopNotificationsTest::~DesktopNotificationsTest() { |
82 } | 82 } |
83 | 83 |
84 void DesktopNotificationsTest::SetUp() { | 84 void DesktopNotificationsTest::SetUp() { |
85 profile_.reset(new TestingProfile()); | 85 profile_.reset(new TestingProfile()); |
86 balloon_collection_ = new MockBalloonCollection(); | 86 balloon_collection_ = new MockBalloonCollection(); |
87 ui_manager_.reset( | 87 ui_manager_.reset( |
88 new NotificationUIManager(profile_->GetTestingPrefService())); | 88 new NotificationUIManager(profile_->GetLocalState())); |
89 ui_manager_->Initialize(balloon_collection_); | 89 ui_manager_->Initialize(balloon_collection_); |
90 balloon_collection_->set_space_change_listener(ui_manager_.get()); | 90 balloon_collection_->set_space_change_listener(ui_manager_.get()); |
91 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); | 91 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); |
92 log_output_.clear(); | 92 log_output_.clear(); |
93 } | 93 } |
94 | 94 |
95 void DesktopNotificationsTest::TearDown() { | 95 void DesktopNotificationsTest::TearDown() { |
96 service_.reset(NULL); | 96 service_.reset(NULL); |
97 ui_manager_.reset(NULL); | 97 ui_manager_.reset(NULL); |
98 profile_.reset(NULL); | 98 profile_.reset(NULL); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 EXPECT_TRUE(box.Contains(gfx::Point(min_x, min_y))); | 365 EXPECT_TRUE(box.Contains(gfx::Point(min_x, min_y))); |
366 EXPECT_TRUE(box.Contains(gfx::Point(min_x, max_y))); | 366 EXPECT_TRUE(box.Contains(gfx::Point(min_x, max_y))); |
367 EXPECT_TRUE(box.Contains(gfx::Point(max_x, min_y))); | 367 EXPECT_TRUE(box.Contains(gfx::Point(max_x, min_y))); |
368 EXPECT_TRUE(box.Contains(gfx::Point(max_x, max_y))); | 368 EXPECT_TRUE(box.Contains(gfx::Point(max_x, max_y))); |
369 } | 369 } |
370 } | 370 } |
371 } | 371 } |
372 | 372 |
373 TEST_F(DesktopNotificationsTest, TestPositionPreference) { | 373 TEST_F(DesktopNotificationsTest, TestPositionPreference) { |
374 // Set position preference to lower right. | 374 // Set position preference to lower right. |
375 profile_->GetPrefs()->SetInteger(prefs::kDesktopNotificationPosition, | 375 profile_->GetLocalState()->SetInteger(prefs::kDesktopNotificationPosition, |
376 BalloonCollection::LOWER_RIGHT); | 376 BalloonCollection::LOWER_RIGHT); |
377 | 377 |
378 // Create some notifications. | 378 // Create some notifications. |
379 ViewHostMsg_ShowNotification_Params params = StandardTestNotification(); | 379 ViewHostMsg_ShowNotification_Params params = StandardTestNotification(); |
380 for (int id = 0; id <= 3; ++id) { | 380 for (int id = 0; id <= 3; ++id) { |
381 params.notification_id = id; | 381 params.notification_id = id; |
382 EXPECT_TRUE(service_->ShowDesktopNotification( | 382 EXPECT_TRUE(service_->ShowDesktopNotification( |
383 params, 0, 0, DesktopNotificationService::PageNotification)); | 383 params, 0, 0, DesktopNotificationService::PageNotification)); |
384 } | 384 } |
385 | 385 |
386 std::deque<Balloon*>& balloons = balloon_collection_->balloons(); | 386 std::deque<Balloon*>& balloons = balloon_collection_->balloons(); |
(...skipping 17 matching lines...) Expand all Loading... |
404 EXPECT_LT(current_y, last_y); | 404 EXPECT_LT(current_y, last_y); |
405 #endif | 405 #endif |
406 } | 406 } |
407 | 407 |
408 last_x = current_x; | 408 last_x = current_x; |
409 last_y = current_y; | 409 last_y = current_y; |
410 } | 410 } |
411 | 411 |
412 // Now change the position to upper right. This should cause an immediate | 412 // Now change the position to upper right. This should cause an immediate |
413 // repositioning, and we check for the reverse ordering. | 413 // repositioning, and we check for the reverse ordering. |
414 profile_->GetPrefs()->SetInteger(prefs::kDesktopNotificationPosition, | 414 profile_->GetLocalState()->SetInteger(prefs::kDesktopNotificationPosition, |
415 BalloonCollection::UPPER_RIGHT); | 415 BalloonCollection::UPPER_RIGHT); |
416 last_x = -1; | 416 last_x = -1; |
417 last_y = -1; | 417 last_y = -1; |
418 | 418 |
419 for (iter = balloons.begin(); iter != balloons.end(); ++iter) { | 419 for (iter = balloons.begin(); iter != balloons.end(); ++iter) { |
420 int current_x = (*iter)->GetPosition().x(); | 420 int current_x = (*iter)->GetPosition().x(); |
421 int current_y = (*iter)->GetPosition().y(); | 421 int current_y = (*iter)->GetPosition().y(); |
422 | 422 |
423 if (last_x > 0) | 423 if (last_x > 0) |
424 EXPECT_EQ(last_x, current_x); | 424 EXPECT_EQ(last_x, current_x); |
425 | 425 |
426 if (last_y > 0) { | 426 if (last_y > 0) { |
427 #if defined(OS_MACOSX) | 427 #if defined(OS_MACOSX) |
428 EXPECT_LT(current_y, last_y); | 428 EXPECT_LT(current_y, last_y); |
429 #else | 429 #else |
430 EXPECT_GT(current_y, last_y); | 430 EXPECT_GT(current_y, last_y); |
431 #endif | 431 #endif |
432 } | 432 } |
433 | 433 |
434 last_x = current_x; | 434 last_x = current_x; |
435 last_y = current_y; | 435 last_y = current_y; |
436 } | 436 } |
437 | 437 |
438 // Now change the position to upper left. Confirm that the X value for the | 438 // Now change the position to upper left. Confirm that the X value for the |
439 // balloons gets smaller. | 439 // balloons gets smaller. |
440 profile_->GetPrefs()->SetInteger(prefs::kDesktopNotificationPosition, | 440 profile_->GetLocalState()->SetInteger(prefs::kDesktopNotificationPosition, |
441 BalloonCollection::UPPER_LEFT); | 441 BalloonCollection::UPPER_LEFT); |
442 | 442 |
443 int current_x = (*balloons.begin())->GetPosition().x(); | 443 int current_x = (*balloons.begin())->GetPosition().x(); |
444 EXPECT_LT(current_x, last_x); | 444 EXPECT_LT(current_x, last_x); |
445 } | 445 } |
OLD | NEW |