blob: 773ebd99e6bbc7e0c7b68e6b250e528c36b32cb8 [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"
[email protected]22401dc2014-03-21 01:38:5725#include "extensions/browser/extension_host.h"
[email protected]ca975942014-01-07 12:06:4726#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2427#include "extensions/browser/extension_system.h"
[email protected]98b6d942013-11-10 00:34:0728#include "extensions/browser/process_manager.h"
[email protected]fafdc842014-01-17 18:09:0829#include "extensions/browser/process_map.h"
limasdf184283c2017-04-14 08:22:1030#include "extensions/browser/test_extension_registry_observer.h"
[email protected]99bee642014-05-31 22:36:4331#include "extensions/common/constants.h"
emaxx895210ec2017-04-19 14:37:3032#include "extensions/test/background_page_watcher.h"
Evan Stade889ce4712018-01-28 15:26:2633#include "ui/message_center/public/cpp/notification.h"
34#include "ui/message_center/public/cpp/notification_delegate.h"
[email protected]6cd63ea2013-03-07 18:17:0435
[email protected]c5eed492012-01-04 17:07:5036using content::NavigationController;
[email protected]4ca15302012-01-03 05:53:2037using content::WebContents;
[email protected]1c321ee52012-05-21 03:02:3438using extensions::Extension;
[email protected]ca975942014-01-07 12:06:4739using extensions::ExtensionRegistry;
[email protected]4ca15302012-01-03 05:53:2040
Evan Stadebde440902018-01-26 20:10:3441class ExtensionCrashRecoveryTest : public ExtensionBrowserTest {
[email protected]1eb175082010-02-10 09:26:1642 protected:
Evan Stadebde440902018-01-26 20:10:3443 void SetUpOnMainThread() override {
44 ExtensionBrowserTest::SetUpOnMainThread();
45 display_service_ =
46 std::make_unique<NotificationDisplayServiceTester>(profile());
47 }
[email protected]6cd63ea2013-03-07 18:17:0448
[email protected]eaa7dd182010-12-14 11:09:0049 ExtensionService* GetExtensionService() {
[email protected]03d25812014-06-22 19:41:5550 return extensions::ExtensionSystem::Get(browser()->profile())->
51 extension_service();
[email protected]1eb175082010-02-10 09:26:1652 }
53
[email protected]98b6d942013-11-10 00:34:0754 extensions::ProcessManager* GetProcessManager() {
reillyg0ea3fa902014-10-28 15:30:2355 return extensions::ProcessManager::Get(browser()->profile());
[email protected]1eb175082010-02-10 09:26:1656 }
57
[email protected]0bb29bd2014-04-30 21:39:1858 ExtensionRegistry* GetExtensionRegistry() {
59 return ExtensionRegistry::Get(browser()->profile());
60 }
61
[email protected]ca975942014-01-07 12:06:4762 size_t GetEnabledExtensionCount() {
[email protected]0bb29bd2014-04-30 21:39:1863 return GetExtensionRegistry()->enabled_extensions().size();
[email protected]ca975942014-01-07 12:06:4764 }
65
66 size_t GetTerminatedExtensionCount() {
[email protected]0bb29bd2014-04-30 21:39:1867 return GetExtensionRegistry()->terminated_extensions().size();
[email protected]ca975942014-01-07 12:06:4768 }
69
[email protected]0bb29bd2014-04-30 21:39:1870 void CrashExtension(const std::string& extension_id) {
71 const Extension* extension = GetExtensionRegistry()->GetExtensionById(
72 extension_id, ExtensionRegistry::ENABLED);
[email protected]1eb175082010-02-10 09:26:1673 ASSERT_TRUE(extension);
[email protected]98b6d942013-11-10 00:34:0774 extensions::ExtensionHost* extension_host = GetProcessManager()->
[email protected]06024c62011-10-20 20:57:1275 GetBackgroundHostForExtension(extension_id);
[email protected]1eb175082010-02-10 09:26:1676 ASSERT_TRUE(extension_host);
77
Wez0abfbf512018-03-03 01:54:4578 extension_host->render_process_host()->Shutdown(
79 content::RESULT_CODE_KILLED);
[email protected]ee8abdeb2010-03-10 11:02:3280 ASSERT_TRUE(WaitForExtensionCrash(extension_id));
[email protected]98b6d942013-11-10 00:34:0781 ASSERT_FALSE(GetProcessManager()->
[email protected]06024c62011-10-20 20:57:1282 GetBackgroundHostForExtension(extension_id));
[email protected]260122c2013-05-22 15:05:5583
84 // Wait for extension crash balloon to appear.
fdorayfd4c7ba2016-06-10 17:44:3685 base::RunLoop().RunUntilIdle();
[email protected]1eb175082010-02-10 09:26:1686 }
87
[email protected]0bb29bd2014-04-30 21:39:1888 void CheckExtensionConsistency(const std::string& extension_id) {
89 const Extension* extension = GetExtensionRegistry()->GetExtensionById(
90 extension_id, ExtensionRegistry::ENABLED);
[email protected]1eb175082010-02-10 09:26:1691 ASSERT_TRUE(extension);
[email protected]98b6d942013-11-10 00:34:0792 extensions::ExtensionHost* extension_host = GetProcessManager()->
[email protected]84df8332011-12-06 18:22:4693 GetBackgroundHostForExtension(extension_id);
[email protected]1eb175082010-02-10 09:26:1694 ASSERT_TRUE(extension_host);
rdevlin.cronin6ae04a012015-04-03 20:19:4095 extensions::ProcessManager::FrameSet frames =
96 GetProcessManager()->GetAllFrames();
97 ASSERT_NE(frames.end(),
98 frames.find(extension_host->host_contents()->GetMainFrame()));
99 ASSERT_FALSE(GetProcessManager()->GetAllFrames().empty());
[email protected]1eb175082010-02-10 09:26:16100 ASSERT_TRUE(extension_host->IsRenderViewLive());
[email protected]6f371442011-11-09 06:45:46101 extensions::ProcessMap* process_map =
[email protected]fafdc842014-01-17 18:09:08102 extensions::ProcessMap::Get(browser()->profile());
[email protected]6f371442011-11-09 06:45:46103 ASSERT_TRUE(process_map->Contains(
[email protected]9f76c1e2012-03-05 15:15:58104 extension_id,
105 extension_host->render_view_host()->GetProcess()->GetID()));
[email protected]1eb175082010-02-10 09:26:16106 }
107
108 void LoadTestExtension() {
109 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
[email protected]84df8332011-12-06 18:22:46110 const Extension* extension = LoadExtension(
111 test_data_dir_.AppendASCII("common").AppendASCII("background_page"));
[email protected]1eb175082010-02-10 09:26:16112 ASSERT_TRUE(extension);
[email protected]ee8abdeb2010-03-10 11:02:32113 first_extension_id_ = extension->id();
[email protected]84df8332011-12-06 18:22:46114 CheckExtensionConsistency(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16115 }
116
[email protected]ee8abdeb2010-03-10 11:02:32117 void LoadSecondExtension() {
[email protected]84df8332011-12-06 18:22:46118 const Extension* extension = LoadExtension(
119 test_data_dir_.AppendASCII("install").AppendASCII("install"));
[email protected]ee8abdeb2010-03-10 11:02:32120 ASSERT_TRUE(extension);
121 second_extension_id_ = extension->id();
[email protected]84df8332011-12-06 18:22:46122 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32123 }
124
Evan Stadebde440902018-01-26 20:10:34125 void AcceptNotification(const std::string& extension_id) {
limasdf184283c2017-04-14 08:22:10126 extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry());
Evan Stadebde440902018-01-26 20:10:34127 display_service_->SimulateClick(NotificationHandler::Type::TRANSIENT,
128 "app.background.crashed." + extension_id,
129 base::nullopt, base::nullopt);
limasdf184283c2017-04-14 08:22:10130 auto* extension = observer.WaitForExtensionLoaded();
131 extensions::BackgroundPageWatcher(GetProcessManager(), extension)
132 .WaitForOpen();
[email protected]6cd63ea2013-03-07 18:17:04133 }
134
Evan Stadebde440902018-01-26 20:10:34135 size_t CountNotifications() {
136 return display_service_
137 ->GetDisplayedNotificationsForType(NotificationHandler::Type::TRANSIENT)
138 .size();
[email protected]6cd63ea2013-03-07 18:17:04139 }
140
Evan Stadebde440902018-01-26 20:10:34141 std::string first_extension_id_;
142 std::string second_extension_id_;
143 std::unique_ptr<NotificationDisplayServiceTester> display_service_;
[email protected]9a224572013-05-12 23:08:56144};
[email protected]bce52eaa2013-05-11 19:23:21145
Alex Moshchukb4cf29e2017-09-12 17:00:11146IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) {
[email protected]ca975942014-01-07 12:06:47147 const size_t count_before = GetEnabledExtensionCount();
148 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]1eb175082010-02-10 09:26:16149 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46150 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47151 ASSERT_EQ(count_before, GetEnabledExtensionCount());
152 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
Evan Stadebde440902018-01-26 20:10:34153 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
[email protected]1eb175082010-02-10 09:26:16154
[email protected]2c4fb7b2011-04-02 06:33:29155 SCOPED_TRACE("after clicking the balloon");
[email protected]84df8332011-12-06 18:22:46156 CheckExtensionConsistency(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47157 ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount());
[email protected]1eb175082010-02-10 09:26:16158}
159
[email protected]6b75d79b0f92013-05-16 17:37:05160// Flaky, http://crbug.com/241191.
Alex Moshchukb4cf29e2017-09-12 17:00:11161IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, DISABLED_CloseAndReload) {
[email protected]ca975942014-01-07 12:06:47162 const size_t count_before = GetEnabledExtensionCount();
163 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]1eb175082010-02-10 09:26:16164 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46165 CrashExtension(first_extension_id_);
[email protected]2c4fb7b2011-04-02 06:33:29166
[email protected]ca975942014-01-07 12:06:47167 ASSERT_EQ(count_before, GetEnabledExtensionCount());
168 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]bb7f40952011-01-13 00:21:20169
Evan Stadebde440902018-01-26 20:10:34170 // In 2013, when this test became flaky, this line was part of the test.
171 // CancelNotification() no longer exists.
172 // ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
[email protected]ee8abdeb2010-03-10 11:02:32173 ReloadExtension(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16174
175 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46176 CheckExtensionConsistency(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47177 ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount());
[email protected]1eb175082010-02-10 09:26:16178}
179
Alex Moshchukb4cf29e2017-09-12 17:00:11180IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) {
[email protected]ca975942014-01-07 12:06:47181 const size_t count_before = GetEnabledExtensionCount();
[email protected]1eb175082010-02-10 09:26:16182 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46183 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47184 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]1eb175082010-02-10 09:26:16185
[email protected]ee8abdeb2010-03-10 11:02:32186 ReloadExtension(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16187
188 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46189 CheckExtensionConsistency(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16190
[email protected]47ae23372013-01-29 01:50:48191 WebContents* current_tab =
192 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]1eb175082010-02-10 09:26:16193 ASSERT_TRUE(current_tab);
194
[email protected]2c4fb7b2011-04-02 06:33:29195 // The balloon should automatically hide after the extension is successfully
[email protected]1eb175082010-02-10 09:26:16196 // reloaded.
Evan Stadebde440902018-01-26 20:10:34197 ASSERT_EQ(0U, CountNotifications());
[email protected]1eb175082010-02-10 09:26:16198}
[email protected]ee8abdeb2010-03-10 11:02:32199
Alex Moshchukb4cf29e2017-09-12 17:00:11200IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
201 ReloadIndependentlyChangeTabs) {
[email protected]ca975942014-01-07 12:06:47202 const size_t count_before = GetEnabledExtensionCount();
[email protected]ed56a7a02010-12-22 21:15:13203 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46204 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47205 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ed56a7a02010-12-22 21:15:13206
[email protected]47ae23372013-01-29 01:50:48207 WebContents* original_tab =
208 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed56a7a02010-12-22 21:15:13209 ASSERT_TRUE(original_tab);
Evan Stadebde440902018-01-26 20:10:34210 ASSERT_EQ(1U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13211
[email protected]2c4fb7b2011-04-02 06:33:29212 // Open a new tab, but the balloon will still be there.
[email protected]a37d4b02012-06-25 21:56:10213 chrome::NewTab(browser());
[email protected]47ae23372013-01-29 01:50:48214 WebContents* new_current_tab =
215 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed56a7a02010-12-22 21:15:13216 ASSERT_TRUE(new_current_tab);
217 ASSERT_NE(new_current_tab, original_tab);
Evan Stadebde440902018-01-26 20:10:34218 ASSERT_EQ(1U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13219
220 ReloadExtension(first_extension_id_);
221
222 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46223 CheckExtensionConsistency(first_extension_id_);
[email protected]ed56a7a02010-12-22 21:15:13224
[email protected]2c4fb7b2011-04-02 06:33:29225 // The balloon should automatically hide after the extension is successfully
[email protected]ed56a7a02010-12-22 21:15:13226 // reloaded.
Evan Stadebde440902018-01-26 20:10:34227 ASSERT_EQ(0U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13228}
229
Alex Moshchukb4cf29e2017-09-12 17:00:11230IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
231 ReloadIndependentlyNavigatePage) {
[email protected]ca975942014-01-07 12:06:47232 const size_t count_before = GetEnabledExtensionCount();
[email protected]ed56a7a02010-12-22 21:15:13233 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46234 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47235 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ed56a7a02010-12-22 21:15:13236
[email protected]47ae23372013-01-29 01:50:48237 WebContents* current_tab =
238 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed56a7a02010-12-22 21:15:13239 ASSERT_TRUE(current_tab);
Evan Stadebde440902018-01-26 20:10:34240 ASSERT_EQ(1U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13241
242 // Navigate to another page.
[email protected]650b2d52013-02-10 03:41:45243 ui_test_utils::NavigateToURL(
244 browser(), ui_test_utils::GetTestUrl(
245 base::FilePath(base::FilePath::kCurrentDirectory),
246 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
Evan Stadebde440902018-01-26 20:10:34247 ASSERT_EQ(1U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13248
249 ReloadExtension(first_extension_id_);
250
251 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46252 CheckExtensionConsistency(first_extension_id_);
[email protected]ed56a7a02010-12-22 21:15:13253
[email protected]1a6273b72011-04-23 00:50:55254 // The balloon should automatically hide after the extension is successfully
[email protected]ed56a7a02010-12-22 21:15:13255 // reloaded.
Evan Stadebde440902018-01-26 20:10:34256 ASSERT_EQ(0U, CountNotifications());
[email protected]ed56a7a02010-12-22 21:15:13257}
258
Alex Moshchukb4cf29e2017-09-12 17:00:11259IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ShutdownWhileCrashed) {
[email protected]ca975942014-01-07 12:06:47260 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32261 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46262 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47263 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32264}
265
Alex Moshchukb4cf29e2017-09-12 17:00:11266IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) {
[email protected]ca975942014-01-07 12:06:47267 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32268 LoadTestExtension();
269 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46270 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47271 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
Evan Stadebde440902018-01-26 20:10:34272 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
[email protected]ee8abdeb2010-03-10 11:02:32273
[email protected]2c4fb7b2011-04-02 06:33:29274 SCOPED_TRACE("after clicking the balloon");
[email protected]84df8332011-12-06 18:22:46275 CheckExtensionConsistency(first_extension_id_);
276 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32277}
278
Alex Moshchukb4cf29e2017-09-12 17:00:11279IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) {
[email protected]ca975942014-01-07 12:06:47280 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32281 LoadTestExtension();
282 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46283 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47284 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
Evan Stadebde440902018-01-26 20:10:34285 ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
[email protected]ee8abdeb2010-03-10 11:02:32286
[email protected]2c4fb7b2011-04-02 06:33:29287 SCOPED_TRACE("after clicking the balloon");
[email protected]84df8332011-12-06 18:22:46288 CheckExtensionConsistency(first_extension_id_);
289 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32290}
291
Alex Moshchukb4cf29e2017-09-12 17:00:11292IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
[email protected]ee8abdeb2010-03-10 11:02:32293 TwoExtensionsCrashBothAtOnce) {
[email protected]ca975942014-01-07 12:06:47294 const size_t count_before = GetEnabledExtensionCount();
295 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32296 LoadTestExtension();
297 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46298 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47299 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
300 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]84df8332011-12-06 18:22:46301 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47302 ASSERT_EQ(count_before, GetEnabledExtensionCount());
303 ASSERT_EQ(crash_count_before + 2, GetTerminatedExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32304
305 {
[email protected]2c4fb7b2011-04-02 06:33:29306 SCOPED_TRACE("first balloon");
Evan Stadebde440902018-01-26 20:10:34307 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
[email protected]84df8332011-12-06 18:22:46308 CheckExtensionConsistency(first_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32309 }
310
311 {
[email protected]2c4fb7b2011-04-02 06:33:29312 SCOPED_TRACE("second balloon");
Evan Stadebde440902018-01-26 20:10:34313 ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
[email protected]84df8332011-12-06 18:22:46314 CheckExtensionConsistency(first_extension_id_);
315 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32316 }
317}
318
Alex Moshchukb4cf29e2017-09-12 17:00:11319IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) {
[email protected]ca975942014-01-07 12:06:47320 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32321 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46322 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47323 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32324 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46325 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47326 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32327
328 {
[email protected]2c4fb7b2011-04-02 06:33:29329 SCOPED_TRACE("first balloon");
Evan Stadebde440902018-01-26 20:10:34330 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
[email protected]84df8332011-12-06 18:22:46331 CheckExtensionConsistency(first_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32332 }
333
334 {
[email protected]2c4fb7b2011-04-02 06:33:29335 SCOPED_TRACE("second balloon");
Evan Stadebde440902018-01-26 20:10:34336 ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
[email protected]84df8332011-12-06 18:22:46337 CheckExtensionConsistency(first_extension_id_);
338 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32339 }
340}
341
342// Make sure that when we don't do anything about the crashed extensions
343// and close the browser, it doesn't crash. The browser is closed implicitly
344// at the end of each browser test.
Alex Moshchukb4cf29e2017-09-12 17:00:11345IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
346 TwoExtensionsShutdownWhileCrashed) {
[email protected]ca975942014-01-07 12:06:47347 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32348 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46349 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47350 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32351 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46352 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47353 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32354}
355
[email protected]bd099412013-05-17 04:20:16356// Flaky, http://crbug.com/241573.
Alex Moshchukb4cf29e2017-09-12 17:00:11357IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
[email protected]bd099412013-05-17 04:20:16358 DISABLED_TwoExtensionsIgnoreFirst) {
[email protected]ca975942014-01-07 12:06:47359 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32360 LoadTestExtension();
361 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46362 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47363 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
[email protected]84df8332011-12-06 18:22:46364 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47365 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32366
[email protected]ede5e61a2011-12-03 01:05:31367 // Accept notification 1 before canceling notification 0.
368 // Otherwise, on Linux and Windows, there is a race here, in which
369 // canceled notifications do not immediately go away.
Evan Stadebde440902018-01-26 20:10:34370 ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
371 // In 2013, when this test became flaky, these lines were part of the test.
372 // CancelNotification() no longer exists.
373 // ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
[email protected]ee8abdeb2010-03-10 11:02:32374
[email protected]2c4fb7b2011-04-02 06:33:29375 SCOPED_TRACE("balloons done");
[email protected]ca975942014-01-07 12:06:47376 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
[email protected]84df8332011-12-06 18:22:46377 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32378}
379
Alex Moshchukb4cf29e2017-09-12 17:00:11380IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
381 TwoExtensionsReloadIndependently) {
[email protected]ca975942014-01-07 12:06:47382 const size_t count_before = GetEnabledExtensionCount();
[email protected]ee8abdeb2010-03-10 11:02:32383 LoadTestExtension();
384 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46385 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47386 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
[email protected]84df8332011-12-06 18:22:46387 CrashExtension(second_extension_id_);
[email protected]ca975942014-01-07 12:06:47388 ASSERT_EQ(count_before, GetEnabledExtensionCount());
[email protected]ee8abdeb2010-03-10 11:02:32389
390 {
391 SCOPED_TRACE("first: reload");
[email protected]47ae23372013-01-29 01:50:48392 WebContents* current_tab =
393 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ee8abdeb2010-03-10 11:02:32394 ASSERT_TRUE(current_tab);
[email protected]1a6273b72011-04-23 00:50:55395 // At the beginning we should have one balloon displayed for each extension.
Evan Stadebde440902018-01-26 20:10:34396 ASSERT_EQ(2U, CountNotifications());
[email protected]ee8abdeb2010-03-10 11:02:32397 ReloadExtension(first_extension_id_);
[email protected]1a6273b72011-04-23 00:50:55398 // One of the balloons should hide after the extension is reloaded.
Evan Stadebde440902018-01-26 20:10:34399 ASSERT_EQ(1U, CountNotifications());
[email protected]84df8332011-12-06 18:22:46400 CheckExtensionConsistency(first_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32401 }
402
403 {
[email protected]2c4fb7b2011-04-02 06:33:29404 SCOPED_TRACE("second: balloon");
Evan Stadebde440902018-01-26 20:10:34405 ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
[email protected]84df8332011-12-06 18:22:46406 CheckExtensionConsistency(first_extension_id_);
407 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32408 }
409}
[email protected]bb7f40952011-01-13 00:21:20410
Alex Moshchukb4cf29e2017-09-12 17:00:11411IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) {
[email protected]ca975942014-01-07 12:06:47412 const size_t count_before = GetEnabledExtensionCount();
413 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]0dfe05c2011-02-23 23:03:36414 LoadTestExtension();
415 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46416 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47417 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
418 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]0dfe05c2011-02-23 23:03:36419
Evan Stadebde440902018-01-26 20:10:34420 ASSERT_EQ(1U, CountNotifications());
[email protected]0dfe05c2011-02-23 23:03:36421 UninstallExtension(first_extension_id_);
fdorayfd4c7ba2016-06-10 17:44:36422 base::RunLoop().RunUntilIdle();
[email protected]0dfe05c2011-02-23 23:03:36423
424 SCOPED_TRACE("after uninstalling");
[email protected]ca975942014-01-07 12:06:47425 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
426 ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount());
Evan Stadebde440902018-01-26 20:10:34427 ASSERT_EQ(0U, CountNotifications());
[email protected]0dfe05c2011-02-23 23:03:36428}
429
Alex Moshchukb4cf29e2017-09-12 17:00:11430IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUnloadAll) {
[email protected]ca975942014-01-07 12:06:47431 const size_t count_before = GetEnabledExtensionCount();
432 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]bb7f40952011-01-13 00:21:20433 LoadTestExtension();
434 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46435 CrashExtension(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47436 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
437 ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]bb7f40952011-01-13 00:21:20438
[email protected]bb1bc9b32013-12-21 03:09:14439 GetExtensionService()->UnloadAllExtensionsForTest();
[email protected]ca975942014-01-07 12:06:47440 ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount());
[email protected]bb7f40952011-01-13 00:21:20441}
[email protected]b3f7fe22011-11-11 19:27:56442
443// Test that when an extension with a background page that has a tab open
444// crashes, the tab stays open, and reloading it reloads the extension.
Alex Moshchukb4cf29e2017-09-12 17:00:11445// Regression test for issue 71629 and 763808.
446IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
447 ReloadTabsWithBackgroundPage) {
[email protected]c0849252012-05-12 13:51:27448 TabStripModel* tab_strip = browser()->tab_strip_model();
[email protected]ca975942014-01-07 12:06:47449 const size_t count_before = GetEnabledExtensionCount();
450 const size_t crash_count_before = GetTerminatedExtensionCount();
[email protected]b3f7fe22011-11-11 19:27:56451 LoadTestExtension();
452
453 // Open a tab extension.
[email protected]a37d4b02012-06-25 21:56:10454 chrome::NewTab(browser());
[email protected]99bee642014-05-31 22:36:43455 ui_test_utils::NavigateToURL(browser(),
456 GURL(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24457 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43458 first_extension_id_ + "/background.html"));
[email protected]b3f7fe22011-11-11 19:27:56459
460 const int tabs_before = tab_strip->count();
[email protected]84df8332011-12-06 18:22:46461 CrashExtension(first_extension_id_);
[email protected]b3f7fe22011-11-11 19:27:56462
463 // Tab should still be open, and extension should be crashed.
464 EXPECT_EQ(tabs_before, tab_strip->count());
[email protected]ca975942014-01-07 12:06:47465 EXPECT_EQ(count_before, GetEnabledExtensionCount());
466 EXPECT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
[email protected]b3f7fe22011-11-11 19:27:56467
Evan Stadebde440902018-01-26 20:10:34468 extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry());
[email protected]b3f7fe22011-11-11 19:27:56469 {
[email protected]a7fe9112012-07-20 02:34:45470 content::WindowedNotificationObserver observer(
[email protected]b3f7fe22011-11-11 19:27:56471 content::NOTIFICATION_LOAD_STOP,
Evan Stadebde440902018-01-26 20:10:34472 content::Source<NavigationController>(&browser()
473 ->tab_strip_model()
474 ->GetActiveWebContents()
475 ->GetController()));
nick3b04f322016-08-31 19:29:19476 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
[email protected]b3f7fe22011-11-11 19:27:56477 observer.Wait();
478 }
Evan Stadebde440902018-01-26 20:10:34479 auto* extension = observer.WaitForExtensionLoaded();
480 EXPECT_EQ(first_extension_id_, extension->id());
481
[email protected]b3f7fe22011-11-11 19:27:56482 // Extension should now be loaded.
[email protected]84df8332011-12-06 18:22:46483 SCOPED_TRACE("after reloading the tab");
484 CheckExtensionConsistency(first_extension_id_);
[email protected]ca975942014-01-07 12:06:47485 ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
Evan Stadebde440902018-01-26 20:10:34486 ASSERT_EQ(0U, CountNotifications());
[email protected]b3f7fe22011-11-11 19:27:56487}