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/wm_state.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 wm_state_.reset(new views::corewm::WMState); |
| 112 #endif |
106 #if defined(USE_ASH) | 113 #if defined(USE_ASH) |
107 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 114 ui::ScopedAnimationDurationScaleMode normal_duration_mode( |
108 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); | 115 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
109 // The message center is notmally initialized on |g_browser_process| which | 116 // The message center is notmally initialized on |g_browser_process| which |
110 // is not created for these tests. | 117 // is not created for these tests. |
111 message_center::MessageCenter::Initialize(); | 118 message_center::MessageCenter::Initialize(); |
112 // The ContextFactory must exist before any Compositors are created. | 119 // The ContextFactory must exist before any Compositors are created. |
113 bool allow_test_contexts = true; | 120 bool allow_test_contexts = true; |
114 ui::InitializeContextFactoryForTests(allow_test_contexts); | 121 ui::InitializeContextFactoryForTests(allow_test_contexts); |
115 // MockBalloonCollection retrieves information about the screen on creation. | 122 // MockBalloonCollection retrieves information about the screen on creation. |
116 // So it is necessary to make sure the desktop gets created first. | 123 // So it is necessary to make sure the desktop gets created first. |
117 ash::Shell::CreateInstance(new ash::test::TestShellDelegate); | 124 ash::Shell::CreateInstance(new ash::test::TestShellDelegate); |
118 #endif | 125 #endif |
119 | |
120 chrome::RegisterLocalState(local_state_.registry()); | 126 chrome::RegisterLocalState(local_state_.registry()); |
121 profile_.reset(new TestingProfile()); | 127 profile_.reset(new TestingProfile()); |
122 ui_manager_.reset(new BalloonNotificationUIManager(&local_state_)); | 128 ui_manager_.reset(new BalloonNotificationUIManager(&local_state_)); |
123 balloon_collection_ = new MockBalloonCollection(); | 129 balloon_collection_ = new MockBalloonCollection(); |
124 ui_manager_->SetBalloonCollection(balloon_collection_); | 130 ui_manager_->SetBalloonCollection(balloon_collection_); |
125 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); | 131 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); |
126 log_output_.clear(); | 132 log_output_.clear(); |
127 } | 133 } |
128 | 134 |
129 void DesktopNotificationsTest::TearDown() { | 135 void DesktopNotificationsTest::TearDown() { |
130 service_.reset(NULL); | 136 service_.reset(NULL); |
131 ui_manager_.reset(NULL); | 137 ui_manager_.reset(NULL); |
132 profile_.reset(NULL); | 138 profile_.reset(NULL); |
133 #if defined(USE_ASH) | 139 #if defined(USE_ASH) |
134 ash::Shell::DeleteInstance(); | 140 ash::Shell::DeleteInstance(); |
135 // The message center is notmally shutdown on |g_browser_process| which | 141 // The message center is notmally shutdown on |g_browser_process| which |
136 // is not created for these tests. | 142 // is not created for these tests. |
137 message_center::MessageCenter::Shutdown(); | 143 message_center::MessageCenter::Shutdown(); |
138 aura::Env::DeleteInstance(); | 144 aura::Env::DeleteInstance(); |
139 ui::TerminateContextFactoryForTests(); | 145 ui::TerminateContextFactoryForTests(); |
140 #endif | 146 #endif |
| 147 #if defined(USE_AURA) |
| 148 wm_state_.reset(); |
| 149 #endif |
141 ui::ShutdownInputMethodForTesting(); | 150 ui::ShutdownInputMethodForTesting(); |
142 } | 151 } |
143 | 152 |
144 content::ShowDesktopNotificationHostMsgParams | 153 content::ShowDesktopNotificationHostMsgParams |
145 DesktopNotificationsTest::StandardTestNotification() { | 154 DesktopNotificationsTest::StandardTestNotification() { |
146 content::ShowDesktopNotificationHostMsgParams params; | 155 content::ShowDesktopNotificationHostMsgParams params; |
147 params.notification_id = 0; | 156 params.notification_id = 0; |
148 params.origin = GURL("http://www.google.com"); | 157 params.origin = GURL("http://www.google.com"); |
149 params.icon_url = GURL("/icon.png"); | 158 params.icon_url = GURL("/icon.png"); |
150 params.title = ASCIIToUTF16("Title"); | 159 params.title = ASCIIToUTF16("Title"); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 } | 575 } |
567 | 576 |
568 // Now change the position to upper left. Confirm that the X value for the | 577 // Now change the position to upper left. Confirm that the X value for the |
569 // balloons gets smaller. | 578 // balloons gets smaller. |
570 local_state_.SetInteger(prefs::kDesktopNotificationPosition, | 579 local_state_.SetInteger(prefs::kDesktopNotificationPosition, |
571 BalloonCollection::UPPER_LEFT); | 580 BalloonCollection::UPPER_LEFT); |
572 | 581 |
573 int current_x = (*balloons.begin())->GetPosition().x(); | 582 int current_x = (*balloons.begin())->GetPosition().x(); |
574 EXPECT_LT(current_x, last_x); | 583 EXPECT_LT(current_x, last_x); |
575 } | 584 } |
OLD | NEW |