| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/process_util.h" | 5 #include "base/process_util.h" |
| 6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/extensions/extension_browsertest.h" | 7 #include "chrome/browser/extensions/extension_browsertest.h" |
| 8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
| 9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 size_t CountBalloons() { | 57 size_t CountBalloons() { |
| 58 NotificationUIManager* manager = | 58 NotificationUIManager* manager = |
| 59 g_browser_process->notification_ui_manager(); | 59 g_browser_process->notification_ui_manager(); |
| 60 BalloonCollection::Balloons balloons = | 60 BalloonCollection::Balloons balloons = |
| 61 manager->balloon_collection()->GetActiveBalloons(); | 61 manager->balloon_collection()->GetActiveBalloons(); |
| 62 return balloons.size(); | 62 return balloons.size(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void CrashExtension(size_t index) { | 65 void CrashExtension(std::string extension_id) { |
| 66 ASSERT_LT(index, GetExtensionService()->extensions()->size()); | |
| 67 const Extension* extension = | 66 const Extension* extension = |
| 68 GetExtensionService()->extensions()->at(index); | 67 GetExtensionService()->extensions()->GetByID(extension_id); |
| 69 ASSERT_TRUE(extension); | 68 ASSERT_TRUE(extension); |
| 70 std::string extension_id(extension->id()); | |
| 71 ExtensionHost* extension_host = GetExtensionProcessManager()-> | 69 ExtensionHost* extension_host = GetExtensionProcessManager()-> |
| 72 GetBackgroundHostForExtension(extension_id); | 70 GetBackgroundHostForExtension(extension_id); |
| 73 ASSERT_TRUE(extension_host); | 71 ASSERT_TRUE(extension_host); |
| 74 | 72 |
| 75 content::RenderProcessHost* extension_rph = | 73 content::RenderProcessHost* extension_rph = |
| 76 extension_host->render_view_host()->process(); | 74 extension_host->render_view_host()->process(); |
| 77 base::KillProcess(extension_rph->GetHandle(), content::RESULT_CODE_KILLED, | 75 base::KillProcess(extension_rph->GetHandle(), content::RESULT_CODE_KILLED, |
| 78 false); | 76 false); |
| 79 ASSERT_TRUE(WaitForExtensionCrash(extension_id)); | 77 ASSERT_TRUE(WaitForExtensionCrash(extension_id)); |
| 80 ASSERT_FALSE(GetExtensionProcessManager()-> | 78 ASSERT_FALSE(GetExtensionProcessManager()-> |
| 81 GetBackgroundHostForExtension(extension_id)); | 79 GetBackgroundHostForExtension(extension_id)); |
| 82 } | 80 } |
| 83 | 81 |
| 84 void CheckExtensionConsistency(size_t index) { | 82 void CheckExtensionConsistency(std::string extension_id) { |
| 85 ASSERT_LT(index, GetExtensionService()->extensions()->size()); | |
| 86 const Extension* extension = | 83 const Extension* extension = |
| 87 GetExtensionService()->extensions()->at(index); | 84 GetExtensionService()->extensions()->GetByID(extension_id); |
| 88 ASSERT_TRUE(extension); | 85 ASSERT_TRUE(extension); |
| 89 ExtensionHost* extension_host = GetExtensionProcessManager()-> | 86 ExtensionHost* extension_host = GetExtensionProcessManager()-> |
| 90 GetBackgroundHostForExtension(extension->id()); | 87 GetBackgroundHostForExtension(extension_id); |
| 91 ASSERT_TRUE(extension_host); | 88 ASSERT_TRUE(extension_host); |
| 92 ASSERT_TRUE(GetExtensionProcessManager()->HasExtensionHost(extension_host)); | 89 ASSERT_TRUE(GetExtensionProcessManager()->HasExtensionHost(extension_host)); |
| 93 ASSERT_TRUE(extension_host->IsRenderViewLive()); | 90 ASSERT_TRUE(extension_host->IsRenderViewLive()); |
| 94 extensions::ProcessMap* process_map = | 91 extensions::ProcessMap* process_map = |
| 95 browser()->profile()->GetExtensionService()->process_map(); | 92 browser()->profile()->GetExtensionService()->process_map(); |
| 96 ASSERT_TRUE(process_map->Contains( | 93 ASSERT_TRUE(process_map->Contains( |
| 97 extension->id(), extension_host->render_view_host()->process()-> | 94 extension_id, extension_host->render_view_host()->process()->GetID())); |
| 98 GetID())); | |
| 99 } | 95 } |
| 100 | 96 |
| 101 void LoadTestExtension() { | 97 void LoadTestExtension() { |
| 102 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); | 98 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 103 const size_t size_before = GetExtensionService()->extensions()->size(); | 99 const Extension* extension = LoadExtension( |
| 104 ASSERT_TRUE(LoadExtension( | 100 test_data_dir_.AppendASCII("common").AppendASCII("background_page")); |
| 105 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | |
| 106 const Extension* extension = GetExtensionService()->extensions()->back(); | |
| 107 ASSERT_TRUE(extension); | 101 ASSERT_TRUE(extension); |
| 108 first_extension_id_ = extension->id(); | 102 first_extension_id_ = extension->id(); |
| 109 CheckExtensionConsistency(size_before); | 103 CheckExtensionConsistency(first_extension_id_); |
| 110 } | 104 } |
| 111 | 105 |
| 112 void LoadSecondExtension() { | 106 void LoadSecondExtension() { |
| 113 int offset = GetExtensionService()->extensions()->size(); | 107 const Extension* extension = LoadExtension( |
| 114 ASSERT_TRUE(LoadExtension( | 108 test_data_dir_.AppendASCII("install").AppendASCII("install")); |
| 115 test_data_dir_.AppendASCII("install").AppendASCII("install"))); | |
| 116 const Extension* extension = | |
| 117 GetExtensionService()->extensions()->at(offset); | |
| 118 ASSERT_TRUE(extension); | 109 ASSERT_TRUE(extension); |
| 119 second_extension_id_ = extension->id(); | 110 second_extension_id_ = extension->id(); |
| 120 CheckExtensionConsistency(offset); | 111 CheckExtensionConsistency(second_extension_id_); |
| 121 } | 112 } |
| 122 | 113 |
| 123 std::string first_extension_id_; | 114 std::string first_extension_id_; |
| 124 std::string second_extension_id_; | 115 std::string second_extension_id_; |
| 125 }; | 116 }; |
| 126 | 117 |
| 127 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) { | 118 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) { |
| 128 const size_t size_before = GetExtensionService()->extensions()->size(); | 119 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 129 const size_t crash_size_before = | 120 const size_t crash_size_before = |
| 130 GetExtensionService()->terminated_extensions()->size(); | 121 GetExtensionService()->terminated_extensions()->size(); |
| 131 LoadTestExtension(); | 122 LoadTestExtension(); |
| 132 CrashExtension(size_before); | 123 CrashExtension(first_extension_id_); |
| 133 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 124 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 134 ASSERT_EQ(crash_size_before + 1, | 125 ASSERT_EQ(crash_size_before + 1, |
| 135 GetExtensionService()->terminated_extensions()->size()); | 126 GetExtensionService()->terminated_extensions()->size()); |
| 136 AcceptNotification(0); | 127 AcceptNotification(0); |
| 137 | 128 |
| 138 SCOPED_TRACE("after clicking the balloon"); | 129 SCOPED_TRACE("after clicking the balloon"); |
| 139 CheckExtensionConsistency(size_before); | 130 CheckExtensionConsistency(first_extension_id_); |
| 140 ASSERT_EQ(crash_size_before, | 131 ASSERT_EQ(crash_size_before, |
| 141 GetExtensionService()->terminated_extensions()->size()); | 132 GetExtensionService()->terminated_extensions()->size()); |
| 142 } | 133 } |
| 143 | 134 |
| 144 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) { | 135 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) { |
| 145 const size_t size_before = GetExtensionService()->extensions()->size(); | 136 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 146 const size_t crash_size_before = | 137 const size_t crash_size_before = |
| 147 GetExtensionService()->terminated_extensions()->size(); | 138 GetExtensionService()->terminated_extensions()->size(); |
| 148 LoadTestExtension(); | 139 LoadTestExtension(); |
| 149 CrashExtension(size_before); | 140 CrashExtension(first_extension_id_); |
| 150 | 141 |
| 151 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 142 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 152 ASSERT_EQ(crash_size_before + 1, | 143 ASSERT_EQ(crash_size_before + 1, |
| 153 GetExtensionService()->terminated_extensions()->size()); | 144 GetExtensionService()->terminated_extensions()->size()); |
| 154 | 145 |
| 155 CancelNotification(0); | 146 CancelNotification(0); |
| 156 ReloadExtension(first_extension_id_); | 147 ReloadExtension(first_extension_id_); |
| 157 | 148 |
| 158 SCOPED_TRACE("after reloading"); | 149 SCOPED_TRACE("after reloading"); |
| 159 CheckExtensionConsistency(size_before); | 150 CheckExtensionConsistency(first_extension_id_); |
| 160 ASSERT_EQ(crash_size_before, | 151 ASSERT_EQ(crash_size_before, |
| 161 GetExtensionService()->terminated_extensions()->size()); | 152 GetExtensionService()->terminated_extensions()->size()); |
| 162 } | 153 } |
| 163 | 154 |
| 164 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) { | 155 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) { |
| 165 const size_t size_before = GetExtensionService()->extensions()->size(); | 156 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 166 LoadTestExtension(); | 157 LoadTestExtension(); |
| 167 CrashExtension(size_before); | 158 CrashExtension(first_extension_id_); |
| 168 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 159 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 169 | 160 |
| 170 ReloadExtension(first_extension_id_); | 161 ReloadExtension(first_extension_id_); |
| 171 | 162 |
| 172 SCOPED_TRACE("after reloading"); | 163 SCOPED_TRACE("after reloading"); |
| 173 CheckExtensionConsistency(size_before); | 164 CheckExtensionConsistency(first_extension_id_); |
| 174 | 165 |
| 175 TabContents* current_tab = browser()->GetSelectedTabContents(); | 166 TabContents* current_tab = browser()->GetSelectedTabContents(); |
| 176 ASSERT_TRUE(current_tab); | 167 ASSERT_TRUE(current_tab); |
| 177 | 168 |
| 178 // The balloon should automatically hide after the extension is successfully | 169 // The balloon should automatically hide after the extension is successfully |
| 179 // reloaded. | 170 // reloaded. |
| 180 ASSERT_EQ(0U, CountBalloons()); | 171 ASSERT_EQ(0U, CountBalloons()); |
| 181 } | 172 } |
| 182 | 173 |
| 183 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 174 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 184 ReloadIndependentlyChangeTabs) { | 175 ReloadIndependentlyChangeTabs) { |
| 185 const size_t size_before = GetExtensionService()->extensions()->size(); | 176 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 186 LoadTestExtension(); | 177 LoadTestExtension(); |
| 187 CrashExtension(size_before); | 178 CrashExtension(first_extension_id_); |
| 188 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 179 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 189 | 180 |
| 190 TabContents* original_tab = browser()->GetSelectedTabContents(); | 181 TabContents* original_tab = browser()->GetSelectedTabContents(); |
| 191 ASSERT_TRUE(original_tab); | 182 ASSERT_TRUE(original_tab); |
| 192 ASSERT_EQ(1U, CountBalloons()); | 183 ASSERT_EQ(1U, CountBalloons()); |
| 193 | 184 |
| 194 // Open a new tab, but the balloon will still be there. | 185 // Open a new tab, but the balloon will still be there. |
| 195 browser()->NewTab(); | 186 browser()->NewTab(); |
| 196 TabContents* new_current_tab = browser()->GetSelectedTabContents(); | 187 TabContents* new_current_tab = browser()->GetSelectedTabContents(); |
| 197 ASSERT_TRUE(new_current_tab); | 188 ASSERT_TRUE(new_current_tab); |
| 198 ASSERT_NE(new_current_tab, original_tab); | 189 ASSERT_NE(new_current_tab, original_tab); |
| 199 ASSERT_EQ(1U, CountBalloons()); | 190 ASSERT_EQ(1U, CountBalloons()); |
| 200 | 191 |
| 201 ReloadExtension(first_extension_id_); | 192 ReloadExtension(first_extension_id_); |
| 202 | 193 |
| 203 SCOPED_TRACE("after reloading"); | 194 SCOPED_TRACE("after reloading"); |
| 204 CheckExtensionConsistency(size_before); | 195 CheckExtensionConsistency(first_extension_id_); |
| 205 | 196 |
| 206 // The balloon should automatically hide after the extension is successfully | 197 // The balloon should automatically hide after the extension is successfully |
| 207 // reloaded. | 198 // reloaded. |
| 208 ASSERT_EQ(0U, CountBalloons()); | 199 ASSERT_EQ(0U, CountBalloons()); |
| 209 } | 200 } |
| 210 | 201 |
| 211 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 202 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 212 ReloadIndependentlyNavigatePage) { | 203 ReloadIndependentlyNavigatePage) { |
| 213 const size_t size_before = GetExtensionService()->extensions()->size(); | 204 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 214 LoadTestExtension(); | 205 LoadTestExtension(); |
| 215 CrashExtension(size_before); | 206 CrashExtension(first_extension_id_); |
| 216 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 207 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 217 | 208 |
| 218 TabContents* current_tab = browser()->GetSelectedTabContents(); | 209 TabContents* current_tab = browser()->GetSelectedTabContents(); |
| 219 ASSERT_TRUE(current_tab); | 210 ASSERT_TRUE(current_tab); |
| 220 ASSERT_EQ(1U, CountBalloons()); | 211 ASSERT_EQ(1U, CountBalloons()); |
| 221 | 212 |
| 222 // Navigate to another page. | 213 // Navigate to another page. |
| 223 ui_test_utils::NavigateToURL(browser(), | 214 ui_test_utils::NavigateToURL(browser(), |
| 224 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 215 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 225 FilePath(FILE_PATH_LITERAL("title1.html")))); | 216 FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 226 ASSERT_EQ(1U, CountBalloons()); | 217 ASSERT_EQ(1U, CountBalloons()); |
| 227 | 218 |
| 228 ReloadExtension(first_extension_id_); | 219 ReloadExtension(first_extension_id_); |
| 229 | 220 |
| 230 SCOPED_TRACE("after reloading"); | 221 SCOPED_TRACE("after reloading"); |
| 231 CheckExtensionConsistency(size_before); | 222 CheckExtensionConsistency(first_extension_id_); |
| 232 | 223 |
| 233 // The balloon should automatically hide after the extension is successfully | 224 // The balloon should automatically hide after the extension is successfully |
| 234 // reloaded. | 225 // reloaded. |
| 235 ASSERT_EQ(0U, CountBalloons()); | 226 ASSERT_EQ(0U, CountBalloons()); |
| 236 } | 227 } |
| 237 | 228 |
| 238 // Make sure that when we don't do anything about the crashed extension | 229 // Make sure that when we don't do anything about the crashed extension |
| 239 // and close the browser, it doesn't crash. The browser is closed implicitly | 230 // and close the browser, it doesn't crash. The browser is closed implicitly |
| 240 // at the end of each browser test. | 231 // at the end of each browser test. |
| 241 // | 232 // |
| 242 // http://crbug.com/84719 | 233 // http://crbug.com/84719 |
| 243 #if defined(OS_LINUX) | 234 #if defined(OS_LINUX) |
| 244 #define MAYBE_ShutdownWhileCrashed DISABLED_ShutdownWhileCrashed | 235 #define MAYBE_ShutdownWhileCrashed DISABLED_ShutdownWhileCrashed |
| 245 #else | 236 #else |
| 246 #define MAYBE_ShutdownWhileCrashed ShutdownWhileCrashed | 237 #define MAYBE_ShutdownWhileCrashed ShutdownWhileCrashed |
| 247 #endif // defined(OS_LINUX) | 238 #endif // defined(OS_LINUX) |
| 248 | 239 |
| 249 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_ShutdownWhileCrashed) { | 240 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_ShutdownWhileCrashed) { |
| 250 const size_t size_before = GetExtensionService()->extensions()->size(); | 241 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 251 LoadTestExtension(); | 242 LoadTestExtension(); |
| 252 CrashExtension(size_before); | 243 CrashExtension(first_extension_id_); |
| 253 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 244 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 254 } | 245 } |
| 255 | 246 |
| 256 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) { | 247 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) { |
| 257 const size_t size_before = GetExtensionService()->extensions()->size(); | 248 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 258 LoadTestExtension(); | 249 LoadTestExtension(); |
| 259 LoadSecondExtension(); | 250 LoadSecondExtension(); |
| 260 CrashExtension(size_before); | 251 CrashExtension(first_extension_id_); |
| 261 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 252 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 262 AcceptNotification(0); | 253 AcceptNotification(0); |
| 263 | 254 |
| 264 SCOPED_TRACE("after clicking the balloon"); | 255 SCOPED_TRACE("after clicking the balloon"); |
| 265 CheckExtensionConsistency(size_before); | 256 CheckExtensionConsistency(first_extension_id_); |
| 266 CheckExtensionConsistency(size_before + 1); | 257 CheckExtensionConsistency(second_extension_id_); |
| 267 } | 258 } |
| 268 | 259 |
| 269 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) { | 260 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) { |
| 270 const size_t size_before = GetExtensionService()->extensions()->size(); | 261 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 271 LoadTestExtension(); | 262 LoadTestExtension(); |
| 272 LoadSecondExtension(); | 263 LoadSecondExtension(); |
| 273 CrashExtension(size_before + 1); | 264 CrashExtension(second_extension_id_); |
| 274 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 265 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 275 AcceptNotification(0); | 266 AcceptNotification(0); |
| 276 | 267 |
| 277 SCOPED_TRACE("after clicking the balloon"); | 268 SCOPED_TRACE("after clicking the balloon"); |
| 278 CheckExtensionConsistency(size_before); | 269 CheckExtensionConsistency(first_extension_id_); |
| 279 CheckExtensionConsistency(size_before + 1); | 270 CheckExtensionConsistency(second_extension_id_); |
| 280 } | 271 } |
| 281 | 272 |
| 282 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 273 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 283 TwoExtensionsCrashBothAtOnce) { | 274 TwoExtensionsCrashBothAtOnce) { |
| 284 const size_t size_before = GetExtensionService()->extensions()->size(); | 275 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 285 const size_t crash_size_before = | 276 const size_t crash_size_before = |
| 286 GetExtensionService()->terminated_extensions()->size(); | 277 GetExtensionService()->terminated_extensions()->size(); |
| 287 LoadTestExtension(); | 278 LoadTestExtension(); |
| 288 LoadSecondExtension(); | 279 LoadSecondExtension(); |
| 289 CrashExtension(size_before); | 280 CrashExtension(first_extension_id_); |
| 290 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 281 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 291 ASSERT_EQ(crash_size_before + 1, | 282 ASSERT_EQ(crash_size_before + 1, |
| 292 GetExtensionService()->terminated_extensions()->size()); | 283 GetExtensionService()->terminated_extensions()->size()); |
| 293 CrashExtension(size_before); | 284 CrashExtension(second_extension_id_); |
| 294 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 285 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 295 ASSERT_EQ(crash_size_before + 2, | 286 ASSERT_EQ(crash_size_before + 2, |
| 296 GetExtensionService()->terminated_extensions()->size()); | 287 GetExtensionService()->terminated_extensions()->size()); |
| 297 | 288 |
| 298 { | 289 { |
| 299 SCOPED_TRACE("first balloon"); | 290 SCOPED_TRACE("first balloon"); |
| 300 AcceptNotification(0); | 291 AcceptNotification(0); |
| 301 CheckExtensionConsistency(size_before); | 292 CheckExtensionConsistency(first_extension_id_); |
| 302 } | 293 } |
| 303 | 294 |
| 304 { | 295 { |
| 305 SCOPED_TRACE("second balloon"); | 296 SCOPED_TRACE("second balloon"); |
| 306 AcceptNotification(0); | 297 AcceptNotification(0); |
| 307 CheckExtensionConsistency(size_before); | 298 CheckExtensionConsistency(first_extension_id_); |
| 308 CheckExtensionConsistency(size_before + 1); | 299 CheckExtensionConsistency(second_extension_id_); |
| 309 } | 300 } |
| 310 } | 301 } |
| 311 | 302 |
| 312 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) { | 303 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) { |
| 313 const size_t size_before = GetExtensionService()->extensions()->size(); | 304 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 314 LoadTestExtension(); | 305 LoadTestExtension(); |
| 315 CrashExtension(size_before); | 306 CrashExtension(first_extension_id_); |
| 316 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 307 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 317 LoadSecondExtension(); | 308 LoadSecondExtension(); |
| 318 CrashExtension(size_before); | 309 CrashExtension(second_extension_id_); |
| 319 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 310 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 320 | 311 |
| 321 { | 312 { |
| 322 SCOPED_TRACE("first balloon"); | 313 SCOPED_TRACE("first balloon"); |
| 323 AcceptNotification(0); | 314 AcceptNotification(0); |
| 324 CheckExtensionConsistency(size_before); | 315 CheckExtensionConsistency(first_extension_id_); |
| 325 } | 316 } |
| 326 | 317 |
| 327 { | 318 { |
| 328 SCOPED_TRACE("second balloon"); | 319 SCOPED_TRACE("second balloon"); |
| 329 AcceptNotification(0); | 320 AcceptNotification(0); |
| 330 CheckExtensionConsistency(size_before); | 321 CheckExtensionConsistency(first_extension_id_); |
| 331 CheckExtensionConsistency(size_before + 1); | 322 CheckExtensionConsistency(second_extension_id_); |
| 332 } | 323 } |
| 333 } | 324 } |
| 334 | 325 |
| 335 // http://crbug.com/84719 | 326 // http://crbug.com/84719 |
| 336 #if defined(OS_LINUX) | 327 #if defined(OS_LINUX) |
| 337 #define MAYBE_TwoExtensionsShutdownWhileCrashed \ | 328 #define MAYBE_TwoExtensionsShutdownWhileCrashed \ |
| 338 DISABLED_TwoExtensionsShutdownWhileCrashed | 329 DISABLED_TwoExtensionsShutdownWhileCrashed |
| 339 #else | 330 #else |
| 340 #define MAYBE_TwoExtensionsShutdownWhileCrashed \ | 331 #define MAYBE_TwoExtensionsShutdownWhileCrashed \ |
| 341 TwoExtensionsShutdownWhileCrashed | 332 TwoExtensionsShutdownWhileCrashed |
| 342 #endif // defined(OS_LINUX) | 333 #endif // defined(OS_LINUX) |
| 343 | 334 |
| 344 // Make sure that when we don't do anything about the crashed extensions | 335 // Make sure that when we don't do anything about the crashed extensions |
| 345 // and close the browser, it doesn't crash. The browser is closed implicitly | 336 // and close the browser, it doesn't crash. The browser is closed implicitly |
| 346 // at the end of each browser test. | 337 // at the end of each browser test. |
| 347 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 338 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 348 MAYBE_TwoExtensionsShutdownWhileCrashed) { | 339 MAYBE_TwoExtensionsShutdownWhileCrashed) { |
| 349 const size_t size_before = GetExtensionService()->extensions()->size(); | 340 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 350 LoadTestExtension(); | 341 LoadTestExtension(); |
| 351 CrashExtension(size_before); | 342 CrashExtension(first_extension_id_); |
| 352 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 343 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 353 LoadSecondExtension(); | 344 LoadSecondExtension(); |
| 354 CrashExtension(size_before); | 345 CrashExtension(second_extension_id_); |
| 355 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 346 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 356 } | 347 } |
| 357 | 348 |
| 358 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 349 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 359 TwoExtensionsIgnoreFirst) { | 350 TwoExtensionsIgnoreFirst) { |
| 360 const size_t size_before = GetExtensionService()->extensions()->size(); | 351 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 361 LoadTestExtension(); | 352 LoadTestExtension(); |
| 362 LoadSecondExtension(); | 353 LoadSecondExtension(); |
| 363 CrashExtension(size_before); | 354 CrashExtension(first_extension_id_); |
| 364 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 355 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 365 CrashExtension(size_before); | 356 CrashExtension(second_extension_id_); |
| 366 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 357 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 367 | 358 |
| 368 // Accept notification 1 before canceling notification 0. | 359 // Accept notification 1 before canceling notification 0. |
| 369 // Otherwise, on Linux and Windows, there is a race here, in which | 360 // Otherwise, on Linux and Windows, there is a race here, in which |
| 370 // canceled notifications do not immediately go away. | 361 // canceled notifications do not immediately go away. |
| 371 AcceptNotification(1); | 362 AcceptNotification(1); |
| 372 CancelNotification(0); | 363 CancelNotification(0); |
| 373 | 364 |
| 374 SCOPED_TRACE("balloons done"); | 365 SCOPED_TRACE("balloons done"); |
| 375 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 366 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 376 EXPECT_EQ(second_extension_id_, | 367 CheckExtensionConsistency(second_extension_id_); |
| 377 GetExtensionService()->extensions()->at(size_before)->id()); | |
| 378 CheckExtensionConsistency(size_before); | |
| 379 } | 368 } |
| 380 | 369 |
| 381 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 370 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 382 TwoExtensionsReloadIndependently) { | 371 TwoExtensionsReloadIndependently) { |
| 383 const size_t size_before = GetExtensionService()->extensions()->size(); | 372 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 384 LoadTestExtension(); | 373 LoadTestExtension(); |
| 385 LoadSecondExtension(); | 374 LoadSecondExtension(); |
| 386 CrashExtension(size_before); | 375 CrashExtension(first_extension_id_); |
| 387 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 376 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 388 CrashExtension(size_before); | 377 CrashExtension(second_extension_id_); |
| 389 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 378 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 390 | 379 |
| 391 { | 380 { |
| 392 SCOPED_TRACE("first: reload"); | 381 SCOPED_TRACE("first: reload"); |
| 393 TabContents* current_tab = browser()->GetSelectedTabContents(); | 382 TabContents* current_tab = browser()->GetSelectedTabContents(); |
| 394 ASSERT_TRUE(current_tab); | 383 ASSERT_TRUE(current_tab); |
| 395 // At the beginning we should have one balloon displayed for each extension. | 384 // At the beginning we should have one balloon displayed for each extension. |
| 396 ASSERT_EQ(2U, CountBalloons()); | 385 ASSERT_EQ(2U, CountBalloons()); |
| 397 ReloadExtension(first_extension_id_); | 386 ReloadExtension(first_extension_id_); |
| 398 // One of the balloons should hide after the extension is reloaded. | 387 // One of the balloons should hide after the extension is reloaded. |
| 399 ASSERT_EQ(1U, CountBalloons()); | 388 ASSERT_EQ(1U, CountBalloons()); |
| 400 CheckExtensionConsistency(size_before); | 389 CheckExtensionConsistency(first_extension_id_); |
| 401 } | 390 } |
| 402 | 391 |
| 403 { | 392 { |
| 404 SCOPED_TRACE("second: balloon"); | 393 SCOPED_TRACE("second: balloon"); |
| 405 AcceptNotification(0); | 394 AcceptNotification(0); |
| 406 CheckExtensionConsistency(size_before); | 395 CheckExtensionConsistency(first_extension_id_); |
| 407 CheckExtensionConsistency(size_before + 1); | 396 CheckExtensionConsistency(second_extension_id_); |
| 408 } | 397 } |
| 409 } | 398 } |
| 410 | 399 |
| 411 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) { | 400 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) { |
| 412 const size_t size_before = GetExtensionService()->extensions()->size(); | 401 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 413 const size_t crash_size_before = | 402 const size_t crash_size_before = |
| 414 GetExtensionService()->terminated_extensions()->size(); | 403 GetExtensionService()->terminated_extensions()->size(); |
| 415 LoadTestExtension(); | 404 LoadTestExtension(); |
| 416 LoadSecondExtension(); | 405 LoadSecondExtension(); |
| 417 CrashExtension(size_before); | 406 CrashExtension(first_extension_id_); |
| 418 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 407 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 419 ASSERT_EQ(crash_size_before + 1, | 408 ASSERT_EQ(crash_size_before + 1, |
| 420 GetExtensionService()->terminated_extensions()->size()); | 409 GetExtensionService()->terminated_extensions()->size()); |
| 421 | 410 |
| 422 ASSERT_EQ(1U, CountBalloons()); | 411 ASSERT_EQ(1U, CountBalloons()); |
| 423 UninstallExtension(first_extension_id_); | 412 UninstallExtension(first_extension_id_); |
| 424 MessageLoop::current()->RunAllPending(); | 413 MessageLoop::current()->RunAllPending(); |
| 425 | 414 |
| 426 SCOPED_TRACE("after uninstalling"); | 415 SCOPED_TRACE("after uninstalling"); |
| 427 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 416 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 428 ASSERT_EQ(crash_size_before, | 417 ASSERT_EQ(crash_size_before, |
| 429 GetExtensionService()->terminated_extensions()->size()); | 418 GetExtensionService()->terminated_extensions()->size()); |
| 430 ASSERT_EQ(0U, CountBalloons()); | 419 ASSERT_EQ(0U, CountBalloons()); |
| 431 } | 420 } |
| 432 | 421 |
| 433 // http://crbug.com/84719 | 422 // http://crbug.com/84719 |
| 434 #if defined(OS_LINUX) | 423 #if defined(OS_LINUX) |
| 435 #define MAYBE_CrashAndUnloadAll DISABLED_CrashAndUnloadAll | 424 #define MAYBE_CrashAndUnloadAll DISABLED_CrashAndUnloadAll |
| 436 #else | 425 #else |
| 437 #define MAYBE_CrashAndUnloadAll CrashAndUnloadAll | 426 #define MAYBE_CrashAndUnloadAll CrashAndUnloadAll |
| 438 #endif // defined(OS_LINUX) | 427 #endif // defined(OS_LINUX) |
| 439 | 428 |
| 440 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_CrashAndUnloadAll) { | 429 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_CrashAndUnloadAll) { |
| 441 const size_t size_before = GetExtensionService()->extensions()->size(); | 430 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 442 const size_t crash_size_before = | 431 const size_t crash_size_before = |
| 443 GetExtensionService()->terminated_extensions()->size(); | 432 GetExtensionService()->terminated_extensions()->size(); |
| 444 LoadTestExtension(); | 433 LoadTestExtension(); |
| 445 LoadSecondExtension(); | 434 LoadSecondExtension(); |
| 446 CrashExtension(size_before); | 435 CrashExtension(first_extension_id_); |
| 447 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 436 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 448 ASSERT_EQ(crash_size_before + 1, | 437 ASSERT_EQ(crash_size_before + 1, |
| 449 GetExtensionService()->terminated_extensions()->size()); | 438 GetExtensionService()->terminated_extensions()->size()); |
| 450 | 439 |
| 451 GetExtensionService()->UnloadAllExtensions(); | 440 GetExtensionService()->UnloadAllExtensions(); |
| 452 ASSERT_EQ(crash_size_before, | 441 ASSERT_EQ(crash_size_before, |
| 453 GetExtensionService()->terminated_extensions()->size()); | 442 GetExtensionService()->terminated_extensions()->size()); |
| 454 } | 443 } |
| 455 | 444 |
| 456 // Test that when an extension with a background page that has a tab open | 445 // Test that when an extension with a background page that has a tab open |
| 457 // crashes, the tab stays open, and reloading it reloads the extension. | 446 // crashes, the tab stays open, and reloading it reloads the extension. |
| 458 // Regression test for issue 71629. | 447 // Regression test for issue 71629. |
| 459 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 448 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 460 ReloadTabsWithBackgroundPage) { | 449 ReloadTabsWithBackgroundPage) { |
| 461 TabStripModel* tab_strip = browser()->tabstrip_model(); | 450 TabStripModel* tab_strip = browser()->tabstrip_model(); |
| 462 const size_t size_before = GetExtensionService()->extensions()->size(); | 451 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 463 const size_t crash_size_before = | 452 const size_t crash_size_before = |
| 464 GetExtensionService()->terminated_extensions()->size(); | 453 GetExtensionService()->terminated_extensions()->size(); |
| 465 LoadTestExtension(); | 454 LoadTestExtension(); |
| 466 | 455 |
| 467 // Open a tab extension. | 456 // Open a tab extension. |
| 468 browser()->NewTab(); | 457 browser()->NewTab(); |
| 469 ui_test_utils::NavigateToURL( | 458 ui_test_utils::NavigateToURL( |
| 470 browser(), | 459 browser(), |
| 471 GURL("chrome-extension://" + first_extension_id_ + "/background.html")); | 460 GURL("chrome-extension://" + first_extension_id_ + "/background.html")); |
| 472 | 461 |
| 473 const int tabs_before = tab_strip->count(); | 462 const int tabs_before = tab_strip->count(); |
| 474 CrashExtension(size_before); | 463 CrashExtension(first_extension_id_); |
| 475 | 464 |
| 476 // Tab should still be open, and extension should be crashed. | 465 // Tab should still be open, and extension should be crashed. |
| 477 EXPECT_EQ(tabs_before, tab_strip->count()); | 466 EXPECT_EQ(tabs_before, tab_strip->count()); |
| 478 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); | 467 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 479 EXPECT_EQ(crash_size_before + 1, | 468 EXPECT_EQ(crash_size_before + 1, |
| 480 GetExtensionService()->terminated_extensions()->size()); | 469 GetExtensionService()->terminated_extensions()->size()); |
| 481 | 470 |
| 482 { | 471 { |
| 483 ui_test_utils::WindowedNotificationObserver observer( | 472 ui_test_utils::WindowedNotificationObserver observer( |
| 484 content::NOTIFICATION_LOAD_STOP, | 473 content::NOTIFICATION_LOAD_STOP, |
| 485 content::Source<NavigationController>( | 474 content::Source<NavigationController>( |
| 486 &browser()->GetSelectedTabContentsWrapper()->controller())); | 475 &browser()->GetSelectedTabContentsWrapper()->controller())); |
| 487 browser()->Reload(CURRENT_TAB); | 476 browser()->Reload(CURRENT_TAB); |
| 488 observer.Wait(); | 477 observer.Wait(); |
| 489 } | 478 } |
| 490 // Extension should now be loaded. | 479 // Extension should now be loaded. |
| 480 SCOPED_TRACE("after reloading the tab"); |
| 481 CheckExtensionConsistency(first_extension_id_); |
| 491 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 482 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 492 ASSERT_EQ(0U, CountBalloons()); | 483 ASSERT_EQ(0U, CountBalloons()); |
| 493 } | 484 } |
| OLD | NEW |