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