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

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

Issue 9416031: Prerendered pages are swapped in at browser::Navigate time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit tests Created 8 years, 9 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
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 <deque> 5 #include <deque>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // TabContents, at the end of a navigation caused by a call to 163 // TabContents, at the end of a navigation caused by a call to
164 // NavigateToURLImpl(). 164 // NavigateToURLImpl().
165 if (final_status() == FINAL_STATUS_USED) 165 if (final_status() == FINAL_STATUS_USED)
166 EXPECT_TRUE(new_render_view_host_); 166 EXPECT_TRUE(new_render_view_host_);
167 167
168 EXPECT_EQ(should_be_shown_, was_shown_); 168 EXPECT_EQ(should_be_shown_, was_shown_);
169 169
170 // When the PrerenderContents is destroyed, quit the UI message loop. 170 // When the PrerenderContents is destroyed, quit the UI message loop.
171 // This happens on navigation to used prerendered pages, and soon 171 // This happens on navigation to used prerendered pages, and soon
172 // after cancellation of unused prerendered pages. 172 // after cancellation of unused prerendered pages.
173 if (quit_message_loop_on_destruction_) 173 if (quit_message_loop_on_destruction_) {
174 MessageLoopForUI::current()->Quit(); 174 // The message loop may not be running if this is swapped in
175 // synchronously on a Navigation.
176 MessageLoop* loop = MessageLoopForUI::current();
177 if (loop->is_running())
178 loop->Quit();
179 }
175 } 180 }
176 181
177 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE { 182 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE {
178 // On quit, it's possible to end up here when render processes are closed 183 // On quit, it's possible to end up here when render processes are closed
179 // before the PrerenderManager is destroyed. As a result, it's possible to 184 // before the PrerenderManager is destroyed. As a result, it's possible to
180 // get either FINAL_STATUS_APP_TERMINATING or FINAL_STATUS_RENDERER_CRASHED 185 // get either FINAL_STATUS_APP_TERMINATING or FINAL_STATUS_RENDERER_CRASHED
181 // on quit. 186 // on quit.
182 // 187 //
183 // It's also possible for this to be called after we've been notified of 188 // It's also possible for this to be called after we've been notified of
184 // app termination, but before we've been deleted, which is why the second 189 // app termination, but before we've been deleted, which is why the second
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 GetPrerenderContents()->prerender_contents()->web_contents(); 785 GetPrerenderContents()->prerender_contents()->web_contents();
781 if (GetPrerenderContents()->number_of_loads() == 0) { 786 if (GetPrerenderContents()->number_of_loads() == 0) {
782 page_load_observer.reset( 787 page_load_observer.reset(
783 new ui_test_utils::WindowedNotificationObserver( 788 new ui_test_utils::WindowedNotificationObserver(
784 content::NOTIFICATION_LOAD_STOP, 789 content::NOTIFICATION_LOAD_STOP,
785 content::Source<NavigationController>( 790 content::Source<NavigationController>(
786 &web_contents->GetController()))); 791 &web_contents->GetController())));
787 } 792 }
788 } 793 }
789 794
790 // ui_test_utils::NavigateToURL waits until DidStopLoading is called on 795 // Navigate to the prerendered URL, but don't run the message loop. Browser
791 // the current tab. As that tab is going to end up deleted, and may never 796 // issued navigations to prerendered pages will synchronously swap in the
792 // finish loading before that happens, exit the message loop on the deletion 797 // prerendered page.
793 // of the used prerender contents instead.
794 //
795 // As PrerenderTestURL waits until the prerendered page has completely
796 // loaded, there is no race between loading |dest_url| and swapping the
797 // prerendered TabContents into the tab.
798 ui_test_utils::NavigateToURLWithDisposition( 798 ui_test_utils::NavigateToURLWithDisposition(
799 browser(), dest_url, disposition, ui_test_utils::BROWSER_TEST_NONE); 799 browser(), dest_url, disposition, ui_test_utils::BROWSER_TEST_NONE);
800 ui_test_utils::RunMessageLoop();
801 800
802 // Make sure the PrerenderContents found earlier was used or removed. 801 // Make sure the PrerenderContents found earlier was used or removed.
803 EXPECT_TRUE(GetPrerenderContents() == NULL); 802 EXPECT_TRUE(GetPrerenderContents() == NULL);
804 803
805 if (call_javascript_ && web_contents) { 804 if (call_javascript_ && web_contents) {
806 if (page_load_observer.get()) 805 if (page_load_observer.get())
807 page_load_observer->Wait(); 806 page_load_observer->Wait();
808 807
809 bool display_test_result = false; 808 bool display_test_result = false;
810 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 809 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) { 1945 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) {
1947 std::deque<FinalStatus> expected_final_status_queue; 1946 std::deque<FinalStatus> expected_final_status_queue;
1948 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT); 1947 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT);
1949 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); 1948 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED);
1950 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", 1949 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html",
1951 expected_final_status_queue, 1); 1950 expected_final_status_queue, 1);
1952 NavigateToDestURL(); 1951 NavigateToDestURL();
1953 } 1952 }
1954 1953
1955 } // namespace prerender 1954 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_contents.h » ('j') | chrome/browser/prerender/prerender_contents.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698