| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_host.h" | 11 #include "chrome/browser/notifications/balloon_host.h" |
| 12 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
| 13 #include "chrome/browser/notifications/notification_delegate.h" | 13 #include "chrome/browser/notifications/notification_delegate.h" |
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | 14 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/tabs/tab_strip_model.h" | 16 #include "chrome/browser/tabs/tab_strip_model.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
| 21 #include "content/browser/tab_contents/tab_contents.h" | |
| 22 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
| 24 | 24 |
| 25 using content::WebContents; |
| 26 |
| 25 class ExtensionCrashRecoveryTest : public ExtensionBrowserTest { | 27 class ExtensionCrashRecoveryTest : public ExtensionBrowserTest { |
| 26 protected: | 28 protected: |
| 27 ExtensionService* GetExtensionService() { | 29 ExtensionService* GetExtensionService() { |
| 28 return browser()->profile()->GetExtensionService(); | 30 return browser()->profile()->GetExtensionService(); |
| 29 } | 31 } |
| 30 | 32 |
| 31 ExtensionProcessManager* GetExtensionProcessManager() { | 33 ExtensionProcessManager* GetExtensionProcessManager() { |
| 32 return browser()->profile()->GetExtensionProcessManager(); | 34 return browser()->profile()->GetExtensionProcessManager(); |
| 33 } | 35 } |
| 34 | 36 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 const size_t size_before = GetExtensionService()->extensions()->size(); | 158 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 157 LoadTestExtension(); | 159 LoadTestExtension(); |
| 158 CrashExtension(first_extension_id_); | 160 CrashExtension(first_extension_id_); |
| 159 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 161 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 160 | 162 |
| 161 ReloadExtension(first_extension_id_); | 163 ReloadExtension(first_extension_id_); |
| 162 | 164 |
| 163 SCOPED_TRACE("after reloading"); | 165 SCOPED_TRACE("after reloading"); |
| 164 CheckExtensionConsistency(first_extension_id_); | 166 CheckExtensionConsistency(first_extension_id_); |
| 165 | 167 |
| 166 TabContents* current_tab = browser()->GetSelectedTabContents(); | 168 WebContents* current_tab = browser()->GetSelectedWebContents(); |
| 167 ASSERT_TRUE(current_tab); | 169 ASSERT_TRUE(current_tab); |
| 168 | 170 |
| 169 // The balloon should automatically hide after the extension is successfully | 171 // The balloon should automatically hide after the extension is successfully |
| 170 // reloaded. | 172 // reloaded. |
| 171 ASSERT_EQ(0U, CountBalloons()); | 173 ASSERT_EQ(0U, CountBalloons()); |
| 172 } | 174 } |
| 173 | 175 |
| 174 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 176 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 175 ReloadIndependentlyChangeTabs) { | 177 ReloadIndependentlyChangeTabs) { |
| 176 const size_t size_before = GetExtensionService()->extensions()->size(); | 178 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 177 LoadTestExtension(); | 179 LoadTestExtension(); |
| 178 CrashExtension(first_extension_id_); | 180 CrashExtension(first_extension_id_); |
| 179 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 181 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 180 | 182 |
| 181 TabContents* original_tab = browser()->GetSelectedTabContents(); | 183 WebContents* original_tab = browser()->GetSelectedWebContents(); |
| 182 ASSERT_TRUE(original_tab); | 184 ASSERT_TRUE(original_tab); |
| 183 ASSERT_EQ(1U, CountBalloons()); | 185 ASSERT_EQ(1U, CountBalloons()); |
| 184 | 186 |
| 185 // Open a new tab, but the balloon will still be there. | 187 // Open a new tab, but the balloon will still be there. |
| 186 browser()->NewTab(); | 188 browser()->NewTab(); |
| 187 TabContents* new_current_tab = browser()->GetSelectedTabContents(); | 189 WebContents* new_current_tab = browser()->GetSelectedWebContents(); |
| 188 ASSERT_TRUE(new_current_tab); | 190 ASSERT_TRUE(new_current_tab); |
| 189 ASSERT_NE(new_current_tab, original_tab); | 191 ASSERT_NE(new_current_tab, original_tab); |
| 190 ASSERT_EQ(1U, CountBalloons()); | 192 ASSERT_EQ(1U, CountBalloons()); |
| 191 | 193 |
| 192 ReloadExtension(first_extension_id_); | 194 ReloadExtension(first_extension_id_); |
| 193 | 195 |
| 194 SCOPED_TRACE("after reloading"); | 196 SCOPED_TRACE("after reloading"); |
| 195 CheckExtensionConsistency(first_extension_id_); | 197 CheckExtensionConsistency(first_extension_id_); |
| 196 | 198 |
| 197 // The balloon should automatically hide after the extension is successfully | 199 // The balloon should automatically hide after the extension is successfully |
| 198 // reloaded. | 200 // reloaded. |
| 199 ASSERT_EQ(0U, CountBalloons()); | 201 ASSERT_EQ(0U, CountBalloons()); |
| 200 } | 202 } |
| 201 | 203 |
| 202 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 204 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 203 ReloadIndependentlyNavigatePage) { | 205 ReloadIndependentlyNavigatePage) { |
| 204 const size_t size_before = GetExtensionService()->extensions()->size(); | 206 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 205 LoadTestExtension(); | 207 LoadTestExtension(); |
| 206 CrashExtension(first_extension_id_); | 208 CrashExtension(first_extension_id_); |
| 207 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 209 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 208 | 210 |
| 209 TabContents* current_tab = browser()->GetSelectedTabContents(); | 211 WebContents* current_tab = browser()->GetSelectedWebContents(); |
| 210 ASSERT_TRUE(current_tab); | 212 ASSERT_TRUE(current_tab); |
| 211 ASSERT_EQ(1U, CountBalloons()); | 213 ASSERT_EQ(1U, CountBalloons()); |
| 212 | 214 |
| 213 // Navigate to another page. | 215 // Navigate to another page. |
| 214 ui_test_utils::NavigateToURL(browser(), | 216 ui_test_utils::NavigateToURL(browser(), |
| 215 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 217 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 216 FilePath(FILE_PATH_LITERAL("title1.html")))); | 218 FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 217 ASSERT_EQ(1U, CountBalloons()); | 219 ASSERT_EQ(1U, CountBalloons()); |
| 218 | 220 |
| 219 ReloadExtension(first_extension_id_); | 221 ReloadExtension(first_extension_id_); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 const size_t size_before = GetExtensionService()->extensions()->size(); | 374 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 373 LoadTestExtension(); | 375 LoadTestExtension(); |
| 374 LoadSecondExtension(); | 376 LoadSecondExtension(); |
| 375 CrashExtension(first_extension_id_); | 377 CrashExtension(first_extension_id_); |
| 376 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 378 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 377 CrashExtension(second_extension_id_); | 379 CrashExtension(second_extension_id_); |
| 378 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 380 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 379 | 381 |
| 380 { | 382 { |
| 381 SCOPED_TRACE("first: reload"); | 383 SCOPED_TRACE("first: reload"); |
| 382 TabContents* current_tab = browser()->GetSelectedTabContents(); | 384 WebContents* current_tab = browser()->GetSelectedWebContents(); |
| 383 ASSERT_TRUE(current_tab); | 385 ASSERT_TRUE(current_tab); |
| 384 // At the beginning we should have one balloon displayed for each extension. | 386 // At the beginning we should have one balloon displayed for each extension. |
| 385 ASSERT_EQ(2U, CountBalloons()); | 387 ASSERT_EQ(2U, CountBalloons()); |
| 386 ReloadExtension(first_extension_id_); | 388 ReloadExtension(first_extension_id_); |
| 387 // One of the balloons should hide after the extension is reloaded. | 389 // One of the balloons should hide after the extension is reloaded. |
| 388 ASSERT_EQ(1U, CountBalloons()); | 390 ASSERT_EQ(1U, CountBalloons()); |
| 389 CheckExtensionConsistency(first_extension_id_); | 391 CheckExtensionConsistency(first_extension_id_); |
| 390 } | 392 } |
| 391 | 393 |
| 392 { | 394 { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 // Tab should still be open, and extension should be crashed. | 467 // Tab should still be open, and extension should be crashed. |
| 466 EXPECT_EQ(tabs_before, tab_strip->count()); | 468 EXPECT_EQ(tabs_before, tab_strip->count()); |
| 467 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); | 469 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 468 EXPECT_EQ(crash_size_before + 1, | 470 EXPECT_EQ(crash_size_before + 1, |
| 469 GetExtensionService()->terminated_extensions()->size()); | 471 GetExtensionService()->terminated_extensions()->size()); |
| 470 | 472 |
| 471 { | 473 { |
| 472 ui_test_utils::WindowedNotificationObserver observer( | 474 ui_test_utils::WindowedNotificationObserver observer( |
| 473 content::NOTIFICATION_LOAD_STOP, | 475 content::NOTIFICATION_LOAD_STOP, |
| 474 content::Source<NavigationController>( | 476 content::Source<NavigationController>( |
| 475 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> | 477 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> |
| 476 GetController())); | 478 GetController())); |
| 477 browser()->Reload(CURRENT_TAB); | 479 browser()->Reload(CURRENT_TAB); |
| 478 observer.Wait(); | 480 observer.Wait(); |
| 479 } | 481 } |
| 480 // Extension should now be loaded. | 482 // Extension should now be loaded. |
| 481 SCOPED_TRACE("after reloading the tab"); | 483 SCOPED_TRACE("after reloading the tab"); |
| 482 CheckExtensionConsistency(first_extension_id_); | 484 CheckExtensionConsistency(first_extension_id_); |
| 483 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 485 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 484 ASSERT_EQ(0U, CountBalloons()); | 486 ASSERT_EQ(0U, CountBalloons()); |
| 485 } | 487 } |
| OLD | NEW |