summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 09:26:16 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 09:26:16 +0000
commit1eb175082bf16c5f7d92972f5d20277cb665d8e8 (patch)
tree3dedbb89b997b8a9fc37b001a911371468d848b8 /chrome/browser/extensions/extension_crash_recovery_browsertest.cc
parent31584b27d7956971710d50ffba70f00f5ea9433e (diff)
downloadchromium_src-1eb175082bf16c5f7d92972f5d20277cb665d8e8.zip
chromium_src-1eb175082bf16c5f7d92972f5d20277cb665d8e8.tar.gz
chromium_src-1eb175082bf16c5f7d92972f5d20277cb665d8e8.tar.bz2
Add basic tests for extension crash recovery.
Also update the test infrastructure to support the required features. TEST=browser_tests BUG=30405 Review URL: http://codereview.chromium.org/572038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_crash_recovery_browsertest.cc')
-rw-r--r--chrome/browser/extensions/extension_crash_recovery_browsertest.cc129
1 files changed, 129 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
new file mode 100644
index 0000000..51f4347
--- /dev/null
+++ b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
@@ -0,0 +1,129 @@
+// 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.
+
+#include "base/process_util.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/extensions/crashed_extension_infobar.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_process_manager.h"
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/tab_contents/infobar_delegate.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/test/ui_test_utils.h"
+
+class ExtensionCrashRecoveryTest : public ExtensionBrowserTest {
+ protected:
+ ExtensionsService* GetExtensionsService() {
+ return browser()->profile()->GetExtensionsService();
+ }
+
+ ExtensionProcessManager* GetExtensionProcessManager() {
+ return browser()->profile()->GetExtensionProcessManager();
+ }
+
+ CrashedExtensionInfoBarDelegate* GetCrashedExtensionInfoBarDelegate() {
+ TabContents* current_tab = browser()->GetSelectedTabContents();
+ EXPECT_EQ(1, current_tab->infobar_delegate_count());
+ InfoBarDelegate* delegate = current_tab->GetInfoBarDelegateAt(0);
+ return delegate->AsCrashedExtensionInfoBarDelegate();
+ }
+
+ void AcceptCrashedExtensionInfobar() {
+ CrashedExtensionInfoBarDelegate* infobar =
+ GetCrashedExtensionInfoBarDelegate();
+ ASSERT_TRUE(infobar);
+ infobar->Accept();
+ if (GetExtensionsService()->extensions()->empty())
+ WaitForExtensionLoad();
+ }
+
+ void CancelCrashedExtensionInfobar() {
+ CrashedExtensionInfoBarDelegate* infobar =
+ GetCrashedExtensionInfoBarDelegate();
+ ASSERT_TRUE(infobar);
+ infobar->Cancel();
+ }
+
+ void CrashExtension() {
+ Extension* extension = GetExtensionsService()->extensions()->at(0);
+ ASSERT_TRUE(extension);
+ ExtensionHost* extension_host =
+ GetExtensionProcessManager()->GetBackgroundHostForExtension(extension);
+ ASSERT_TRUE(extension_host);
+
+ RenderProcessHost* extension_rph =
+ extension_host->render_view_host()->process();
+ base::KillProcess(extension_rph->GetHandle(),
+ base::PROCESS_END_KILLED_BY_USER, false);
+ 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);
+ ASSERT_TRUE(extension);
+ ExtensionHost* extension_host =
+ GetExtensionProcessManager()->GetBackgroundHostForExtension(extension);
+ ASSERT_TRUE(extension_host);
+ ASSERT_TRUE(GetExtensionProcessManager()->HasExtensionHost(extension_host));
+ ASSERT_TRUE(extension_host->IsRenderViewLive());
+ ASSERT_EQ(extension_host->render_view_host()->process(),
+ GetExtensionProcessManager()->GetExtensionProcess(extension->id()));
+ }
+
+ void LoadTestExtension() {
+ ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
+ ASSERT_TRUE(LoadExtension(
+ test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
+ Extension* extension = GetExtensionsService()->extensions()->at(0);
+ ASSERT_TRUE(extension);
+ extension_id_ = extension->id();
+ CheckExtensionConsistency();
+ }
+
+ std::string extension_id_;
+};
+
+IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) {
+ LoadTestExtension();
+ CrashExtension();
+ AcceptCrashedExtensionInfobar();
+
+ SCOPED_TRACE("after clicking the infobar");
+ CheckExtensionConsistency();
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) {
+ LoadTestExtension();
+ CrashExtension();
+ CancelCrashedExtensionInfobar();
+ ReloadExtension(extension_id_);
+
+ SCOPED_TRACE("after reloading");
+ CheckExtensionConsistency();
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) {
+ LoadTestExtension();
+ CrashExtension();
+
+ ReloadExtension(extension_id_);
+
+ SCOPED_TRACE("after reloading");
+ CheckExtensionConsistency();
+
+ TabContents* current_tab = browser()->GetSelectedTabContents();
+ ASSERT_TRUE(current_tab);
+
+ // The infobar should automatically hide after the extension is successfully
+ // reloaded.
+ ASSERT_EQ(0, current_tab->infobar_delegate_count());
+}