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/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/strings/stringprintf.h" |
6 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
7 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
9 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.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/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 #include "content/public/common/page_transition_types.h" | 16 #include "content/public/common/page_transition_types.h" |
| 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 18 #include "net/test/embedded_test_server/http_request.h" |
| 19 #include "net/test/embedded_test_server/http_response.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
17 | 21 |
18 using content::NavigationController; | 22 using content::NavigationController; |
19 using content::OpenURLParams; | 23 using content::OpenURLParams; |
20 using content::Referrer; | 24 using content::Referrer; |
21 | 25 |
22 namespace { | 26 namespace { |
23 | 27 |
24 void SimulateRendererCrash(Browser* browser) { | 28 void SimulateRendererCrash(Browser* browser) { |
25 content::WindowedNotificationObserver observer( | 29 content::WindowedNotificationObserver observer( |
26 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 30 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
27 content::NotificationService::AllSources()); | 31 content::NotificationService::AllSources()); |
28 browser->OpenURL(OpenURLParams( | 32 browser->OpenURL(OpenURLParams( |
29 GURL(content::kChromeUICrashURL), Referrer(), CURRENT_TAB, | 33 GURL(content::kChromeUICrashURL), Referrer(), CURRENT_TAB, |
30 content::PAGE_TRANSITION_TYPED, false)); | 34 content::PAGE_TRANSITION_TYPED, false)); |
31 observer.Wait(); | 35 observer.Wait(); |
32 } | 36 } |
33 | 37 |
| 38 // A request handler which returns a different result each time but stays fresh |
| 39 // into the far future. |
| 40 class CacheMaxAgeHandler { |
| 41 public: |
| 42 explicit CacheMaxAgeHandler(const std::string& path) |
| 43 : path_(path), request_count_(0) { } |
| 44 |
| 45 scoped_ptr<net::test_server::HttpResponse> HandleRequest( |
| 46 const net::test_server::HttpRequest& request) { |
| 47 if (request.relative_url != path_) |
| 48 return scoped_ptr<net::test_server::HttpResponse>(); |
| 49 |
| 50 request_count_++; |
| 51 scoped_ptr<net::test_server::BasicHttpResponse> response( |
| 52 new net::test_server::BasicHttpResponse); |
| 53 response->set_content(base::StringPrintf("<title>%d</title>", |
| 54 request_count_)); |
| 55 response->set_content_type("text/html"); |
| 56 response->AddCustomHeader("Cache-Control", "max-age=99999"); |
| 57 return response.PassAs<net::test_server::HttpResponse>(); |
| 58 } |
| 59 private: |
| 60 std::string path_; |
| 61 int request_count_; |
| 62 }; |
| 63 |
34 } // namespace | 64 } // namespace |
35 | 65 |
36 class CrashRecoveryBrowserTest : public InProcessBrowserTest { | 66 class CrashRecoveryBrowserTest : public InProcessBrowserTest { |
37 }; | 67 }; |
38 | 68 |
39 // Test that reload works after a crash. | 69 // Test that reload works after a crash. |
40 // Disabled, http://crbug.com/29331 , http://crbug.com/69637 . | 70 // Disabled, http://crbug.com/29331 , http://crbug.com/69637 . |
41 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) { | 71 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) { |
42 // The title of the active tab should change each time this URL is loaded. | 72 // The title of the active tab should change each time this URL is loaded. |
43 GURL url( | 73 GURL url( |
(...skipping 11 matching lines...) Expand all Loading... |
55 content::Source<NavigationController>( | 85 content::Source<NavigationController>( |
56 &browser()->tab_strip_model()->GetActiveWebContents()-> | 86 &browser()->tab_strip_model()->GetActiveWebContents()-> |
57 GetController())); | 87 GetController())); |
58 chrome::Reload(browser(), CURRENT_TAB); | 88 chrome::Reload(browser(), CURRENT_TAB); |
59 observer.Wait(); | 89 observer.Wait(); |
60 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 90 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
61 &title_after_crash)); | 91 &title_after_crash)); |
62 EXPECT_NE(title_before_crash, title_after_crash); | 92 EXPECT_NE(title_before_crash, title_after_crash); |
63 } | 93 } |
64 | 94 |
| 95 // Test that reload after a crash forces a cache revalidation. |
| 96 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, ReloadCacheRevalidate) { |
| 97 const char kTestPath[] = "/test"; |
| 98 |
| 99 // Use the test server so as not to bypass cache behavior. The title of the |
| 100 // active tab should change only when this URL is reloaded. |
| 101 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 102 embedded_test_server()->RegisterRequestHandler( |
| 103 base::Bind(&CacheMaxAgeHandler::HandleRequest, |
| 104 base::Owned(new CacheMaxAgeHandler(kTestPath)))); |
| 105 ui_test_utils::NavigateToURL(browser(), |
| 106 embedded_test_server()->GetURL(kTestPath)); |
| 107 |
| 108 base::string16 title_before_crash; |
| 109 base::string16 title_after_crash; |
| 110 |
| 111 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 112 &title_before_crash)); |
| 113 SimulateRendererCrash(browser()); |
| 114 content::WindowedNotificationObserver observer( |
| 115 content::NOTIFICATION_LOAD_STOP, |
| 116 content::Source<NavigationController>( |
| 117 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 118 GetController())); |
| 119 chrome::Reload(browser(), CURRENT_TAB); |
| 120 observer.Wait(); |
| 121 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
| 122 &title_after_crash)); |
| 123 EXPECT_NE(title_before_crash, title_after_crash); |
| 124 } |
| 125 |
65 // Tests that loading a crashed page in a new tab correctly updates the title. | 126 // 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 | 127 // 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 | 128 // ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab |
68 // was not committed. This prevents regression of that bug. | 129 // was not committed. This prevents regression of that bug. |
69 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) { | 130 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) { |
70 const base::FilePath::CharType* kTitle2File = | 131 const base::FilePath::CharType* kTitle2File = |
71 FILE_PATH_LITERAL("title2.html"); | 132 FILE_PATH_LITERAL("title2.html"); |
72 | 133 |
73 ui_test_utils::NavigateToURL( | 134 ui_test_utils::NavigateToURL( |
74 browser(), ui_test_utils::GetTestUrl( | 135 browser(), ui_test_utils::GetTestUrl( |
(...skipping 10 matching lines...) Expand all Loading... |
85 content::NOTIFICATION_LOAD_STOP, | 146 content::NOTIFICATION_LOAD_STOP, |
86 content::Source<NavigationController>( | 147 content::Source<NavigationController>( |
87 &browser()->tab_strip_model()->GetActiveWebContents()-> | 148 &browser()->tab_strip_model()->GetActiveWebContents()-> |
88 GetController())); | 149 GetController())); |
89 chrome::Reload(browser(), CURRENT_TAB); | 150 chrome::Reload(browser(), CURRENT_TAB); |
90 observer.Wait(); | 151 observer.Wait(); |
91 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), | 152 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), |
92 &title_after_crash)); | 153 &title_after_crash)); |
93 EXPECT_EQ(title_before_crash, title_after_crash); | 154 EXPECT_EQ(title_before_crash, title_after_crash); |
94 } | 155 } |
OLD | NEW |