diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 11:02:32 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 11:02:32 +0000 |
commit | ee8abdeb19fc1b8a90225176e36b3bb7f1bed1da (patch) | |
tree | 5ecd8607359289ff4a06bf5b92a81b7eee01eabc /chrome/browser | |
parent | ea2328bc3c3c192a84134b38a1e3dae133c3044b (diff) | |
download | chromium_src-ee8abdeb19fc1b8a90225176e36b3bb7f1bed1da.zip chromium_src-ee8abdeb19fc1b8a90225176e36b3bb7f1bed1da.tar.gz chromium_src-ee8abdeb19fc1b8a90225176e36b3bb7f1bed1da.tar.bz2 |
Add more tests for extension crash recovery.
This should cover most cases I'd like to cover.
TEST=none
BUG=30405
Review URL: http://codereview.chromium.org/718002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/extensions/extension_crash_recovery_browsertest.cc | 212 | ||||
-rw-r--r-- | chrome/browser/task_manager_browsertest.cc | 38 |
2 files changed, 219 insertions, 31 deletions
diff --git a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc index 51f4347..0bf5815 100644 --- a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc +++ b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc @@ -26,32 +26,34 @@ class ExtensionCrashRecoveryTest : public ExtensionBrowserTest { return browser()->profile()->GetExtensionProcessManager(); } - CrashedExtensionInfoBarDelegate* GetCrashedExtensionInfoBarDelegate() { + CrashedExtensionInfoBarDelegate* GetCrashedExtensionInfoBarDelegate( + int index) { TabContents* current_tab = browser()->GetSelectedTabContents(); - EXPECT_EQ(1, current_tab->infobar_delegate_count()); - InfoBarDelegate* delegate = current_tab->GetInfoBarDelegateAt(0); + EXPECT_LT(index, current_tab->infobar_delegate_count()); + InfoBarDelegate* delegate = current_tab->GetInfoBarDelegateAt(index); return delegate->AsCrashedExtensionInfoBarDelegate(); } - void AcceptCrashedExtensionInfobar() { + void AcceptCrashedExtensionInfobar(int index) { CrashedExtensionInfoBarDelegate* infobar = - GetCrashedExtensionInfoBarDelegate(); + GetCrashedExtensionInfoBarDelegate(index); ASSERT_TRUE(infobar); infobar->Accept(); - if (GetExtensionsService()->extensions()->empty()) - WaitForExtensionLoad(); + WaitForExtensionLoad(); } - void CancelCrashedExtensionInfobar() { + void CancelCrashedExtensionInfobar(int index) { CrashedExtensionInfoBarDelegate* infobar = - GetCrashedExtensionInfoBarDelegate(); + GetCrashedExtensionInfoBarDelegate(index); ASSERT_TRUE(infobar); infobar->Cancel(); } - void CrashExtension() { - Extension* extension = GetExtensionsService()->extensions()->at(0); + void CrashExtension(size_t index) { + ASSERT_LT(index, GetExtensionsService()->extensions()->size()); + Extension* extension = GetExtensionsService()->extensions()->at(index); ASSERT_TRUE(extension); + std::string extension_id(extension->id()); ExtensionHost* extension_host = GetExtensionProcessManager()->GetBackgroundHostForExtension(extension); ASSERT_TRUE(extension_host); @@ -60,15 +62,14 @@ class ExtensionCrashRecoveryTest : public ExtensionBrowserTest { extension_host->render_view_host()->process(); base::KillProcess(extension_rph->GetHandle(), base::PROCESS_END_KILLED_BY_USER, false); - ASSERT_TRUE(WaitForExtensionCrash(extension_id_)); + ASSERT_TRUE(WaitForExtensionCrash(extension_id)); ASSERT_FALSE( GetExtensionProcessManager()->GetBackgroundHostForExtension(extension)); - ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); } - void CheckExtensionConsistency() { - ASSERT_EQ(1U, GetExtensionsService()->extensions()->size()); - Extension* extension = GetExtensionsService()->extensions()->at(0); + void CheckExtensionConsistency(size_t index) { + ASSERT_LT(index, GetExtensionsService()->extensions()->size()); + Extension* extension = GetExtensionsService()->extensions()->at(index); ASSERT_TRUE(extension); ExtensionHost* extension_host = GetExtensionProcessManager()->GetBackgroundHostForExtension(extension); @@ -82,43 +83,57 @@ class ExtensionCrashRecoveryTest : public ExtensionBrowserTest { void LoadTestExtension() { ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); ASSERT_TRUE(LoadExtension( - test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); + test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); Extension* extension = GetExtensionsService()->extensions()->at(0); ASSERT_TRUE(extension); - extension_id_ = extension->id(); - CheckExtensionConsistency(); + first_extension_id_ = extension->id(); + CheckExtensionConsistency(0); } - std::string extension_id_; + void LoadSecondExtension() { + int offset = GetExtensionsService()->extensions()->size(); + ASSERT_TRUE(LoadExtension( + test_data_dir_.AppendASCII("install").AppendASCII("install"))); + Extension* extension = GetExtensionsService()->extensions()->at(offset); + ASSERT_TRUE(extension); + second_extension_id_ = extension->id(); + CheckExtensionConsistency(offset); + } + + std::string first_extension_id_; + std::string second_extension_id_; }; IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) { LoadTestExtension(); - CrashExtension(); - AcceptCrashedExtensionInfobar(); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); + AcceptCrashedExtensionInfobar(0); SCOPED_TRACE("after clicking the infobar"); - CheckExtensionConsistency(); + CheckExtensionConsistency(0); } IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) { LoadTestExtension(); - CrashExtension(); - CancelCrashedExtensionInfobar(); - ReloadExtension(extension_id_); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); + CancelCrashedExtensionInfobar(0); + ReloadExtension(first_extension_id_); SCOPED_TRACE("after reloading"); - CheckExtensionConsistency(); + CheckExtensionConsistency(0); } IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) { LoadTestExtension(); - CrashExtension(); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); - ReloadExtension(extension_id_); + ReloadExtension(first_extension_id_); SCOPED_TRACE("after reloading"); - CheckExtensionConsistency(); + CheckExtensionConsistency(0); TabContents* current_tab = browser()->GetSelectedTabContents(); ASSERT_TRUE(current_tab); @@ -127,3 +142,140 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) { // reloaded. ASSERT_EQ(0, current_tab->infobar_delegate_count()); } + +// Make sure that when we don't do anything about the crashed extension +// and close the browser, it doesn't crash. The browser is closed implicitly +// at the end of each browser test. +IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ShutdownWhileCrashed) { + LoadTestExtension(); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); +} + +IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) { + LoadTestExtension(); + LoadSecondExtension(); + CrashExtension(0); + ASSERT_EQ(1U, GetExtensionsService()->extensions()->size()); + AcceptCrashedExtensionInfobar(0); + + SCOPED_TRACE("after clicking the infobar"); + CheckExtensionConsistency(0); + CheckExtensionConsistency(1); +} + +IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) { + LoadTestExtension(); + LoadSecondExtension(); + CrashExtension(1); + ASSERT_EQ(1U, GetExtensionsService()->extensions()->size()); + AcceptCrashedExtensionInfobar(0); + + SCOPED_TRACE("after clicking the infobar"); + CheckExtensionConsistency(0); + CheckExtensionConsistency(1); +} + +IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, + TwoExtensionsCrashBothAtOnce) { + LoadTestExtension(); + LoadSecondExtension(); + CrashExtension(0); + ASSERT_EQ(1U, GetExtensionsService()->extensions()->size()); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); + + { + SCOPED_TRACE("first infobar"); + AcceptCrashedExtensionInfobar(0); + CheckExtensionConsistency(0); + } + + { + SCOPED_TRACE("second infobar"); + AcceptCrashedExtensionInfobar(0); + CheckExtensionConsistency(0); + CheckExtensionConsistency(1); + } +} + +IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) { + LoadTestExtension(); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); + LoadSecondExtension(); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); + + { + SCOPED_TRACE("first infobar"); + AcceptCrashedExtensionInfobar(0); + CheckExtensionConsistency(0); + } + + { + SCOPED_TRACE("second infobar"); + AcceptCrashedExtensionInfobar(0); + CheckExtensionConsistency(0); + CheckExtensionConsistency(1); + } +} + +// Make sure that when we don't do anything about the crashed extensions +// and close the browser, it doesn't crash. The browser is closed implicitly +// at the end of each browser test. +IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, + TwoExtensionsShutdownWhileCrashed) { + LoadTestExtension(); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); + LoadSecondExtension(); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); +} + +IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, + TwoExtensionsIgnoreFirst) { + LoadTestExtension(); + LoadSecondExtension(); + CrashExtension(0); + ASSERT_EQ(1U, GetExtensionsService()->extensions()->size()); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); + + CancelCrashedExtensionInfobar(0); + AcceptCrashedExtensionInfobar(1); + + SCOPED_TRACE("infobars done"); + ASSERT_EQ(1U, GetExtensionsService()->extensions()->size()); + CheckExtensionConsistency(0); +} + +IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, + TwoExtensionsReloadIndependently) { + LoadTestExtension(); + LoadSecondExtension(); + CrashExtension(0); + ASSERT_EQ(1U, GetExtensionsService()->extensions()->size()); + CrashExtension(0); + ASSERT_TRUE(GetExtensionsService()->extensions()->empty()); + + { + SCOPED_TRACE("first: reload"); + TabContents* current_tab = browser()->GetSelectedTabContents(); + ASSERT_TRUE(current_tab); + // At the beginning we should have one infobar displayed for each extension. + ASSERT_EQ(2, current_tab->infobar_delegate_count()); + ReloadExtension(first_extension_id_); + // One of the infobars should hide after the extension is reloaded. + ASSERT_EQ(1, current_tab->infobar_delegate_count()); + CheckExtensionConsistency(0); + } + + { + SCOPED_TRACE("second: infobar"); + AcceptCrashedExtensionInfobar(0); + CheckExtensionConsistency(0); + CheckExtensionConsistency(1); + } +} diff --git a/chrome/browser/task_manager_browsertest.cc b/chrome/browser/task_manager_browsertest.cc index 4d2eab8..d9f99cf 100644 --- a/chrome/browser/task_manager_browsertest.cc +++ b/chrome/browser/task_manager_browsertest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,7 +7,10 @@ #include "app/l10n_util.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" +#include "chrome/browser/extensions/crashed_extension_infobar.h" #include "chrome/browser/extensions/extension_browsertest.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/page_transition_types.h" #include "chrome/test/in_process_browser_test.h" @@ -145,6 +148,39 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillExtension) { WaitForResourceChange(2); } +IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillExtensionAndReload) { + // Show the task manager. This populates the model, and helps with debugging + // (you see the task manager). + browser()->window()->ShowTaskManager(); + + ASSERT_TRUE(LoadExtension( + test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); + + // Wait until we see the loaded extension in the task manager (the three + // resources are: the browser process, New Tab Page, and the extension). + WaitForResourceChange(3); + + EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); + EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); + ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); + + // Kill the extension process and make sure we notice it. + TaskManager::GetInstance()->KillProcess(2); + WaitForResourceChange(2); + + // Reload the extension using the "crashed extension" infobar while the task + // manager is still visible. Make sure we don't crash and the extension + // gets reloaded and noticed in the task manager. + TabContents* current_tab = browser()->GetSelectedTabContents(); + ASSERT_EQ(1, current_tab->infobar_delegate_count()); + InfoBarDelegate* delegate = current_tab->GetInfoBarDelegateAt(0); + CrashedExtensionInfoBarDelegate* crashed_delegate = + delegate->AsCrashedExtensionInfoBarDelegate(); + ASSERT_TRUE(crashed_delegate); + crashed_delegate->Accept(); + WaitForResourceChange(3); +} + // Regression test for http://crbug.com/18693. IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) { // Show the task manager. This populates the model, and helps with debugging |