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

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 1940363002: Add two tests to ensure WebContents does not leak on prerender swap in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits in comments addressed Created 4 years, 7 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
« no previous file with comments | « no previous file | chrome/test/data/prerender/prerender_loader_with_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 <stddef.h> 5 #include <stddef.h>
6 #include <deque> 6 #include <deque>
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 3063 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 favicon::FaviconDriver* favicon_driver = 3074 favicon::FaviconDriver* favicon_driver =
3075 favicon::ContentFaviconDriver::FromWebContents(GetActiveWebContents()); 3075 favicon::ContentFaviconDriver::FromWebContents(GetActiveWebContents());
3076 if (!favicon_driver->FaviconIsValid()) { 3076 if (!favicon_driver->FaviconIsValid()) {
3077 // If the favicon has not been set yet, wait for it to be. 3077 // If the favicon has not been set yet, wait for it to be.
3078 FaviconUpdateWatcher favicon_update_watcher(GetActiveWebContents()); 3078 FaviconUpdateWatcher favicon_update_watcher(GetActiveWebContents());
3079 favicon_update_watcher.Wait(); 3079 favicon_update_watcher.Wait();
3080 } 3080 }
3081 EXPECT_TRUE(favicon_driver->FaviconIsValid()); 3081 EXPECT_TRUE(favicon_driver->FaviconIsValid());
3082 } 3082 }
3083 3083
3084 // Checks that when prerendered page is swapped in and the referring page
3085 // neither had set an unload nor it had set a beforeunload handler, the old
3086 // WebContents will not leak.
3087 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderOldWebContentsDeleted) {
3088 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
3089 WebContentsDestructionObserver destruction_observer(GetActiveWebContents());
3090 NavigateToDestURL();
3091 destruction_observer.Wait();
3092 }
3093
3084 // Checks that when a prerendered page is swapped in to a referring page, the 3094 // Checks that when a prerendered page is swapped in to a referring page, the
3085 // unload handlers on the referring page are executed and its WebContents is 3095 // unload handlers on the referring page are executed and its WebContents is
3086 // destroyed. 3096 // destroyed.
3087 // TODO(pasko): A similar test for BeforeUnload. See http://crbug.com/600693
3088 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) { 3097 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) {
3089 // Matches URL in prerender_loader_with_unload.html. 3098 // Matches URL in prerender_loader_with_unload.html.
3090 const GURL unload_url("http://unload-url.test"); 3099 const GURL unload_url("http://unload-url.test");
3091 base::FilePath empty_file = ui_test_utils::GetTestFilePath( 3100 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
3092 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); 3101 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
3093 RequestCounter unload_counter; 3102 RequestCounter unload_counter;
3094 BrowserThread::PostTask( 3103 BrowserThread::PostTask(
3095 BrowserThread::IO, FROM_HERE, 3104 BrowserThread::IO, FROM_HERE,
3096 base::Bind(&CreateCountingInterceptorOnIO, 3105 base::Bind(&CreateCountingInterceptorOnIO,
3097 unload_url, empty_file, unload_counter.AsWeakPtr())); 3106 unload_url, empty_file, unload_counter.AsWeakPtr()));
3098 3107
3099 set_loader_path("/prerender/prerender_loader_with_unload.html"); 3108 set_loader_path("/prerender/prerender_loader_with_unload.html");
3100 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 3109 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
3101 WebContentsDestructionObserver destruction_observer(GetActiveWebContents()); 3110 WebContentsDestructionObserver destruction_observer(GetActiveWebContents());
3102 NavigateToDestURL(); 3111 NavigateToDestURL();
3103 unload_counter.WaitForCount(1); 3112 unload_counter.WaitForCount(1);
3104 destruction_observer.Wait(); 3113 destruction_observer.Wait();
3105 } 3114 }
3106 3115
3116 // Checks that a beforeunload handler is executed on the referring page when a
3117 // prerendered page is swapped in. Also checks that the WebContents of the
3118 // referring page is destroyed.
3119 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderBeforeUnload) {
3120 // This URL is requested from prerender_loader_with_beforeunload.html.
3121 const GURL beforeunload_url("http://unload-url.test");
3122 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
3123 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
3124 RequestCounter request_counter;
3125 BrowserThread::PostTask(
3126 BrowserThread::IO, FROM_HERE,
3127 base::Bind(&CreateCountingInterceptorOnIO,
3128 beforeunload_url, empty_file, request_counter.AsWeakPtr()));
3129
3130 set_loader_path("/prerender/prerender_loader_with_beforeunload.html");
3131 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
3132 WebContentsDestructionObserver destruction_observer(GetActiveWebContents());
3133 NavigateToDestURL();
3134 request_counter.WaitForCount(1);
3135 destruction_observer.Wait();
3136 }
3137
3107 // Checks that a hanging unload on the referring page of a prerender swap does 3138 // Checks that a hanging unload on the referring page of a prerender swap does
3108 // not crash the browser on exit. 3139 // not crash the browser on exit.
3109 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHangingUnload) { 3140 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHangingUnload) {
3110 // Matches URL in prerender_loader_with_unload.html. 3141 // Matches URL in prerender_loader_with_unload.html.
3111 const GURL hang_url("http://unload-url.test"); 3142 const GURL hang_url("http://unload-url.test");
3112 base::FilePath empty_file = ui_test_utils::GetTestFilePath( 3143 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
3113 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); 3144 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
3114 BrowserThread::PostTask( 3145 BrowserThread::PostTask(
3115 BrowserThread::IO, FROM_HERE, 3146 BrowserThread::IO, FROM_HERE,
3116 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, 3147 base::Bind(&CreateHangingFirstRequestInterceptorOnIO,
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
4004 browser()->tab_strip_model()->GetActiveWebContents(); 4035 browser()->tab_strip_model()->GetActiveWebContents();
4005 bool display_test_result = false; 4036 bool display_test_result = false;
4006 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, 4037 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents,
4007 "DidDisplayReallyPass()", 4038 "DidDisplayReallyPass()",
4008 &display_test_result)); 4039 &display_test_result));
4009 ASSERT_TRUE(display_test_result); 4040 ASSERT_TRUE(display_test_result);
4010 } 4041 }
4011 #endif // !defined(DISABLE_NACL) 4042 #endif // !defined(DISABLE_NACL)
4012 4043
4013 } // namespace prerender 4044 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/prerender/prerender_loader_with_beforeunload.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698