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