| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 // TODO(jam): http://crbug.com/350550 | 33 // TODO(jam): http://crbug.com/350550 |
| 34 #if !(defined(OS_CHROMEOS) && defined(ADDRESS_SANITIZER)) | 34 #if !(defined(OS_CHROMEOS) && defined(ADDRESS_SANITIZER)) |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 void SimulateRendererCrash(Browser* browser) { | 38 void SimulateRendererCrash(Browser* browser) { |
| 39 content::WindowedNotificationObserver observer( | 39 content::WindowedNotificationObserver observer( |
| 40 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 40 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 41 content::NotificationService::AllSources()); | 41 content::NotificationService::AllSources()); |
| 42 browser->OpenURL(OpenURLParams( | 42 browser->OpenURL(OpenURLParams(GURL(content::kChromeUICrashURL), Referrer(), |
| 43 GURL(content::kChromeUICrashURL), Referrer(), CURRENT_TAB, | 43 WindowOpenDisposition::CURRENT_TAB, |
| 44 ui::PAGE_TRANSITION_TYPED, false)); | 44 ui::PAGE_TRANSITION_TYPED, false)); |
| 45 observer.Wait(); | 45 observer.Wait(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // A request handler which returns a different result each time but stays fresh | 48 // A request handler which returns a different result each time but stays fresh |
| 49 // into the far future. | 49 // into the far future. |
| 50 class CacheMaxAgeHandler { | 50 class CacheMaxAgeHandler { |
| 51 public: | 51 public: |
| 52 explicit CacheMaxAgeHandler(const std::string& path) | 52 explicit CacheMaxAgeHandler(const std::string& path) |
| 53 : path_(path), request_count_(0) { } | 53 : path_(path), request_count_(0) { } |
| 54 | 54 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 GURL url( | 92 GURL url( |
| 93 "data:text/html,<script>document.title=new Date().valueOf()</script>"); | 93 "data:text/html,<script>document.title=new Date().valueOf()</script>"); |
| 94 ui_test_utils::NavigateToURL(browser(), url); | 94 ui_test_utils::NavigateToURL(browser(), url); |
| 95 | 95 |
| 96 base::string16 title_before_crash; | 96 base::string16 title_before_crash; |
| 97 base::string16 title_after_crash; | 97 base::string16 title_after_crash; |
| 98 | 98 |
| 99 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 99 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 100 &title_before_crash)); | 100 &title_before_crash)); |
| 101 SimulateRendererCrash(browser()); | 101 SimulateRendererCrash(browser()); |
| 102 chrome::Reload(browser(), CURRENT_TAB); | 102 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 103 content::WaitForLoadStop(GetActiveWebContents()); | 103 content::WaitForLoadStop(GetActiveWebContents()); |
| 104 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 104 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 105 &title_after_crash)); | 105 &title_after_crash)); |
| 106 EXPECT_NE(title_before_crash, title_after_crash); | 106 EXPECT_NE(title_before_crash, title_after_crash); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Test that reload after a crash forces a cache revalidation. | 109 // Test that reload after a crash forces a cache revalidation. |
| 110 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, ReloadCacheRevalidate) { | 110 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, ReloadCacheRevalidate) { |
| 111 const char kTestPath[] = "/test"; | 111 const char kTestPath[] = "/test"; |
| 112 | 112 |
| 113 // Use the test server so as not to bypass cache behavior. The title of the | 113 // Use the test server so as not to bypass cache behavior. The title of the |
| 114 // active tab should change only when this URL is reloaded. | 114 // active tab should change only when this URL is reloaded. |
| 115 ASSERT_TRUE(embedded_test_server()->Start()); | 115 ASSERT_TRUE(embedded_test_server()->Start()); |
| 116 embedded_test_server()->RegisterRequestHandler( | 116 embedded_test_server()->RegisterRequestHandler( |
| 117 base::Bind(&CacheMaxAgeHandler::HandleRequest, | 117 base::Bind(&CacheMaxAgeHandler::HandleRequest, |
| 118 base::Owned(new CacheMaxAgeHandler(kTestPath)))); | 118 base::Owned(new CacheMaxAgeHandler(kTestPath)))); |
| 119 ui_test_utils::NavigateToURL(browser(), | 119 ui_test_utils::NavigateToURL(browser(), |
| 120 embedded_test_server()->GetURL(kTestPath)); | 120 embedded_test_server()->GetURL(kTestPath)); |
| 121 | 121 |
| 122 base::string16 title_before_crash; | 122 base::string16 title_before_crash; |
| 123 base::string16 title_after_crash; | 123 base::string16 title_after_crash; |
| 124 | 124 |
| 125 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 125 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 126 &title_before_crash)); | 126 &title_before_crash)); |
| 127 SimulateRendererCrash(browser()); | 127 SimulateRendererCrash(browser()); |
| 128 chrome::Reload(browser(), CURRENT_TAB); | 128 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 129 content::WaitForLoadStop(GetActiveWebContents()); | 129 content::WaitForLoadStop(GetActiveWebContents()); |
| 130 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 130 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 131 &title_after_crash)); | 131 &title_after_crash)); |
| 132 EXPECT_NE(title_before_crash, title_after_crash); | 132 EXPECT_NE(title_before_crash, title_after_crash); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Tests that loading a crashed page in a new tab correctly updates the title. | 135 // Tests that loading a crashed page in a new tab correctly updates the title. |
| 136 // There was an earlier bug (1270510) in process-per-site in which the max page | 136 // There was an earlier bug (1270510) in process-per-site in which the max page |
| 137 // ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab | 137 // ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab |
| 138 // was not committed. This prevents regression of that bug. | 138 // was not committed. This prevents regression of that bug. |
| 139 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) { | 139 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) { |
| 140 const base::FilePath::CharType kTitle2File[] = | 140 const base::FilePath::CharType kTitle2File[] = |
| 141 FILE_PATH_LITERAL("title2.html"); | 141 FILE_PATH_LITERAL("title2.html"); |
| 142 | 142 |
| 143 ui_test_utils::NavigateToURL( | 143 ui_test_utils::NavigateToURL( |
| 144 browser(), ui_test_utils::GetTestUrl( | 144 browser(), ui_test_utils::GetTestUrl( |
| 145 base::FilePath(base::FilePath::kCurrentDirectory), | 145 base::FilePath(base::FilePath::kCurrentDirectory), |
| 146 base::FilePath(kTitle2File))); | 146 base::FilePath(kTitle2File))); |
| 147 | 147 |
| 148 base::string16 title_before_crash; | 148 base::string16 title_before_crash; |
| 149 base::string16 title_after_crash; | 149 base::string16 title_after_crash; |
| 150 | 150 |
| 151 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 151 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 152 &title_before_crash)); | 152 &title_before_crash)); |
| 153 SimulateRendererCrash(browser()); | 153 SimulateRendererCrash(browser()); |
| 154 chrome::Reload(browser(), CURRENT_TAB); | 154 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 155 content::WaitForLoadStop(GetActiveWebContents()); | 155 content::WaitForLoadStop(GetActiveWebContents()); |
| 156 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 156 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 157 &title_after_crash)); | 157 &title_after_crash)); |
| 158 EXPECT_EQ(title_before_crash, title_after_crash); | 158 EXPECT_EQ(title_before_crash, title_after_crash); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // Tests that reloads of navigation errors behave correctly after a crash. | 161 // Tests that reloads of navigation errors behave correctly after a crash. |
| 162 // Regression test for http://crbug.com/348918 | 162 // Regression test for http://crbug.com/348918 |
| 163 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, DoubleReloadWithError) { | 163 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, DoubleReloadWithError) { |
| 164 GURL url("chrome://bogus"); | 164 GURL url("chrome://bogus"); |
| 165 ui_test_utils::NavigateToURL(browser(), url); | 165 ui_test_utils::NavigateToURL(browser(), url); |
| 166 ASSERT_EQ(url, GetActiveWebContents()->GetVisibleURL()); | 166 ASSERT_EQ(url, GetActiveWebContents()->GetVisibleURL()); |
| 167 | 167 |
| 168 SimulateRendererCrash(browser()); | 168 SimulateRendererCrash(browser()); |
| 169 | 169 |
| 170 chrome::Reload(browser(), CURRENT_TAB); | 170 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 171 content::WaitForLoadStop(GetActiveWebContents()); | 171 content::WaitForLoadStop(GetActiveWebContents()); |
| 172 ASSERT_EQ(url, GetActiveWebContents()->GetVisibleURL()); | 172 ASSERT_EQ(url, GetActiveWebContents()->GetVisibleURL()); |
| 173 | 173 |
| 174 chrome::Reload(browser(), CURRENT_TAB); | 174 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 175 content::WaitForLoadStop(GetActiveWebContents()); | 175 content::WaitForLoadStop(GetActiveWebContents()); |
| 176 ASSERT_EQ(url, GetActiveWebContents()->GetVisibleURL()); | 176 ASSERT_EQ(url, GetActiveWebContents()->GetVisibleURL()); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace | 179 } // namespace |
| 180 | 180 |
| 181 #endif | 181 #endif |
| OLD | NEW |