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