OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
11 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
12 #include "content/public/test/content_browser_test.h" | 12 #include "content/public/test/content_browser_test.h" |
13 #include "content/public/test/content_browser_test_utils.h" | 13 #include "content/public/test/content_browser_test_utils.h" |
14 #include "content/public/test/test_navigation_observer.h" | 14 #include "content/public/test/test_navigation_observer.h" |
15 #include "content/shell/browser/shell.h" | 15 #include "content/shell/browser/shell.h" |
16 #include "net/dns/mock_host_resolver.h" | 16 #include "net/dns/mock_host_resolver.h" |
17 #include "net/test/embedded_test_server/embedded_test_server.h" | 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 18 #include "net/test/url_request/url_request_failed_job.h" |
18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { | 23 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { |
23 public: | 24 public: |
24 BrowserSideNavigationBrowserTest() {} | 25 BrowserSideNavigationBrowserTest() {} |
25 | 26 |
26 protected: | 27 protected: |
27 void SetUpCommandLine(base::CommandLine* command_line) override { | 28 void SetUpCommandLine(base::CommandLine* command_line) override { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 153 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
153 EXPECT_EQ(url, observer.last_navigation_url()); | 154 EXPECT_EQ(url, observer.last_navigation_url()); |
154 EXPECT_TRUE(observer.last_navigation_succeeded()); | 155 EXPECT_TRUE(observer.last_navigation_succeeded()); |
155 } | 156 } |
156 | 157 |
157 // The RenderFrameHost should not have changed. | 158 // The RenderFrameHost should not have changed. |
158 EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | 159 EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) |
159 ->GetFrameTree()->root()->current_frame_host()); | 160 ->GetFrameTree()->root()->current_frame_host()); |
160 } | 161 } |
161 | 162 |
| 163 // Ensure that browser side navigation handles navigation failures. |
| 164 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, FailedNavigation) { |
| 165 // Perform a navigation with no live renderer. |
| 166 { |
| 167 TestNavigationObserver observer(shell()->web_contents()); |
| 168 GURL url(embedded_test_server()->GetURL("/title1.html")); |
| 169 NavigateToURL(shell(), url); |
| 170 EXPECT_EQ(url, observer.last_navigation_url()); |
| 171 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 172 } |
| 173 |
| 174 // Now navigate to an unreachable url. |
| 175 { |
| 176 TestNavigationObserver observer(shell()->web_contents()); |
| 177 GURL error_url( |
| 178 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET)); |
| 179 net::URLRequestFailedJob::AddUrlHandler(); |
| 180 NavigateToURL(shell(), error_url); |
| 181 EXPECT_EQ(error_url, observer.last_navigation_url()); |
| 182 NavigationEntry* entry = |
| 183 shell()->web_contents()->GetController().GetLastCommittedEntry(); |
| 184 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
| 185 } |
| 186 } |
| 187 |
162 } // namespace content | 188 } // namespace content |
OLD | NEW |