| 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_params.h" | 10 #include "chrome/common/render_messages_params.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 : ui_thread_(BrowserThread::UI, &message_loop_) { | 65 : ui_thread_(BrowserThread::UI, &message_loop_) { |
| 66 } | 66 } |
| 67 | 67 |
| 68 DesktopNotificationsTest::~DesktopNotificationsTest() { | 68 DesktopNotificationsTest::~DesktopNotificationsTest() { |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DesktopNotificationsTest::SetUp() { | 71 void DesktopNotificationsTest::SetUp() { |
| 72 profile_.reset(new TestingProfile()); | 72 profile_.reset(new TestingProfile()); |
| 73 balloon_collection_ = new MockBalloonCollection(); | 73 balloon_collection_ = new MockBalloonCollection(); |
| 74 ui_manager_.reset( | 74 ui_manager_.reset( |
| 75 new NotificationUIManager(profile_->GetTestingPrefService())); | 75 new NotificationUIManager(profile_->GetLocalState())); |
| 76 ui_manager_->Initialize(balloon_collection_); | 76 ui_manager_->Initialize(balloon_collection_); |
| 77 balloon_collection_->set_space_change_listener(ui_manager_.get()); | 77 balloon_collection_->set_space_change_listener(ui_manager_.get()); |
| 78 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); | 78 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); |
| 79 log_output_.clear(); | 79 log_output_.clear(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void DesktopNotificationsTest::TearDown() { | 82 void DesktopNotificationsTest::TearDown() { |
| 83 service_.reset(NULL); | 83 service_.reset(NULL); |
| 84 ui_manager_.reset(NULL); | 84 ui_manager_.reset(NULL); |
| 85 profile_.reset(NULL); | 85 profile_.reset(NULL); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 EXPECT_TRUE(box.Contains(gfx::Point(min_x, min_y))); | 352 EXPECT_TRUE(box.Contains(gfx::Point(min_x, min_y))); |
| 353 EXPECT_TRUE(box.Contains(gfx::Point(min_x, max_y))); | 353 EXPECT_TRUE(box.Contains(gfx::Point(min_x, max_y))); |
| 354 EXPECT_TRUE(box.Contains(gfx::Point(max_x, min_y))); | 354 EXPECT_TRUE(box.Contains(gfx::Point(max_x, min_y))); |
| 355 EXPECT_TRUE(box.Contains(gfx::Point(max_x, max_y))); | 355 EXPECT_TRUE(box.Contains(gfx::Point(max_x, max_y))); |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 | 359 |
| 360 TEST_F(DesktopNotificationsTest, TestPositionPreference) { | 360 TEST_F(DesktopNotificationsTest, TestPositionPreference) { |
| 361 // Set position preference to lower right. | 361 // Set position preference to lower right. |
| 362 profile_->GetPrefs()->SetInteger(prefs::kDesktopNotificationPosition, | 362 profile_->GetLocalState()->SetInteger(prefs::kDesktopNotificationPosition, |
| 363 BalloonCollection::LOWER_RIGHT); | 363 BalloonCollection::LOWER_RIGHT); |
| 364 | 364 |
| 365 // Create some notifications. | 365 // Create some notifications. |
| 366 ViewHostMsg_ShowNotification_Params params = StandardTestNotification(); | 366 ViewHostMsg_ShowNotification_Params params = StandardTestNotification(); |
| 367 for (int id = 0; id <= 3; ++id) { | 367 for (int id = 0; id <= 3; ++id) { |
| 368 params.notification_id = id; | 368 params.notification_id = id; |
| 369 EXPECT_TRUE(service_->ShowDesktopNotification( | 369 EXPECT_TRUE(service_->ShowDesktopNotification( |
| 370 params, 0, 0, DesktopNotificationService::PageNotification)); | 370 params, 0, 0, DesktopNotificationService::PageNotification)); |
| 371 } | 371 } |
| 372 | 372 |
| 373 std::deque<Balloon*>& balloons = balloon_collection_->balloons(); | 373 std::deque<Balloon*>& balloons = balloon_collection_->balloons(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 391 EXPECT_LT(current_y, last_y); | 391 EXPECT_LT(current_y, last_y); |
| 392 #endif | 392 #endif |
| 393 } | 393 } |
| 394 | 394 |
| 395 last_x = current_x; | 395 last_x = current_x; |
| 396 last_y = current_y; | 396 last_y = current_y; |
| 397 } | 397 } |
| 398 | 398 |
| 399 // Now change the position to upper right. This should cause an immediate | 399 // Now change the position to upper right. This should cause an immediate |
| 400 // repositioning, and we check for the reverse ordering. | 400 // repositioning, and we check for the reverse ordering. |
| 401 profile_->GetPrefs()->SetInteger(prefs::kDesktopNotificationPosition, | 401 profile_->GetLocalState()->SetInteger(prefs::kDesktopNotificationPosition, |
| 402 BalloonCollection::UPPER_RIGHT); | 402 BalloonCollection::UPPER_RIGHT); |
| 403 last_x = -1; | 403 last_x = -1; |
| 404 last_y = -1; | 404 last_y = -1; |
| 405 | 405 |
| 406 for (iter = balloons.begin(); iter != balloons.end(); ++iter) { | 406 for (iter = balloons.begin(); iter != balloons.end(); ++iter) { |
| 407 int current_x = (*iter)->GetPosition().x(); | 407 int current_x = (*iter)->GetPosition().x(); |
| 408 int current_y = (*iter)->GetPosition().y(); | 408 int current_y = (*iter)->GetPosition().y(); |
| 409 | 409 |
| 410 if (last_x > 0) | 410 if (last_x > 0) |
| 411 EXPECT_EQ(last_x, current_x); | 411 EXPECT_EQ(last_x, current_x); |
| 412 | 412 |
| 413 if (last_y > 0) { | 413 if (last_y > 0) { |
| 414 #if defined(OS_MACOSX) | 414 #if defined(OS_MACOSX) |
| 415 EXPECT_LT(current_y, last_y); | 415 EXPECT_LT(current_y, last_y); |
| 416 #else | 416 #else |
| 417 EXPECT_GT(current_y, last_y); | 417 EXPECT_GT(current_y, last_y); |
| 418 #endif | 418 #endif |
| 419 } | 419 } |
| 420 | 420 |
| 421 last_x = current_x; | 421 last_x = current_x; |
| 422 last_y = current_y; | 422 last_y = current_y; |
| 423 } | 423 } |
| 424 | 424 |
| 425 // Now change the position to upper left. Confirm that the X value for the | 425 // Now change the position to upper left. Confirm that the X value for the |
| 426 // balloons gets smaller. | 426 // balloons gets smaller. |
| 427 profile_->GetPrefs()->SetInteger(prefs::kDesktopNotificationPosition, | 427 profile_->GetLocalState()->SetInteger(prefs::kDesktopNotificationPosition, |
| 428 BalloonCollection::UPPER_LEFT); | 428 BalloonCollection::UPPER_LEFT); |
| 429 | 429 |
| 430 int current_x = (*balloons.begin())->GetPosition().x(); | 430 int current_x = (*balloons.begin())->GetPosition().x(); |
| 431 EXPECT_LT(current_x, last_x); | 431 EXPECT_LT(current_x, last_x); |
| 432 } | 432 } |
| OLD | NEW |