OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 95 |
96 // PrerenderContents that stops the UI message loop on DidStopLoading(). | 96 // PrerenderContents that stops the UI message loop on DidStopLoading(). |
97 class TestPrerenderContents : public PrerenderContents { | 97 class TestPrerenderContents : public PrerenderContents { |
98 public: | 98 public: |
99 TestPrerenderContents( | 99 TestPrerenderContents( |
100 PrerenderManager* prerender_manager, | 100 PrerenderManager* prerender_manager, |
101 PrerenderTracker* prerender_tracker, | 101 PrerenderTracker* prerender_tracker, |
102 Profile* profile, | 102 Profile* profile, |
103 const GURL& url, | 103 const GURL& url, |
104 const GURL& referrer, | 104 const GURL& referrer, |
105 int number_of_loads, | 105 int expected_number_of_loads, |
106 FinalStatus expected_final_status) | 106 FinalStatus expected_final_status) |
107 : PrerenderContents(prerender_manager, prerender_tracker, profile, | 107 : PrerenderContents(prerender_manager, prerender_tracker, profile, |
108 url, referrer, ORIGIN_LINK_REL_PRERENDER, | 108 url, referrer, ORIGIN_LINK_REL_PRERENDER, |
109 PrerenderManager::kNoExperiment), | 109 PrerenderManager::kNoExperiment), |
110 number_of_loads_(0), | 110 number_of_loads_(0), |
111 expected_number_of_loads_(number_of_loads), | 111 expected_number_of_loads_(expected_number_of_loads), |
112 expected_final_status_(expected_final_status), | 112 expected_final_status_(expected_final_status), |
113 new_render_view_host_(NULL), | 113 new_render_view_host_(NULL), |
114 was_hidden_(false), | 114 was_hidden_(false), |
115 was_shown_(false), | 115 was_shown_(false), |
116 should_be_shown_(expected_final_status == FINAL_STATUS_USED), | 116 should_be_shown_(expected_final_status == FINAL_STATUS_USED), |
117 quit_message_loop_on_destruction_(true) { | 117 quit_message_loop_on_destruction_(true) { |
118 if (expected_number_of_loads == 0) | |
119 MessageLoopForUI::current()->Quit(); | |
118 } | 120 } |
119 | 121 |
120 virtual ~TestPrerenderContents() { | 122 virtual ~TestPrerenderContents() { |
121 EXPECT_EQ(expected_final_status_, final_status()) << | 123 EXPECT_EQ(expected_final_status_, final_status()) << |
122 " when testing URL " << prerender_url().path() << | 124 " when testing URL " << prerender_url().path() << |
123 " (Expected: " << NameFromFinalStatus(expected_final_status_) << | 125 " (Expected: " << NameFromFinalStatus(expected_final_status_) << |
124 ", Actual: " << NameFromFinalStatus(final_status()) << ")"; | 126 ", Actual: " << NameFromFinalStatus(final_status()) << ")"; |
125 // Prerendering RenderViewHosts should be hidden before the first | 127 // Prerendering RenderViewHosts should be hidden before the first |
126 // navigation, so this should be happen for every PrerenderContents for | 128 // navigation, so this should be happen for every PrerenderContents for |
127 // which a RenderViewHost is created, regardless of whether or not it's | 129 // which a RenderViewHost is created, regardless of whether or not it's |
128 // used. | 130 // used. |
129 if (new_render_view_host_) { | 131 if (new_render_view_host_) |
130 EXPECT_TRUE(was_hidden_); | 132 EXPECT_TRUE(was_hidden_); |
131 } | |
132 | 133 |
133 // A used PrerenderContents will only be destroyed when we swap out | 134 // A used PrerenderContents will only be destroyed when we swap out |
134 // TabContents, at the end of a navigation caused by a call to | 135 // TabContents, at the end of a navigation caused by a call to |
135 // NavigateToURLImpl(). | 136 // NavigateToURLImpl(). |
136 if (final_status() == FINAL_STATUS_USED) | 137 if (final_status() == FINAL_STATUS_USED) |
137 EXPECT_TRUE(new_render_view_host_); | 138 EXPECT_TRUE(new_render_view_host_); |
138 | 139 |
139 EXPECT_EQ(should_be_shown_, was_shown_); | 140 EXPECT_EQ(should_be_shown_, was_shown_); |
140 | 141 |
141 // When the PrerenderContents is destroyed, quit the UI message loop. | 142 // When the PrerenderContents is destroyed, quit the UI message loop. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 | 239 |
239 bool quit_message_loop_on_destruction_; | 240 bool quit_message_loop_on_destruction_; |
240 }; | 241 }; |
241 | 242 |
242 // PrerenderManager that uses TestPrerenderContents. | 243 // PrerenderManager that uses TestPrerenderContents. |
243 class WaitForLoadPrerenderContentsFactory : public PrerenderContents::Factory { | 244 class WaitForLoadPrerenderContentsFactory : public PrerenderContents::Factory { |
244 public: | 245 public: |
245 WaitForLoadPrerenderContentsFactory( | 246 WaitForLoadPrerenderContentsFactory( |
246 int number_of_loads, | 247 int number_of_loads, |
247 const std::deque<FinalStatus>& expected_final_status_queue) | 248 const std::deque<FinalStatus>& expected_final_status_queue) |
248 : number_of_loads_(number_of_loads) { | 249 : number_of_loads_(number_of_loads), |
249 expected_final_status_queue_.resize(expected_final_status_queue.size()); | 250 expected_final_status_queue_(expected_final_status_queue) { |
250 std::copy(expected_final_status_queue.begin(), | |
251 expected_final_status_queue.end(), | |
252 expected_final_status_queue_.begin()); | |
253 VLOG(1) << "Factory created with queue length " << | 251 VLOG(1) << "Factory created with queue length " << |
254 expected_final_status_queue_.size(); | 252 expected_final_status_queue_.size(); |
255 } | 253 } |
256 | 254 |
257 virtual PrerenderContents* CreatePrerenderContents( | 255 virtual PrerenderContents* CreatePrerenderContents( |
258 PrerenderManager* prerender_manager, | 256 PrerenderManager* prerender_manager, |
259 PrerenderTracker* prerender_tracker, | 257 PrerenderTracker* prerender_tracker, |
260 Profile* profile, | 258 Profile* profile, |
261 const GURL& url, | 259 const GURL& url, |
262 const GURL& referrer, | 260 const GURL& referrer, |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 browser()->OpenURL(src_url, GURL(), CURRENT_TAB, PageTransition::TYPED); | 606 browser()->OpenURL(src_url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
609 | 607 |
610 ui_test_utils::RunMessageLoop(); | 608 ui_test_utils::RunMessageLoop(); |
611 | 609 |
612 TestPrerenderContents* prerender_contents = GetPrerenderContents(); | 610 TestPrerenderContents* prerender_contents = GetPrerenderContents(); |
613 | 611 |
614 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) { | 612 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) { |
615 ASSERT_TRUE(prerender_contents != NULL); | 613 ASSERT_TRUE(prerender_contents != NULL); |
616 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); | 614 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); |
617 | 615 |
618 if (call_javascript_) { | 616 if (call_javascript_ && total_navigations > 0) { |
619 // Check if page behaves as expected while in prerendered state. | 617 // Check if page behaves as expected while in prerendered state. |
620 bool prerender_test_result = false; | 618 bool prerender_test_result = false; |
621 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 619 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
622 prerender_contents->render_view_host_mutable(), L"", | 620 prerender_contents->render_view_host_mutable(), L"", |
623 L"window.domAutomationController.send(DidPrerenderPass())", | 621 L"window.domAutomationController.send(DidPrerenderPass())", |
624 &prerender_test_result)); | 622 &prerender_test_result)); |
625 EXPECT_TRUE(prerender_test_result); | 623 EXPECT_TRUE(prerender_test_result); |
626 } | 624 } |
627 } else { | 625 } else { |
628 // In the failure case, we should have removed dest_url_ from the | 626 // In the failure case, we should have removed |dest_url_| from the |
629 // prerender_manager. | 627 // prerender_manager. |
630 EXPECT_TRUE(prerender_contents == NULL); | 628 EXPECT_TRUE(prerender_contents == NULL); |
631 } | 629 } |
632 } | 630 } |
633 | 631 |
634 void NavigateToURLImpl(const GURL& dest_url, | 632 void NavigateToURLImpl(const GURL& dest_url, |
635 WindowOpenDisposition disposition) const { | 633 WindowOpenDisposition disposition) const { |
636 // Make sure in navigating we have a URL to use in the PrerenderManager. | 634 // Make sure in navigating we have a URL to use in the PrerenderManager. |
637 ASSERT_TRUE(GetPrerenderContents() != NULL); | 635 ASSERT_TRUE(GetPrerenderContents() != NULL); |
638 | 636 |
(...skipping 28 matching lines...) Expand all Loading... | |
667 tab_contents = browser()->GetSelectedTabContents(); | 665 tab_contents = browser()->GetSelectedTabContents(); |
668 break; | 666 break; |
669 case NEW_BACKGROUND_TAB: | 667 case NEW_BACKGROUND_TAB: |
670 tab_contents = | 668 tab_contents = |
671 browser()->GetTabContentsAt(browser()->active_index() + 1); | 669 browser()->GetTabContentsAt(browser()->active_index() + 1); |
672 break; | 670 break; |
673 default: | 671 default: |
674 ASSERT_TRUE(false) << "Unsupported creation disposition"; | 672 ASSERT_TRUE(false) << "Unsupported creation disposition"; |
675 } | 673 } |
676 ASSERT_TRUE(tab_contents); | 674 ASSERT_TRUE(tab_contents); |
675 if (tab_contents->IsLoading()) | |
Paweł Hajdan Jr.
2011/08/25 23:32:52
I think this may be prone to flakiness. Have you c
mmenke
2011/08/26 15:47:20
I don't think there was any flakiness in this part
| |
676 ui_test_utils::WaitForLoadStop(tab_contents); | |
677 | 677 |
678 bool display_test_result = false; | 678 bool display_test_result = false; |
679 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 679 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
680 tab_contents->render_view_host(), L"", | 680 tab_contents->render_view_host(), L"", |
681 L"window.domAutomationController.send(DidDisplayPass())", | 681 L"window.domAutomationController.send(DidDisplayPass())", |
682 &display_test_result)); | 682 &display_test_result)); |
683 EXPECT_TRUE(display_test_result); | 683 EXPECT_TRUE(display_test_result); |
684 } | 684 } |
685 } | 685 } |
686 | 686 |
(...skipping 16 matching lines...) Expand all Loading... | |
703 } | 703 } |
704 | 704 |
705 // Checks that the visibility API works. | 705 // Checks that the visibility API works. |
706 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibility) { | 706 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibility) { |
707 PrerenderTestURL("files/prerender/prerender_visibility.html", | 707 PrerenderTestURL("files/prerender/prerender_visibility.html", |
708 FINAL_STATUS_USED, | 708 FINAL_STATUS_USED, |
709 1); | 709 1); |
710 NavigateToDestURL(); | 710 NavigateToDestURL(); |
711 } | 711 } |
712 | 712 |
713 // Checks that the visibility API works when the prerender is quickly opened | |
714 // in a new tab before it stops loading. | |
715 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityQuickSwitch) { | |
716 PrerenderTestURL("files/prerender/prerender_visibility_quick.html", | |
717 FINAL_STATUS_USED, 0); | |
718 NavigateToDestURL(); | |
719 } | |
720 | |
713 // Checks that the visibility API works when opening a page in a new hidden | 721 // Checks that the visibility API works when opening a page in a new hidden |
714 // tab. | 722 // tab. |
715 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityBackgroundTab) { | 723 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityBackgroundTab) { |
716 PrerenderTestURL("files/prerender/prerender_visibility_hidden.html", | 724 PrerenderTestURL("files/prerender/prerender_visibility_hidden.html", |
717 FINAL_STATUS_USED, | 725 FINAL_STATUS_USED, |
718 1); | 726 1); |
719 NavigateToDestURLWithDisposition(NEW_BACKGROUND_TAB); | 727 NavigateToDestURLWithDisposition(NEW_BACKGROUND_TAB); |
720 } | 728 } |
721 | 729 |
730 // Checks that the visibility API works when opening a page in a new hidden | |
731 // tab, which is switched to before it stops loading. | |
732 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
733 PrerenderVisibilityBackgroundTabQuickSwitch) { | |
734 PrerenderTestURL("files/prerender/prerender_visibility_hidden_quick.html", | |
735 FINAL_STATUS_USED, 0); | |
736 NavigateToDestURLWithDisposition(NEW_BACKGROUND_TAB); | |
737 } | |
738 | |
722 // Checks that the visibility API works when opening a page in a new foreground | 739 // Checks that the visibility API works when opening a page in a new foreground |
723 // tab. | 740 // tab. |
724 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityForegroundTab) { | 741 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityForegroundTab) { |
725 PrerenderTestURL("files/prerender/prerender_visibility.html", | 742 PrerenderTestURL("files/prerender/prerender_visibility.html", |
726 FINAL_STATUS_USED, | 743 FINAL_STATUS_USED, |
727 1); | 744 1); |
728 NavigateToDestURLWithDisposition(NEW_FOREGROUND_TAB); | 745 NavigateToDestURLWithDisposition(NEW_FOREGROUND_TAB); |
729 } | 746 } |
730 | 747 |
748 // Checks that the visibility API works when the prerender is quickly opened | |
749 // in a new tab foreground before it stops loading. | |
750 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
751 PrerenderVisibilityForegroundTabQuickSwitch) { | |
752 PrerenderTestURL("files/prerender/prerender_visibility_quick.html", | |
753 FINAL_STATUS_USED, 0); | |
754 NavigateToDestURL(); | |
755 } | |
756 | |
731 // Checks that the prerendering of a page is canceled correctly when a | 757 // Checks that the prerendering of a page is canceled correctly when a |
732 // Javascript alert is called. | 758 // Javascript alert is called. |
733 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertBeforeOnload) { | 759 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertBeforeOnload) { |
734 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", | 760 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", |
735 FINAL_STATUS_JAVASCRIPT_ALERT, | 761 FINAL_STATUS_JAVASCRIPT_ALERT, |
736 1); | 762 1); |
737 } | 763 } |
738 | 764 |
739 // Checks that the prerendering of a page is canceled correctly when a | 765 // Checks that the prerendering of a page is canceled correctly when a |
740 // Javascript alert is called. | 766 // Javascript alert is called. |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1675 bool original_prerender_page = false; | 1701 bool original_prerender_page = false; |
1676 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1702 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1677 browser()->GetSelectedTabContents()->render_view_host(), L"", | 1703 browser()->GetSelectedTabContents()->render_view_host(), L"", |
1678 L"window.domAutomationController.send(IsOriginalPrerenderPage())", | 1704 L"window.domAutomationController.send(IsOriginalPrerenderPage())", |
1679 &original_prerender_page)); | 1705 &original_prerender_page)); |
1680 EXPECT_TRUE(original_prerender_page); | 1706 EXPECT_TRUE(original_prerender_page); |
1681 } | 1707 } |
1682 } | 1708 } |
1683 | 1709 |
1684 } // namespace prerender | 1710 } // namespace prerender |
OLD | NEW |