| 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/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 8 #include "chrome/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
| 9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "content/browser/tab_contents/navigation_entry.h" | 11 #include "content/browser/tab_contents/navigation_entry.h" |
| 12 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 13 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 14 #include "content/public/common/page_transition_types.h" | 15 #include "content/public/common/page_transition_types.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 void SimulateRendererCrash(Browser* browser) { | 20 void SimulateRendererCrash(Browser* browser) { |
| 20 ui_test_utils::WindowedNotificationObserver observer( | 21 ui_test_utils::WindowedNotificationObserver observer( |
| 21 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, | 22 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
| 22 content::NotificationService::AllSources()); | 23 content::NotificationService::AllSources()); |
| 23 browser->OpenURL(GURL(chrome::kChromeUICrashURL), GURL(), CURRENT_TAB, | 24 browser->OpenURL(GURL(chrome::kChromeUICrashURL), GURL(), CURRENT_TAB, |
| 24 content::PAGE_TRANSITION_TYPED); | 25 content::PAGE_TRANSITION_TYPED); |
| 25 observer.Wait(); | 26 observer.Wait(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 class CrashRecoveryBrowserTest : public InProcessBrowserTest { | 31 class CrashRecoveryBrowserTest : public InProcessBrowserTest { |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 // Test that reload works after a crash. | 34 // Test that reload works after a crash. |
| 34 // Disabled, http://crbug.com/29331, http://crbug.com/69637. | 35 // Disabled, http://crbug.com/29331 , http://crbug.com/69637 . |
| 35 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) { | 36 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) { |
| 36 // The title of the active tab should change each time this URL is loaded. | 37 // The title of the active tab should change each time this URL is loaded. |
| 37 GURL url( | 38 GURL url( |
| 38 "data:text/html,<script>document.title=new Date().valueOf()</script>"); | 39 "data:text/html,<script>document.title=new Date().valueOf()</script>"); |
| 39 ui_test_utils::NavigateToURL(browser(), url); | 40 ui_test_utils::NavigateToURL(browser(), url); |
| 40 | 41 |
| 41 string16 title_before_crash; | 42 string16 title_before_crash; |
| 42 string16 title_after_crash; | 43 string16 title_after_crash; |
| 43 | 44 |
| 44 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 45 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 45 &title_before_crash)); | 46 &title_before_crash)); |
| 46 SimulateRendererCrash(browser()); | 47 SimulateRendererCrash(browser()); |
| 47 ui_test_utils::WindowedNotificationObserver observer( | 48 ui_test_utils::WindowedNotificationObserver observer( |
| 48 content::NOTIFICATION_LOAD_STOP, | 49 content::NOTIFICATION_LOAD_STOP, |
| 49 content::Source<NavigationController>( | 50 content::Source<NavigationController>( |
| 50 &browser()->GetSelectedTabContentsWrapper()->controller())); | 51 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
| 52 controller())); |
| 51 browser()->Reload(CURRENT_TAB); | 53 browser()->Reload(CURRENT_TAB); |
| 52 observer.Wait(); | 54 observer.Wait(); |
| 53 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 55 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 54 &title_after_crash)); | 56 &title_after_crash)); |
| 55 EXPECT_NE(title_before_crash, title_after_crash); | 57 EXPECT_NE(title_before_crash, title_after_crash); |
| 56 } | 58 } |
| 57 | 59 |
| 58 // Tests that loading a crashed page in a new tab correctly updates the title. | 60 // Tests that loading a crashed page in a new tab correctly updates the title. |
| 59 // There was an earlier bug (1270510) in process-per-site in which the max page | 61 // There was an earlier bug (1270510) in process-per-site in which the max page |
| 60 // ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab | 62 // ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab |
| 61 // was not committed. This prevents regression of that bug. | 63 // was not committed. This prevents regression of that bug. |
| 62 // http://crbug.com/57158 - Times out sometimes on all platforms. | 64 // http://crbug.com/57158 - Times out sometimes on all platforms. |
| 63 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) { | 65 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) { |
| 64 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); | 66 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); |
| 65 | 67 |
| 66 ui_test_utils::NavigateToURL(browser(), | 68 ui_test_utils::NavigateToURL(browser(), |
| 67 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 69 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 68 FilePath(kTitle2File))); | 70 FilePath(kTitle2File))); |
| 69 | 71 |
| 70 string16 title_before_crash; | 72 string16 title_before_crash; |
| 71 string16 title_after_crash; | 73 string16 title_after_crash; |
| 72 | 74 |
| 73 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 75 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 74 &title_before_crash)); | 76 &title_before_crash)); |
| 75 SimulateRendererCrash(browser()); | 77 SimulateRendererCrash(browser()); |
| 76 ui_test_utils::WindowedNotificationObserver observer( | 78 ui_test_utils::WindowedNotificationObserver observer( |
| 77 content::NOTIFICATION_LOAD_STOP, | 79 content::NOTIFICATION_LOAD_STOP, |
| 78 content::Source<NavigationController>( | 80 content::Source<NavigationController>( |
| 79 &browser()->GetSelectedTabContentsWrapper()->controller())); | 81 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
| 82 controller())); |
| 80 browser()->Reload(CURRENT_TAB); | 83 browser()->Reload(CURRENT_TAB); |
| 81 observer.Wait(); | 84 observer.Wait(); |
| 82 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 85 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 83 &title_after_crash)); | 86 &title_after_crash)); |
| 84 EXPECT_EQ(title_before_crash, title_after_crash); | 87 EXPECT_EQ(title_before_crash, title_after_crash); |
| 85 } | 88 } |
| OLD | NEW |