| 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 "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/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | 10 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" |
| 11 #include "chrome/browser/notifications/fake_balloon_view.h" | 11 #include "chrome/browser/notifications/fake_balloon_view.h" |
| 12 #include "chrome/browser/prefs/browser_prefs.h" | 12 #include "chrome/browser/prefs/browser_prefs.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 16 #include "chrome/test/base/testing_profile_manager.h" | 16 #include "chrome/test/base/testing_profile_manager.h" |
| 17 #include "content/public/common/show_desktop_notification_params.h" | 17 #include "content/public/common/show_desktop_notification_params.h" |
| 18 #include "ui/base/ime/input_method_initializer.h" | 18 #include "ui/base/ime/input_method_initializer.h" |
| 19 #include "ui/message_center/message_center.h" | 19 #include "ui/message_center/message_center.h" |
| 20 | 20 |
| 21 #if defined(USE_ASH) | 21 #if defined(USE_ASH) |
| 22 #include "ash/shell.h" | 22 #include "ash/shell.h" |
| 23 #include "ash/test/test_shell_delegate.h" | 23 #include "ash/test/test_shell_delegate.h" |
| 24 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
| 25 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
| 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 27 #include "ui/compositor/test/context_factories_for_test.h" | 27 #include "ui/compositor/test/context_factories_for_test.h" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 #if defined(USE_AURA) |
| 31 #include "ui/views/corewm/transient_window_stacking_client.h" |
| 32 #endif |
| 33 |
| 30 | 34 |
| 31 using content::BrowserThread; | 35 using content::BrowserThread; |
| 32 | 36 |
| 33 // static | 37 // static |
| 34 const int MockBalloonCollection::kMockBalloonSpace = 5; | 38 const int MockBalloonCollection::kMockBalloonSpace = 5; |
| 35 | 39 |
| 36 // static | 40 // static |
| 37 std::string DesktopNotificationsTest::log_output_; | 41 std::string DesktopNotificationsTest::log_output_; |
| 38 | 42 |
| 39 MockBalloonCollection::MockBalloonCollection() {} | 43 MockBalloonCollection::MockBalloonCollection() {} |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DesktopNotificationsTest::DesktopNotificationsTest() | 100 DesktopNotificationsTest::DesktopNotificationsTest() |
| 97 : ui_thread_(BrowserThread::UI, &message_loop_), | 101 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 98 balloon_collection_(NULL) { | 102 balloon_collection_(NULL) { |
| 99 } | 103 } |
| 100 | 104 |
| 101 DesktopNotificationsTest::~DesktopNotificationsTest() { | 105 DesktopNotificationsTest::~DesktopNotificationsTest() { |
| 102 } | 106 } |
| 103 | 107 |
| 104 void DesktopNotificationsTest::SetUp() { | 108 void DesktopNotificationsTest::SetUp() { |
| 105 ui::InitializeInputMethodForTesting(); | 109 ui::InitializeInputMethodForTesting(); |
| 110 #if defined(USE_AURA) |
| 111 // SetWindowStackingClient() takes ownership of TransientWindowStackingClient. |
| 112 aura::client::SetWindowStackingClient( |
| 113 new views::corewm::TransientWindowStackingClient); |
| 114 #endif |
| 106 #if defined(USE_ASH) | 115 #if defined(USE_ASH) |
| 107 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 116 ui::ScopedAnimationDurationScaleMode normal_duration_mode( |
| 108 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); | 117 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 109 // The message center is notmally initialized on |g_browser_process| which | 118 // The message center is notmally initialized on |g_browser_process| which |
| 110 // is not created for these tests. | 119 // is not created for these tests. |
| 111 message_center::MessageCenter::Initialize(); | 120 message_center::MessageCenter::Initialize(); |
| 112 // The ContextFactory must exist before any Compositors are created. | 121 // The ContextFactory must exist before any Compositors are created. |
| 113 bool allow_test_contexts = true; | 122 bool allow_test_contexts = true; |
| 114 ui::InitializeContextFactoryForTests(allow_test_contexts); | 123 ui::InitializeContextFactoryForTests(allow_test_contexts); |
| 115 // MockBalloonCollection retrieves information about the screen on creation. | 124 // MockBalloonCollection retrieves information about the screen on creation. |
| 116 // So it is necessary to make sure the desktop gets created first. | 125 // So it is necessary to make sure the desktop gets created first. |
| 117 ash::Shell::CreateInstance(new ash::test::TestShellDelegate); | 126 ash::Shell::CreateInstance(new ash::test::TestShellDelegate); |
| 118 #endif | 127 #endif |
| 119 | |
| 120 chrome::RegisterLocalState(local_state_.registry()); | 128 chrome::RegisterLocalState(local_state_.registry()); |
| 121 profile_.reset(new TestingProfile()); | 129 profile_.reset(new TestingProfile()); |
| 122 ui_manager_.reset(new BalloonNotificationUIManager(&local_state_)); | 130 ui_manager_.reset(new BalloonNotificationUIManager(&local_state_)); |
| 123 balloon_collection_ = new MockBalloonCollection(); | 131 balloon_collection_ = new MockBalloonCollection(); |
| 124 ui_manager_->SetBalloonCollection(balloon_collection_); | 132 ui_manager_->SetBalloonCollection(balloon_collection_); |
| 125 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); | 133 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); |
| 126 log_output_.clear(); | 134 log_output_.clear(); |
| 127 } | 135 } |
| 128 | 136 |
| 129 void DesktopNotificationsTest::TearDown() { | 137 void DesktopNotificationsTest::TearDown() { |
| 130 service_.reset(NULL); | 138 service_.reset(NULL); |
| 131 ui_manager_.reset(NULL); | 139 ui_manager_.reset(NULL); |
| 132 profile_.reset(NULL); | 140 profile_.reset(NULL); |
| 133 #if defined(USE_ASH) | 141 #if defined(USE_ASH) |
| 134 ash::Shell::DeleteInstance(); | 142 ash::Shell::DeleteInstance(); |
| 135 // The message center is notmally shutdown on |g_browser_process| which | 143 // The message center is notmally shutdown on |g_browser_process| which |
| 136 // is not created for these tests. | 144 // is not created for these tests. |
| 137 message_center::MessageCenter::Shutdown(); | 145 message_center::MessageCenter::Shutdown(); |
| 138 aura::Env::DeleteInstance(); | 146 aura::Env::DeleteInstance(); |
| 139 ui::TerminateContextFactoryForTests(); | 147 ui::TerminateContextFactoryForTests(); |
| 140 #endif | 148 #endif |
| 149 #if defined(USE_AURA) |
| 150 aura::client::SetWindowStackingClient(NULL); |
| 151 #endif |
| 141 ui::ShutdownInputMethodForTesting(); | 152 ui::ShutdownInputMethodForTesting(); |
| 142 } | 153 } |
| 143 | 154 |
| 144 content::ShowDesktopNotificationHostMsgParams | 155 content::ShowDesktopNotificationHostMsgParams |
| 145 DesktopNotificationsTest::StandardTestNotification() { | 156 DesktopNotificationsTest::StandardTestNotification() { |
| 146 content::ShowDesktopNotificationHostMsgParams params; | 157 content::ShowDesktopNotificationHostMsgParams params; |
| 147 params.notification_id = 0; | 158 params.notification_id = 0; |
| 148 params.origin = GURL("http://www.google.com"); | 159 params.origin = GURL("http://www.google.com"); |
| 149 params.icon_url = GURL("/icon.png"); | 160 params.icon_url = GURL("/icon.png"); |
| 150 params.title = ASCIIToUTF16("Title"); | 161 params.title = ASCIIToUTF16("Title"); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 } | 577 } |
| 567 | 578 |
| 568 // Now change the position to upper left. Confirm that the X value for the | 579 // Now change the position to upper left. Confirm that the X value for the |
| 569 // balloons gets smaller. | 580 // balloons gets smaller. |
| 570 local_state_.SetInteger(prefs::kDesktopNotificationPosition, | 581 local_state_.SetInteger(prefs::kDesktopNotificationPosition, |
| 571 BalloonCollection::UPPER_LEFT); | 582 BalloonCollection::UPPER_LEFT); |
| 572 | 583 |
| 573 int current_x = (*balloons.begin())->GetPosition().x(); | 584 int current_x = (*balloons.begin())->GetPosition().x(); |
| 574 EXPECT_LT(current_x, last_x); | 585 EXPECT_LT(current_x, last_x); |
| 575 } | 586 } |
| OLD | NEW |