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 for a race in ReloadOriginalRequest. Not crashing means that the | |
Charlie Reis
2015/07/14 22:23:10
nit: This tests a race in ReloadOriginalRequest, w
lfg
2015/07/14 22:47:27
Done.
| |
2149 // test is successful. | |
2150 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, ReloadOriginalRequest) { | |
2151 GURL url(embedded_test_server()->GetURL( | |
Charlie Reis
2015/07/14 22:23:10
nit: original_url
lfg
2015/07/14 22:47:27
Done.
| |
2152 "/navigation_controller/simple_page_1.html")); | |
2153 NavigateToURL(shell(), url); | |
2154 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
2155 ->GetFrameTree() | |
2156 ->root(); | |
2157 RenderProcessKilledObserver kill_observer(shell()->web_contents()); | |
2158 | |
2159 // Redirect. | |
Charlie Reis
2015/07/14 22:23:10
nit: Redirect so that we can use ReloadOriginalReq
lfg
2015/07/14 22:47:27
Done.
| |
2160 GURL foo_url(embedded_test_server()->GetURL( | |
Charlie Reis
2015/07/14 22:23:10
nit: redirect_url
lfg
2015/07/14 22:47:27
Done.
| |
2161 "foo.com", "/navigation_controller/simple_page_1.html")); | |
2162 { | |
2163 std::string script = "location.replace('" + foo_url.spec() + "');"; | |
2164 FrameNavigateParamsCapturer capturer(root); | |
2165 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | |
2166 capturer.Wait(); | |
2167 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | |
2168 capturer.params().transition); | |
2169 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
2170 } | |
2171 | |
2172 // Modify an entry in the session history and reload the original request. | |
2173 { | |
2174 // We first send a replaceState() to the renderer, which will cause the | |
2175 // renderer to send back a DidCommitProvisionalLoad. Immediatelly after, | |
Charlie Reis
2015/07/14 22:23:10
nit: Immediately
lfg
2015/07/14 22:47:27
Done.
| |
2176 // we send a ReloadOriginalRequest (which in this case is a different | |
2177 // origin) and will also cause the renderer to commit the frame. In the | |
2178 // end we verify that both navigations committed and that the URLs are | |
2179 // correct. | |
2180 std::string script = "history.replaceState({}, '', 'foo');"; | |
2181 root->render_manager() | |
2182 ->current_frame_host() | |
2183 ->ExecuteJavaScriptWithUserGestureForTests(base::UTF8ToUTF16(script)); | |
2184 EXPECT_FALSE(shell()->web_contents()->IsLoading()); | |
2185 shell()->web_contents()->GetController().ReloadOriginalRequestURL(false); | |
2186 EXPECT_TRUE(shell()->web_contents()->IsLoading()); | |
Charlie Reis
2015/07/14 22:23:10
Also add:
EXPECT_EQ(redirect_url, shell()->web_con
lfg
2015/07/14 22:47:27
Done.
| |
2187 | |
2188 // Wait until there's no more navigations. | |
2189 GURL modified_url(embedded_test_server()->GetURL( | |
2190 "foo.com", "/navigation_controller/foo")); | |
2191 FrameNavigateParamsCapturer capturer(root); | |
2192 capturer.set_wait_for_load(false); | |
2193 capturer.set_navigations_remaining(2); | |
2194 capturer.Wait(); | |
2195 EXPECT_EQ(2U, capturer.all_details().size()); | |
2196 EXPECT_EQ(modified_url, capturer.all_params()[0].url); | |
2197 EXPECT_EQ(url, capturer.all_params()[1].url); | |
2198 EXPECT_EQ(url, shell()->web_contents()->GetLastCommittedURL()); | |
Charlie Reis
2015/07/14 22:23:10
Yes, I like this approach.
lfg
2015/07/14 22:47:27
Done.
| |
2199 } | |
2200 | |
2201 // Make sure the renderer is still alive. | |
2202 EXPECT_TRUE( | |
2203 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | |
2204 } | |
2205 | |
2133 } // namespace content | 2206 } // namespace content |
OLD | NEW |