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

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 15742019: Avoid DidStopLoading messages from the old renderer process during a transfer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clarify comment. Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/app_process_apitest.cc ('k') | chrome/test/data/beforeunload.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 detach_callback_.Run(); 176 detach_callback_.Run();
177 } 177 }
178 178
179 private: 179 private:
180 base::Closure attach_callback_; 180 base::Closure attach_callback_;
181 base::Closure detach_callback_; 181 base::Closure detach_callback_;
182 182
183 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); 183 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
184 }; 184 };
185 185
186 class TransfersAllRedirectsContentBrowserClient 186 // Causes the browser to swap processes on a redirect to an HTTPS URL.
187 class TransferHttpsRedirectsContentBrowserClient
187 : public chrome::ChromeContentBrowserClient { 188 : public chrome::ChromeContentBrowserClient {
188 public: 189 public:
189 virtual bool ShouldSwapProcessesForRedirect( 190 virtual bool ShouldSwapProcessesForRedirect(
190 content::ResourceContext* resource_context, 191 content::ResourceContext* resource_context,
191 const GURL& current_url, 192 const GURL& current_url,
192 const GURL& new_url) OVERRIDE { 193 const GURL& new_url) OVERRIDE {
193 return true; 194 return new_url.SchemeIs(chrome::kHttpsScheme);
194 } 195 }
195 }; 196 };
196 197
197 // Used by CloseWithAppMenuOpen. Invokes CloseWindow on the supplied browser. 198 // Used by CloseWithAppMenuOpen. Invokes CloseWindow on the supplied browser.
198 void CloseWindowCallback(Browser* browser) { 199 void CloseWindowCallback(Browser* browser) {
199 chrome::CloseWindow(browser); 200 chrome::CloseWindow(browser);
200 } 201 }
201 202
202 // Used by CloseWithAppMenuOpen. Posts a CloseWindowCallback and shows the app 203 // Used by CloseWithAppMenuOpen. Posts a CloseWindowCallback and shows the app
203 // menu. 204 // menu.
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 alert->CloseModalDialog(); 370 alert->CloseModalDialog();
370 EXPECT_FALSE( 371 EXPECT_FALSE(
371 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); 372 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading());
372 373
373 // Clear the beforeunload handler so the test can easily exit. 374 // Clear the beforeunload handler so the test can easily exit.
374 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost()-> 375 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost()->
375 ExecuteJavascriptInWebFrame(string16(), 376 ExecuteJavascriptInWebFrame(string16(),
376 ASCIIToUTF16("onbeforeunload=null;")); 377 ASCIIToUTF16("onbeforeunload=null;"));
377 } 378 }
378 379
380 // Ensure that a transferred cross-process navigation does not generate
381 // DidStopLoading events until the navigation commits. If it did, then
382 // ui_test_utils::NavigateToURL would proceed before the URL had committed.
383 // http://crbug.com/243957.
384 IN_PROC_BROWSER_TEST_F(BrowserTest, NoStopDuringTransferUntilCommit) {
385 // Create HTTP and HTTPS servers for a cross-site transition.
386 ASSERT_TRUE(test_server()->Start());
387 net::SpawnedTestServer https_test_server(net::SpawnedTestServer::TYPE_HTTPS,
388 net::SpawnedTestServer::kLocalhost,
389 base::FilePath(kDocRoot));
390 ASSERT_TRUE(https_test_server.Start());
391
392 // Temporarily replace ContentBrowserClient with one that will cause a
393 // process swap on all redirects to HTTPS URLs.
394 TransferHttpsRedirectsContentBrowserClient new_client;
395 content::ContentBrowserClient* old_client =
396 SetBrowserClientForTesting(&new_client);
397
398 GURL init_url(test_server()->GetURL("files/title1.html"));
399 ui_test_utils::NavigateToURL(browser(), init_url);
400
401 // Navigate to a same-site page that redirects, causing a transfer.
402 GURL dest_url(https_test_server.GetURL("files/title2.html"));
403 GURL redirect_url(test_server()->GetURL("server-redirect?" +
404 dest_url.spec()));
405 ui_test_utils::NavigateToURL(browser(), redirect_url);
406
407 // We should immediately see the new committed entry.
408 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
409 EXPECT_FALSE(contents->GetController().GetPendingEntry());
410 EXPECT_EQ(dest_url,
411 contents->GetController().GetLastCommittedEntry()->GetURL());
412
413 // Restore previous browser client.
414 SetBrowserClientForTesting(old_client);
415 }
416
379 // Tests that a cross-process redirect will only cause the beforeunload 417 // Tests that a cross-process redirect will only cause the beforeunload
380 // handler to run once. 418 // handler to run once.
381 IN_PROC_BROWSER_TEST_F(BrowserTest, SingleBeforeUnloadAfterRedirect) { 419 IN_PROC_BROWSER_TEST_F(BrowserTest, SingleBeforeUnloadAfterRedirect) {
382 // Create HTTP and HTTPS servers for cross-site transition. 420 // Create HTTP and HTTPS servers for a cross-site transition.
383 ASSERT_TRUE(test_server()->Start()); 421 ASSERT_TRUE(test_server()->Start());
384 net::SpawnedTestServer https_test_server(net::SpawnedTestServer::TYPE_HTTPS, 422 net::SpawnedTestServer https_test_server(net::SpawnedTestServer::TYPE_HTTPS,
385 net::SpawnedTestServer::kLocalhost, 423 net::SpawnedTestServer::kLocalhost,
386 base::FilePath(kDocRoot)); 424 base::FilePath(kDocRoot));
387 ASSERT_TRUE(https_test_server.Start()); 425 ASSERT_TRUE(https_test_server.Start());
388 426
389 // Temporarily replace ContentBrowserClient with one that will cause a 427 // Temporarily replace ContentBrowserClient with one that will cause a
390 // process swap on all redirects. 428 // process swap on all redirects to HTTPS URLs.
391 TransfersAllRedirectsContentBrowserClient new_client; 429 TransferHttpsRedirectsContentBrowserClient new_client;
392 content::ContentBrowserClient* old_client = 430 content::ContentBrowserClient* old_client =
393 SetBrowserClientForTesting(&new_client); 431 SetBrowserClientForTesting(&new_client);
394 432
395 // Navigate to a page with a beforeunload handler. 433 // Navigate to a page with a beforeunload handler.
396 GURL url(test_server()->GetURL("files/beforeunload.html")); 434 GURL url(test_server()->GetURL("files/beforeunload.html"));
397 ui_test_utils::NavigateToURL(browser(), url); 435 ui_test_utils::NavigateToURL(browser(), url);
398 436
399 // Navigate to a URL that redirects to another process and approve the 437 // Navigate to a URL that redirects to another process and approve the
400 // beforeunload dialog that pops up. 438 // beforeunload dialog that pops up.
401 content::WindowedNotificationObserver nav_observer( 439 content::WindowedNotificationObserver nav_observer(
(...skipping 1755 matching lines...) Expand 10 before | Expand all | Expand 10 after
2157 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); 2195 RunTest(browser(), GetHrefURL(), modifiers, button, disposition);
2158 } 2196 }
2159 2197
2160 // Shift-middle-clicks open in a foreground tab. 2198 // Shift-middle-clicks open in a foreground tab.
2161 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftMiddleClickTest) { 2199 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftMiddleClickTest) {
2162 int modifiers = WebKit::WebInputEvent::ShiftKey; 2200 int modifiers = WebKit::WebInputEvent::ShiftKey;
2163 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle; 2201 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle;
2164 WindowOpenDisposition disposition = NEW_FOREGROUND_TAB; 2202 WindowOpenDisposition disposition = NEW_FOREGROUND_TAB;
2165 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); 2203 RunTest(browser(), GetHrefURL(), modifiers, button, disposition);
2166 } 2204 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_process_apitest.cc ('k') | chrome/test/data/beforeunload.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698