blob: 4b49a8d493c5077b221a20c89b15b5199b51d9cf [file] [log] [blame]
[email protected]9f76c1e2012-03-05 15:15:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]1eb175082010-02-10 09:26:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]6cd63ea2013-03-07 18:17:045#include "chrome/browser/browser_process.h"
[email protected]1eb175082010-02-10 09:26:166#include "chrome/browser/extensions/extension_browsertest.h"
7#include "chrome/browser/extensions/extension_host.h"
[email protected]eaa7dd182010-12-14 11:09:008#include "chrome/browser/extensions/extension_service.h"
[email protected]be93bba02012-10-24 16:44:039#include "chrome/browser/extensions/extension_system.h"
[email protected]1272b1e62012-04-04 14:42:4510#include "chrome/browser/notifications/balloon.h"
11#include "chrome/browser/notifications/balloon_collection.h"
[email protected]2c4fb7b2011-04-02 06:33:2912#include "chrome/browser/notifications/balloon_host.h"
[email protected]a93e63f52012-12-18 04:26:4013#include "chrome/browser/notifications/balloon_notification_ui_manager.h"
[email protected]2c4fb7b2011-04-02 06:33:2914#include "chrome/browser/notifications/notification.h"
15#include "chrome/browser/notifications/notification_delegate.h"
[email protected]8ecad5e2010-12-02 21:18:3316#include "chrome/browser/profiles/profile.h"
[email protected]7b5dc002010-11-16 23:08:1017#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1018#include "chrome/browser/ui/browser_commands.h"
[email protected]b56e2e32012-05-11 21:18:0419#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]af44e7fb2011-07-29 18:32:3220#include "chrome/test/base/ui_test_utils.h"
[email protected]cdcb1dee2012-01-04 00:46:2021#include "content/public/browser/navigation_controller.h"
[email protected]f3b1a082011-11-18 00:34:3022#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3323#include "content/public/browser/render_view_host.h"
[email protected]4ca15302012-01-03 05:53:2024#include "content/public/browser/web_contents.h"
[email protected]b39ef1cb2011-10-25 04:46:5525#include "content/public/common/result_codes.h"
[email protected]98b6d942013-11-10 00:34:0726#include "extensions/browser/process_manager.h"
[email protected]6cd63ea2013-03-07 18:17:0427#include "ui/message_center/message_center.h"
[email protected]aa611d42013-03-24 00:32:5128#include "ui/message_center/message_center_switches.h"
[email protected]fb1aac14e2013-05-14 05:30:2429#include "ui/message_center/message_center_util.h"
[email protected]6cd63ea2013-03-07 18:17:0430#include "ui/message_center/notification_list.h"
[email protected]6cd63ea2013-03-07 18:17:0431
[email protected]c5eed492012-01-04 17:07:5032using content::NavigationController;
[email protected]4ca15302012-01-03 05:53:2033using content::WebContents;
[email protected]1c321ee52012-05-21 03:02:3434using extensions::Extension;
[email protected]4ca15302012-01-03 05:53:2035
[email protected]5a95d772013-02-06 21:16:2836// Tests are timing out waiting for extension to crash.
37// http://crbug.com/174705
[email protected]b1441682013-05-17 23:35:2438#if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_LINUX)
[email protected]5a95d772013-02-06 21:16:2839#define MAYBE_ExtensionCrashRecoveryTest DISABLED_ExtensionCrashRecoveryTest
40#else
41#define MAYBE_ExtensionCrashRecoveryTest ExtensionCrashRecoveryTest
[email protected]b1441682013-05-17 23:35:2442#endif // defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_LINUX)
[email protected]5a95d772013-02-06 21:16:2843
[email protected]6cd63ea2013-03-07 18:17:0444class ExtensionCrashRecoveryTestBase : public ExtensionBrowserTest {
[email protected]1eb175082010-02-10 09:26:1645 protected:
[email protected]6cd63ea2013-03-07 18:17:0446 virtual void AcceptNotification(size_t index) = 0;
47 virtual void CancelNotification(size_t index) = 0;
48 virtual size_t CountBalloons() = 0;
49
[email protected]eaa7dd182010-12-14 11:09:0050 ExtensionService* GetExtensionService() {
51 return browser()->profile()->GetExtensionService();
[email protected]1eb175082010-02-10 09:26:1652 }
53
[email protected]98b6d942013-11-10 00:34:0754 extensions::ProcessManager* GetProcessManager() {
[email protected]be93bba02012-10-24 16:44:0355 return extensions::ExtensionSystem::Get(browser()->profile())->
56 process_manager();
[email protected]1eb175082010-02-10 09:26:1657 }
58
[email protected]84df8332011-12-06 18:22:4659 void CrashExtension(std::string extension_id) {
[email protected]9adb9692010-10-29 23:14:0260 const Extension* extension =
[email protected]330840c2012-08-29 22:21:0161 GetExtensionService()->GetExtensionById(extension_id, false);
[email protected]1eb175082010-02-10 09:26:1662 ASSERT_TRUE(extension);
[email protected]98b6d942013-11-10 00:34:0763 extensions::ExtensionHost* extension_host = GetProcessManager()->
[email protected]06024c62011-10-20 20:57:1264 GetBackgroundHostForExtension(extension_id);
[email protected]1eb175082010-02-10 09:26:1665 ASSERT_TRUE(extension_host);
66
[email protected]330840c2012-08-29 22:21:0167 base::KillProcess(extension_host->render_process_host()->GetHandle(),
68 content::RESULT_CODE_KILLED, false);
[email protected]ee8abdeb2010-03-10 11:02:3269 ASSERT_TRUE(WaitForExtensionCrash(extension_id));
[email protected]98b6d942013-11-10 00:34:0770 ASSERT_FALSE(GetProcessManager()->
[email protected]06024c62011-10-20 20:57:1271 GetBackgroundHostForExtension(extension_id));
[email protected]260122c2013-05-22 15:05:5572
73 // Wait for extension crash balloon to appear.
[email protected]b3a25092013-05-28 22:08:1674 base::MessageLoop::current()->RunUntilIdle();
[email protected]1eb175082010-02-10 09:26:1675 }
76
[email protected]84df8332011-12-06 18:22:4677 void CheckExtensionConsistency(std::string extension_id) {
[email protected]9adb9692010-10-29 23:14:0278 const Extension* extension =
[email protected]84df8332011-12-06 18:22:4679 GetExtensionService()->extensions()->GetByID(extension_id);
[email protected]1eb175082010-02-10 09:26:1680 ASSERT_TRUE(extension);
[email protected]98b6d942013-11-10 00:34:0781 extensions::ExtensionHost* extension_host = GetProcessManager()->
[email protected]84df8332011-12-06 18:22:4682 GetBackgroundHostForExtension(extension_id);
[email protected]1eb175082010-02-10 09:26:1683 ASSERT_TRUE(extension_host);
[email protected]98b6d942013-11-10 00:34:0784 extensions::ProcessManager::ViewSet all_views =
85 GetProcessManager()->GetAllViews();
86 extensions::ProcessManager::ViewSet::const_iterator it =
[email protected]d1fe1352012-04-26 00:47:3287 all_views.find(extension_host->host_contents()->GetRenderViewHost());
88 ASSERT_FALSE(it == all_views.end());
[email protected]1eb175082010-02-10 09:26:1689 ASSERT_TRUE(extension_host->IsRenderViewLive());
[email protected]6f371442011-11-09 06:45:4690 extensions::ProcessMap* process_map =
91 browser()->profile()->GetExtensionService()->process_map();
92 ASSERT_TRUE(process_map->Contains(
[email protected]9f76c1e2012-03-05 15:15:5893 extension_id,
94 extension_host->render_view_host()->GetProcess()->GetID()));
[email protected]1eb175082010-02-10 09:26:1695 }
96
97 void LoadTestExtension() {
98 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
[email protected]84df8332011-12-06 18:22:4699 const Extension* extension = LoadExtension(
100 test_data_dir_.AppendASCII("common").AppendASCII("background_page"));
[email protected]1eb175082010-02-10 09:26:16101 ASSERT_TRUE(extension);
[email protected]ee8abdeb2010-03-10 11:02:32102 first_extension_id_ = extension->id();
[email protected]84df8332011-12-06 18:22:46103 CheckExtensionConsistency(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16104 }
105
[email protected]ee8abdeb2010-03-10 11:02:32106 void LoadSecondExtension() {
[email protected]84df8332011-12-06 18:22:46107 const Extension* extension = LoadExtension(
108 test_data_dir_.AppendASCII("install").AppendASCII("install"));
[email protected]ee8abdeb2010-03-10 11:02:32109 ASSERT_TRUE(extension);
110 second_extension_id_ = extension->id();
[email protected]84df8332011-12-06 18:22:46111 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32112 }
113
114 std::string first_extension_id_;
115 std::string second_extension_id_;
[email protected]6cd63ea2013-03-07 18:17:04116};
117
[email protected]fb1aac14e2013-05-14 05:30:24118class MAYBE_ExtensionCrashRecoveryTest
[email protected]6cd63ea2013-03-07 18:17:04119 : public ExtensionCrashRecoveryTestBase {
120 protected:
[email protected]aa3174b2013-03-15 09:12:48121 virtual void AcceptNotification(size_t index) OVERRIDE {
[email protected]fb1aac14e2013-05-14 05:30:24122 if (message_center::IsRichNotificationEnabled()) {
123 message_center::MessageCenter* message_center =
124 message_center::MessageCenter::Get();
125 ASSERT_GT(message_center->NotificationCount(), index);
126 message_center::NotificationList::Notifications::reverse_iterator it =
[email protected]ae37e7a2013-09-24 06:59:36127 message_center->GetVisibleNotifications().rbegin();
[email protected]fb1aac14e2013-05-14 05:30:24128 for (size_t i=0; i < index; ++i)
129 it++;
130 std::string id = (*it)->id();
131 message_center->ClickOnNotification(id);
132 } else {
133 Balloon* balloon = GetNotificationDelegate(index);
134 ASSERT_TRUE(balloon);
135 balloon->OnClick();
136 }
[email protected]6cd63ea2013-03-07 18:17:04137 WaitForExtensionLoad();
138 }
139
[email protected]aa3174b2013-03-15 09:12:48140 virtual void CancelNotification(size_t index) OVERRIDE {
[email protected]fb1aac14e2013-05-14 05:30:24141 if (message_center::IsRichNotificationEnabled()) {
142 message_center::MessageCenter* message_center =
143 message_center::MessageCenter::Get();
144 ASSERT_GT(message_center->NotificationCount(), index);
145 message_center::NotificationList::Notifications::reverse_iterator it =
[email protected]ae37e7a2013-09-24 06:59:36146 message_center->GetVisibleNotifications().rbegin();
[email protected]fb1aac14e2013-05-14 05:30:24147 for (size_t i=0; i < index; i++) { it++; }
148 ASSERT_TRUE(g_browser_process->notification_ui_manager()->
149 CancelById((*it)->id()));
150 } else {
151 Balloon* balloon = GetNotificationDelegate(index);
152 ASSERT_TRUE(balloon);
153 std::string id = balloon->notification().notification_id();
154 ASSERT_TRUE(g_browser_process->notification_ui_manager()->CancelById(id));
155 }
[email protected]6cd63ea2013-03-07 18:17:04156 }
157
[email protected]aa3174b2013-03-15 09:12:48158 virtual size_t CountBalloons() OVERRIDE {
[email protected]fb1aac14e2013-05-14 05:30:24159 if (message_center::IsRichNotificationEnabled())
160 return message_center::MessageCenter::Get()->NotificationCount();
161
162 return BalloonNotificationUIManager::GetInstanceForTesting()->
163 balloon_collection()->GetActiveBalloons().size();
[email protected]9a224572013-05-12 23:08:56164 }
[email protected]fb1aac14e2013-05-14 05:30:24165
166private:
167 Balloon* GetNotificationDelegate(size_t index) {
168 BalloonNotificationUIManager* manager =
169 BalloonNotificationUIManager::GetInstanceForTesting();
170 BalloonCollection::Balloons balloons =
171 manager->balloon_collection()->GetActiveBalloons();
172 return index < balloons.size() ? balloons.at(index) : NULL;
173 }
[email protected]9a224572013-05-12 23:08:56174};
[email protected]bce52eaa2013-05-11 19:23:21175
[email protected]c890fd42013-05-20 11:46:44176// Flaky: http://crbug.com/242167.
177IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest, DISABLED_Basic) {
[email protected]eaa7dd182010-12-14 11:09:00178 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]bb7f40952011-01-13 00:21:20179 const size_t crash_size_before =
180 GetExtensionService()->terminated_extensions()->size();
[email protected]1eb175082010-02-10 09:26:16181 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46182 CrashExtension(first_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00183 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]bb7f40952011-01-13 00:21:20184 ASSERT_EQ(crash_size_before + 1,
185 GetExtensionService()->terminated_extensions()->size());
[email protected]e3dfc742012-11-29 22:42:02186 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
[email protected]1eb175082010-02-10 09:26:16187
[email protected]2c4fb7b2011-04-02 06:33:29188 SCOPED_TRACE("after clicking the balloon");
[email protected]84df8332011-12-06 18:22:46189 CheckExtensionConsistency(first_extension_id_);
[email protected]bb7f40952011-01-13 00:21:20190 ASSERT_EQ(crash_size_before,
191 GetExtensionService()->terminated_extensions()->size());
[email protected]1eb175082010-02-10 09:26:16192}
193
[email protected]6b75d79b0f92013-05-16 17:37:05194// Flaky, http://crbug.com/241191.
195IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
196 DISABLED_CloseAndReload) {
[email protected]eaa7dd182010-12-14 11:09:00197 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]bb7f40952011-01-13 00:21:20198 const size_t crash_size_before =
199 GetExtensionService()->terminated_extensions()->size();
[email protected]1eb175082010-02-10 09:26:16200 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46201 CrashExtension(first_extension_id_);
[email protected]2c4fb7b2011-04-02 06:33:29202
[email protected]eaa7dd182010-12-14 11:09:00203 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]bb7f40952011-01-13 00:21:20204 ASSERT_EQ(crash_size_before + 1,
205 GetExtensionService()->terminated_extensions()->size());
206
[email protected]e3dfc742012-11-29 22:42:02207 ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
[email protected]ee8abdeb2010-03-10 11:02:32208 ReloadExtension(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16209
210 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46211 CheckExtensionConsistency(first_extension_id_);
[email protected]bb7f40952011-01-13 00:21:20212 ASSERT_EQ(crash_size_before,
213 GetExtensionService()->terminated_extensions()->size());
[email protected]1eb175082010-02-10 09:26:16214}
215
[email protected]4d90d432013-06-13 01:27:59216// Test is timing out on Windows http://crbug.com/174705.
217#if defined(OS_WIN)
218#define MAYBE_ReloadIndependently DISABLED_ReloadIndependently
219#else
220#define MAYBE_ReloadIndependently ReloadIndependently
221#endif // defined(OS_WIN)
222IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
223 MAYBE_ReloadIndependently) {
[email protected]eaa7dd182010-12-14 11:09:00224 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]1eb175082010-02-10 09:26:16225 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46226 CrashExtension(first_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00227 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]1eb175082010-02-10 09:26:16228
[email protected]ee8abdeb2010-03-10 11:02:32229 ReloadExtension(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16230
231 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46232 CheckExtensionConsistency(first_extension_id_);
[email protected]1eb175082010-02-10 09:26:16233
[email protected]47ae23372013-01-29 01:50:48234 WebContents* current_tab =
235 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]1eb175082010-02-10 09:26:16236 ASSERT_TRUE(current_tab);
237
[email protected]2c4fb7b2011-04-02 06:33:29238 // The balloon should automatically hide after the extension is successfully
[email protected]1eb175082010-02-10 09:26:16239 // reloaded.
[email protected]2c4fb7b2011-04-02 06:33:29240 ASSERT_EQ(0U, CountBalloons());
[email protected]1eb175082010-02-10 09:26:16241}
[email protected]ee8abdeb2010-03-10 11:02:32242
[email protected]8c85ea82013-05-23 09:36:42243// Test is timing out on Windows http://crbug.com/174705.
244#if defined(OS_WIN)
245#define MAYBE_ReloadIndependentlyChangeTabs DISABLED_ReloadIndependentlyChangeTabs
246#else
247#define MAYBE_ReloadIndependentlyChangeTabs ReloadIndependentlyChangeTabs
248#endif // defined(OS_WIN)
249
[email protected]5a95d772013-02-06 21:16:28250IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
[email protected]8c85ea82013-05-23 09:36:42251 MAYBE_ReloadIndependentlyChangeTabs) {
[email protected]ed56a7a02010-12-22 21:15:13252 const size_t size_before = GetExtensionService()->extensions()->size();
253 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46254 CrashExtension(first_extension_id_);
[email protected]ed56a7a02010-12-22 21:15:13255 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
256
[email protected]47ae23372013-01-29 01:50:48257 WebContents* original_tab =
258 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed56a7a02010-12-22 21:15:13259 ASSERT_TRUE(original_tab);
[email protected]2c4fb7b2011-04-02 06:33:29260 ASSERT_EQ(1U, CountBalloons());
[email protected]ed56a7a02010-12-22 21:15:13261
[email protected]2c4fb7b2011-04-02 06:33:29262 // Open a new tab, but the balloon will still be there.
[email protected]a37d4b02012-06-25 21:56:10263 chrome::NewTab(browser());
[email protected]47ae23372013-01-29 01:50:48264 WebContents* new_current_tab =
265 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed56a7a02010-12-22 21:15:13266 ASSERT_TRUE(new_current_tab);
267 ASSERT_NE(new_current_tab, original_tab);
[email protected]2c4fb7b2011-04-02 06:33:29268 ASSERT_EQ(1U, CountBalloons());
[email protected]ed56a7a02010-12-22 21:15:13269
270 ReloadExtension(first_extension_id_);
271
272 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46273 CheckExtensionConsistency(first_extension_id_);
[email protected]ed56a7a02010-12-22 21:15:13274
[email protected]2c4fb7b2011-04-02 06:33:29275 // The balloon should automatically hide after the extension is successfully
[email protected]ed56a7a02010-12-22 21:15:13276 // reloaded.
[email protected]2c4fb7b2011-04-02 06:33:29277 ASSERT_EQ(0U, CountBalloons());
[email protected]ed56a7a02010-12-22 21:15:13278}
279
[email protected]5a95d772013-02-06 21:16:28280IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
[email protected]4cf6acf2013-02-27 02:03:16281 DISABLED_ReloadIndependentlyNavigatePage) {
[email protected]ed56a7a02010-12-22 21:15:13282 const size_t size_before = GetExtensionService()->extensions()->size();
283 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46284 CrashExtension(first_extension_id_);
[email protected]ed56a7a02010-12-22 21:15:13285 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
286
[email protected]47ae23372013-01-29 01:50:48287 WebContents* current_tab =
288 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed56a7a02010-12-22 21:15:13289 ASSERT_TRUE(current_tab);
[email protected]2c4fb7b2011-04-02 06:33:29290 ASSERT_EQ(1U, CountBalloons());
[email protected]ed56a7a02010-12-22 21:15:13291
292 // Navigate to another page.
[email protected]650b2d52013-02-10 03:41:45293 ui_test_utils::NavigateToURL(
294 browser(), ui_test_utils::GetTestUrl(
295 base::FilePath(base::FilePath::kCurrentDirectory),
296 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
[email protected]2c4fb7b2011-04-02 06:33:29297 ASSERT_EQ(1U, CountBalloons());
[email protected]ed56a7a02010-12-22 21:15:13298
299 ReloadExtension(first_extension_id_);
300
301 SCOPED_TRACE("after reloading");
[email protected]84df8332011-12-06 18:22:46302 CheckExtensionConsistency(first_extension_id_);
[email protected]ed56a7a02010-12-22 21:15:13303
[email protected]1a6273b72011-04-23 00:50:55304 // The balloon should automatically hide after the extension is successfully
[email protected]ed56a7a02010-12-22 21:15:13305 // reloaded.
[email protected]2c4fb7b2011-04-02 06:33:29306 ASSERT_EQ(0U, CountBalloons());
[email protected]ed56a7a02010-12-22 21:15:13307}
308
[email protected]ee8abdeb2010-03-10 11:02:32309// Make sure that when we don't do anything about the crashed extension
310// and close the browser, it doesn't crash. The browser is closed implicitly
311// at the end of each browser test.
[email protected]03c7f66c2011-06-29 15:41:48312//
313// http://crbug.com/84719
[email protected]4ccc8cc2011-06-07 21:25:30314#if defined(OS_LINUX)
[email protected]5884f1602011-06-29 16:30:57315#define MAYBE_ShutdownWhileCrashed DISABLED_ShutdownWhileCrashed
[email protected]4ccc8cc2011-06-07 21:25:30316#else
[email protected]fa69a9a92011-06-29 16:02:59317#define MAYBE_ShutdownWhileCrashed ShutdownWhileCrashed
[email protected]03c7f66c2011-06-29 15:41:48318#endif // defined(OS_LINUX)
319
[email protected]5a95d772013-02-06 21:16:28320IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
321 MAYBE_ShutdownWhileCrashed) {
[email protected]eaa7dd182010-12-14 11:09:00322 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]ee8abdeb2010-03-10 11:02:32323 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46324 CrashExtension(first_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00325 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]ee8abdeb2010-03-10 11:02:32326}
327
[email protected]485669852013-05-16 11:05:47328// Flaky, http://crbug.com/241245.
[email protected]5a95d772013-02-06 21:16:28329IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
[email protected]485669852013-05-16 11:05:47330 DISABLED_TwoExtensionsCrashFirst) {
[email protected]eaa7dd182010-12-14 11:09:00331 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]ee8abdeb2010-03-10 11:02:32332 LoadTestExtension();
333 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46334 CrashExtension(first_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00335 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
[email protected]e3dfc742012-11-29 22:42:02336 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
[email protected]ee8abdeb2010-03-10 11:02:32337
[email protected]2c4fb7b2011-04-02 06:33:29338 SCOPED_TRACE("after clicking the balloon");
[email protected]84df8332011-12-06 18:22:46339 CheckExtensionConsistency(first_extension_id_);
340 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32341}
342
[email protected]55f904892013-05-20 15:19:01343// Flaky: http://crbug.com/242196
[email protected]5a95d772013-02-06 21:16:28344IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
[email protected]55f904892013-05-20 15:19:01345 DISABLED_TwoExtensionsCrashSecond) {
[email protected]eaa7dd182010-12-14 11:09:00346 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]ee8abdeb2010-03-10 11:02:32347 LoadTestExtension();
348 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46349 CrashExtension(second_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00350 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
[email protected]e3dfc742012-11-29 22:42:02351 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
[email protected]ee8abdeb2010-03-10 11:02:32352
[email protected]2c4fb7b2011-04-02 06:33:29353 SCOPED_TRACE("after clicking the balloon");
[email protected]84df8332011-12-06 18:22:46354 CheckExtensionConsistency(first_extension_id_);
355 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32356}
357
[email protected]5a95d772013-02-06 21:16:28358IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
[email protected]ee8abdeb2010-03-10 11:02:32359 TwoExtensionsCrashBothAtOnce) {
[email protected]eaa7dd182010-12-14 11:09:00360 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]bb7f40952011-01-13 00:21:20361 const size_t crash_size_before =
362 GetExtensionService()->terminated_extensions()->size();
[email protected]ee8abdeb2010-03-10 11:02:32363 LoadTestExtension();
364 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46365 CrashExtension(first_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00366 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
[email protected]bb7f40952011-01-13 00:21:20367 ASSERT_EQ(crash_size_before + 1,
368 GetExtensionService()->terminated_extensions()->size());
[email protected]84df8332011-12-06 18:22:46369 CrashExtension(second_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00370 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]bb7f40952011-01-13 00:21:20371 ASSERT_EQ(crash_size_before + 2,
372 GetExtensionService()->terminated_extensions()->size());
[email protected]ee8abdeb2010-03-10 11:02:32373
374 {
[email protected]2c4fb7b2011-04-02 06:33:29375 SCOPED_TRACE("first balloon");
[email protected]e3dfc742012-11-29 22:42:02376 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
[email protected]84df8332011-12-06 18:22:46377 CheckExtensionConsistency(first_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32378 }
379
380 {
[email protected]2c4fb7b2011-04-02 06:33:29381 SCOPED_TRACE("second balloon");
[email protected]e3dfc742012-11-29 22:42:02382 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
[email protected]84df8332011-12-06 18:22:46383 CheckExtensionConsistency(first_extension_id_);
384 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32385 }
386}
387
[email protected]5a95d772013-02-06 21:16:28388IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
389 TwoExtensionsOneByOne) {
[email protected]eaa7dd182010-12-14 11:09:00390 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]ee8abdeb2010-03-10 11:02:32391 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46392 CrashExtension(first_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00393 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]ee8abdeb2010-03-10 11:02:32394 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46395 CrashExtension(second_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00396 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]ee8abdeb2010-03-10 11:02:32397
398 {
[email protected]2c4fb7b2011-04-02 06:33:29399 SCOPED_TRACE("first balloon");
[email protected]e3dfc742012-11-29 22:42:02400 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
[email protected]84df8332011-12-06 18:22:46401 CheckExtensionConsistency(first_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32402 }
403
404 {
[email protected]2c4fb7b2011-04-02 06:33:29405 SCOPED_TRACE("second balloon");
[email protected]e3dfc742012-11-29 22:42:02406 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
[email protected]84df8332011-12-06 18:22:46407 CheckExtensionConsistency(first_extension_id_);
408 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32409 }
410}
411
[email protected]4ccc8cc2011-06-07 21:25:30412// http://crbug.com/84719
[email protected]5a95d772013-02-06 21:16:28413#if defined(OS_LINUX)
[email protected]4ccc8cc2011-06-07 21:25:30414#define MAYBE_TwoExtensionsShutdownWhileCrashed \
415 DISABLED_TwoExtensionsShutdownWhileCrashed
416#else
417#define MAYBE_TwoExtensionsShutdownWhileCrashed \
418 TwoExtensionsShutdownWhileCrashed
[email protected]5a95d772013-02-06 21:16:28419#endif // defined(OS_LINUX)
[email protected]4ccc8cc2011-06-07 21:25:30420
[email protected]ee8abdeb2010-03-10 11:02:32421// Make sure that when we don't do anything about the crashed extensions
422// and close the browser, it doesn't crash. The browser is closed implicitly
423// at the end of each browser test.
[email protected]5a95d772013-02-06 21:16:28424IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
[email protected]4ccc8cc2011-06-07 21:25:30425 MAYBE_TwoExtensionsShutdownWhileCrashed) {
[email protected]eaa7dd182010-12-14 11:09:00426 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]ee8abdeb2010-03-10 11:02:32427 LoadTestExtension();
[email protected]84df8332011-12-06 18:22:46428 CrashExtension(first_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00429 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]ee8abdeb2010-03-10 11:02:32430 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46431 CrashExtension(second_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00432 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]ee8abdeb2010-03-10 11:02:32433}
434
[email protected]bd099412013-05-17 04:20:16435// Flaky, http://crbug.com/241573.
[email protected]5a95d772013-02-06 21:16:28436IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
[email protected]bd099412013-05-17 04:20:16437 DISABLED_TwoExtensionsIgnoreFirst) {
[email protected]eaa7dd182010-12-14 11:09:00438 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]ee8abdeb2010-03-10 11:02:32439 LoadTestExtension();
440 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46441 CrashExtension(first_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00442 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
[email protected]84df8332011-12-06 18:22:46443 CrashExtension(second_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00444 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]ee8abdeb2010-03-10 11:02:32445
[email protected]ede5e61a2011-12-03 01:05:31446 // Accept notification 1 before canceling notification 0.
447 // Otherwise, on Linux and Windows, there is a race here, in which
448 // canceled notifications do not immediately go away.
[email protected]e3dfc742012-11-29 22:42:02449 ASSERT_NO_FATAL_FAILURE(AcceptNotification(1));
450 ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
[email protected]ee8abdeb2010-03-10 11:02:32451
[email protected]2c4fb7b2011-04-02 06:33:29452 SCOPED_TRACE("balloons done");
[email protected]eaa7dd182010-12-14 11:09:00453 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
[email protected]84df8332011-12-06 18:22:46454 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32455}
456
[email protected]f7d966a2013-05-16 00:03:43457// Flaky, http://crbug.com/241164.
[email protected]5a95d772013-02-06 21:16:28458IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
[email protected]f7d966a2013-05-16 00:03:43459 DISABLED_TwoExtensionsReloadIndependently) {
[email protected]eaa7dd182010-12-14 11:09:00460 const size_t size_before = GetExtensionService()->extensions()->size();
[email protected]ee8abdeb2010-03-10 11:02:32461 LoadTestExtension();
462 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46463 CrashExtension(first_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00464 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
[email protected]84df8332011-12-06 18:22:46465 CrashExtension(second_extension_id_);
[email protected]eaa7dd182010-12-14 11:09:00466 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
[email protected]ee8abdeb2010-03-10 11:02:32467
468 {
469 SCOPED_TRACE("first: reload");
[email protected]47ae23372013-01-29 01:50:48470 WebContents* current_tab =
471 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ee8abdeb2010-03-10 11:02:32472 ASSERT_TRUE(current_tab);
[email protected]1a6273b72011-04-23 00:50:55473 // At the beginning we should have one balloon displayed for each extension.
[email protected]2c4fb7b2011-04-02 06:33:29474 ASSERT_EQ(2U, CountBalloons());
[email protected]ee8abdeb2010-03-10 11:02:32475 ReloadExtension(first_extension_id_);
[email protected]1a6273b72011-04-23 00:50:55476 // One of the balloons should hide after the extension is reloaded.
[email protected]2c4fb7b2011-04-02 06:33:29477 ASSERT_EQ(1U, CountBalloons());
[email protected]84df8332011-12-06 18:22:46478 CheckExtensionConsistency(first_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32479 }
480
481 {
[email protected]2c4fb7b2011-04-02 06:33:29482 SCOPED_TRACE("second: balloon");
[email protected]e3dfc742012-11-29 22:42:02483 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
[email protected]84df8332011-12-06 18:22:46484 CheckExtensionConsistency(first_extension_id_);
485 CheckExtensionConsistency(second_extension_id_);
[email protected]ee8abdeb2010-03-10 11:02:32486 }
487}
[email protected]bb7f40952011-01-13 00:21:20488
[email protected]5d2b0cd2013-05-24 07:47:12489// http://crbug.com/243648
490#if defined(OS_WIN)
491#define MAYBE_CrashAndUninstall DISABLED_CrashAndUninstall
492#else
493#define MAYBE_CrashAndUninstall CrashAndUninstall
494#endif
495IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
496 MAYBE_CrashAndUninstall) {
[email protected]0dfe05c2011-02-23 23:03:36497 const size_t size_before = GetExtensionService()->extensions()->size();
498 const size_t crash_size_before =
499 GetExtensionService()->terminated_extensions()->size();
500 LoadTestExtension();
501 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46502 CrashExtension(first_extension_id_);
[email protected]0dfe05c2011-02-23 23:03:36503 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
504 ASSERT_EQ(crash_size_before + 1,
505 GetExtensionService()->terminated_extensions()->size());
506
[email protected]2c4fb7b2011-04-02 06:33:29507 ASSERT_EQ(1U, CountBalloons());
[email protected]0dfe05c2011-02-23 23:03:36508 UninstallExtension(first_extension_id_);
[email protected]b3a25092013-05-28 22:08:16509 base::MessageLoop::current()->RunUntilIdle();
[email protected]0dfe05c2011-02-23 23:03:36510
511 SCOPED_TRACE("after uninstalling");
512 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
513 ASSERT_EQ(crash_size_before,
514 GetExtensionService()->terminated_extensions()->size());
[email protected]2c4fb7b2011-04-02 06:33:29515 ASSERT_EQ(0U, CountBalloons());
[email protected]0dfe05c2011-02-23 23:03:36516}
517
[email protected]4ccc8cc2011-06-07 21:25:30518// http://crbug.com/84719
519#if defined(OS_LINUX)
520#define MAYBE_CrashAndUnloadAll DISABLED_CrashAndUnloadAll
521#else
522#define MAYBE_CrashAndUnloadAll CrashAndUnloadAll
523#endif // defined(OS_LINUX)
524
[email protected]5a95d772013-02-06 21:16:28525IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
526 MAYBE_CrashAndUnloadAll) {
[email protected]bb7f40952011-01-13 00:21:20527 const size_t size_before = GetExtensionService()->extensions()->size();
528 const size_t crash_size_before =
529 GetExtensionService()->terminated_extensions()->size();
530 LoadTestExtension();
531 LoadSecondExtension();
[email protected]84df8332011-12-06 18:22:46532 CrashExtension(first_extension_id_);
[email protected]bb7f40952011-01-13 00:21:20533 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
534 ASSERT_EQ(crash_size_before + 1,
535 GetExtensionService()->terminated_extensions()->size());
536
[email protected]bb1bc9b32013-12-21 03:09:14537 GetExtensionService()->UnloadAllExtensionsForTest();
[email protected]bb7f40952011-01-13 00:21:20538 ASSERT_EQ(crash_size_before,
539 GetExtensionService()->terminated_extensions()->size());
540}
[email protected]b3f7fe22011-11-11 19:27:56541
[email protected]260122c2013-05-22 15:05:55542// Fails a DCHECK on Aura and Linux: http://crbug.com/169622
543// Failing on Windows: http://crbug.com/232340
544#if defined(USE_AURA) || defined(OS_WIN) || defined(OS_LINUX)
[email protected]60c3e912013-01-12 20:16:28545#define MAYBE_ReloadTabsWithBackgroundPage DISABLED_ReloadTabsWithBackgroundPage
546#else
547#define MAYBE_ReloadTabsWithBackgroundPage ReloadTabsWithBackgroundPage
[email protected]3e902a82013-04-17 11:42:42548#endif
[email protected]60c3e912013-01-12 20:16:28549
[email protected]b3f7fe22011-11-11 19:27:56550// Test that when an extension with a background page that has a tab open
551// crashes, the tab stays open, and reloading it reloads the extension.
552// Regression test for issue 71629.
[email protected]5a95d772013-02-06 21:16:28553IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest,
[email protected]60c3e912013-01-12 20:16:28554 MAYBE_ReloadTabsWithBackgroundPage) {
[email protected]c0849252012-05-12 13:51:27555 TabStripModel* tab_strip = browser()->tab_strip_model();
[email protected]b3f7fe22011-11-11 19:27:56556 const size_t size_before = GetExtensionService()->extensions()->size();
557 const size_t crash_size_before =
558 GetExtensionService()->terminated_extensions()->size();
559 LoadTestExtension();
560
561 // Open a tab extension.
[email protected]a37d4b02012-06-25 21:56:10562 chrome::NewTab(browser());
[email protected]b3f7fe22011-11-11 19:27:56563 ui_test_utils::NavigateToURL(
564 browser(),
565 GURL("chrome-extension://" + first_extension_id_ + "/background.html"));
566
567 const int tabs_before = tab_strip->count();
[email protected]84df8332011-12-06 18:22:46568 CrashExtension(first_extension_id_);
[email protected]b3f7fe22011-11-11 19:27:56569
570 // Tab should still be open, and extension should be crashed.
571 EXPECT_EQ(tabs_before, tab_strip->count());
572 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size());
573 EXPECT_EQ(crash_size_before + 1,
574 GetExtensionService()->terminated_extensions()->size());
575
576 {
[email protected]a7fe9112012-07-20 02:34:45577 content::WindowedNotificationObserver observer(
[email protected]b3f7fe22011-11-11 19:27:56578 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50579 content::Source<NavigationController>(
[email protected]47ae23372013-01-29 01:50:48580 &browser()->tab_strip_model()->GetActiveWebContents()->
581 GetController()));
[email protected]a37d4b02012-06-25 21:56:10582 chrome::Reload(browser(), CURRENT_TAB);
[email protected]b3f7fe22011-11-11 19:27:56583 observer.Wait();
584 }
585 // Extension should now be loaded.
[email protected]84df8332011-12-06 18:22:46586 SCOPED_TRACE("after reloading the tab");
587 CheckExtensionConsistency(first_extension_id_);
[email protected]b3f7fe22011-11-11 19:27:56588 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
589 ASSERT_EQ(0U, CountBalloons());
590}