Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

Issue 1189413005: Fix race when reloading original URL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing include Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
2136 class RenderProcessKilledObserver : public WebContentsObserver {
2137 public:
2138 RenderProcessKilledObserver(WebContents* web_contents)
2139 : WebContentsObserver(web_contents) {}
2140 ~RenderProcessKilledObserver() override {}
2141
2142 void RenderProcessGone(base::TerminationStatus status) override {
2143 CHECK_NE(status,
2144 base::TerminationStatus::TERMINATION_STATUS_PROCESS_WAS_KILLED);
2145 }
2146 };
2147
2148 }
2149
2150 // This tests for a race in ReloadOriginalRequest. Not crashing means that the
2151 // test is successful.
2152 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, ReloadOriginalRequest) {
2153 GURL url(embedded_test_server()->GetURL(
2154 "/navigation_controller/simple_page_1.html"));
2155 NavigateToURL(shell(), url);
2156 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
2157 ->GetFrameTree()
2158 ->root();
2159 RenderProcessKilledObserver kill_observer(shell()->web_contents());
2160
2161 // Redirect.
2162 {
2163 GURL foo_url(embedded_test_server()->GetURL(
2164 "foo.com", "/navigation_controller/simple_page_1.html"));
2165 std::string script = "location.replace('" + foo_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 std::string script = "history.replaceState({}, '', 'foo');";
2177 root->render_manager()
2178 ->current_frame_host()
2179 ->ExecuteJavaScriptWithUserGestureForTests(base::UTF8ToUTF16(script));
Charlie Reis 2015/07/08 23:23:37 Please add a comment saying why this has to be don
lfg 2015/07/14 18:58:31 Done.
2180 EXPECT_FALSE(shell()->web_contents()->IsLoading());
2181 shell()->web_contents()->GetController().ReloadOriginalRequestURL(false);
2182 EXPECT_TRUE(shell()->web_contents()->IsLoading());
2183
2184 // Wait until there's no more navigations.
2185 while (shell()->web_contents()->GetLastCommittedURL() != url)
Charlie Reis 2015/07/08 23:23:37 Does replaceState generate a load stop? I'm wonde
lfg 2015/07/14 18:58:31 It only generates a load stop when IsLoading() is
2186 RunAllPendingInMessageLoop();
2187
2188 // Make sure the renderer is still alive.
2189 EXPECT_TRUE(
2190 ExecuteScript(shell()->web_contents(), "console.log('Success');"));
2191 }
2192 }
2193
2133 } // namespace content 2194 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698