OLD | NEW |
---|---|
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 Loading... | |
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. | |
dominich
2012/02/28 16:21:00
Is it worth splitting the tests into browser- and
| |
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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 GetPrerenderContents()->prerender_contents()->web_contents(); | 784 GetPrerenderContents()->prerender_contents()->web_contents(); |
780 if (GetPrerenderContents()->number_of_loads() == 0) { | 785 if (GetPrerenderContents()->number_of_loads() == 0) { |
781 page_load_observer.reset( | 786 page_load_observer.reset( |
782 new ui_test_utils::WindowedNotificationObserver( | 787 new ui_test_utils::WindowedNotificationObserver( |
783 content::NOTIFICATION_LOAD_STOP, | 788 content::NOTIFICATION_LOAD_STOP, |
784 content::Source<NavigationController>( | 789 content::Source<NavigationController>( |
785 &web_contents->GetController()))); | 790 &web_contents->GetController()))); |
786 } | 791 } |
787 } | 792 } |
788 | 793 |
789 // ui_test_utils::NavigateToURL waits until DidStopLoading is called on | 794 // Navigate to the prerendered URL, but don't run the message loop. Browser |
790 // the current tab. As that tab is going to end up deleted, and may never | 795 // issued navigations to prerendered pages will synchronously swap in the |
791 // finish loading before that happens, exit the message loop on the deletion | 796 // prerendered page. |
792 // of the used prerender contents instead. | |
793 // | |
794 // As PrerenderTestURL waits until the prerendered page has completely | |
795 // loaded, there is no race between loading |dest_url| and swapping the | |
796 // prerendered TabContents into the tab. | |
797 ui_test_utils::NavigateToURLWithDisposition( | 797 ui_test_utils::NavigateToURLWithDisposition( |
798 browser(), dest_url, disposition, ui_test_utils::BROWSER_TEST_NONE); | 798 browser(), dest_url, disposition, ui_test_utils::BROWSER_TEST_NONE); |
799 ui_test_utils::RunMessageLoop(); | |
800 | 799 |
801 // Make sure the PrerenderContents found earlier was used or removed. | 800 // Make sure the PrerenderContents found earlier was used or removed. |
802 EXPECT_TRUE(GetPrerenderContents() == NULL); | 801 EXPECT_TRUE(GetPrerenderContents() == NULL); |
803 | 802 |
804 if (call_javascript_ && web_contents) { | 803 if (call_javascript_ && web_contents) { |
805 if (page_load_observer.get()) | 804 if (page_load_observer.get()) |
806 page_load_observer->Wait(); | 805 page_load_observer->Wait(); |
807 | 806 |
808 bool display_test_result = false; | 807 bool display_test_result = false; |
809 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 808 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1940 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) { | 1939 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) { |
1941 std::deque<FinalStatus> expected_final_status_queue; | 1940 std::deque<FinalStatus> expected_final_status_queue; |
1942 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT); | 1941 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT); |
1943 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); | 1942 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); |
1944 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", | 1943 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", |
1945 expected_final_status_queue, 1); | 1944 expected_final_status_queue, 1); |
1946 NavigateToDestURL(); | 1945 NavigateToDestURL(); |
1947 } | 1946 } |
1948 | 1947 |
1949 } // namespace prerender | 1948 } // namespace prerender |
OLD | NEW |