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