blob: cba53054090682d29d71b1f50c146a742fd36f0c [file] [log] [blame]
[email protected]9f76c1e2012-03-05 15:15:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]1eb175082010-02-10 09:26:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avia2f4804a2015-12-24 23:11:135#include <stddef.h>
6
fdorayfd4c7ba2016-06-10 17:44:367#include "base/run_loop.h"
avia2f4804a2015-12-24 23:11:138#include "build/build_config.h"
[email protected]6cd63ea2013-03-07 18:17:049#include "chrome/browser/browser_process.h"
[email protected]1eb175082010-02-10 09:26:1610#include "chrome/browser/extensions/extension_browsertest.h"
[email protected]eaa7dd182010-12-14 11:09:0011#include "chrome/browser/extensions/extension_service.h"
Evan Stadebde440902018-01-26 20:10:3412#include "chrome/browser/notifications/notification_display_service_tester.h"
[email protected]8ecad5e2010-12-02 21:18:3313#include "chrome/browser/profiles/profile.h"
[email protected]7b5dc002010-11-16 23:08:1014#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1015#include "chrome/browser/ui/browser_commands.h"
[email protected]b56e2e32012-05-11 21:18:0416#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]af44e7fb2011-07-29 18:32:3217#include "chrome/test/base/ui_test_utils.h"
[email protected]cdcb1dee2012-01-04 00:46:2018#include "content/public/browser/navigation_controller.h"
steelf65a72a2016-10-19 22:16:4519#include "content/public/browser/notification_types.h"
[email protected]f3b1a082011-11-18 00:34:3020#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3321#include "content/public/browser/render_view_host.h"
[email protected]4ca15302012-01-03 05:53:2022#include "content/public/browser/web_contents.h"
[email protected]b39ef1cb2011-10-25 04:46:5523#include "content/public/common/result_codes.h"
[email protected]99bee642014-05-31 22:36:4324#include "content/public/common/url_constants.h"
Lukasz Anforowicz951d6bc2019-06-14 18:29:1825#include "content/public/test/no_renderer_crashes_assertion.h"
Lukasz Anforowiczfb1ccf02018-04-21 14:55:2026#include "content/public/test/test_utils.h"
[email protected]22401dc2014-03-21 01:38:5727#include "extensions/browser/extension_host.h"
[email protected]ca975942014-01-07 12:06:4728#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2429#include "extensions/browser/extension_system.h"
[email protected]98b6d942013-11-10 00:34:0730#include "extensions/browser/process_manager.h"
[email protected]fafdc842014-01-17 18:09:0831#include "extensions/browser/process_map.h"
limasdf184283c2017-04-14 08:22:1032#include "extensions/browser/test_extension_registry_observer.h"
[email protected]99bee642014-05-31 22:36:4333#include "extensions/common/constants.h"
emaxx895210ec2017-04-19 14:37:3034#include "extensions/test/background_page_watcher.h"
Evan Stade889ce4712018-01-28 15:26:2635#include "ui/message_center/public/cpp/notification.h"
36#include "ui/message_center/public/cpp/notification_delegate.h"
[email protected]6cd63ea2013-03-07 18:17:0437
[email protected]c5eed492012-01-04 17:07:5038using content::NavigationController;
[email protected]4ca15302012-01-03 05:53:2039using content::WebContents;
[email protected]1c321ee52012-05-21 03:02:3440using extensions::Extension;
[email protected]ca975942014-01-07 12:06:4741using extensions::ExtensionRegistry;
[email protected]4ca15302012-01-03 05:53:2042
Devlin Cronin836f545d2018-05-09 00:25:0543class ExtensionCrashRecoveryTest : public extensions::ExtensionBrowserTest {
[email protected]1eb175082010-02-10 09:26:1644 protected:
Evan Stadebde440902018-01-26 20:10:3445 void SetUpOnMainThread() override {
Devlin Cronin836f545d2018-05-09 00:25:0546 extensions::ExtensionBrowserTest::SetUpOnMainThread();
Evan Stadebde440902018-01-26 20:10:3447 display_service_ =
48 std::make_unique<NotificationDisplayServiceTester>(profile());
49 }
[email protected]6cd63ea2013-03-07 18:17:0450
Devlin Cronin251bd412018-05-30 00:55:4251 extensions::ExtensionService* GetExtensionService() {
[email protected]03d25812014-06-22 19:41:5552 return extensions::ExtensionSystem::Get(browser()->profile())->
53 extension_service();
[email protected]1eb175082010-02-10 09:26:1654 }
55
[email protected]98b6d942013-11-10 00:34:0756 extensions::ProcessManager* GetProcessManager() {
reillyg0ea3fa902014-10-28 15:30:2357 return extensions::ProcessManager::Get(browser()->profile());
[email protected]1eb175082010-02-10 09:26:1658 }
59
[email protected]0bb29bd2014-04-30 21:39:1860 ExtensionRegistry* GetExtensionRegistry() {
61 return ExtensionRegistry::Get(browser()->profile());
62 }
63
[email protected]ca975942014-01-07 12:06:4764 size_t GetEnabledExtensionCount() {
[email protected]0bb29bd2014-04-30 21:39:1865 return GetExtensionRegistry()->enabled_extensions().size();
[email protected]ca975942014-01-07 12:06:4766 }
67
68 size_t GetTerminatedExtensionCount() {
[email protected]0bb29bd2014-04-30 21:39:1869 return GetExtensionRegistry()->terminated_extensions().size();
[email protected]ca975942014-01-07 12:06:4770 }
71
[email protected]0bb29bd2014-04-30 21:39:1872 void CrashExtension(const std::string& extension_id) {
73 const Extension* extension = GetExtensionRegistry()->GetExtensionById(
74 extension_id, ExtensionRegistry::ENABLED);
[email protected]1eb175082010-02-10 09:26:1675 ASSERT_TRUE(extension);
[email protected]98b6d942013-11-10 00:34:0776 extensions::ExtensionHost* extension_host = GetProcessManager()->
[email protected]06024c62011-10-20 20:57:1277 GetBackgroundHostForExtension(extension_id);
[email protected]1eb175082010-02-10 09:26:1678 ASSERT_TRUE(extension_host);
79
Wez0abfbf512018-03-03 01:54:4580 extension_host->render_process_host()->Shutdown(
81 content::RESULT_CODE_KILLED);
[email protected]ee8abdeb2010-03-10 11:02:3282 ASSERT_TRUE(WaitForExtensionCrash(extension_id));
[email protected]98b6d942013-11-10 00:34:0783 ASSERT_FALSE(GetProcessManager()->
[email protected]06024c62011-10-20 20:57:1284 GetBackgroundHostForExtension(extension_id));
[email protected]260122c2013-05-22 15:05:5585
86 // Wait for extension crash balloon to appear.
fdorayfd4c7ba2016-06-10 17:44:3687 base::RunLoop().RunUntilIdle();
[email protected]1eb175082010-02-10 09:26:1688 }
89
[email protected]0bb29bd2014-04-30 21:39:1890 void CheckExtensionConsistency(const std::string& extension_id) {
91 const Extension* extension = GetExtensionRegistry()->GetExtensionById(
92 extension_id, ExtensionRegistry::ENABLED);
[email protected]1eb175082010-02-10 09:26:1693 ASSERT_TRUE(extension);
[email protected]98b6d942013-11-10 00:34:0794 extensions::ExtensionHost* extension_host = GetProcessManager()->
[email protected]84df8332011-12-06 18:22:4695 GetBackgroundHostForExtension(extension_id);
[email protected]1eb175082010-02-10 09:26:1696 ASSERT_TRUE(extension_host);
rdevlin.cronin6ae04a012015-04-03 20:19:4097 extensions::ProcessManager::FrameSet frames =
98 GetProcessManager()->GetAllFrames();
99 ASSERT_NE(frames.end(),
100 frames.find(extension_host->host_contents()->GetMainFrame()));
101 ASSERT_FALSE(GetProcessManager()->GetAllFrames().empty());
[email protected]1eb175082010-02-10 09:26:16102 ASSERT_TRUE(extension_host->IsRenderViewLive());
[email protected]6f371442011-11-09 06:45:46103 extensions::ProcessMap* process_map =
[email protected]fafdc842014-01-17 18:09:08104 extensions::ProcessMap::Get(browser()->profile());
[email protected]6f371442011-11-09 06:45:46105 ASSERT_TRUE(process_map->Contains(
[email protected]9f76c1e2012-03-05 15:15:58106 extension_id,
107 extension_host->render_view_host()->GetProcess()->GetID()));
[email protected]1eb175082010-02-10 09:26:16108 }
109
110 void LoadTestExtension() {
Devlin Cronin836f545d2018-05-09 00:25:05111 extensions::ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
[email protected]84df8332011-12-06 18:22:46112 const Extension* extension = LoadExtension(
113 test_data_dir_.AppendASCII("common").AppendASCII("background_page"));
[email protected]1eb175082010-02-10 09:26:16114 ASSERT_TRUE(extension);
[email protected]ee8abdeb2010-03-10 11:02:32115 first_extension_id_ = extension->id();
[email protected]84df8332011-12-06 18:22:46116 CheckExtensionConsistency(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16117 }
118
[email protected]ee8abdeb2010-03-10 11:02:32119 void LoadSecondExtension() {
[email protected]84df8332011-12-06 18:22:46120 const Extension* extension = LoadExtension(
121 test_data_dir_.AppendASCII("install").AppendASCII("install"));
[email protected]ee8abdeb2010-03-10 11:02:32122 ASSERT_TRUE(extension);
123 second_extension_id_ = extension->id();
[email protected]84df8332011-12-06 18:22:46124 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32125 }
126
Evan Stadebde440902018-01-26 20:10:34127 void AcceptNotification(const std::string& extension_id) {
limasdf184283c2017-04-14 08:22:10128 extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry());
Evan Stadebde440902018-01-26 20:10:34129 display_service_->SimulateClick(NotificationHandler::Type::TRANSIENT,
130 "app.background.crashed." + extension_id,
131 base::nullopt, base::nullopt);
limasdf184283c2017-04-14 08:22:10132 auto* extension = observer.WaitForExtensionLoaded();
133 extensions::BackgroundPageWatcher(GetProcessManager(), extension)
134 .WaitForOpen();
[email protected]6cd63ea2013-03-07 18:17:04135 }
136
Evan Stadebde440902018-01-26 20:10:34137 size_t CountNotifications() {
138 return display_service_
139 ->GetDisplayedNotificationsForType(NotificationHandler::Type::TRANSIENT)
140 .size();
[email protected]6cd63ea2013-03-07 18:17:04141 }
142
Evan Stadebde440902018-01-26 20:10:34143 std::string first_extension_id_;
144 std::string second_extension_id_;
145 std::unique_ptr<NotificationDisplayServiceTester> display_service_;
Lukasz Anforowicz951d6bc2019-06-14 18:29:18146 content::ScopedAllowRendererCrashes scoped_allow_renderer_crashes_;
[email protected]9a224572013-05-12 23:08:56147};
[email protected]bce52eaa2013-05-11 19:23:21148
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56149// Flaky on ASAN builds (https://crbug.com/997634)
150#if defined(ADDRESS_SANITIZER)
151#define MAYBE_Basic DISABLED_Basic
152#else
153#define MAYBE_Basic Basic
154#endif
155IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_Basic) {
[email protected]ca975942014-01-07 12:06:47156 const size_t count_before = GetEnabledExtensionCount();
157 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]1eb175082010-02-10 09:26:16158 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46159 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47160 ASSERT_EQ(count_before, GetEnabledExtensionCount());
161 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
Evan Stadebde440902018-01-26 20:10:34162 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
[email protected]1eb175082010-02-10 09:26:16163
[email protected]2c4fb7b2011-04-02 06:33:29164 SCOPED_TRACE("after clicking the balloon");
[email protected]84df8332011-12-06 18:22:46165 CheckExtensionConsistency(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47166 ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount());
[email protected]1eb175082010-02-10 09:26:16167}
168
[email protected]6b75d79b0f92013-05-16 17:37:05169// Flaky, http://crbug.com/241191.
Alex Moshchukb4cf29e2017-09-12 17:00:11170IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, DISABLED_CloseAndReload) {
[email protected]ca975942014-01-07 12:06:47171 const size_t count_before = GetEnabledExtensionCount();
172 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]1eb175082010-02-10 09:26:16173 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46174 CrashExtension(first_extension_id_);
[email protected]2c4fb7b2011-04-02 06:33:29175
[email protected]ca975942014-01-07 12:06:47176 ASSERT_EQ(count_before, GetEnabledExtensionCount());
177 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]bb7f40952011-01-13 00:21:20178
Evan Stadebde440902018-01-26 20:10:34179 // In 2013, when this test became flaky, this line was part of the test.
180 // CancelNotification() no longer exists.
181 // ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
[email protected]ee8abdeb2010-03-10 11:02:32182 ReloadExtension(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16183
184 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46185 CheckExtensionConsistency(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47186 ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount());
[email protected]1eb175082010-02-10 09:26:16187}
188
Francois Dorayc3007a72018-06-14 13:10:17189// Flaky. crbug.com/846172
190#if defined(OS_LINUX) || defined(OS_WIN)
191#define MAYBE_ReloadIndependently DISABLED_ReloadIndependently
192#else
193#define MAYBE_ReloadIndependently ReloadIndependently
194#endif
Alex Moshchukb4cf29e2017-09-12 17:00:11195IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) {
[email protected]ca975942014-01-07 12:06:47196 const size_t count_before = GetEnabledExtensionCount();
[email protected]1eb175082010-02-10 09:26:16197 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46198 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47199 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]1eb175082010-02-10 09:26:16200
[email protected]ee8abdeb2010-03-10 11:02:32201 ReloadExtension(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16202
203 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46204 CheckExtensionConsistency(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16205
[email protected]47ae23372013-01-29 01:50:48206 WebContents* current_tab =
207 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]1eb175082010-02-10 09:26:16208 ASSERT_TRUE(current_tab);
209
[email protected]2c4fb7b2011-04-02 06:33:29210 // The balloon should automatically hide after the extension is successfully
[email protected]1eb175082010-02-10 09:26:16211 // reloaded.
Evan Stadebde440902018-01-26 20:10:34212 ASSERT_EQ(0U, CountNotifications());
[email protected]1eb175082010-02-10 09:26:16213}
[email protected]ee8abdeb2010-03-10 11:02:32214
Yuta Kitamura335109f2018-05-24 07:50:41215// Flaky. crbug.com/846172
Francois Dorayc3007a72018-06-14 13:10:17216#if defined(OS_LINUX) || defined(OS_WIN)
Yuta Kitamura335109f2018-05-24 07:50:41217#define MAYBE_ReloadIndependentlyChangeTabs \
218 DISABLED_ReloadIndependentlyChangeTabs
219#else
220#define MAYBE_ReloadIndependentlyChangeTabs ReloadIndependentlyChangeTabs
221#endif
Alex Moshchukb4cf29e2017-09-12 17:00:11222IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
Adithya Srinivasana7ed9ba2018-05-29 18:46:40223 MAYBE_ReloadIndependentlyChangeTabs) {
[email protected]ca975942014-01-07 12:06:47224 const size_t count_before = GetEnabledExtensionCount();
[email protected]ed56a7a02010-12-22 21:15:13225 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46226 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47227 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ed56a7a02010-12-22 21:15:13228
[email protected]47ae23372013-01-29 01:50:48229 WebContents* original_tab =
230 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed56a7a02010-12-22 21:15:13231 ASSERT_TRUE(original_tab);
Evan Stadebde440902018-01-26 20:10:34232 ASSERT_EQ(1U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13233
[email protected]2c4fb7b2011-04-02 06:33:29234 // Open a new tab, but the balloon will still be there.
[email protected]a37d4b02012-06-25 21:56:10235 chrome::NewTab(browser());
[email protected]47ae23372013-01-29 01:50:48236 WebContents* new_current_tab =
237 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed56a7a02010-12-22 21:15:13238 ASSERT_TRUE(new_current_tab);
239 ASSERT_NE(new_current_tab, original_tab);
Evan Stadebde440902018-01-26 20:10:34240 ASSERT_EQ(1U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13241
242 ReloadExtension(first_extension_id_);
243
244 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46245 CheckExtensionConsistency(first_extension_id_);
[email protected]ed56a7a02010-12-22 21:15:13246
[email protected]2c4fb7b2011-04-02 06:33:29247 // The balloon should automatically hide after the extension is successfully
[email protected]ed56a7a02010-12-22 21:15:13248 // reloaded.
Evan Stadebde440902018-01-26 20:10:34249 ASSERT_EQ(0U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13250}
251
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56252// Flaky on ASAN builds (https://crbug.com/997634)
253#if defined(ADDRESS_SANITIZER)
254#define MAYBE_ReloadIndependentlyNavigatePage \
255 DISABLED_ReloadIndependentlyNavigatePage
256#else
257#define MAYBE_ReloadIndependentlyNavigatePage ReloadIndependentlyNavigatePage
258#endif
Alex Moshchukb4cf29e2017-09-12 17:00:11259IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56260 MAYBE_ReloadIndependentlyNavigatePage) {
[email protected]ca975942014-01-07 12:06:47261 const size_t count_before = GetEnabledExtensionCount();
[email protected]ed56a7a02010-12-22 21:15:13262 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46263 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47264 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ed56a7a02010-12-22 21:15:13265
[email protected]47ae23372013-01-29 01:50:48266 WebContents* current_tab =
267 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed56a7a02010-12-22 21:15:13268 ASSERT_TRUE(current_tab);
Evan Stadebde440902018-01-26 20:10:34269 ASSERT_EQ(1U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13270
271 // Navigate to another page.
[email protected]650b2d52013-02-10 03:41:45272 ui_test_utils::NavigateToURL(
273 browser(), ui_test_utils::GetTestUrl(
274 base::FilePath(base::FilePath::kCurrentDirectory),
275 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
Evan Stadebde440902018-01-26 20:10:34276 ASSERT_EQ(1U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13277
278 ReloadExtension(first_extension_id_);
279
280 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46281 CheckExtensionConsistency(first_extension_id_);
[email protected]ed56a7a02010-12-22 21:15:13282
[email protected]1a6273b72011-04-23 00:50:55283 // The balloon should automatically hide after the extension is successfully
[email protected]ed56a7a02010-12-22 21:15:13284 // reloaded.
Evan Stadebde440902018-01-26 20:10:34285 ASSERT_EQ(0U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13286}
287
Alex Moshchukb4cf29e2017-09-12 17:00:11288IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ShutdownWhileCrashed) {
[email protected]ca975942014-01-07 12:06:47289 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32290 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46291 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47292 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32293}
294
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56295// Flaky on ASAN builds (https://crbug.com/997634)
296#if defined(ADDRESS_SANITIZER)
297#define MAYBE_TwoExtensionsCrashFirst DISABLED_TwoExtensionsCrashFirst
298#else
299#define MAYBE_TwoExtensionsCrashFirst TwoExtensionsCrashFirst
300#endif
301IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
302 MAYBE_TwoExtensionsCrashFirst) {
[email protected]ca975942014-01-07 12:06:47303 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32304 LoadTestExtension();
305 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46306 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47307 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
Evan Stadebde440902018-01-26 20:10:34308 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
[email protected]ee8abdeb2010-03-10 11:02:32309
[email protected]2c4fb7b2011-04-02 06:33:29310 SCOPED_TRACE("after clicking the balloon");
[email protected]84df8332011-12-06 18:22:46311 CheckExtensionConsistency(first_extension_id_);
312 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32313}
314
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56315// Flaky on ASAN builds (https://crbug.com/997634)
316#if defined(ADDRESS_SANITIZER)
317#define MAYBE_TwoExtensionsCrashSecond DISABLED_TwoExtensionsCrashSecond
318#else
319#define MAYBE_TwoExtensionsCrashSecond TwoExtensionsCrashSecond
320#endif
321IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
322 MAYBE_TwoExtensionsCrashSecond) {
[email protected]ca975942014-01-07 12:06:47323 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32324 LoadTestExtension();
325 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46326 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47327 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
Evan Stadebde440902018-01-26 20:10:34328 ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
[email protected]ee8abdeb2010-03-10 11:02:32329
[email protected]2c4fb7b2011-04-02 06:33:29330 SCOPED_TRACE("after clicking the balloon");
[email protected]84df8332011-12-06 18:22:46331 CheckExtensionConsistency(first_extension_id_);
332 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32333}
334
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56335// Flaky on ASAN builds (https://crbug.com/997634)
336#if defined(ADDRESS_SANITIZER)
337#define MAYBE_TwoExtensionsCrashBothAtOnce DISABLED_TwoExtensionsCrashBothAtOnce
338#else
339#define MAYBE_TwoExtensionsCrashBothAtOnce TwoExtensionsCrashBothAtOnce
340#endif
Alex Moshchukb4cf29e2017-09-12 17:00:11341IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56342 MAYBE_TwoExtensionsCrashBothAtOnce) {
[email protected]ca975942014-01-07 12:06:47343 const size_t count_before = GetEnabledExtensionCount();
344 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32345 LoadTestExtension();
346 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46347 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47348 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
349 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]84df8332011-12-06 18:22:46350 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47351 ASSERT_EQ(count_before, GetEnabledExtensionCount());
352 ASSERT_EQ(crash_count_before + 2, GetTerminatedExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32353
354 {
[email protected]2c4fb7b2011-04-02 06:33:29355 SCOPED_TRACE("first balloon");
Evan Stadebde440902018-01-26 20:10:34356 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
[email protected]84df8332011-12-06 18:22:46357 CheckExtensionConsistency(first_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32358 }
359
360 {
[email protected]2c4fb7b2011-04-02 06:33:29361 SCOPED_TRACE("second balloon");
Evan Stadebde440902018-01-26 20:10:34362 ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
[email protected]84df8332011-12-06 18:22:46363 CheckExtensionConsistency(first_extension_id_);
364 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32365 }
366}
367
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56368// Flaky on ASAN builds (https://crbug.com/997634)
369#if defined(ADDRESS_SANITIZER)
370#define MAYBE_TwoExtensionsOneByOne DISABLED_TwoExtensionsOneByOne
371#else
372#define MAYBE_TwoExtensionsOneByOne TwoExtensionsOneByOne
373#endif
374IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
375 MAYBE_TwoExtensionsOneByOne) {
[email protected]ca975942014-01-07 12:06:47376 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32377 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46378 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47379 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32380 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46381 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47382 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32383
384 {
[email protected]2c4fb7b2011-04-02 06:33:29385 SCOPED_TRACE("first balloon");
Evan Stadebde440902018-01-26 20:10:34386 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
[email protected]84df8332011-12-06 18:22:46387 CheckExtensionConsistency(first_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32388 }
389
390 {
[email protected]2c4fb7b2011-04-02 06:33:29391 SCOPED_TRACE("second balloon");
Evan Stadebde440902018-01-26 20:10:34392 ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
[email protected]84df8332011-12-06 18:22:46393 CheckExtensionConsistency(first_extension_id_);
394 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32395 }
396}
397
398// Make sure that when we don't do anything about the crashed extensions
399// and close the browser, it doesn't crash. The browser is closed implicitly
400// at the end of each browser test.
Alex Moshchukb4cf29e2017-09-12 17:00:11401IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
402 TwoExtensionsShutdownWhileCrashed) {
[email protected]ca975942014-01-07 12:06:47403 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32404 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46405 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47406 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32407 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46408 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47409 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32410}
411
[email protected]bd099412013-05-17 04:20:16412// Flaky, http://crbug.com/241573.
Alex Moshchukb4cf29e2017-09-12 17:00:11413IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
[email protected]bd099412013-05-17 04:20:16414 DISABLED_TwoExtensionsIgnoreFirst) {
[email protected]ca975942014-01-07 12:06:47415 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32416 LoadTestExtension();
417 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46418 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47419 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
[email protected]84df8332011-12-06 18:22:46420 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47421 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32422
[email protected]ede5e61a2011-12-03 01:05:31423 // Accept notification 1 before canceling notification 0.
424 // Otherwise, on Linux and Windows, there is a race here, in which
425 // canceled notifications do not immediately go away.
Evan Stadebde440902018-01-26 20:10:34426 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
427 // In 2013, when this test became flaky, these lines were part of the test.
428 // CancelNotification() no longer exists.
429 // ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
[email protected]ee8abdeb2010-03-10 11:02:32430
[email protected]2c4fb7b2011-04-02 06:33:29431 SCOPED_TRACE("balloons done");
[email protected]ca975942014-01-07 12:06:47432 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
[email protected]84df8332011-12-06 18:22:46433 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32434}
435
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56436// Flaky on ASAN builds (https://crbug.com/997634)
437#if defined(ADDRESS_SANITIZER)
438#define MAYBE_TwoExtensionsReloadIndependently \
439 DISABLED_TwoExtensionsReloadIndependently
440#else
441#define MAYBE_TwoExtensionsReloadIndependently TwoExtensionsReloadIndependently
442#endif
Alex Moshchukb4cf29e2017-09-12 17:00:11443IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
Marijn Kruisselbrink585d8e3e2019-08-26 18:44:56444 MAYBE_TwoExtensionsReloadIndependently) {
[email protected]ca975942014-01-07 12:06:47445 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32446 LoadTestExtension();
447 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46448 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47449 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
[email protected]84df8332011-12-06 18:22:46450 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47451 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32452
453 {
454 SCOPED_TRACE("first: reload");
[email protected]47ae23372013-01-29 01:50:48455 WebContents* current_tab =
456 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ee8abdeb2010-03-10 11:02:32457 ASSERT_TRUE(current_tab);
[email protected]1a6273b72011-04-23 00:50:55458 // At the beginning we should have one balloon displayed for each extension.
Evan Stadebde440902018-01-26 20:10:34459 ASSERT_EQ(2U, CountNotifications());
[email protected]ee8abdeb2010-03-10 11:02:32460 ReloadExtension(first_extension_id_);
[email protected]1a6273b72011-04-23 00:50:55461 // One of the balloons should hide after the extension is reloaded.
Evan Stadebde440902018-01-26 20:10:34462 ASSERT_EQ(1U, CountNotifications());
[email protected]84df8332011-12-06 18:22:46463 CheckExtensionConsistency(first_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32464 }
465
466 {
[email protected]2c4fb7b2011-04-02 06:33:29467 SCOPED_TRACE("second: balloon");
Evan Stadebde440902018-01-26 20:10:34468 ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
[email protected]84df8332011-12-06 18:22:46469 CheckExtensionConsistency(first_extension_id_);
470 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32471 }
472}
[email protected]bb7f40952011-01-13 00:21:20473
Alex Moshchukb4cf29e2017-09-12 17:00:11474IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) {
[email protected]ca975942014-01-07 12:06:47475 const size_t count_before = GetEnabledExtensionCount();
476 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]0dfe05c2011-02-23 23:03:36477 LoadTestExtension();
478 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46479 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47480 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
481 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]0dfe05c2011-02-23 23:03:36482
Evan Stadebde440902018-01-26 20:10:34483 ASSERT_EQ(1U, CountNotifications());
[email protected]0dfe05c2011-02-23 23:03:36484 UninstallExtension(first_extension_id_);
fdorayfd4c7ba2016-06-10 17:44:36485 base::RunLoop().RunUntilIdle();
[email protected]0dfe05c2011-02-23 23:03:36486
487 SCOPED_TRACE("after uninstalling");
[email protected]ca975942014-01-07 12:06:47488 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
489 ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount());
Evan Stadebde440902018-01-26 20:10:34490 ASSERT_EQ(0U, CountNotifications());
[email protected]0dfe05c2011-02-23 23:03:36491}
492
Alex Moshchukb4cf29e2017-09-12 17:00:11493IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUnloadAll) {
[email protected]ca975942014-01-07 12:06:47494 const size_t count_before = GetEnabledExtensionCount();
495 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]bb7f40952011-01-13 00:21:20496 LoadTestExtension();
497 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46498 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47499 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
500 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]bb7f40952011-01-13 00:21:20501
[email protected]bb1bc9b32013-12-21 03:09:14502 GetExtensionService()->UnloadAllExtensionsForTest();
[email protected]ca975942014-01-07 12:06:47503 ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount());
[email protected]bb7f40952011-01-13 00:21:20504}
[email protected]b3f7fe22011-11-11 19:27:56505
506// Test that when an extension with a background page that has a tab open
507// crashes, the tab stays open, and reloading it reloads the extension.
Alex Moshchukb4cf29e2017-09-12 17:00:11508// Regression test for issue 71629 and 763808.
509IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
Lukasz Anforowiczfb1ccf02018-04-21 14:55:20510 ReloadTabsWithBackgroundPage) {
511 // TODO(https://crbug.com/831078): Fix the test.
512 if (content::AreAllSitesIsolatedForTesting())
513 return;
514
[email protected]c0849252012-05-12 13:51:27515 TabStripModel* tab_strip = browser()->tab_strip_model();
[email protected]ca975942014-01-07 12:06:47516 const size_t count_before = GetEnabledExtensionCount();
517 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]b3f7fe22011-11-11 19:27:56518 LoadTestExtension();
519
520 // Open a tab extension.
[email protected]a37d4b02012-06-25 21:56:10521 chrome::NewTab(browser());
[email protected]99bee642014-05-31 22:36:43522 ui_test_utils::NavigateToURL(browser(),
523 GURL(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24524 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43525 first_extension_id_ + "/background.html"));
[email protected]b3f7fe22011-11-11 19:27:56526
527 const int tabs_before = tab_strip->count();
[email protected]84df8332011-12-06 18:22:46528 CrashExtension(first_extension_id_);
[email protected]b3f7fe22011-11-11 19:27:56529
530 // Tab should still be open, and extension should be crashed.
531 EXPECT_EQ(tabs_before, tab_strip->count());
[email protected]ca975942014-01-07 12:06:47532 EXPECT_EQ(count_before, GetEnabledExtensionCount());
533 EXPECT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]b3f7fe22011-11-11 19:27:56534
Evan Stadebde440902018-01-26 20:10:34535 extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry());
[email protected]b3f7fe22011-11-11 19:27:56536 {
[email protected]a7fe9112012-07-20 02:34:45537 content::WindowedNotificationObserver observer(
[email protected]b3f7fe22011-11-11 19:27:56538 content::NOTIFICATION_LOAD_STOP,
Evan Stadebde440902018-01-26 20:10:34539 content::Source<NavigationController>(&browser()
540 ->tab_strip_model()
541 ->GetActiveWebContents()
542 ->GetController()));
nick3b04f322016-08-31 19:29:19543 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
[email protected]b3f7fe22011-11-11 19:27:56544 observer.Wait();
545 }
Evan Stadebde440902018-01-26 20:10:34546 auto* extension = observer.WaitForExtensionLoaded();
547 EXPECT_EQ(first_extension_id_, extension->id());
548
[email protected]b3f7fe22011-11-11 19:27:56549 // Extension should now be loaded.
[email protected]84df8332011-12-06 18:22:46550 SCOPED_TRACE("after reloading the tab");
551 CheckExtensionConsistency(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47552 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
Evan Stadebde440902018-01-26 20:10:34553 ASSERT_EQ(0U, CountNotifications());
[email protected]b3f7fe22011-11-11 19:27:56554}