| 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/notifications/balloon.h" | 11 #include "chrome/browser/notifications/balloon.h" |
| 12 #include "chrome/browser/notifications/balloon_collection.h" | 12 #include "chrome/browser/notifications/balloon_collection.h" |
| 13 #include "chrome/browser/notifications/balloon_host.h" | 13 #include "chrome/browser/notifications/balloon_host.h" |
| 14 #include "chrome/browser/notifications/notification.h" | 14 #include "chrome/browser/notifications/notification.h" |
| 15 #include "chrome/browser/notifications/notification_delegate.h" | 15 #include "chrome/browser/notifications/notification_delegate.h" |
| 16 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
| 23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
| 27 | 27 |
| 28 using content::NavigationController; | 28 using content::NavigationController; |
| 29 using content::WebContents; | 29 using content::WebContents; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 const size_t size_before = GetExtensionService()->extensions()->size(); | 168 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 169 LoadTestExtension(); | 169 LoadTestExtension(); |
| 170 CrashExtension(first_extension_id_); | 170 CrashExtension(first_extension_id_); |
| 171 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 171 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 172 | 172 |
| 173 ReloadExtension(first_extension_id_); | 173 ReloadExtension(first_extension_id_); |
| 174 | 174 |
| 175 SCOPED_TRACE("after reloading"); | 175 SCOPED_TRACE("after reloading"); |
| 176 CheckExtensionConsistency(first_extension_id_); | 176 CheckExtensionConsistency(first_extension_id_); |
| 177 | 177 |
| 178 WebContents* current_tab = browser()->GetSelectedWebContents(); | 178 WebContents* current_tab = browser()->GetActiveWebContents(); |
| 179 ASSERT_TRUE(current_tab); | 179 ASSERT_TRUE(current_tab); |
| 180 | 180 |
| 181 // The balloon should automatically hide after the extension is successfully | 181 // The balloon should automatically hide after the extension is successfully |
| 182 // reloaded. | 182 // reloaded. |
| 183 ASSERT_EQ(0U, CountBalloons()); | 183 ASSERT_EQ(0U, CountBalloons()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 186 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 187 ReloadIndependentlyChangeTabs) { | 187 ReloadIndependentlyChangeTabs) { |
| 188 const size_t size_before = GetExtensionService()->extensions()->size(); | 188 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 189 LoadTestExtension(); | 189 LoadTestExtension(); |
| 190 CrashExtension(first_extension_id_); | 190 CrashExtension(first_extension_id_); |
| 191 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 191 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 192 | 192 |
| 193 WebContents* original_tab = browser()->GetSelectedWebContents(); | 193 WebContents* original_tab = browser()->GetActiveWebContents(); |
| 194 ASSERT_TRUE(original_tab); | 194 ASSERT_TRUE(original_tab); |
| 195 ASSERT_EQ(1U, CountBalloons()); | 195 ASSERT_EQ(1U, CountBalloons()); |
| 196 | 196 |
| 197 // Open a new tab, but the balloon will still be there. | 197 // Open a new tab, but the balloon will still be there. |
| 198 browser()->NewTab(); | 198 browser()->NewTab(); |
| 199 WebContents* new_current_tab = browser()->GetSelectedWebContents(); | 199 WebContents* new_current_tab = browser()->GetActiveWebContents(); |
| 200 ASSERT_TRUE(new_current_tab); | 200 ASSERT_TRUE(new_current_tab); |
| 201 ASSERT_NE(new_current_tab, original_tab); | 201 ASSERT_NE(new_current_tab, original_tab); |
| 202 ASSERT_EQ(1U, CountBalloons()); | 202 ASSERT_EQ(1U, CountBalloons()); |
| 203 | 203 |
| 204 ReloadExtension(first_extension_id_); | 204 ReloadExtension(first_extension_id_); |
| 205 | 205 |
| 206 SCOPED_TRACE("after reloading"); | 206 SCOPED_TRACE("after reloading"); |
| 207 CheckExtensionConsistency(first_extension_id_); | 207 CheckExtensionConsistency(first_extension_id_); |
| 208 | 208 |
| 209 // The balloon should automatically hide after the extension is successfully | 209 // The balloon should automatically hide after the extension is successfully |
| 210 // reloaded. | 210 // reloaded. |
| 211 ASSERT_EQ(0U, CountBalloons()); | 211 ASSERT_EQ(0U, CountBalloons()); |
| 212 } | 212 } |
| 213 | 213 |
| 214 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 214 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 215 ReloadIndependentlyNavigatePage) { | 215 ReloadIndependentlyNavigatePage) { |
| 216 const size_t size_before = GetExtensionService()->extensions()->size(); | 216 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 217 LoadTestExtension(); | 217 LoadTestExtension(); |
| 218 CrashExtension(first_extension_id_); | 218 CrashExtension(first_extension_id_); |
| 219 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 219 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 220 | 220 |
| 221 WebContents* current_tab = browser()->GetSelectedWebContents(); | 221 WebContents* current_tab = browser()->GetActiveWebContents(); |
| 222 ASSERT_TRUE(current_tab); | 222 ASSERT_TRUE(current_tab); |
| 223 ASSERT_EQ(1U, CountBalloons()); | 223 ASSERT_EQ(1U, CountBalloons()); |
| 224 | 224 |
| 225 // Navigate to another page. | 225 // Navigate to another page. |
| 226 ui_test_utils::NavigateToURL(browser(), | 226 ui_test_utils::NavigateToURL(browser(), |
| 227 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 227 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 228 FilePath(FILE_PATH_LITERAL("title1.html")))); | 228 FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 229 ASSERT_EQ(1U, CountBalloons()); | 229 ASSERT_EQ(1U, CountBalloons()); |
| 230 | 230 |
| 231 ReloadExtension(first_extension_id_); | 231 ReloadExtension(first_extension_id_); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 const size_t size_before = GetExtensionService()->extensions()->size(); | 384 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 385 LoadTestExtension(); | 385 LoadTestExtension(); |
| 386 LoadSecondExtension(); | 386 LoadSecondExtension(); |
| 387 CrashExtension(first_extension_id_); | 387 CrashExtension(first_extension_id_); |
| 388 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 388 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 389 CrashExtension(second_extension_id_); | 389 CrashExtension(second_extension_id_); |
| 390 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 390 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 391 | 391 |
| 392 { | 392 { |
| 393 SCOPED_TRACE("first: reload"); | 393 SCOPED_TRACE("first: reload"); |
| 394 WebContents* current_tab = browser()->GetSelectedWebContents(); | 394 WebContents* current_tab = browser()->GetActiveWebContents(); |
| 395 ASSERT_TRUE(current_tab); | 395 ASSERT_TRUE(current_tab); |
| 396 // At the beginning we should have one balloon displayed for each extension. | 396 // At the beginning we should have one balloon displayed for each extension. |
| 397 ASSERT_EQ(2U, CountBalloons()); | 397 ASSERT_EQ(2U, CountBalloons()); |
| 398 ReloadExtension(first_extension_id_); | 398 ReloadExtension(first_extension_id_); |
| 399 // One of the balloons should hide after the extension is reloaded. | 399 // One of the balloons should hide after the extension is reloaded. |
| 400 ASSERT_EQ(1U, CountBalloons()); | 400 ASSERT_EQ(1U, CountBalloons()); |
| 401 CheckExtensionConsistency(first_extension_id_); | 401 CheckExtensionConsistency(first_extension_id_); |
| 402 } | 402 } |
| 403 | 403 |
| 404 { | 404 { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 // Tab should still be open, and extension should be crashed. | 477 // Tab should still be open, and extension should be crashed. |
| 478 EXPECT_EQ(tabs_before, tab_strip->count()); | 478 EXPECT_EQ(tabs_before, tab_strip->count()); |
| 479 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); | 479 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 480 EXPECT_EQ(crash_size_before + 1, | 480 EXPECT_EQ(crash_size_before + 1, |
| 481 GetExtensionService()->terminated_extensions()->size()); | 481 GetExtensionService()->terminated_extensions()->size()); |
| 482 | 482 |
| 483 { | 483 { |
| 484 ui_test_utils::WindowedNotificationObserver observer( | 484 ui_test_utils::WindowedNotificationObserver observer( |
| 485 content::NOTIFICATION_LOAD_STOP, | 485 content::NOTIFICATION_LOAD_STOP, |
| 486 content::Source<NavigationController>( | 486 content::Source<NavigationController>( |
| 487 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 487 &browser()->GetActiveWebContents()->GetController())); |
| 488 GetController())); | |
| 489 browser()->Reload(CURRENT_TAB); | 488 browser()->Reload(CURRENT_TAB); |
| 490 observer.Wait(); | 489 observer.Wait(); |
| 491 } | 490 } |
| 492 // Extension should now be loaded. | 491 // Extension should now be loaded. |
| 493 SCOPED_TRACE("after reloading the tab"); | 492 SCOPED_TRACE("after reloading the tab"); |
| 494 CheckExtensionConsistency(first_extension_id_); | 493 CheckExtensionConsistency(first_extension_id_); |
| 495 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 494 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 496 ASSERT_EQ(0U, CountBalloons()); | 495 ASSERT_EQ(0U, CountBalloons()); |
| 497 } | 496 } |
| OLD | NEW |