Chromium Code Reviews| 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 // Flaky on mac&&linux due to http://crbug.com/89078. | 349 // Flaky on mac&&linux due to http://crbug.com/89078. |
| 359 #if defined(OS_LINUX) || defined(OS_MACOSX) | 350 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 360 #define MAYBE_TwoExtensionsIgnoreFirst FLAKY_TwoExtensionsIgnoreFirst | 351 #define MAYBE_TwoExtensionsIgnoreFirst FLAKY_TwoExtensionsIgnoreFirst |
| 361 #else | 352 #else |
| 362 #define MAYBE_TwoExtensionsIgnoreFirst TwoExtensionsIgnoreFirst | 353 #define MAYBE_TwoExtensionsIgnoreFirst TwoExtensionsIgnoreFirst |
| 363 #endif // defined(OS_LINUX) || defined(OS_MACOSX) | 354 #endif // defined(OS_LINUX) || defined(OS_MACOSX) |
| 364 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 355 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 365 MAYBE_TwoExtensionsIgnoreFirst) { | 356 MAYBE_TwoExtensionsIgnoreFirst) { |
|
Yoyo Zhou
2011/12/05 19:34:09
I think this test is just wrong. It's meant to ign
| |
| 366 const size_t size_before = GetExtensionService()->extensions()->size(); | 357 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 367 LoadTestExtension(); | 358 LoadTestExtension(); |
| 368 LoadSecondExtension(); | 359 LoadSecondExtension(); |
| 369 CrashExtension(size_before); | 360 CrashExtension(first_extension_id_); |
| 370 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 361 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 371 CrashExtension(size_before); | 362 CrashExtension(second_extension_id_); |
| 372 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 363 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 373 | 364 |
| 374 CancelNotification(0); | 365 CancelNotification(0); |
| 375 // Cancelling the balloon at 0 will close the balloon, and the balloon in | 366 // Cancelling the balloon at 0 will close the balloon, and the balloon in |
| 376 // index 1 will move into index 0. | 367 // index 1 will move into index 0. |
| 377 AcceptNotification(0); | 368 AcceptNotification(0); |
| 378 | 369 |
| 379 SCOPED_TRACE("balloons done"); | 370 SCOPED_TRACE("balloons done"); |
| 380 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 371 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 381 CheckExtensionConsistency(size_before); | 372 CheckExtensionConsistency(second_extension_id_); |
| 382 } | 373 } |
| 383 | 374 |
| 384 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 375 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 385 TwoExtensionsReloadIndependently) { | 376 TwoExtensionsReloadIndependently) { |
| 386 const size_t size_before = GetExtensionService()->extensions()->size(); | 377 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 387 LoadTestExtension(); | 378 LoadTestExtension(); |
| 388 LoadSecondExtension(); | 379 LoadSecondExtension(); |
| 389 CrashExtension(size_before); | 380 CrashExtension(first_extension_id_); |
| 390 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 381 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 391 CrashExtension(size_before); | 382 CrashExtension(second_extension_id_); |
| 392 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 383 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 393 | 384 |
| 394 { | 385 { |
| 395 SCOPED_TRACE("first: reload"); | 386 SCOPED_TRACE("first: reload"); |
| 396 TabContents* current_tab = browser()->GetSelectedTabContents(); | 387 TabContents* current_tab = browser()->GetSelectedTabContents(); |
| 397 ASSERT_TRUE(current_tab); | 388 ASSERT_TRUE(current_tab); |
| 398 // At the beginning we should have one balloon displayed for each extension. | 389 // At the beginning we should have one balloon displayed for each extension. |
| 399 ASSERT_EQ(2U, CountBalloons()); | 390 ASSERT_EQ(2U, CountBalloons()); |
| 400 ReloadExtension(first_extension_id_); | 391 ReloadExtension(first_extension_id_); |
| 401 // One of the balloons should hide after the extension is reloaded. | 392 // One of the balloons should hide after the extension is reloaded. |
| 402 ASSERT_EQ(1U, CountBalloons()); | 393 ASSERT_EQ(1U, CountBalloons()); |
| 403 CheckExtensionConsistency(size_before); | 394 CheckExtensionConsistency(first_extension_id_); |
| 404 } | 395 } |
| 405 | 396 |
| 406 { | 397 { |
| 407 SCOPED_TRACE("second: balloon"); | 398 SCOPED_TRACE("second: balloon"); |
| 408 AcceptNotification(0); | 399 AcceptNotification(0); |
| 409 CheckExtensionConsistency(size_before); | 400 CheckExtensionConsistency(first_extension_id_); |
| 410 CheckExtensionConsistency(size_before + 1); | 401 CheckExtensionConsistency(second_extension_id_); |
| 411 } | 402 } |
| 412 } | 403 } |
| 413 | 404 |
| 414 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) { | 405 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) { |
| 415 const size_t size_before = GetExtensionService()->extensions()->size(); | 406 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 416 const size_t crash_size_before = | 407 const size_t crash_size_before = |
| 417 GetExtensionService()->terminated_extensions()->size(); | 408 GetExtensionService()->terminated_extensions()->size(); |
| 418 LoadTestExtension(); | 409 LoadTestExtension(); |
| 419 LoadSecondExtension(); | 410 LoadSecondExtension(); |
| 420 CrashExtension(size_before); | 411 CrashExtension(first_extension_id_); |
| 421 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 412 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 422 ASSERT_EQ(crash_size_before + 1, | 413 ASSERT_EQ(crash_size_before + 1, |
| 423 GetExtensionService()->terminated_extensions()->size()); | 414 GetExtensionService()->terminated_extensions()->size()); |
| 424 | 415 |
| 425 ASSERT_EQ(1U, CountBalloons()); | 416 ASSERT_EQ(1U, CountBalloons()); |
| 426 UninstallExtension(first_extension_id_); | 417 UninstallExtension(first_extension_id_); |
| 427 MessageLoop::current()->RunAllPending(); | 418 MessageLoop::current()->RunAllPending(); |
| 428 | 419 |
| 429 SCOPED_TRACE("after uninstalling"); | 420 SCOPED_TRACE("after uninstalling"); |
| 430 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 421 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 431 ASSERT_EQ(crash_size_before, | 422 ASSERT_EQ(crash_size_before, |
| 432 GetExtensionService()->terminated_extensions()->size()); | 423 GetExtensionService()->terminated_extensions()->size()); |
| 433 ASSERT_EQ(0U, CountBalloons()); | 424 ASSERT_EQ(0U, CountBalloons()); |
| 434 } | 425 } |
| 435 | 426 |
| 436 // http://crbug.com/84719 | 427 // http://crbug.com/84719 |
| 437 #if defined(OS_LINUX) | 428 #if defined(OS_LINUX) |
| 438 #define MAYBE_CrashAndUnloadAll DISABLED_CrashAndUnloadAll | 429 #define MAYBE_CrashAndUnloadAll DISABLED_CrashAndUnloadAll |
| 439 #else | 430 #else |
| 440 #define MAYBE_CrashAndUnloadAll CrashAndUnloadAll | 431 #define MAYBE_CrashAndUnloadAll CrashAndUnloadAll |
| 441 #endif // defined(OS_LINUX) | 432 #endif // defined(OS_LINUX) |
| 442 | 433 |
| 443 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_CrashAndUnloadAll) { | 434 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_CrashAndUnloadAll) { |
| 444 const size_t size_before = GetExtensionService()->extensions()->size(); | 435 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 445 const size_t crash_size_before = | 436 const size_t crash_size_before = |
| 446 GetExtensionService()->terminated_extensions()->size(); | 437 GetExtensionService()->terminated_extensions()->size(); |
| 447 LoadTestExtension(); | 438 LoadTestExtension(); |
| 448 LoadSecondExtension(); | 439 LoadSecondExtension(); |
| 449 CrashExtension(size_before); | 440 CrashExtension(first_extension_id_); |
| 450 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 441 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 451 ASSERT_EQ(crash_size_before + 1, | 442 ASSERT_EQ(crash_size_before + 1, |
| 452 GetExtensionService()->terminated_extensions()->size()); | 443 GetExtensionService()->terminated_extensions()->size()); |
| 453 | 444 |
| 454 GetExtensionService()->UnloadAllExtensions(); | 445 GetExtensionService()->UnloadAllExtensions(); |
| 455 ASSERT_EQ(crash_size_before, | 446 ASSERT_EQ(crash_size_before, |
| 456 GetExtensionService()->terminated_extensions()->size()); | 447 GetExtensionService()->terminated_extensions()->size()); |
| 457 } | 448 } |
| 458 | 449 |
| 459 // Test that when an extension with a background page that has a tab open | 450 // Test that when an extension with a background page that has a tab open |
| 460 // crashes, the tab stays open, and reloading it reloads the extension. | 451 // crashes, the tab stays open, and reloading it reloads the extension. |
| 461 // Regression test for issue 71629. | 452 // Regression test for issue 71629. |
| 462 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 453 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
| 463 ReloadTabsWithBackgroundPage) { | 454 ReloadTabsWithBackgroundPage) { |
| 464 TabStripModel* tab_strip = browser()->tabstrip_model(); | 455 TabStripModel* tab_strip = browser()->tabstrip_model(); |
| 465 const size_t size_before = GetExtensionService()->extensions()->size(); | 456 const size_t size_before = GetExtensionService()->extensions()->size(); |
| 466 const size_t crash_size_before = | 457 const size_t crash_size_before = |
| 467 GetExtensionService()->terminated_extensions()->size(); | 458 GetExtensionService()->terminated_extensions()->size(); |
| 468 LoadTestExtension(); | 459 LoadTestExtension(); |
| 469 | 460 |
| 470 // Open a tab extension. | 461 // Open a tab extension. |
| 471 browser()->NewTab(); | 462 browser()->NewTab(); |
| 472 ui_test_utils::NavigateToURL( | 463 ui_test_utils::NavigateToURL( |
| 473 browser(), | 464 browser(), |
| 474 GURL("chrome-extension://" + first_extension_id_ + "/background.html")); | 465 GURL("chrome-extension://" + first_extension_id_ + "/background.html")); |
| 475 | 466 |
| 476 const int tabs_before = tab_strip->count(); | 467 const int tabs_before = tab_strip->count(); |
| 477 CrashExtension(size_before); | 468 CrashExtension(first_extension_id_); |
| 478 | 469 |
| 479 // Tab should still be open, and extension should be crashed. | 470 // Tab should still be open, and extension should be crashed. |
| 480 EXPECT_EQ(tabs_before, tab_strip->count()); | 471 EXPECT_EQ(tabs_before, tab_strip->count()); |
| 481 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); | 472 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); |
| 482 EXPECT_EQ(crash_size_before + 1, | 473 EXPECT_EQ(crash_size_before + 1, |
| 483 GetExtensionService()->terminated_extensions()->size()); | 474 GetExtensionService()->terminated_extensions()->size()); |
| 484 | 475 |
| 485 { | 476 { |
| 486 ui_test_utils::WindowedNotificationObserver observer( | 477 ui_test_utils::WindowedNotificationObserver observer( |
| 487 content::NOTIFICATION_LOAD_STOP, | 478 content::NOTIFICATION_LOAD_STOP, |
| 488 content::Source<NavigationController>( | 479 content::Source<NavigationController>( |
| 489 &browser()->GetSelectedTabContentsWrapper()->controller())); | 480 &browser()->GetSelectedTabContentsWrapper()->controller())); |
| 490 browser()->Reload(CURRENT_TAB); | 481 browser()->Reload(CURRENT_TAB); |
| 491 observer.Wait(); | 482 observer.Wait(); |
| 492 } | 483 } |
| 493 // Extension should now be loaded. | 484 // Extension should now be loaded. |
| 485 SCOPED_TRACE("after reloading the tab"); | |
| 486 CheckExtensionConsistency(first_extension_id_); | |
| 494 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 487 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
| 495 ASSERT_EQ(0U, CountBalloons()); | 488 ASSERT_EQ(0U, CountBalloons()); |
| 496 } | 489 } |
| OLD | NEW |