OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
11 #include "chrome/browser/notifications/balloon.h" | 11 #include "chrome/browser/notifications/balloon.h" |
12 #include "chrome/browser/notifications/balloon_collection.h" | 12 #include "chrome/browser/notifications/balloon_collection.h" |
13 #include "chrome/browser/notifications/balloon_host.h" | 13 #include "chrome/browser/notifications/balloon_host.h" |
14 #include "chrome/browser/notifications/notification.h" | 14 #include "chrome/browser/notifications/notification.h" |
15 #include "chrome/browser/notifications/notification_delegate.h" | 15 #include "chrome/browser/notifications/notification_delegate.h" |
16 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_ui_manager.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_commands.h" | 19 #include "chrome/browser/ui/browser_commands.h" |
| 20 #include "chrome/browser/ui/browser_tabstrip.h" |
20 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/public/browser/navigation_controller.h" | 24 #include "content/public/browser/navigation_controller.h" |
24 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
27 #include "content/public/common/result_codes.h" | 28 #include "content/public/common/result_codes.h" |
28 | 29 |
29 using content::NavigationController; | 30 using content::NavigationController; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 const size_t size_before = GetExtensionService()->extensions()->size(); | 170 const size_t size_before = GetExtensionService()->extensions()->size(); |
170 LoadTestExtension(); | 171 LoadTestExtension(); |
171 CrashExtension(first_extension_id_); | 172 CrashExtension(first_extension_id_); |
172 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 173 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
173 | 174 |
174 ReloadExtension(first_extension_id_); | 175 ReloadExtension(first_extension_id_); |
175 | 176 |
176 SCOPED_TRACE("after reloading"); | 177 SCOPED_TRACE("after reloading"); |
177 CheckExtensionConsistency(first_extension_id_); | 178 CheckExtensionConsistency(first_extension_id_); |
178 | 179 |
179 WebContents* current_tab = browser()->GetActiveWebContents(); | 180 WebContents* current_tab = chrome::GetActiveWebContents(browser()); |
180 ASSERT_TRUE(current_tab); | 181 ASSERT_TRUE(current_tab); |
181 | 182 |
182 // The balloon should automatically hide after the extension is successfully | 183 // The balloon should automatically hide after the extension is successfully |
183 // reloaded. | 184 // reloaded. |
184 ASSERT_EQ(0U, CountBalloons()); | 185 ASSERT_EQ(0U, CountBalloons()); |
185 } | 186 } |
186 | 187 |
187 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 188 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
188 ReloadIndependentlyChangeTabs) { | 189 ReloadIndependentlyChangeTabs) { |
189 const size_t size_before = GetExtensionService()->extensions()->size(); | 190 const size_t size_before = GetExtensionService()->extensions()->size(); |
190 LoadTestExtension(); | 191 LoadTestExtension(); |
191 CrashExtension(first_extension_id_); | 192 CrashExtension(first_extension_id_); |
192 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 193 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
193 | 194 |
194 WebContents* original_tab = browser()->GetActiveWebContents(); | 195 WebContents* original_tab = chrome::GetActiveWebContents(browser()); |
195 ASSERT_TRUE(original_tab); | 196 ASSERT_TRUE(original_tab); |
196 ASSERT_EQ(1U, CountBalloons()); | 197 ASSERT_EQ(1U, CountBalloons()); |
197 | 198 |
198 // Open a new tab, but the balloon will still be there. | 199 // Open a new tab, but the balloon will still be there. |
199 chrome::NewTab(browser()); | 200 chrome::NewTab(browser()); |
200 WebContents* new_current_tab = browser()->GetActiveWebContents(); | 201 WebContents* new_current_tab = chrome::GetActiveWebContents(browser()); |
201 ASSERT_TRUE(new_current_tab); | 202 ASSERT_TRUE(new_current_tab); |
202 ASSERT_NE(new_current_tab, original_tab); | 203 ASSERT_NE(new_current_tab, original_tab); |
203 ASSERT_EQ(1U, CountBalloons()); | 204 ASSERT_EQ(1U, CountBalloons()); |
204 | 205 |
205 ReloadExtension(first_extension_id_); | 206 ReloadExtension(first_extension_id_); |
206 | 207 |
207 SCOPED_TRACE("after reloading"); | 208 SCOPED_TRACE("after reloading"); |
208 CheckExtensionConsistency(first_extension_id_); | 209 CheckExtensionConsistency(first_extension_id_); |
209 | 210 |
210 // The balloon should automatically hide after the extension is successfully | 211 // The balloon should automatically hide after the extension is successfully |
211 // reloaded. | 212 // reloaded. |
212 ASSERT_EQ(0U, CountBalloons()); | 213 ASSERT_EQ(0U, CountBalloons()); |
213 } | 214 } |
214 | 215 |
215 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, | 216 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, |
216 ReloadIndependentlyNavigatePage) { | 217 ReloadIndependentlyNavigatePage) { |
217 const size_t size_before = GetExtensionService()->extensions()->size(); | 218 const size_t size_before = GetExtensionService()->extensions()->size(); |
218 LoadTestExtension(); | 219 LoadTestExtension(); |
219 CrashExtension(first_extension_id_); | 220 CrashExtension(first_extension_id_); |
220 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 221 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
221 | 222 |
222 WebContents* current_tab = browser()->GetActiveWebContents(); | 223 WebContents* current_tab = chrome::GetActiveWebContents(browser()); |
223 ASSERT_TRUE(current_tab); | 224 ASSERT_TRUE(current_tab); |
224 ASSERT_EQ(1U, CountBalloons()); | 225 ASSERT_EQ(1U, CountBalloons()); |
225 | 226 |
226 // Navigate to another page. | 227 // Navigate to another page. |
227 ui_test_utils::NavigateToURL(browser(), | 228 ui_test_utils::NavigateToURL(browser(), |
228 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 229 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
229 FilePath(FILE_PATH_LITERAL("title1.html")))); | 230 FilePath(FILE_PATH_LITERAL("title1.html")))); |
230 ASSERT_EQ(1U, CountBalloons()); | 231 ASSERT_EQ(1U, CountBalloons()); |
231 | 232 |
232 ReloadExtension(first_extension_id_); | 233 ReloadExtension(first_extension_id_); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 const size_t size_before = GetExtensionService()->extensions()->size(); | 386 const size_t size_before = GetExtensionService()->extensions()->size(); |
386 LoadTestExtension(); | 387 LoadTestExtension(); |
387 LoadSecondExtension(); | 388 LoadSecondExtension(); |
388 CrashExtension(first_extension_id_); | 389 CrashExtension(first_extension_id_); |
389 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 390 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
390 CrashExtension(second_extension_id_); | 391 CrashExtension(second_extension_id_); |
391 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); | 392 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); |
392 | 393 |
393 { | 394 { |
394 SCOPED_TRACE("first: reload"); | 395 SCOPED_TRACE("first: reload"); |
395 WebContents* current_tab = browser()->GetActiveWebContents(); | 396 WebContents* current_tab = chrome::GetActiveWebContents(browser()); |
396 ASSERT_TRUE(current_tab); | 397 ASSERT_TRUE(current_tab); |
397 // At the beginning we should have one balloon displayed for each extension. | 398 // At the beginning we should have one balloon displayed for each extension. |
398 ASSERT_EQ(2U, CountBalloons()); | 399 ASSERT_EQ(2U, CountBalloons()); |
399 ReloadExtension(first_extension_id_); | 400 ReloadExtension(first_extension_id_); |
400 // One of the balloons should hide after the extension is reloaded. | 401 // One of the balloons should hide after the extension is reloaded. |
401 ASSERT_EQ(1U, CountBalloons()); | 402 ASSERT_EQ(1U, CountBalloons()); |
402 CheckExtensionConsistency(first_extension_id_); | 403 CheckExtensionConsistency(first_extension_id_); |
403 } | 404 } |
404 | 405 |
405 { | 406 { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 // Tab should still be open, and extension should be crashed. | 479 // Tab should still be open, and extension should be crashed. |
479 EXPECT_EQ(tabs_before, tab_strip->count()); | 480 EXPECT_EQ(tabs_before, tab_strip->count()); |
480 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); | 481 EXPECT_EQ(size_before, GetExtensionService()->extensions()->size()); |
481 EXPECT_EQ(crash_size_before + 1, | 482 EXPECT_EQ(crash_size_before + 1, |
482 GetExtensionService()->terminated_extensions()->size()); | 483 GetExtensionService()->terminated_extensions()->size()); |
483 | 484 |
484 { | 485 { |
485 ui_test_utils::WindowedNotificationObserver observer( | 486 ui_test_utils::WindowedNotificationObserver observer( |
486 content::NOTIFICATION_LOAD_STOP, | 487 content::NOTIFICATION_LOAD_STOP, |
487 content::Source<NavigationController>( | 488 content::Source<NavigationController>( |
488 &browser()->GetActiveWebContents()->GetController())); | 489 &chrome::GetActiveWebContents(browser())->GetController())); |
489 chrome::Reload(browser(), CURRENT_TAB); | 490 chrome::Reload(browser(), CURRENT_TAB); |
490 observer.Wait(); | 491 observer.Wait(); |
491 } | 492 } |
492 // Extension should now be loaded. | 493 // Extension should now be loaded. |
493 SCOPED_TRACE("after reloading the tab"); | 494 SCOPED_TRACE("after reloading the tab"); |
494 CheckExtensionConsistency(first_extension_id_); | 495 CheckExtensionConsistency(first_extension_id_); |
495 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); | 496 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); |
496 ASSERT_EQ(0U, CountBalloons()); | 497 ASSERT_EQ(0U, CountBalloons()); |
497 } | 498 } |
OLD | NEW |