[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | |
fdoray | fd4c7ba | 2016-06-10 17:44:36 | [diff] [blame] | 7 | #include "base/run_loop.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 8 | #include "build/build_config.h" |
[email protected] | 6cd63ea | 2013-03-07 18:17:04 | [diff] [blame] | 9 | #include "chrome/browser/browser_process.h" |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 10 | #include "chrome/browser/extensions/extension_browsertest.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_service.h" |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 12 | #include "chrome/browser/notifications/notification_display_service_tester.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 13 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 7b5dc00 | 2010-11-16 23:08:10 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | b56e2e3 | 2012-05-11 21:18:04 | [diff] [blame] | 16 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 17 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 18 | #include "content/public/browser/navigation_controller.h" |
steel | f65a72a | 2016-10-19 22:16:45 | [diff] [blame] | 19 | #include "content/public/browser/notification_types.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 20 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 21 | #include "content/public/browser/render_view_host.h" |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 22 | #include "content/public/browser/web_contents.h" |
[email protected] | b39ef1cb | 2011-10-25 04:46:55 | [diff] [blame] | 23 | #include "content/public/common/result_codes.h" |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 24 | #include "content/public/common/url_constants.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 25 | #include "extensions/browser/extension_host.h" |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 26 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 27 | #include "extensions/browser/extension_system.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 28 | #include "extensions/browser/process_manager.h" |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 29 | #include "extensions/browser/process_map.h" |
limasdf | 184283c | 2017-04-14 08:22:10 | [diff] [blame] | 30 | #include "extensions/browser/test_extension_registry_observer.h" |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 31 | #include "extensions/common/constants.h" |
emaxx | 895210ec | 2017-04-19 14:37:30 | [diff] [blame] | 32 | #include "extensions/test/background_page_watcher.h" |
Evan Stade | 889ce471 | 2018-01-28 15:26:26 | [diff] [blame] | 33 | #include "ui/message_center/public/cpp/notification.h" |
| 34 | #include "ui/message_center/public/cpp/notification_delegate.h" |
[email protected] | 6cd63ea | 2013-03-07 18:17:04 | [diff] [blame] | 35 | |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 36 | using content::NavigationController; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 37 | using content::WebContents; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 38 | using extensions::Extension; |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 39 | using extensions::ExtensionRegistry; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 40 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 41 | class ExtensionCrashRecoveryTest : public ExtensionBrowserTest { |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 42 | protected: |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 43 | void SetUpOnMainThread() override { |
| 44 | ExtensionBrowserTest::SetUpOnMainThread(); |
| 45 | display_service_ = |
| 46 | std::make_unique<NotificationDisplayServiceTester>(profile()); |
| 47 | } |
[email protected] | 6cd63ea | 2013-03-07 18:17:04 | [diff] [blame] | 48 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 49 | ExtensionService* GetExtensionService() { |
[email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 50 | return extensions::ExtensionSystem::Get(browser()->profile())-> |
| 51 | extension_service(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 52 | } |
| 53 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 54 | extensions::ProcessManager* GetProcessManager() { |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 55 | return extensions::ProcessManager::Get(browser()->profile()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 58 | ExtensionRegistry* GetExtensionRegistry() { |
| 59 | return ExtensionRegistry::Get(browser()->profile()); |
| 60 | } |
| 61 | |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 62 | size_t GetEnabledExtensionCount() { |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 63 | return GetExtensionRegistry()->enabled_extensions().size(); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | size_t GetTerminatedExtensionCount() { |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 67 | return GetExtensionRegistry()->terminated_extensions().size(); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 70 | void CrashExtension(const std::string& extension_id) { |
| 71 | const Extension* extension = GetExtensionRegistry()->GetExtensionById( |
| 72 | extension_id, ExtensionRegistry::ENABLED); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 73 | ASSERT_TRUE(extension); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 74 | extensions::ExtensionHost* extension_host = GetProcessManager()-> |
[email protected] | 06024c6 | 2011-10-20 20:57:12 | [diff] [blame] | 75 | GetBackgroundHostForExtension(extension_id); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 76 | ASSERT_TRUE(extension_host); |
| 77 | |
Wez | 0abfbf51 | 2018-03-03 01:54:45 | [diff] [blame^] | 78 | extension_host->render_process_host()->Shutdown( |
| 79 | content::RESULT_CODE_KILLED); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 80 | ASSERT_TRUE(WaitForExtensionCrash(extension_id)); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 81 | ASSERT_FALSE(GetProcessManager()-> |
[email protected] | 06024c6 | 2011-10-20 20:57:12 | [diff] [blame] | 82 | GetBackgroundHostForExtension(extension_id)); |
[email protected] | 260122c | 2013-05-22 15:05:55 | [diff] [blame] | 83 | |
| 84 | // Wait for extension crash balloon to appear. |
fdoray | fd4c7ba | 2016-06-10 17:44:36 | [diff] [blame] | 85 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 86 | } |
| 87 | |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 88 | void CheckExtensionConsistency(const std::string& extension_id) { |
| 89 | const Extension* extension = GetExtensionRegistry()->GetExtensionById( |
| 90 | extension_id, ExtensionRegistry::ENABLED); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 91 | ASSERT_TRUE(extension); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 92 | extensions::ExtensionHost* extension_host = GetProcessManager()-> |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 93 | GetBackgroundHostForExtension(extension_id); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 94 | ASSERT_TRUE(extension_host); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 95 | 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] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 100 | ASSERT_TRUE(extension_host->IsRenderViewLive()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 101 | extensions::ProcessMap* process_map = |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 102 | extensions::ProcessMap::Get(browser()->profile()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 103 | ASSERT_TRUE(process_map->Contains( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 104 | extension_id, |
| 105 | extension_host->render_view_host()->GetProcess()->GetID())); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void LoadTestExtension() { |
| 109 | ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 110 | const Extension* extension = LoadExtension( |
| 111 | test_data_dir_.AppendASCII("common").AppendASCII("background_page")); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 112 | ASSERT_TRUE(extension); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 113 | first_extension_id_ = extension->id(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 114 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 115 | } |
| 116 | |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 117 | void LoadSecondExtension() { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 118 | const Extension* extension = LoadExtension( |
| 119 | test_data_dir_.AppendASCII("install").AppendASCII("install")); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 120 | ASSERT_TRUE(extension); |
| 121 | second_extension_id_ = extension->id(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 122 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 123 | } |
| 124 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 125 | void AcceptNotification(const std::string& extension_id) { |
limasdf | 184283c | 2017-04-14 08:22:10 | [diff] [blame] | 126 | extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 127 | display_service_->SimulateClick(NotificationHandler::Type::TRANSIENT, |
| 128 | "app.background.crashed." + extension_id, |
| 129 | base::nullopt, base::nullopt); |
limasdf | 184283c | 2017-04-14 08:22:10 | [diff] [blame] | 130 | auto* extension = observer.WaitForExtensionLoaded(); |
| 131 | extensions::BackgroundPageWatcher(GetProcessManager(), extension) |
| 132 | .WaitForOpen(); |
[email protected] | 6cd63ea | 2013-03-07 18:17:04 | [diff] [blame] | 133 | } |
| 134 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 135 | size_t CountNotifications() { |
| 136 | return display_service_ |
| 137 | ->GetDisplayedNotificationsForType(NotificationHandler::Type::TRANSIENT) |
| 138 | .size(); |
[email protected] | 6cd63ea | 2013-03-07 18:17:04 | [diff] [blame] | 139 | } |
| 140 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 141 | std::string first_extension_id_; |
| 142 | std::string second_extension_id_; |
| 143 | std::unique_ptr<NotificationDisplayServiceTester> display_service_; |
[email protected] | 9a22457 | 2013-05-12 23:08:56 | [diff] [blame] | 144 | }; |
[email protected] | bce52eaa | 2013-05-11 19:23:21 | [diff] [blame] | 145 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 146 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 147 | const size_t count_before = GetEnabledExtensionCount(); |
| 148 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 149 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 150 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 151 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
| 152 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 153 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_)); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 154 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 155 | SCOPED_TRACE("after clicking the balloon"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 156 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 157 | ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | 6b75d79b0f9 | 2013-05-16 17:37:05 | [diff] [blame] | 160 | // Flaky, http://crbug.com/241191. |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 161 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, DISABLED_CloseAndReload) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 162 | const size_t count_before = GetEnabledExtensionCount(); |
| 163 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 164 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 165 | CrashExtension(first_extension_id_); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 166 | |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 167 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
| 168 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 169 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 170 | // 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] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 173 | ReloadExtension(first_extension_id_); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 174 | |
| 175 | SCOPED_TRACE("after reloading"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 176 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 177 | ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 178 | } |
| 179 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 180 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 181 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 182 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 183 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 184 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 185 | |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 186 | ReloadExtension(first_extension_id_); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 187 | |
| 188 | SCOPED_TRACE("after reloading"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 189 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 190 | |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 191 | WebContents* current_tab = |
| 192 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 193 | ASSERT_TRUE(current_tab); |
| 194 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 195 | // The balloon should automatically hide after the extension is successfully |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 196 | // reloaded. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 197 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 198 | } |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 199 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 200 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 201 | ReloadIndependentlyChangeTabs) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 202 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 203 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 204 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 205 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 206 | |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 207 | WebContents* original_tab = |
| 208 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 209 | ASSERT_TRUE(original_tab); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 210 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 211 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 212 | // Open a new tab, but the balloon will still be there. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 213 | chrome::NewTab(browser()); |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 214 | WebContents* new_current_tab = |
| 215 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 216 | ASSERT_TRUE(new_current_tab); |
| 217 | ASSERT_NE(new_current_tab, original_tab); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 218 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 219 | |
| 220 | ReloadExtension(first_extension_id_); |
| 221 | |
| 222 | SCOPED_TRACE("after reloading"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 223 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 224 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 225 | // The balloon should automatically hide after the extension is successfully |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 226 | // reloaded. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 227 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 228 | } |
| 229 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 230 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 231 | ReloadIndependentlyNavigatePage) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 232 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 233 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 234 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 235 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 236 | |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 237 | WebContents* current_tab = |
| 238 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 239 | ASSERT_TRUE(current_tab); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 240 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 241 | |
| 242 | // Navigate to another page. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 243 | 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 Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 247 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 248 | |
| 249 | ReloadExtension(first_extension_id_); |
| 250 | |
| 251 | SCOPED_TRACE("after reloading"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 252 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 253 | |
[email protected] | 1a6273b7 | 2011-04-23 00:50:55 | [diff] [blame] | 254 | // The balloon should automatically hide after the extension is successfully |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 255 | // reloaded. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 256 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 257 | } |
| 258 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 259 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ShutdownWhileCrashed) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 260 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 261 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 262 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 263 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 264 | } |
| 265 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 266 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 267 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 268 | LoadTestExtension(); |
| 269 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 270 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 271 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 272 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_)); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 273 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 274 | SCOPED_TRACE("after clicking the balloon"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 275 | CheckExtensionConsistency(first_extension_id_); |
| 276 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 277 | } |
| 278 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 279 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 280 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 281 | LoadTestExtension(); |
| 282 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 283 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 284 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 285 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_)); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 286 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 287 | SCOPED_TRACE("after clicking the balloon"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 288 | CheckExtensionConsistency(first_extension_id_); |
| 289 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 290 | } |
| 291 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 292 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 293 | TwoExtensionsCrashBothAtOnce) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 294 | const size_t count_before = GetEnabledExtensionCount(); |
| 295 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 296 | LoadTestExtension(); |
| 297 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 298 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 299 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
| 300 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 301 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 302 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
| 303 | ASSERT_EQ(crash_count_before + 2, GetTerminatedExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 304 | |
| 305 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 306 | SCOPED_TRACE("first balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 307 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 308 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 312 | SCOPED_TRACE("second balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 313 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 314 | CheckExtensionConsistency(first_extension_id_); |
| 315 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 319 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 320 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 321 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 322 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 323 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 324 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 325 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 326 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 327 | |
| 328 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 329 | SCOPED_TRACE("first balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 330 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 331 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 335 | SCOPED_TRACE("second balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 336 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 337 | CheckExtensionConsistency(first_extension_id_); |
| 338 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 339 | } |
| 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 Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 345 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 346 | TwoExtensionsShutdownWhileCrashed) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 347 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 348 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 349 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 350 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 351 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 352 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 353 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 354 | } |
| 355 | |
[email protected] | bd09941 | 2013-05-17 04:20:16 | [diff] [blame] | 356 | // Flaky, http://crbug.com/241573. |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 357 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
[email protected] | bd09941 | 2013-05-17 04:20:16 | [diff] [blame] | 358 | DISABLED_TwoExtensionsIgnoreFirst) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 359 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 360 | LoadTestExtension(); |
| 361 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 362 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 363 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 364 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 365 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 366 | |
[email protected] | ede5e61a | 2011-12-03 01:05:31 | [diff] [blame] | 367 | // 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 Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 370 | 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] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 374 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 375 | SCOPED_TRACE("balloons done"); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 376 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 377 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 378 | } |
| 379 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 380 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 381 | TwoExtensionsReloadIndependently) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 382 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 383 | LoadTestExtension(); |
| 384 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 385 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 386 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 387 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 388 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 389 | |
| 390 | { |
| 391 | SCOPED_TRACE("first: reload"); |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 392 | WebContents* current_tab = |
| 393 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 394 | ASSERT_TRUE(current_tab); |
[email protected] | 1a6273b7 | 2011-04-23 00:50:55 | [diff] [blame] | 395 | // At the beginning we should have one balloon displayed for each extension. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 396 | ASSERT_EQ(2U, CountNotifications()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 397 | ReloadExtension(first_extension_id_); |
[email protected] | 1a6273b7 | 2011-04-23 00:50:55 | [diff] [blame] | 398 | // One of the balloons should hide after the extension is reloaded. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 399 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 400 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 404 | SCOPED_TRACE("second: balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 405 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 406 | CheckExtensionConsistency(first_extension_id_); |
| 407 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 408 | } |
| 409 | } |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 410 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 411 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 412 | const size_t count_before = GetEnabledExtensionCount(); |
| 413 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 414 | LoadTestExtension(); |
| 415 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 416 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 417 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
| 418 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 419 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 420 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 421 | UninstallExtension(first_extension_id_); |
fdoray | fd4c7ba | 2016-06-10 17:44:36 | [diff] [blame] | 422 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 423 | |
| 424 | SCOPED_TRACE("after uninstalling"); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 425 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
| 426 | ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 427 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 428 | } |
| 429 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 430 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUnloadAll) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 431 | const size_t count_before = GetEnabledExtensionCount(); |
| 432 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 433 | LoadTestExtension(); |
| 434 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 435 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 436 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
| 437 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 438 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 439 | GetExtensionService()->UnloadAllExtensionsForTest(); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 440 | ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount()); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 441 | } |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 442 | |
| 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 Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 445 | // Regression test for issue 71629 and 763808. |
| 446 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 447 | ReloadTabsWithBackgroundPage) { |
[email protected] | c084925 | 2012-05-12 13:51:27 | [diff] [blame] | 448 | TabStripModel* tab_strip = browser()->tab_strip_model(); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 449 | const size_t count_before = GetEnabledExtensionCount(); |
| 450 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 451 | LoadTestExtension(); |
| 452 | |
| 453 | // Open a tab extension. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 454 | chrome::NewTab(browser()); |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 455 | ui_test_utils::NavigateToURL(browser(), |
| 456 | GURL(std::string(extensions::kExtensionScheme) + |
[email protected] | fb4fe095 | 2014-06-05 09:44:24 | [diff] [blame] | 457 | url::kStandardSchemeSeparator + |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 458 | first_extension_id_ + "/background.html")); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 459 | |
| 460 | const int tabs_before = tab_strip->count(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 461 | CrashExtension(first_extension_id_); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 462 | |
| 463 | // Tab should still be open, and extension should be crashed. |
| 464 | EXPECT_EQ(tabs_before, tab_strip->count()); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 465 | EXPECT_EQ(count_before, GetEnabledExtensionCount()); |
| 466 | EXPECT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 467 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 468 | extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry()); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 469 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 470 | content::WindowedNotificationObserver observer( |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 471 | content::NOTIFICATION_LOAD_STOP, |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 472 | content::Source<NavigationController>(&browser() |
| 473 | ->tab_strip_model() |
| 474 | ->GetActiveWebContents() |
| 475 | ->GetController())); |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 476 | chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 477 | observer.Wait(); |
| 478 | } |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 479 | auto* extension = observer.WaitForExtensionLoaded(); |
| 480 | EXPECT_EQ(first_extension_id_, extension->id()); |
| 481 | |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 482 | // Extension should now be loaded. |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 483 | SCOPED_TRACE("after reloading the tab"); |
| 484 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 485 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 486 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 487 | } |