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/bind.h" | 5 #include "base/bind.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 "base/strings/utf_string_conversions.h" |
8 #include "content/browser/frame_host/frame_navigation_entry.h" | 9 #include "content/browser/frame_host/frame_navigation_entry.h" |
9 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | 11 #include "content/browser/frame_host/navigation_controller_impl.h" |
11 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
12 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
13 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/resource_controller.h" | 15 #include "content/public/browser/resource_controller.h" |
15 #include "content/public/browser/resource_dispatcher_host.h" | 16 #include "content/public/browser/resource_dispatcher_host.h" |
16 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 17 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
17 #include "content/public/browser/resource_throttle.h" | 18 #include "content/public/browser/resource_throttle.h" |
(...skipping 2105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 // This LoadURL ends up purging the pending entry, which is why this is | 2124 // This LoadURL ends up purging the pending entry, which is why this is |
2124 // tricky. | 2125 // tricky. |
2125 EXPECT_EQ(nullptr, controller.GetPendingEntry()); | 2126 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
2126 shell()->web_contents()->Stop(); | 2127 shell()->web_contents()->Stop(); |
2127 watcher.Wait(); | 2128 watcher.Wait(); |
2128 } | 2129 } |
2129 | 2130 |
2130 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 2131 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
2131 } | 2132 } |
2132 | 2133 |
| 2134 namespace { |
| 2135 class RenderProcessKilledObserver : public WebContentsObserver { |
| 2136 public: |
| 2137 RenderProcessKilledObserver(WebContents* web_contents) |
| 2138 : WebContentsObserver(web_contents) {} |
| 2139 ~RenderProcessKilledObserver() override {} |
| 2140 |
| 2141 void RenderProcessGone(base::TerminationStatus status) override { |
| 2142 CHECK_NE(status, |
| 2143 base::TerminationStatus::TERMINATION_STATUS_PROCESS_WAS_KILLED); |
| 2144 } |
| 2145 }; |
| 2146 } |
| 2147 |
| 2148 // This tests a race in ReloadOriginalRequest, where a cross-origin reload was |
| 2149 // causing an in-flight replaceState to look like a cross-origin navigation, |
| 2150 // even though it's in-page. (The reload should not modify the underlying last |
| 2151 // committed entry.) Not crashing means that the test is successful. |
| 2152 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, ReloadOriginalRequest) { |
| 2153 GURL original_url(embedded_test_server()->GetURL( |
| 2154 "/navigation_controller/simple_page_1.html")); |
| 2155 NavigateToURL(shell(), original_url); |
| 2156 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 2157 ->GetFrameTree() |
| 2158 ->root(); |
| 2159 RenderProcessKilledObserver kill_observer(shell()->web_contents()); |
| 2160 |
| 2161 // Redirect so that we can use ReloadOriginalRequest. |
| 2162 GURL redirect_url(embedded_test_server()->GetURL( |
| 2163 "foo.com", "/navigation_controller/simple_page_1.html")); |
| 2164 { |
| 2165 std::string script = "location.replace('" + redirect_url.spec() + "');"; |
| 2166 FrameNavigateParamsCapturer capturer(root); |
| 2167 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
| 2168 capturer.Wait(); |
| 2169 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
| 2170 capturer.params().transition); |
| 2171 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
| 2172 } |
| 2173 |
| 2174 // Modify an entry in the session history and reload the original request. |
| 2175 { |
| 2176 // We first send a replaceState() to the renderer, which will cause the |
| 2177 // renderer to send back a DidCommitProvisionalLoad. Immediately after, |
| 2178 // we send a ReloadOriginalRequest (which in this case is a different |
| 2179 // origin) and will also cause the renderer to commit the frame. In the |
| 2180 // end we verify that both navigations committed and that the URLs are |
| 2181 // correct. |
| 2182 std::string script = "history.replaceState({}, '', 'foo');"; |
| 2183 root->render_manager() |
| 2184 ->current_frame_host() |
| 2185 ->ExecuteJavaScriptWithUserGestureForTests(base::UTF8ToUTF16(script)); |
| 2186 EXPECT_FALSE(shell()->web_contents()->IsLoading()); |
| 2187 shell()->web_contents()->GetController().ReloadOriginalRequestURL(false); |
| 2188 EXPECT_TRUE(shell()->web_contents()->IsLoading()); |
| 2189 EXPECT_EQ(redirect_url, shell()->web_contents()->GetLastCommittedURL()); |
| 2190 |
| 2191 // Wait until there's no more navigations. |
| 2192 GURL modified_url(embedded_test_server()->GetURL( |
| 2193 "foo.com", "/navigation_controller/foo")); |
| 2194 FrameNavigateParamsCapturer capturer(root); |
| 2195 capturer.set_wait_for_load(false); |
| 2196 capturer.set_navigations_remaining(2); |
| 2197 capturer.Wait(); |
| 2198 EXPECT_EQ(2U, capturer.all_details().size()); |
| 2199 EXPECT_EQ(modified_url, capturer.all_params()[0].url); |
| 2200 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
| 2201 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
| 2202 } |
| 2203 |
| 2204 // Make sure the renderer is still alive. |
| 2205 EXPECT_TRUE( |
| 2206 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
| 2207 } |
| 2208 |
2133 } // namespace content | 2209 } // namespace content |
OLD | NEW |