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 "base/process_util.h" | 5 #include "base/process_util.h" |
6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/extensions/extension_browsertest.h" | 7 #include "chrome/browser/extensions/extension_browsertest.h" |
8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/browser/notifications/balloon.h" | 12 #include "chrome/browser/notifications/balloon.h" |
13 #include "chrome/browser/notifications/balloon_collection.h" | 13 #include "chrome/browser/notifications/balloon_collection.h" |
14 #include "chrome/browser/notifications/balloon_host.h" | 14 #include "chrome/browser/notifications/balloon_host.h" |
15 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | 15 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" |
16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
17 #include "chrome/browser/notifications/notification_delegate.h" | 17 #include "chrome/browser/notifications/notification_delegate.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/public/browser/navigation_controller.h" | 23 #include "content/public/browser/navigation_controller.h" |
24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "content/public/common/result_codes.h" | 27 #include "content/public/common/result_codes.h" |
28 | |
29 #if defined(ENABLE_MESSAGE_CENTER) | |
30 #include "base/command_line.h" | |
31 #include "ui/message_center/message_center.h" | 28 #include "ui/message_center/message_center.h" |
32 #include "ui/message_center/message_center_switches.h" | 29 #include "ui/message_center/message_center_switches.h" |
| 30 #include "ui/message_center/message_center_util.h" |
33 #include "ui/message_center/notification_list.h" | 31 #include "ui/message_center/notification_list.h" |
34 #endif | |
35 | 32 |
36 using content::NavigationController; | 33 using content::NavigationController; |
37 using content::WebContents; | 34 using content::WebContents; |
38 using extensions::Extension; | 35 using extensions::Extension; |
39 | 36 |
40 // Tests are timing out waiting for extension to crash. | 37 // Tests are timing out waiting for extension to crash. |
41 // http://crbug.com/174705 | 38 // http://crbug.com/174705 |
42 #if defined(OS_MACOSX) || defined(USE_AURA) | 39 #if defined(OS_MACOSX) || defined(USE_AURA) |
43 #define MAYBE_ExtensionCrashRecoveryTest DISABLED_ExtensionCrashRecoveryTest | 40 #define MAYBE_ExtensionCrashRecoveryTest DISABLED_ExtensionCrashRecoveryTest |
44 #else | 41 #else |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 ASSERT_TRUE(extension); | 107 ASSERT_TRUE(extension); |
111 second_extension_id_ = extension->id(); | 108 second_extension_id_ = extension->id(); |
112 CheckExtensionConsistency(second_extension_id_); | 109 CheckExtensionConsistency(second_extension_id_); |
113 } | 110 } |
114 | 111 |
115 std::string first_extension_id_; | 112 std::string first_extension_id_; |
116 std::string second_extension_id_; | 113 std::string second_extension_id_; |
117 | 114 |
118 }; | 115 }; |
119 | 116 |
120 // TODO(rsesek): Implement and enable these tests. http://crbug.com/179904 | 117 class MAYBE_ExtensionCrashRecoveryTest |
121 #if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_MACOSX) | |
122 | |
123 class MessageCenterExtensionCrashRecoveryTest | |
124 : public ExtensionCrashRecoveryTestBase { | 118 : public ExtensionCrashRecoveryTestBase { |
125 protected: | 119 protected: |
126 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
127 ExtensionCrashRecoveryTestBase::SetUpCommandLine(command_line); | |
128 command_line->AppendSwitch( | |
129 message_center::switches::kEnableRichNotifications); | |
130 } | |
131 | |
132 virtual void AcceptNotification(size_t index) OVERRIDE { | 120 virtual void AcceptNotification(size_t index) OVERRIDE { |
133 message_center::MessageCenter* message_center = | 121 if (message_center::IsRichNotificationEnabled()) { |
134 message_center::MessageCenter::Get(); | 122 message_center::MessageCenter* message_center = |
135 ASSERT_GT(message_center->NotificationCount(), index); | 123 message_center::MessageCenter::Get(); |
136 message_center::NotificationList::Notifications::reverse_iterator it = | 124 ASSERT_GT(message_center->NotificationCount(), index); |
137 message_center->GetNotifications().rbegin(); | 125 message_center::NotificationList::Notifications::reverse_iterator it = |
138 for (size_t i=0; i < index; ++i) | 126 message_center->GetNotifications().rbegin(); |
139 it++; | 127 for (size_t i=0; i < index; ++i) |
140 std::string id = (*it)->id(); | 128 it++; |
141 message_center->ClickOnNotification(id); | 129 std::string id = (*it)->id(); |
| 130 message_center->ClickOnNotification(id); |
| 131 } else { |
| 132 Balloon* balloon = GetNotificationDelegate(index); |
| 133 ASSERT_TRUE(balloon); |
| 134 balloon->OnClick(); |
| 135 } |
142 WaitForExtensionLoad(); | 136 WaitForExtensionLoad(); |
143 } | 137 } |
144 | 138 |
145 virtual void CancelNotification(size_t index) OVERRIDE { | 139 virtual void CancelNotification(size_t index) OVERRIDE { |
146 message_center::MessageCenter* message_center = | 140 if (message_center::IsRichNotificationEnabled()) { |
147 message_center::MessageCenter::Get(); | 141 message_center::MessageCenter* message_center = |
148 ASSERT_GT(message_center->NotificationCount(), index); | 142 message_center::MessageCenter::Get(); |
149 message_center::NotificationList::Notifications::reverse_iterator it = | 143 ASSERT_GT(message_center->NotificationCount(), index); |
150 message_center->GetNotifications().rbegin(); | 144 message_center::NotificationList::Notifications::reverse_iterator it = |
151 for (size_t i=0; i < index; i++) { it++; } | 145 message_center->GetNotifications().rbegin(); |
152 ASSERT_TRUE( | 146 for (size_t i=0; i < index; i++) { it++; } |
153 g_browser_process->notification_ui_manager()->CancelById((*it)->id())); | 147 ASSERT_TRUE(g_browser_process->notification_ui_manager()-> |
| 148 CancelById((*it)->id())); |
| 149 } else { |
| 150 Balloon* balloon = GetNotificationDelegate(index); |
| 151 ASSERT_TRUE(balloon); |
| 152 std::string id = balloon->notification().notification_id(); |
| 153 ASSERT_TRUE(g_browser_process->notification_ui_manager()->CancelById(id)); |
| 154 } |
154 } | 155 } |
155 | 156 |
156 virtual size_t CountBalloons() OVERRIDE { | 157 virtual size_t CountBalloons() OVERRIDE { |
157 message_center::MessageCenter* message_center = | 158 if (message_center::IsRichNotificationEnabled()) |
158 message_center::MessageCenter::Get(); | 159 return message_center::MessageCenter::Get()->NotificationCount(); |
159 return message_center->NotificationCount(); | |
160 } | |
161 }; | |
162 | 160 |
163 typedef MessageCenterExtensionCrashRecoveryTest | 161 return BalloonNotificationUIManager::GetInstanceForTesting()-> |
164 MAYBE_ExtensionCrashRecoveryTest; | 162 balloon_collection()->GetActiveBalloons().size(); |
165 | |
166 #else // defined(ENABLED_MESSAGE_CENTER) | |
167 | |
168 class BalloonExtensionCrashRecoveryTest | |
169 : public ExtensionCrashRecoveryTestBase { | |
170 protected: | |
171 virtual void AcceptNotification(size_t index) OVERRIDE { | |
172 Balloon* balloon = GetNotificationDelegate(index); | |
173 ASSERT_TRUE(balloon); | |
174 balloon->OnClick(); | |
175 WaitForExtensionLoad(); | |
176 } | 163 } |
177 | 164 |
178 virtual void CancelNotification(size_t index) OVERRIDE { | 165 private: |
179 Balloon* balloon = GetNotificationDelegate(index); | 166 Balloon* GetNotificationDelegate(size_t index) { |
180 ASSERT_TRUE(balloon); | 167 BalloonNotificationUIManager* manager = |
181 std::string id = balloon->notification().notification_id(); | 168 BalloonNotificationUIManager::GetInstanceForTesting(); |
182 ASSERT_TRUE(g_browser_process->notification_ui_manager()->CancelById(id)); | 169 BalloonCollection::Balloons balloons = |
183 } | 170 manager->balloon_collection()->GetActiveBalloons(); |
184 | 171 return index < balloons.size() ? balloons.at(index) : NULL; |
185 virtual size_t CountBalloons() OVERRIDE { | 172 } |
186 BalloonNotificationUIManager* manager = | |
187 BalloonNotificationUIManager::GetInstanceForTesting(); | |
188 BalloonCollection::Balloons balloons = | |
189 manager->balloon_collection()->GetActiveBalloons(); | |
190 return balloons.size(); | |
191 } | |
192 private: | |
193 Balloon* GetNotificationDelegate(size_t index) { | |
194 BalloonNotificationUIManager* manager = | |
195 BalloonNotificationUIManager::GetInstanceForTesting(); | |
196 BalloonCollection::Balloons balloons = | |
197 manager->balloon_collection()->GetActiveBalloons(); | |
198 return index < balloons.size() ? balloons.at(index) : NULL; | |
199 } | |
200 }; | 173 }; |
201 | 174 |
202 typedef BalloonExtensionCrashRecoveryTest MAYBE_ExtensionCrashRecoveryTest; | |
203 #endif // defined(ENABLE_MESSAGE_CENTER) | |
204 | |
205 IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest, Basic) { | 175 IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest, Basic) { |
206 const size_t size_before = GetExtensionService()->extensions()->size(); | 176 const size_t size_before = GetExtensionService()->extensions()->size(); |
207 const size_t crash_size_before = | 177 const size_t crash_size_before = |
208 GetExtensionService()->terminated_extensions()->size(); | 178 GetExtensionService()->terminated_extensions()->size(); |
209 LoadTestExtension(); | 179 LoadTestExtension(); |
210 CrashExtension(first_extension_id_); | 180 CrashExtension(first_extension_id_); |
211 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 181 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
212 ASSERT_EQ(crash_size_before + 1, | 182 ASSERT_EQ(crash_size_before + 1, |
213 GetExtensionService()->terminated_extensions()->size()); | 183 GetExtensionService()->terminated_extensions()->size()); |
214 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); | 184 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 GetController())); | 552 GetController())); |
583 chrome::Reload(browser(), CURRENT_TAB); | 553 chrome::Reload(browser(), CURRENT_TAB); |
584 observer.Wait(); | 554 observer.Wait(); |
585 } | 555 } |
586 // Extension should now be loaded. | 556 // Extension should now be loaded. |
587 SCOPED_TRACE("after reloading the tab"); | 557 SCOPED_TRACE("after reloading the tab"); |
588 CheckExtensionConsistency(first_extension_id_); | 558 CheckExtensionConsistency(first_extension_id_); |
589 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 559 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
590 ASSERT_EQ(0U, CountBalloons()); | 560 ASSERT_EQ(0U, CountBalloons()); |
591 } | 561 } |
OLD | NEW |