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 #endif | 28 #endif |
28 | 29 |
29 | 30 |
30 using content::BrowserThread; | 31 using content::BrowserThread; |
31 | 32 |
32 // static | 33 // static |
33 const int MockBalloonCollection::kMockBalloonSpace = 5; | 34 const int MockBalloonCollection::kMockBalloonSpace = 5; |
34 | 35 |
35 // static | 36 // static |
36 std::string DesktopNotificationsTest::log_output_; | 37 std::string DesktopNotificationsTest::log_output_; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 101 } |
101 | 102 |
102 void DesktopNotificationsTest::SetUp() { | 103 void DesktopNotificationsTest::SetUp() { |
103 ui::InitializeInputMethodForTesting(); | 104 ui::InitializeInputMethodForTesting(); |
104 #if defined(USE_ASH) | 105 #if defined(USE_ASH) |
105 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 106 ui::ScopedAnimationDurationScaleMode normal_duration_mode( |
106 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); | 107 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
107 // The message center is notmally initialized on |g_browser_process| which | 108 // The message center is notmally initialized on |g_browser_process| which |
108 // is not created for these tests. | 109 // is not created for these tests. |
109 message_center::MessageCenter::Initialize(); | 110 message_center::MessageCenter::Initialize(); |
| 111 // The ContextFactory must exist before any Compositors are created. |
| 112 bool allow_test_contexts = true; |
| 113 ui::InitializeContextFactoryForTests(allow_test_contexts); |
110 // MockBalloonCollection retrieves information about the screen on creation. | 114 // MockBalloonCollection retrieves information about the screen on creation. |
111 // So it is necessary to make sure the desktop gets created first. | 115 // So it is necessary to make sure the desktop gets created first. |
112 ash::Shell::CreateInstance(new ash::test::TestShellDelegate); | 116 ash::Shell::CreateInstance(new ash::test::TestShellDelegate); |
113 #endif | 117 #endif |
114 | 118 |
115 chrome::RegisterLocalState(local_state_.registry()); | 119 chrome::RegisterLocalState(local_state_.registry()); |
116 profile_.reset(new TestingProfile()); | 120 profile_.reset(new TestingProfile()); |
117 ui_manager_.reset(new BalloonNotificationUIManager(&local_state_)); | 121 ui_manager_.reset(new BalloonNotificationUIManager(&local_state_)); |
118 balloon_collection_ = new MockBalloonCollection(); | 122 balloon_collection_ = new MockBalloonCollection(); |
119 ui_manager_->SetBalloonCollection(balloon_collection_); | 123 ui_manager_->SetBalloonCollection(balloon_collection_); |
120 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); | 124 service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); |
121 log_output_.clear(); | 125 log_output_.clear(); |
122 } | 126 } |
123 | 127 |
124 void DesktopNotificationsTest::TearDown() { | 128 void DesktopNotificationsTest::TearDown() { |
125 service_.reset(NULL); | 129 service_.reset(NULL); |
126 ui_manager_.reset(NULL); | 130 ui_manager_.reset(NULL); |
127 profile_.reset(NULL); | 131 profile_.reset(NULL); |
128 #if defined(USE_ASH) | 132 #if defined(USE_ASH) |
129 ash::Shell::DeleteInstance(); | 133 ash::Shell::DeleteInstance(); |
130 // The message center is notmally shutdown on |g_browser_process| which | 134 // The message center is notmally shutdown on |g_browser_process| which |
131 // is not created for these tests. | 135 // is not created for these tests. |
132 message_center::MessageCenter::Shutdown(); | 136 message_center::MessageCenter::Shutdown(); |
133 aura::Env::DeleteInstance(); | 137 aura::Env::DeleteInstance(); |
| 138 ui::TerminateContextFactoryForTests(); |
134 #endif | 139 #endif |
135 ui::ShutdownInputMethodForTesting(); | 140 ui::ShutdownInputMethodForTesting(); |
136 } | 141 } |
137 | 142 |
138 content::ShowDesktopNotificationHostMsgParams | 143 content::ShowDesktopNotificationHostMsgParams |
139 DesktopNotificationsTest::StandardTestNotification() { | 144 DesktopNotificationsTest::StandardTestNotification() { |
140 content::ShowDesktopNotificationHostMsgParams params; | 145 content::ShowDesktopNotificationHostMsgParams params; |
141 params.notification_id = 0; | 146 params.notification_id = 0; |
142 params.origin = GURL("http://www.google.com"); | 147 params.origin = GURL("http://www.google.com"); |
143 params.is_html = false; | 148 params.is_html = false; |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 } | 567 } |
563 | 568 |
564 // Now change the position to upper left. Confirm that the X value for the | 569 // Now change the position to upper left. Confirm that the X value for the |
565 // balloons gets smaller. | 570 // balloons gets smaller. |
566 local_state_.SetInteger(prefs::kDesktopNotificationPosition, | 571 local_state_.SetInteger(prefs::kDesktopNotificationPosition, |
567 BalloonCollection::UPPER_LEFT); | 572 BalloonCollection::UPPER_LEFT); |
568 | 573 |
569 int current_x = (*balloons.begin())->GetPosition().x(); | 574 int current_x = (*balloons.begin())->GetPosition().x(); |
570 EXPECT_LT(current_x, last_x); | 575 EXPECT_LT(current_x, last_x); |
571 } | 576 } |
OLD | NEW |