[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" |
Lukasz Anforowicz | 951d6bc | 2019-06-14 18:29:18 | [diff] [blame] | 25 | #include "content/public/test/no_renderer_crashes_assertion.h" |
Lukasz Anforowicz | fb1ccf0 | 2018-04-21 14:55:20 | [diff] [blame] | 26 | #include "content/public/test/test_utils.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 27 | #include "extensions/browser/extension_host.h" |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 28 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 29 | #include "extensions/browser/extension_system.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 30 | #include "extensions/browser/process_manager.h" |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 31 | #include "extensions/browser/process_map.h" |
limasdf | 184283c | 2017-04-14 08:22:10 | [diff] [blame] | 32 | #include "extensions/browser/test_extension_registry_observer.h" |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 33 | #include "extensions/common/constants.h" |
emaxx | 895210ec | 2017-04-19 14:37:30 | [diff] [blame] | 34 | #include "extensions/test/background_page_watcher.h" |
Evan Stade | 889ce471 | 2018-01-28 15:26:26 | [diff] [blame] | 35 | #include "ui/message_center/public/cpp/notification.h" |
| 36 | #include "ui/message_center/public/cpp/notification_delegate.h" |
[email protected] | 6cd63ea | 2013-03-07 18:17:04 | [diff] [blame] | 37 | |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 38 | using content::NavigationController; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 39 | using content::WebContents; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 40 | using extensions::Extension; |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 41 | using extensions::ExtensionRegistry; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 42 | |
Devlin Cronin | 836f545d | 2018-05-09 00:25:05 | [diff] [blame] | 43 | class ExtensionCrashRecoveryTest : public extensions::ExtensionBrowserTest { |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 44 | protected: |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 45 | void SetUpOnMainThread() override { |
Devlin Cronin | 836f545d | 2018-05-09 00:25:05 | [diff] [blame] | 46 | extensions::ExtensionBrowserTest::SetUpOnMainThread(); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 47 | display_service_ = |
| 48 | std::make_unique<NotificationDisplayServiceTester>(profile()); |
| 49 | } |
[email protected] | 6cd63ea | 2013-03-07 18:17:04 | [diff] [blame] | 50 | |
Devlin Cronin | 251bd41 | 2018-05-30 00:55:42 | [diff] [blame] | 51 | extensions::ExtensionService* GetExtensionService() { |
[email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 52 | return extensions::ExtensionSystem::Get(browser()->profile())-> |
| 53 | extension_service(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 54 | } |
| 55 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 56 | extensions::ProcessManager* GetProcessManager() { |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 57 | return extensions::ProcessManager::Get(browser()->profile()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 58 | } |
| 59 | |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 60 | ExtensionRegistry* GetExtensionRegistry() { |
| 61 | return ExtensionRegistry::Get(browser()->profile()); |
| 62 | } |
| 63 | |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 64 | size_t GetEnabledExtensionCount() { |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 65 | return GetExtensionRegistry()->enabled_extensions().size(); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | size_t GetTerminatedExtensionCount() { |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 69 | return GetExtensionRegistry()->terminated_extensions().size(); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 72 | void CrashExtension(const std::string& extension_id) { |
| 73 | const Extension* extension = GetExtensionRegistry()->GetExtensionById( |
| 74 | extension_id, ExtensionRegistry::ENABLED); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 75 | ASSERT_TRUE(extension); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 76 | extensions::ExtensionHost* extension_host = GetProcessManager()-> |
[email protected] | 06024c6 | 2011-10-20 20:57:12 | [diff] [blame] | 77 | GetBackgroundHostForExtension(extension_id); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 78 | ASSERT_TRUE(extension_host); |
| 79 | |
Wez | 0abfbf51 | 2018-03-03 01:54:45 | [diff] [blame] | 80 | extension_host->render_process_host()->Shutdown( |
| 81 | content::RESULT_CODE_KILLED); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 82 | ASSERT_TRUE(WaitForExtensionCrash(extension_id)); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 83 | ASSERT_FALSE(GetProcessManager()-> |
[email protected] | 06024c6 | 2011-10-20 20:57:12 | [diff] [blame] | 84 | GetBackgroundHostForExtension(extension_id)); |
[email protected] | 260122c | 2013-05-22 15:05:55 | [diff] [blame] | 85 | |
| 86 | // Wait for extension crash balloon to appear. |
fdoray | fd4c7ba | 2016-06-10 17:44:36 | [diff] [blame] | 87 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 88 | } |
| 89 | |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 90 | void CheckExtensionConsistency(const std::string& extension_id) { |
| 91 | const Extension* extension = GetExtensionRegistry()->GetExtensionById( |
| 92 | extension_id, ExtensionRegistry::ENABLED); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 93 | ASSERT_TRUE(extension); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 94 | extensions::ExtensionHost* extension_host = GetProcessManager()-> |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 95 | GetBackgroundHostForExtension(extension_id); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 96 | ASSERT_TRUE(extension_host); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 97 | 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] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 102 | ASSERT_TRUE(extension_host->IsRenderViewLive()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 103 | extensions::ProcessMap* process_map = |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 104 | extensions::ProcessMap::Get(browser()->profile()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 105 | ASSERT_TRUE(process_map->Contains( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 106 | extension_id, |
| 107 | extension_host->render_view_host()->GetProcess()->GetID())); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void LoadTestExtension() { |
Devlin Cronin | 836f545d | 2018-05-09 00:25:05 | [diff] [blame] | 111 | extensions::ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 112 | const Extension* extension = LoadExtension( |
| 113 | test_data_dir_.AppendASCII("common").AppendASCII("background_page")); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 114 | ASSERT_TRUE(extension); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 115 | first_extension_id_ = extension->id(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 116 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 119 | void LoadSecondExtension() { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 120 | const Extension* extension = LoadExtension( |
| 121 | test_data_dir_.AppendASCII("install").AppendASCII("install")); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 122 | ASSERT_TRUE(extension); |
| 123 | second_extension_id_ = extension->id(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 124 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 125 | } |
| 126 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 127 | void AcceptNotification(const std::string& extension_id) { |
limasdf | 184283c | 2017-04-14 08:22:10 | [diff] [blame] | 128 | extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 129 | display_service_->SimulateClick(NotificationHandler::Type::TRANSIENT, |
| 130 | "app.background.crashed." + extension_id, |
| 131 | base::nullopt, base::nullopt); |
limasdf | 184283c | 2017-04-14 08:22:10 | [diff] [blame] | 132 | auto* extension = observer.WaitForExtensionLoaded(); |
| 133 | extensions::BackgroundPageWatcher(GetProcessManager(), extension) |
| 134 | .WaitForOpen(); |
[email protected] | 6cd63ea | 2013-03-07 18:17:04 | [diff] [blame] | 135 | } |
| 136 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 137 | size_t CountNotifications() { |
| 138 | return display_service_ |
| 139 | ->GetDisplayedNotificationsForType(NotificationHandler::Type::TRANSIENT) |
| 140 | .size(); |
[email protected] | 6cd63ea | 2013-03-07 18:17:04 | [diff] [blame] | 141 | } |
| 142 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 143 | std::string first_extension_id_; |
| 144 | std::string second_extension_id_; |
| 145 | std::unique_ptr<NotificationDisplayServiceTester> display_service_; |
Lukasz Anforowicz | 951d6bc | 2019-06-14 18:29:18 | [diff] [blame] | 146 | content::ScopedAllowRendererCrashes scoped_allow_renderer_crashes_; |
[email protected] | 9a22457 | 2013-05-12 23:08:56 | [diff] [blame] | 147 | }; |
[email protected] | bce52eaa | 2013-05-11 19:23:21 | [diff] [blame] | 148 | |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 149 | // 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 |
| 155 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_Basic) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 156 | const size_t count_before = GetEnabledExtensionCount(); |
| 157 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 158 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 159 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 160 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
| 161 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 162 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_)); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 163 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 164 | SCOPED_TRACE("after clicking the balloon"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 165 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 166 | ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 167 | } |
| 168 | |
[email protected] | 6b75d79b0f9 | 2013-05-16 17:37:05 | [diff] [blame] | 169 | // Flaky, http://crbug.com/241191. |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 170 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, DISABLED_CloseAndReload) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 171 | const size_t count_before = GetEnabledExtensionCount(); |
| 172 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 173 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 174 | CrashExtension(first_extension_id_); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 175 | |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 176 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
| 177 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 178 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 179 | // 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] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 182 | ReloadExtension(first_extension_id_); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 183 | |
| 184 | SCOPED_TRACE("after reloading"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 185 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 186 | ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 187 | } |
| 188 | |
Francois Doray | c3007a7 | 2018-06-14 13:10:17 | [diff] [blame] | 189 | // 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 Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 195 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 196 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 197 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 198 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 199 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 200 | |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 201 | ReloadExtension(first_extension_id_); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 202 | |
| 203 | SCOPED_TRACE("after reloading"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 204 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 205 | |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 206 | WebContents* current_tab = |
| 207 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 208 | ASSERT_TRUE(current_tab); |
| 209 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 210 | // The balloon should automatically hide after the extension is successfully |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 211 | // reloaded. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 212 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 213 | } |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 214 | |
Yuta Kitamura | 335109f | 2018-05-24 07:50:41 | [diff] [blame] | 215 | // Flaky. crbug.com/846172 |
Francois Doray | c3007a7 | 2018-06-14 13:10:17 | [diff] [blame] | 216 | #if defined(OS_LINUX) || defined(OS_WIN) |
Yuta Kitamura | 335109f | 2018-05-24 07:50:41 | [diff] [blame] | 217 | #define MAYBE_ReloadIndependentlyChangeTabs \ |
| 218 | DISABLED_ReloadIndependentlyChangeTabs |
| 219 | #else |
| 220 | #define MAYBE_ReloadIndependentlyChangeTabs ReloadIndependentlyChangeTabs |
| 221 | #endif |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 222 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
Adithya Srinivasan | a7ed9ba | 2018-05-29 18:46:40 | [diff] [blame] | 223 | MAYBE_ReloadIndependentlyChangeTabs) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 224 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 225 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 226 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 227 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 228 | |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 229 | WebContents* original_tab = |
| 230 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 231 | ASSERT_TRUE(original_tab); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 232 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 233 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 234 | // Open a new tab, but the balloon will still be there. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 235 | chrome::NewTab(browser()); |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 236 | WebContents* new_current_tab = |
| 237 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 238 | ASSERT_TRUE(new_current_tab); |
| 239 | ASSERT_NE(new_current_tab, original_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 | ReloadExtension(first_extension_id_); |
| 243 | |
| 244 | SCOPED_TRACE("after reloading"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 245 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 246 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 247 | // The balloon should automatically hide after the extension is successfully |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 248 | // reloaded. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 249 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 250 | } |
| 251 | |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 252 | // 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 Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 259 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 260 | MAYBE_ReloadIndependentlyNavigatePage) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 261 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 262 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 263 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 264 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 265 | |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 266 | WebContents* current_tab = |
| 267 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 268 | ASSERT_TRUE(current_tab); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 269 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 270 | |
| 271 | // Navigate to another page. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 272 | 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 Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 276 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 277 | |
| 278 | ReloadExtension(first_extension_id_); |
| 279 | |
| 280 | SCOPED_TRACE("after reloading"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 281 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 282 | |
[email protected] | 1a6273b7 | 2011-04-23 00:50:55 | [diff] [blame] | 283 | // The balloon should automatically hide after the extension is successfully |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 284 | // reloaded. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 285 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | ed56a7a0 | 2010-12-22 21:15:13 | [diff] [blame] | 286 | } |
| 287 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 288 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ShutdownWhileCrashed) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 289 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 290 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 291 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 292 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 293 | } |
| 294 | |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 295 | // 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 |
| 301 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 302 | MAYBE_TwoExtensionsCrashFirst) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 303 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 304 | LoadTestExtension(); |
| 305 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 306 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 307 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 308 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_)); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 309 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 310 | SCOPED_TRACE("after clicking the balloon"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 311 | CheckExtensionConsistency(first_extension_id_); |
| 312 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 313 | } |
| 314 | |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 315 | // 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 |
| 321 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 322 | MAYBE_TwoExtensionsCrashSecond) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 323 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 324 | LoadTestExtension(); |
| 325 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 326 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 327 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 328 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_)); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 329 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 330 | SCOPED_TRACE("after clicking the balloon"); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 331 | CheckExtensionConsistency(first_extension_id_); |
| 332 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 333 | } |
| 334 | |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 335 | // 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 Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 341 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 342 | MAYBE_TwoExtensionsCrashBothAtOnce) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 343 | const size_t count_before = GetEnabledExtensionCount(); |
| 344 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 345 | LoadTestExtension(); |
| 346 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 347 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 348 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
| 349 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 350 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 351 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
| 352 | ASSERT_EQ(crash_count_before + 2, GetTerminatedExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 353 | |
| 354 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 355 | SCOPED_TRACE("first balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 356 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 357 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 361 | SCOPED_TRACE("second balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 362 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 363 | CheckExtensionConsistency(first_extension_id_); |
| 364 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 368 | // 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 |
| 374 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 375 | MAYBE_TwoExtensionsOneByOne) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 376 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 377 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 378 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 379 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 380 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 381 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 382 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 383 | |
| 384 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 385 | SCOPED_TRACE("first balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 386 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 387 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 391 | SCOPED_TRACE("second balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 392 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 393 | CheckExtensionConsistency(first_extension_id_); |
| 394 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 395 | } |
| 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 Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 401 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 402 | TwoExtensionsShutdownWhileCrashed) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 403 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 404 | LoadTestExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 405 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 406 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 407 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 408 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 409 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 410 | } |
| 411 | |
[email protected] | bd09941 | 2013-05-17 04:20:16 | [diff] [blame] | 412 | // Flaky, http://crbug.com/241573. |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 413 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
[email protected] | bd09941 | 2013-05-17 04:20:16 | [diff] [blame] | 414 | DISABLED_TwoExtensionsIgnoreFirst) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 415 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 416 | LoadTestExtension(); |
| 417 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 418 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 419 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 420 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 421 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 422 | |
[email protected] | ede5e61a | 2011-12-03 01:05:31 | [diff] [blame] | 423 | // 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 Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 426 | 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] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 430 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 431 | SCOPED_TRACE("balloons done"); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 432 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 433 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 434 | } |
| 435 | |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 436 | // 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 Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 443 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
Marijn Kruisselbrink | 585d8e3e | 2019-08-26 18:44:56 | [diff] [blame] | 444 | MAYBE_TwoExtensionsReloadIndependently) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 445 | const size_t count_before = GetEnabledExtensionCount(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 446 | LoadTestExtension(); |
| 447 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 448 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 449 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 450 | CrashExtension(second_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 451 | ASSERT_EQ(count_before, GetEnabledExtensionCount()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 452 | |
| 453 | { |
| 454 | SCOPED_TRACE("first: reload"); |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 455 | WebContents* current_tab = |
| 456 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 457 | ASSERT_TRUE(current_tab); |
[email protected] | 1a6273b7 | 2011-04-23 00:50:55 | [diff] [blame] | 458 | // At the beginning we should have one balloon displayed for each extension. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 459 | ASSERT_EQ(2U, CountNotifications()); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 460 | ReloadExtension(first_extension_id_); |
[email protected] | 1a6273b7 | 2011-04-23 00:50:55 | [diff] [blame] | 461 | // One of the balloons should hide after the extension is reloaded. |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 462 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 463 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 467 | SCOPED_TRACE("second: balloon"); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 468 | ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 469 | CheckExtensionConsistency(first_extension_id_); |
| 470 | CheckExtensionConsistency(second_extension_id_); |
[email protected] | ee8abdeb | 2010-03-10 11:02:32 | [diff] [blame] | 471 | } |
| 472 | } |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 473 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 474 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 475 | const size_t count_before = GetEnabledExtensionCount(); |
| 476 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 477 | LoadTestExtension(); |
| 478 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 479 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 480 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
| 481 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 482 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 483 | ASSERT_EQ(1U, CountNotifications()); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 484 | UninstallExtension(first_extension_id_); |
fdoray | fd4c7ba | 2016-06-10 17:44:36 | [diff] [blame] | 485 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 486 | |
| 487 | SCOPED_TRACE("after uninstalling"); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 488 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
| 489 | ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 490 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 491 | } |
| 492 | |
Alex Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 493 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUnloadAll) { |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 494 | const size_t count_before = GetEnabledExtensionCount(); |
| 495 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 496 | LoadTestExtension(); |
| 497 | LoadSecondExtension(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 498 | CrashExtension(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 499 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
| 500 | ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 501 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 502 | GetExtensionService()->UnloadAllExtensionsForTest(); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 503 | ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount()); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 504 | } |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 505 | |
| 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 Moshchuk | b4cf29e | 2017-09-12 17:00:11 | [diff] [blame] | 508 | // Regression test for issue 71629 and 763808. |
| 509 | IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
Lukasz Anforowicz | fb1ccf0 | 2018-04-21 14:55:20 | [diff] [blame] | 510 | ReloadTabsWithBackgroundPage) { |
| 511 | // TODO(https://crbug.com/831078): Fix the test. |
| 512 | if (content::AreAllSitesIsolatedForTesting()) |
| 513 | return; |
| 514 | |
[email protected] | c084925 | 2012-05-12 13:51:27 | [diff] [blame] | 515 | TabStripModel* tab_strip = browser()->tab_strip_model(); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 516 | const size_t count_before = GetEnabledExtensionCount(); |
| 517 | const size_t crash_count_before = GetTerminatedExtensionCount(); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 518 | LoadTestExtension(); |
| 519 | |
| 520 | // Open a tab extension. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 521 | chrome::NewTab(browser()); |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 522 | ui_test_utils::NavigateToURL(browser(), |
| 523 | GURL(std::string(extensions::kExtensionScheme) + |
[email protected] | fb4fe095 | 2014-06-05 09:44:24 | [diff] [blame] | 524 | url::kStandardSchemeSeparator + |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 525 | first_extension_id_ + "/background.html")); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 526 | |
| 527 | const int tabs_before = tab_strip->count(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 528 | CrashExtension(first_extension_id_); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 529 | |
| 530 | // Tab should still be open, and extension should be crashed. |
| 531 | EXPECT_EQ(tabs_before, tab_strip->count()); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 532 | EXPECT_EQ(count_before, GetEnabledExtensionCount()); |
| 533 | EXPECT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 534 | |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 535 | extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry()); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 536 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 537 | content::WindowedNotificationObserver observer( |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 538 | content::NOTIFICATION_LOAD_STOP, |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 539 | content::Source<NavigationController>(&browser() |
| 540 | ->tab_strip_model() |
| 541 | ->GetActiveWebContents() |
| 542 | ->GetController())); |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 543 | chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 544 | observer.Wait(); |
| 545 | } |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 546 | auto* extension = observer.WaitForExtensionLoaded(); |
| 547 | EXPECT_EQ(first_extension_id_, extension->id()); |
| 548 | |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 549 | // Extension should now be loaded. |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 550 | SCOPED_TRACE("after reloading the tab"); |
| 551 | CheckExtensionConsistency(first_extension_id_); |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 552 | ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); |
Evan Stade | bde44090 | 2018-01-26 20:10:34 | [diff] [blame] | 553 | ASSERT_EQ(0U, CountNotifications()); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 554 | } |