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

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

Issue 1896943002: Remove PrerenderManager::OnCloseWebContentsDeleter::SwappedOut (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make it compile 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/browser/prerender/prerender_manager.cc » ('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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 channel_destroyed_ = true; 319 channel_destroyed_ = true;
320 run_loop_.Quit(); 320 run_loop_.Quit();
321 } 321 }
322 322
323 bool channel_destroyed_; 323 bool channel_destroyed_;
324 base::RunLoop run_loop_; 324 base::RunLoop run_loop_;
325 325
326 DISALLOW_COPY_AND_ASSIGN(ChannelDestructionWatcher); 326 DISALLOW_COPY_AND_ASSIGN(ChannelDestructionWatcher);
327 }; 327 };
328 328
329 // A navigation observer to wait until WebContents is destroyed.
330 class WebContentsDestructionObserver : public WebContentsObserver {
331 public:
332 explicit WebContentsDestructionObserver(WebContents* web_contents)
333 : WebContentsObserver(web_contents) {}
334
335 // Waits for destruction of the observed WebContents.
336 void Wait() {
337 loop_.Run();
338 }
339
340 // WebContentsObserver implementation:
341 void WebContentsDestroyed() override {
342 loop_.Quit();
343 }
344
345 private:
346 DISALLOW_COPY_AND_ASSIGN(WebContentsDestructionObserver);
347 base::RunLoop loop_;
348 };
349
329 // A navigation observer to wait on either a new load or a swap of a 350 // A navigation observer to wait on either a new load or a swap of a
330 // WebContents. On swap, if the new WebContents is still loading, wait for that 351 // WebContents. On swap, if the new WebContents is still loading, wait for that
331 // load to complete as well. Note that the load must begin after the observer is 352 // load to complete as well. Note that the load must begin after the observer is
332 // attached. 353 // attached.
333 class NavigationOrSwapObserver : public WebContentsObserver, 354 class NavigationOrSwapObserver : public WebContentsObserver,
334 public TabStripModelObserver { 355 public TabStripModelObserver {
335 public: 356 public:
336 // Waits for either a new load or a swap of |tab_strip_model|'s active 357 // Waits for either a new load or a swap of |tab_strip_model|'s active
337 // WebContents. 358 // WebContents.
338 NavigationOrSwapObserver(TabStripModel* tab_strip_model, 359 NavigationOrSwapObserver(TabStripModel* tab_strip_model,
(...skipping 2728 matching lines...) Expand 10 before | Expand all | Expand 10 after
3067 favicon::ContentFaviconDriver::FromWebContents(GetActiveWebContents()); 3088 favicon::ContentFaviconDriver::FromWebContents(GetActiveWebContents());
3068 if (!favicon_driver->FaviconIsValid()) { 3089 if (!favicon_driver->FaviconIsValid()) {
3069 // If the favicon has not been set yet, wait for it to be. 3090 // If the favicon has not been set yet, wait for it to be.
3070 FaviconUpdateWatcher favicon_update_watcher(GetActiveWebContents()); 3091 FaviconUpdateWatcher favicon_update_watcher(GetActiveWebContents());
3071 favicon_update_watcher.Wait(); 3092 favicon_update_watcher.Wait();
3072 } 3093 }
3073 EXPECT_TRUE(favicon_driver->FaviconIsValid()); 3094 EXPECT_TRUE(favicon_driver->FaviconIsValid());
3074 } 3095 }
3075 3096
3076 // Checks that when a prerendered page is swapped in to a referring page, the 3097 // Checks that when a prerendered page is swapped in to a referring page, the
3077 // unload handlers on the referring page are executed. 3098 // unload handlers on the referring page are executed and its WebContents is
3099 // destroyed.
3100 // TODO(pasko): A similar test for BeforeUnload. See http://crbug.com/600693
3078 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) { 3101 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) {
3079 // Matches URL in prerender_loader_with_unload.html. 3102 // Matches URL in prerender_loader_with_unload.html.
3080 const GURL unload_url("http://unload-url.test"); 3103 const GURL unload_url("http://unload-url.test");
3081 base::FilePath empty_file = ui_test_utils::GetTestFilePath( 3104 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
3082 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); 3105 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
3083 RequestCounter unload_counter; 3106 RequestCounter unload_counter;
3084 BrowserThread::PostTask( 3107 BrowserThread::PostTask(
3085 BrowserThread::IO, FROM_HERE, 3108 BrowserThread::IO, FROM_HERE,
3086 base::Bind(&CreateCountingInterceptorOnIO, 3109 base::Bind(&CreateCountingInterceptorOnIO,
3087 unload_url, empty_file, unload_counter.AsWeakPtr())); 3110 unload_url, empty_file, unload_counter.AsWeakPtr()));
3088 3111
3089 set_loader_path("/prerender/prerender_loader_with_unload.html"); 3112 set_loader_path("/prerender/prerender_loader_with_unload.html");
3090 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 3113 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
3114 WebContentsDestructionObserver destruction_observer(GetActiveWebContents());
3091 NavigateToDestURL(); 3115 NavigateToDestURL();
3092 unload_counter.WaitForCount(1); 3116 unload_counter.WaitForCount(1);
3117 destruction_observer.Wait();
3093 } 3118 }
3094 3119
3095 // Checks that a hanging unload on the referring page of a prerender swap does 3120 // Checks that a hanging unload on the referring page of a prerender swap does
3096 // not crash the browser on exit. 3121 // not crash the browser on exit.
3097 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHangingUnload) { 3122 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHangingUnload) {
3098 // Matches URL in prerender_loader_with_unload.html. 3123 // Matches URL in prerender_loader_with_unload.html.
3099 const GURL hang_url("http://unload-url.test"); 3124 const GURL hang_url("http://unload-url.test");
3100 base::FilePath empty_file = ui_test_utils::GetTestFilePath( 3125 base::FilePath empty_file = ui_test_utils::GetTestFilePath(
3101 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html"))); 3126 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("empty.html")));
3102 BrowserThread::PostTask( 3127 BrowserThread::PostTask(
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
4061 4086
4062 NavigateToDestURL(); 4087 NavigateToDestURL();
4063 EXPECT_EQ(1U, task_manager.tasks().size()); 4088 EXPECT_EQ(1U, task_manager.tasks().size());
4064 } 4089 }
4065 4090
4066 } // namespace 4091 } // namespace
4067 4092
4068 #endif // defined(ENABLE_TASK_MANAGER) 4093 #endif // defined(ENABLE_TASK_MANAGER)
4069 4094
4070 } // namespace prerender 4095 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698