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/browser_tabstrip.h" | |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
24 #include "content/public/browser/navigation_controller.h" | 23 #include "content/public/browser/navigation_controller.h" |
25 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
26 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
27 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
28 #include "content/public/common/result_codes.h" | 27 #include "content/public/common/result_codes.h" |
29 | 28 |
30 using content::NavigationController; | 29 using content::NavigationController; |
31 using content::WebContents; | 30 using content::WebContents; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 const size_t size_before = GetExtensionService()->extensions()->size(); | 170 const size_t size_before = GetExtensionService()->extensions()->size(); |
172 LoadTestExtension(); | 171 LoadTestExtension(); |
173 CrashExtension(first_extension_id_); | 172 CrashExtension(first_extension_id_); |
174 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 173 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
175 | 174 |
176 ReloadExtension(first_extension_id_); | 175 ReloadExtension(first_extension_id_); |
177 | 176 |
178 SCOPED_TRACE("after reloading"); | 177 SCOPED_TRACE("after reloading"); |
179 CheckExtensionConsistency(first_extension_id_); | 178 CheckExtensionConsistency(first_extension_id_); |
180 | 179 |
181 WebContents* current_tab = chrome::GetActiveWebContents(browser()); | 180 WebContents* current_tab = |
| 181 browser()->tab_strip_model()->GetActiveWebContents(); |
182 ASSERT_TRUE(current_tab); | 182 ASSERT_TRUE(current_tab); |
183 | 183 |
184 // The balloon should automatically hide after the extension is successfully | 184 // The balloon should automatically hide after the extension is successfully |
185 // reloaded. | 185 // reloaded. |
186 ASSERT_EQ(0U, CountBalloons()); | 186 ASSERT_EQ(0U, CountBalloons()); |
187 } | 187 } |
188 | 188 |
189 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 189 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
190 ReloadIndependentlyChangeTabs) { | 190 ReloadIndependentlyChangeTabs) { |
191 const size_t size_before = GetExtensionService()->extensions()->size(); | 191 const size_t size_before = GetExtensionService()->extensions()->size(); |
192 LoadTestExtension(); | 192 LoadTestExtension(); |
193 CrashExtension(first_extension_id_); | 193 CrashExtension(first_extension_id_); |
194 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 194 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
195 | 195 |
196 WebContents* original_tab = chrome::GetActiveWebContents(browser()); | 196 WebContents* original_tab = |
| 197 browser()->tab_strip_model()->GetActiveWebContents(); |
197 ASSERT_TRUE(original_tab); | 198 ASSERT_TRUE(original_tab); |
198 ASSERT_EQ(1U, CountBalloons()); | 199 ASSERT_EQ(1U, CountBalloons()); |
199 | 200 |
200 // Open a new tab, but the balloon will still be there. | 201 // Open a new tab, but the balloon will still be there. |
201 chrome::NewTab(browser()); | 202 chrome::NewTab(browser()); |
202 WebContents* new_current_tab = chrome::GetActiveWebContents(browser()); | 203 WebContents* new_current_tab = |
| 204 browser()->tab_strip_model()->GetActiveWebContents(); |
203 ASSERT_TRUE(new_current_tab); | 205 ASSERT_TRUE(new_current_tab); |
204 ASSERT_NE(new_current_tab, original_tab); | 206 ASSERT_NE(new_current_tab, original_tab); |
205 ASSERT_EQ(1U, CountBalloons()); | 207 ASSERT_EQ(1U, CountBalloons()); |
206 | 208 |
207 ReloadExtension(first_extension_id_); | 209 ReloadExtension(first_extension_id_); |
208 | 210 |
209 SCOPED_TRACE("after reloading"); | 211 SCOPED_TRACE("after reloading"); |
210 CheckExtensionConsistency(first_extension_id_); | 212 CheckExtensionConsistency(first_extension_id_); |
211 | 213 |
212 // The balloon should automatically hide after the extension is successfully | 214 // The balloon should automatically hide after the extension is successfully |
213 // reloaded. | 215 // reloaded. |
214 ASSERT_EQ(0U, CountBalloons()); | 216 ASSERT_EQ(0U, CountBalloons()); |
215 } | 217 } |
216 | 218 |
217 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 219 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
218 ReloadIndependentlyNavigatePage) { | 220 ReloadIndependentlyNavigatePage) { |
219 const size_t size_before = GetExtensionService()->extensions()->size(); | 221 const size_t size_before = GetExtensionService()->extensions()->size(); |
220 LoadTestExtension(); | 222 LoadTestExtension(); |
221 CrashExtension(first_extension_id_); | 223 CrashExtension(first_extension_id_); |
222 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 224 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
223 | 225 |
224 WebContents* current_tab = chrome::GetActiveWebContents(browser()); | 226 WebContents* current_tab = |
| 227 browser()->tab_strip_model()->GetActiveWebContents(); |
225 ASSERT_TRUE(current_tab); | 228 ASSERT_TRUE(current_tab); |
226 ASSERT_EQ(1U, CountBalloons()); | 229 ASSERT_EQ(1U, CountBalloons()); |
227 | 230 |
228 // Navigate to another page. | 231 // Navigate to another page. |
229 ui_test_utils::NavigateToURL(browser(), | 232 ui_test_utils::NavigateToURL(browser(), |
230 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 233 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
231 FilePath(FILE_PATH_LITERAL("title1.html")))); | 234 FilePath(FILE_PATH_LITERAL("title1.html")))); |
232 ASSERT_EQ(1U, CountBalloons()); | 235 ASSERT_EQ(1U, CountBalloons()); |
233 | 236 |
234 ReloadExtension(first_extension_id_); | 237 ReloadExtension(first_extension_id_); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 const size_t size_before = GetExtensionService()->extensions()->size(); | 390 const size_t size_before = GetExtensionService()->extensions()->size(); |
388 LoadTestExtension(); | 391 LoadTestExtension(); |
389 LoadSecondExtension(); | 392 LoadSecondExtension(); |
390 CrashExtension(first_extension_id_); | 393 CrashExtension(first_extension_id_); |
391 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 394 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
392 CrashExtension(second_extension_id_); | 395 CrashExtension(second_extension_id_); |
393 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 396 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
394 | 397 |
395 { | 398 { |
396 SCOPED_TRACE("first: reload"); | 399 SCOPED_TRACE("first: reload"); |
397 WebContents* current_tab = chrome::GetActiveWebContents(browser()); | 400 WebContents* current_tab = |
| 401 browser()->tab_strip_model()->GetActiveWebContents(); |
398 ASSERT_TRUE(current_tab); | 402 ASSERT_TRUE(current_tab); |
399 // At the beginning we should have one balloon displayed for each extension. | 403 // At the beginning we should have one balloon displayed for each extension. |
400 ASSERT_EQ(2U, CountBalloons()); | 404 ASSERT_EQ(2U, CountBalloons()); |
401 ReloadExtension(first_extension_id_); | 405 ReloadExtension(first_extension_id_); |
402 // One of the balloons should hide after the extension is reloaded. | 406 // One of the balloons should hide after the extension is reloaded. |
403 ASSERT_EQ(1U, CountBalloons()); | 407 ASSERT_EQ(1U, CountBalloons()); |
404 CheckExtensionConsistency(first_extension_id_); | 408 CheckExtensionConsistency(first_extension_id_); |
405 } | 409 } |
406 | 410 |
407 { | 411 { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 // Tab should still be open, and extension should be crashed. | 491 // Tab should still be open, and extension should be crashed. |
488 EXPECT_EQ(tabs_before, tab_strip->count()); | 492 EXPECT_EQ(tabs_before, tab_strip->count()); |
489 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); | 493 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); |
490 EXPECT_EQ(crash_size_before + 1, | 494 EXPECT_EQ(crash_size_before + 1, |
491 GetExtensionService()->terminated_extensions()->size()); | 495 GetExtensionService()->terminated_extensions()->size()); |
492 | 496 |
493 { | 497 { |
494 content::WindowedNotificationObserver observer( | 498 content::WindowedNotificationObserver observer( |
495 content::NOTIFICATION_LOAD_STOP, | 499 content::NOTIFICATION_LOAD_STOP, |
496 content::Source<NavigationController>( | 500 content::Source<NavigationController>( |
497 &chrome::GetActiveWebContents(browser())->GetController())); | 501 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 502 GetController())); |
498 chrome::Reload(browser(), CURRENT_TAB); | 503 chrome::Reload(browser(), CURRENT_TAB); |
499 observer.Wait(); | 504 observer.Wait(); |
500 } | 505 } |
501 // Extension should now be loaded. | 506 // Extension should now be loaded. |
502 SCOPED_TRACE("after reloading the tab"); | 507 SCOPED_TRACE("after reloading the tab"); |
503 CheckExtensionConsistency(first_extension_id_); | 508 CheckExtensionConsistency(first_extension_id_); |
504 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 509 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
505 ASSERT_EQ(0U, CountBalloons()); | 510 ASSERT_EQ(0U, CountBalloons()); |
506 } | 511 } |
OLD | NEW |