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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/browsing_data_helper.h" | 14 #include "chrome/browser/browsing_data_helper.h" |
15 #include "chrome/browser/browsing_data_remover.h" | 15 #include "chrome/browser/browsing_data_remover.h" |
16 #include "chrome/browser/content_settings/host_content_settings_map.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map.h" |
17 #include "chrome/browser/favicon/favicon_tab_helper.h" | 17 #include "chrome/browser/favicon/favicon_tab_helper.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/prerender/prerender_contents.h" | 19 #include "chrome/browser/prerender/prerender_contents.h" |
20 #include "chrome/browser/prerender/prerender_handle.h" | |
20 #include "chrome/browser/prerender/prerender_link_manager.h" | 21 #include "chrome/browser/prerender/prerender_link_manager.h" |
21 #include "chrome/browser/prerender/prerender_link_manager_factory.h" | 22 #include "chrome/browser/prerender/prerender_link_manager_factory.h" |
22 #include "chrome/browser/prerender/prerender_manager.h" | 23 #include "chrome/browser/prerender/prerender_manager.h" |
23 #include "chrome/browser/prerender/prerender_manager_factory.h" | 24 #include "chrome/browser/prerender/prerender_manager_factory.h" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
26 #include "chrome/browser/task_manager/task_manager.h" | 27 #include "chrome/browser/task_manager/task_manager.h" |
27 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 28 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_commands.h" | 30 #include "chrome/browser/ui/browser_commands.h" |
30 #include "chrome/browser/ui/browser_finder.h" | 31 #include "chrome/browser/ui/browser_finder.h" |
31 #include "chrome/browser/ui/browser_tabstrip.h" | 32 #include "chrome/browser/ui/browser_tabstrip.h" |
32 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
33 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 35 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
34 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
35 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
36 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
37 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
38 #include "chrome/test/base/in_process_browser_test.h" | 40 #include "chrome/test/base/in_process_browser_test.h" |
39 #include "chrome/test/base/ui_test_utils.h" | 41 #include "chrome/test/base/ui_test_utils.h" |
40 #include "content/public/browser/devtools_agent_host_registry.h" | 42 #include "content/public/browser/devtools_agent_host_registry.h" |
41 #include "content/public/browser/devtools_client_host.h" | 43 #include "content/public/browser/devtools_client_host.h" |
42 #include "content/public/browser/devtools_manager.h" | 44 #include "content/public/browser/devtools_manager.h" |
43 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
44 #include "content/public/browser/render_view_host.h" | 46 #include "content/public/browser/render_view_host.h" |
45 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
46 #include "content/public/common/url_constants.h" | 48 #include "content/public/common/url_constants.h" |
47 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
48 #include "net/base/mock_host_resolver.h" | 50 #include "net/base/mock_host_resolver.h" |
49 #include "net/url_request/url_request_context.h" | 51 #include "net/url_request/url_request_context.h" |
50 #include "net/url_request/url_request_context_getter.h" | 52 #include "net/url_request/url_request_context_getter.h" |
51 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
54 #include "content/public/test/test_navigation_observer.h" | |
52 | 55 |
53 using content::BrowserThread; | 56 using content::BrowserThread; |
54 using content::DevToolsAgentHost; | 57 using content::DevToolsAgentHost; |
55 using content::DevToolsAgentHostRegistry; | 58 using content::DevToolsAgentHostRegistry; |
56 using content::DevToolsClientHost; | 59 using content::DevToolsClientHost; |
57 using content::DevToolsManager; | 60 using content::DevToolsManager; |
58 using content::NavigationController; | 61 using content::NavigationController; |
59 using content::OpenURLParams; | 62 using content::OpenURLParams; |
60 using content::Referrer; | 63 using content::Referrer; |
61 using content::RenderViewHost; | 64 using content::RenderViewHost; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 prerender_manager->CancelAllPrerenders(); | 107 prerender_manager->CancelAllPrerenders(); |
105 } | 108 } |
106 | 109 |
107 // Returns true if and only if the final status is one in which the prerendered | 110 // Returns true if and only if the final status is one in which the prerendered |
108 // page should prerender correctly. The page still may not be used. | 111 // page should prerender correctly. The page still may not be used. |
109 bool ShouldRenderPrerenderedPageCorrectly(FinalStatus status) { | 112 bool ShouldRenderPrerenderedPageCorrectly(FinalStatus status) { |
110 switch (status) { | 113 switch (status) { |
111 case FINAL_STATUS_USED: | 114 case FINAL_STATUS_USED: |
112 case FINAL_STATUS_WINDOW_OPENER: | 115 case FINAL_STATUS_WINDOW_OPENER: |
113 case FINAL_STATUS_APP_TERMINATING: | 116 case FINAL_STATUS_APP_TERMINATING: |
114 case FINAL_STATUS_FRAGMENT_MISMATCH: | |
115 case FINAL_STATUS_CACHE_OR_HISTORY_CLEARED: | 117 case FINAL_STATUS_CACHE_OR_HISTORY_CLEARED: |
116 // We'll crash the renderer after it's loaded. | 118 // We'll crash the renderer after it's loaded. |
117 case FINAL_STATUS_RENDERER_CRASHED: | 119 case FINAL_STATUS_RENDERER_CRASHED: |
118 case FINAL_STATUS_CANCELLED: | 120 case FINAL_STATUS_CANCELLED: |
119 case FINAL_STATUS_DEVTOOLS_ATTACHED: | 121 case FINAL_STATUS_DEVTOOLS_ATTACHED: |
120 case FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH: | |
121 return true; | 122 return true; |
122 default: | 123 default: |
123 return false; | 124 return false; |
124 } | 125 } |
125 } | 126 } |
126 | 127 |
127 // PrerenderContents that stops the UI message loop on DidStopLoading(). | 128 // PrerenderContents that stops the UI message loop on DidStopLoading(). |
128 class TestPrerenderContents : public PrerenderContents { | 129 class TestPrerenderContents : public PrerenderContents { |
129 public: | 130 public: |
131 using PrerenderContents::PendingPrerenderInfo; | |
dominich
2012/07/02 20:43:03
Should these just be made protected in PrerenderCo
gavinp
2012/07/03 16:41:02
They are already protected, this would not work ot
| |
132 using PrerenderContents::PendingPrerenderList; | |
133 using PrerenderContents::pending_prerender_list; | |
134 | |
130 TestPrerenderContents( | 135 TestPrerenderContents( |
131 PrerenderManager* prerender_manager, | 136 PrerenderManager* prerender_manager, |
132 PrerenderTracker* prerender_tracker, | 137 PrerenderTracker* prerender_tracker, |
133 Profile* profile, | 138 Profile* profile, |
134 const GURL& url, | 139 const GURL& url, |
135 const content::Referrer& referrer, | 140 const content::Referrer& referrer, |
136 int expected_number_of_loads, | 141 int expected_number_of_loads, |
137 FinalStatus expected_final_status, | 142 FinalStatus expected_final_status, |
138 bool prerender_should_wait_for_ready_title) | 143 bool prerender_should_wait_for_ready_title) |
139 : PrerenderContents(prerender_manager, prerender_tracker, | 144 : PrerenderContents(prerender_manager, prerender_tracker, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 | 225 |
221 virtual void DidStopLoading() OVERRIDE { | 226 virtual void DidStopLoading() OVERRIDE { |
222 PrerenderContents::DidStopLoading(); | 227 PrerenderContents::DidStopLoading(); |
223 ++number_of_loads_; | 228 ++number_of_loads_; |
224 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status_) && | 229 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status_) && |
225 number_of_loads_ == expected_number_of_loads_) { | 230 number_of_loads_ == expected_number_of_loads_) { |
226 MessageLoopForUI::current()->Quit(); | 231 MessageLoopForUI::current()->Quit(); |
227 } | 232 } |
228 } | 233 } |
229 | 234 |
230 virtual void AddPendingPrerender(const GURL& url, | 235 virtual void AddPendingPrerender( |
231 const content::Referrer& referrer, | 236 const base::WeakPtr<PrerenderHandle> weak_prerender_handle, |
232 const gfx::Size& size) OVERRIDE { | 237 const GURL& url, |
233 PrerenderContents::AddPendingPrerender(url, referrer, size); | 238 const content::Referrer& referrer, |
239 const gfx::Size& size) OVERRIDE { | |
240 PrerenderContents::AddPendingPrerender( | |
241 weak_prerender_handle, url, referrer, size); | |
234 if (expected_pending_prerenders_ > 0 && | 242 if (expected_pending_prerenders_ > 0 && |
235 pending_prerender_list()->size() == expected_pending_prerenders_) { | 243 pending_prerender_list()->size() == expected_pending_prerenders_) { |
236 MessageLoop::current()->Quit(); | 244 MessageLoop::current()->Quit(); |
237 } | 245 } |
238 } | 246 } |
239 | 247 |
240 virtual WebContents* CreateWebContents( | 248 virtual WebContents* CreateWebContents( |
241 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE { | 249 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE { |
242 WebContents* web_contents = PrerenderContents::CreateWebContents( | 250 WebContents* web_contents = PrerenderContents::CreateWebContents( |
243 session_storage_namespace); | 251 session_storage_namespace); |
(...skipping 23 matching lines...) Expand all Loading... | |
267 EXPECT_EQ(expected_pending_prerenders, pending_prerender_list()->size()); | 275 EXPECT_EQ(expected_pending_prerenders, pending_prerender_list()->size()); |
268 } | 276 } |
269 | 277 |
270 // For tests that open the prerender in a new background tab, the RenderView | 278 // For tests that open the prerender in a new background tab, the RenderView |
271 // will not have been made visible when the PrerenderContents is destroyed | 279 // will not have been made visible when the PrerenderContents is destroyed |
272 // even though it is used. | 280 // even though it is used. |
273 void set_should_be_shown(bool value) { should_be_shown_ = value; } | 281 void set_should_be_shown(bool value) { should_be_shown_ = value; } |
274 | 282 |
275 int number_of_loads() const { return number_of_loads_; } | 283 int number_of_loads() const { return number_of_loads_; } |
276 | 284 |
285 FinalStatus expected_final_status() const { return expected_final_status_; } | |
286 | |
277 private: | 287 private: |
278 virtual void OnRenderViewHostCreated( | 288 virtual void OnRenderViewHostCreated( |
279 RenderViewHost* new_render_view_host) OVERRIDE { | 289 RenderViewHost* new_render_view_host) OVERRIDE { |
280 // Used to make sure the RenderViewHost is hidden and, if used, | 290 // Used to make sure the RenderViewHost is hidden and, if used, |
281 // subsequently shown. | 291 // subsequently shown. |
282 notification_registrar().Add( | 292 notification_registrar().Add( |
283 this, | 293 this, |
284 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 294 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
285 content::Source<RenderWidgetHost>(new_render_view_host)); | 295 content::Source<RenderWidgetHost>(new_render_view_host)); |
286 | 296 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 #endif | 493 #endif |
484 use_https_src_server_(false), | 494 use_https_src_server_(false), |
485 call_javascript_(true), | 495 call_javascript_(true), |
486 loader_path_("files/prerender/prerender_loader.html"), | 496 loader_path_("files/prerender/prerender_loader.html"), |
487 explicitly_set_browser_(NULL) { | 497 explicitly_set_browser_(NULL) { |
488 EnableDOMAutomation(); | 498 EnableDOMAutomation(); |
489 } | 499 } |
490 | 500 |
491 virtual ~PrerenderBrowserTest() {} | 501 virtual ~PrerenderBrowserTest() {} |
492 | 502 |
503 content::SessionStorageNamespace* GetSessionStorageNamespace() const { | |
504 return current_browser()->tab_strip_model()->GetActiveTabContents()-> | |
dominich
2012/07/02 20:43:03
Is this fragile on, say, OSX where we can have a b
gavinp
2012/07/03 16:41:02
Done.
| |
505 web_contents()-> GetRenderViewHost()->GetSessionStorageNamespace(); | |
506 } | |
507 | |
493 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 508 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
494 #if defined(ENABLE_SAFE_BROWSING) | 509 #if defined(ENABLE_SAFE_BROWSING) |
495 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get()); | 510 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get()); |
496 #endif | 511 #endif |
497 } | 512 } |
498 | 513 |
499 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 514 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
500 command_line->AppendSwitchASCII(switches::kPrerenderMode, | 515 command_line->AppendSwitchASCII(switches::kPrerenderMode, |
501 switches::kPrerenderModeSwitchValueEnabled); | 516 switches::kPrerenderModeSwitchValueEnabled); |
502 #if defined(OS_MACOSX) | 517 #if defined(OS_MACOSX) |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 &js_result)); | 711 &js_result)); |
697 EXPECT_TRUE(js_result); | 712 EXPECT_TRUE(js_result); |
698 } | 713 } |
699 | 714 |
700 void NavigateToURL(const std::string& dest_html_file) const { | 715 void NavigateToURL(const std::string& dest_html_file) const { |
701 GURL dest_url = test_server()->GetURL(dest_html_file); | 716 GURL dest_url = test_server()->GetURL(dest_html_file); |
702 NavigateToURLImpl(dest_url, CURRENT_TAB); | 717 NavigateToURLImpl(dest_url, CURRENT_TAB); |
703 } | 718 } |
704 | 719 |
705 bool UrlIsInPrerenderManager(const std::string& html_file) const { | 720 bool UrlIsInPrerenderManager(const std::string& html_file) const { |
706 GURL dest_url = test_server()->GetURL(html_file); | 721 return UrlIsInPrerenderManager(test_server()->GetURL(html_file)); |
707 return (GetPrerenderManager()->FindEntry(dest_url) != NULL); | |
708 } | 722 } |
709 | 723 |
710 bool UrlIsInPrerenderManager(const GURL& url) { | 724 bool UrlIsInPrerenderManager(const GURL& url) const { |
711 return (GetPrerenderManager()->FindEntry(url) != NULL); | 725 return GetPrerenderManager()->FindPrerenderData( |
726 url, GetSessionStorageNamespace()) != NULL; | |
712 } | 727 } |
713 | 728 |
714 bool UrlIsPendingInPrerenderManager(const std::string& html_file) const { | 729 bool UrlIsPendingInPrerenderManager(const std::string& html_file) const { |
730 TestPrerenderContents* test_prerender_contents = GetPrerenderContents(); | |
731 if (!test_prerender_contents) | |
732 return false; | |
715 GURL dest_url = test_server()->GetURL(html_file); | 733 GURL dest_url = test_server()->GetURL(html_file); |
716 return GetPrerenderManager()->IsPendingEntry(dest_url); | 734 for (TestPrerenderContents::PendingPrerenderList::const_iterator |
735 it = test_prerender_contents->pending_prerender_list()->begin(), | |
736 end = test_prerender_contents->pending_prerender_list()->end(); | |
737 it != end; | |
738 ++it) { | |
739 if (it->url == dest_url && it->weak_prerender_handle) { | |
740 EXPECT_FALSE(GetPrerenderManager()->FindPrerenderData( | |
741 dest_url, GetSessionStorageNamespace())); | |
742 EXPECT_TRUE( | |
743 test_prerender_contents->IsPendingEntry(it->weak_prerender_handle)); | |
744 EXPECT_TRUE(it->weak_prerender_handle->IsPending()); | |
745 return true; | |
746 } | |
747 } | |
748 return false; | |
717 } | 749 } |
718 | 750 |
719 void set_use_https_src(bool use_https_src_server) { | 751 void set_use_https_src(bool use_https_src_server) { |
720 use_https_src_server_ = use_https_src_server; | 752 use_https_src_server_ = use_https_src_server; |
721 } | 753 } |
722 | 754 |
723 void DisableJavascriptCalls() { | 755 void DisableJavascriptCalls() { |
724 call_javascript_ = false; | 756 call_javascript_ = false; |
725 } | 757 } |
726 | 758 |
(...skipping 30 matching lines...) Expand all Loading... | |
757 return static_cast<int>(history_list->GetSize()); | 789 return static_cast<int>(history_list->GetSize()); |
758 } | 790 } |
759 | 791 |
760 #if defined(ENABLE_SAFE_BROWSING) | 792 #if defined(ENABLE_SAFE_BROWSING) |
761 FakeSafeBrowsingService* GetSafeBrowsingService() { | 793 FakeSafeBrowsingService* GetSafeBrowsingService() { |
762 return safe_browsing_factory_->most_recent_service(); | 794 return safe_browsing_factory_->most_recent_service(); |
763 } | 795 } |
764 #endif | 796 #endif |
765 | 797 |
766 TestPrerenderContents* GetPrerenderContents() const { | 798 TestPrerenderContents* GetPrerenderContents() const { |
799 PrerenderHandle::PrerenderData* prerender_data = | |
800 GetPrerenderManager()->FindPrerenderData( | |
801 dest_url_, GetSessionStorageNamespace()); | |
767 return static_cast<TestPrerenderContents*>( | 802 return static_cast<TestPrerenderContents*>( |
768 GetPrerenderManager()->FindEntry(dest_url_)); | 803 prerender_data ? prerender_data->contents : NULL); |
769 } | 804 } |
770 | 805 |
771 void set_loader_path(const std::string& path) { | 806 void set_loader_path(const std::string& path) { |
772 loader_path_ = path; | 807 loader_path_ = path; |
773 } | 808 } |
774 | 809 |
775 void set_loader_query_and_fragment(const std::string& query_and_fragment) { | 810 void set_loader_query_and_fragment(const std::string& query_and_fragment) { |
776 loader_query_and_fragment_ = query_and_fragment; | 811 loader_query_and_fragment_ = query_and_fragment; |
777 } | 812 } |
778 | 813 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
875 bool prerender_test_result = false; | 910 bool prerender_test_result = false; |
876 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 911 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
877 prerender_contents->GetRenderViewHostMutable(), L"", | 912 prerender_contents->GetRenderViewHostMutable(), L"", |
878 L"window.domAutomationController.send(DidPrerenderPass())", | 913 L"window.domAutomationController.send(DidPrerenderPass())", |
879 &prerender_test_result)); | 914 &prerender_test_result)); |
880 EXPECT_TRUE(prerender_test_result); | 915 EXPECT_TRUE(prerender_test_result); |
881 } | 916 } |
882 } else { | 917 } else { |
883 // In the failure case, we should have removed |dest_url_| from the | 918 // In the failure case, we should have removed |dest_url_| from the |
884 // prerender_manager. We ignore dummy PrerenderContents (as indicated | 919 // prerender_manager. We ignore dummy PrerenderContents (as indicated |
885 // by not having started). | 920 // by not having started), and PrerenderContents that are expected to |
921 // be left in the manager until the test finishes. | |
886 EXPECT_TRUE(prerender_contents == NULL || | 922 EXPECT_TRUE(prerender_contents == NULL || |
887 !prerender_contents->prerendering_has_started()); | 923 !prerender_contents->prerendering_has_started() || |
924 prerender_contents->expected_final_status() == | |
925 FINAL_STATUS_MANAGER_SHUTDOWN); | |
888 } | 926 } |
889 } | 927 } |
890 | 928 |
891 void NavigateToURLImpl(const GURL& dest_url, | 929 void NavigateToURLImpl(const GURL& dest_url, |
892 WindowOpenDisposition disposition) const { | 930 WindowOpenDisposition disposition) const { |
893 ASSERT_TRUE(GetPrerenderManager() != NULL); | 931 ASSERT_TRUE(GetPrerenderManager() != NULL); |
894 // Make sure in navigating we have a URL to use in the PrerenderManager. | 932 // Make sure in navigating we have a URL to use in the PrerenderManager. |
895 ASSERT_TRUE(GetPrerenderContents() != NULL); | 933 ASSERT_TRUE(GetPrerenderContents() != NULL); |
896 | 934 |
897 // If opening the page in a background tab, it won't be shown when swapped | 935 // If opening the page in a background tab, it won't be shown when swapped |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
946 const { | 984 const { |
947 TestPrerenderContents* prerender_contents = GetPrerenderContents(); | 985 TestPrerenderContents* prerender_contents = GetPrerenderContents(); |
948 ASSERT_TRUE(prerender_contents != NULL); | 986 ASSERT_TRUE(prerender_contents != NULL); |
949 | 987 |
950 RenderViewHost* render_view_host = | 988 RenderViewHost* render_view_host = |
951 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(); | 989 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(); |
952 render_view_host->ExecuteJavascriptInWebFrame( | 990 render_view_host->ExecuteJavascriptInWebFrame( |
953 string16(), | 991 string16(), |
954 ASCIIToUTF16(javascript_function_name)); | 992 ASCIIToUTF16(javascript_function_name)); |
955 | 993 |
956 // Run message loop until the prerender contents is destroyed. | 994 if (prerender_contents->expected_final_status() != |
957 ui_test_utils::RunMessageLoop(); | 995 FINAL_STATUS_APP_TERMINATING) { |
996 // Run message loop until the prerender contents is destroyed. | |
997 ui_test_utils::RunMessageLoop(); | |
998 } else { | |
999 // We don't expect to pick up a running prerender, so instead | |
1000 // something else. | |
1001 content::TestNavigationObserver observer( | |
1002 content::NotificationService::AllSources(), NULL, 1); | |
1003 base::RunLoop run_loop; | |
1004 observer.WaitForObservation( | |
1005 base::Bind(&ui_test_utils::RunThisRunLoop, | |
1006 base::Unretained(&run_loop)), | |
1007 ui_test_utils::GetQuitTaskForRunLoop(&run_loop)); | |
1008 } | |
958 } | 1009 } |
959 | 1010 |
960 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; | 1011 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; |
961 #if defined(ENABLE_SAFE_BROWSING) | 1012 #if defined(ENABLE_SAFE_BROWSING) |
962 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; | 1013 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; |
963 #endif | 1014 #endif |
964 GURL dest_url_; | 1015 GURL dest_url_; |
965 bool use_https_src_server_; | 1016 bool use_https_src_server_; |
966 bool call_javascript_; | 1017 bool call_javascript_; |
967 std::string loader_path_; | 1018 std::string loader_path_; |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1631 std::string()); | 1682 std::string()); |
1632 ui_test_utils::RunMessageLoop(); | 1683 ui_test_utils::RunMessageLoop(); |
1633 } | 1684 } |
1634 | 1685 |
1635 // Checks that we correctly use a prerendered page when navigating to a | 1686 // Checks that we correctly use a prerendered page when navigating to a |
1636 // fragment. | 1687 // fragment. |
1637 // DISABLED: http://crbug.com/84154 | 1688 // DISABLED: http://crbug.com/84154 |
1638 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1689 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
1639 DISABLED_PrerenderPageNavigateFragment) { | 1690 DISABLED_PrerenderPageNavigateFragment) { |
1640 PrerenderTestURL("files/prerender/prerender_fragment.html", | 1691 PrerenderTestURL("files/prerender/prerender_fragment.html", |
1641 FINAL_STATUS_FRAGMENT_MISMATCH, | 1692 FINAL_STATUS_APP_TERMINATING, |
dominich
2012/07/02 20:43:03
Why is this not USED?
also below a few times.
gavinp
2012/07/03 16:41:02
The URLs do not compare as equal.
dominich
2012/07/03 17:08:39
So this would be TIMED_OUT in production? Maybe we
| |
1642 1); | 1693 1); |
1643 NavigateToURL("files/prerender/prerender_fragment.html#fragment"); | 1694 NavigateToURL("files/prerender/prerender_fragment.html#fragment"); |
1644 } | 1695 } |
1645 | 1696 |
1646 // Checks that we correctly use a prerendered page when we prerender a fragment | 1697 // Checks that we correctly use a prerendered page when we prerender a fragment |
dominich
2012/07/03 17:08:39
this should be enabled and the comment should be c
gavinp
2012/07/03 18:45:40
Is http://code.google.com/p/chromium/issues/detail
| |
1647 // but navigate to the main page. | 1698 // but navigate to the main page. |
1648 // http://crbug.com/83901 | 1699 // http://crbug.com/83901 |
1649 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1700 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
1650 DISABLED_PrerenderFragmentNavigatePage) { | 1701 DISABLED_PrerenderFragmentNavigatePage) { |
1651 PrerenderTestURL("files/prerender/prerender_fragment.html#fragment", | 1702 PrerenderTestURL("files/prerender/prerender_fragment.html#fragment", |
1652 FINAL_STATUS_FRAGMENT_MISMATCH, | 1703 FINAL_STATUS_APP_TERMINATING, |
1653 1); | 1704 1); |
1654 NavigateToURL("files/prerender/prerender_fragment.html"); | 1705 NavigateToURL("files/prerender/prerender_fragment.html"); |
1655 } | 1706 } |
1656 | 1707 |
1657 // Checks that we correctly use a prerendered page when we prerender a fragment | 1708 // Checks that we correctly use a prerendered page when we prerender a fragment |
1658 // but navigate to a different fragment on the same page. | 1709 // but navigate to a different fragment on the same page. |
1659 // DISABLED: http://crbug.com/84154 | 1710 // DISABLED: http://crbug.com/84154 |
1660 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1711 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
1661 DISABLED_PrerenderFragmentNavigateFragment) { | 1712 DISABLED_PrerenderFragmentNavigateFragment) { |
1662 PrerenderTestURL("files/prerender/prerender_fragment.html#other_fragment", | 1713 PrerenderTestURL("files/prerender/prerender_fragment.html#other_fragment", |
1663 FINAL_STATUS_FRAGMENT_MISMATCH, | 1714 FINAL_STATUS_APP_TERMINATING, |
1664 1); | 1715 1); |
1665 NavigateToURL("files/prerender/prerender_fragment.html#fragment"); | 1716 NavigateToURL("files/prerender/prerender_fragment.html#fragment"); |
1666 } | 1717 } |
1667 | 1718 |
1668 // Checks that we correctly use a prerendered page when the page uses a client | 1719 // Checks that we correctly use a prerendered page when the page uses a client |
1669 // redirect to refresh from a fragment on the same page. | 1720 // redirect to refresh from a fragment on the same page. |
1670 // http://crbug.com/83901 | 1721 // http://crbug.com/83901 |
1671 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1722 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
1672 DISABLED_PrerenderClientRedirectFromFragment) { | 1723 DISABLED_PrerenderClientRedirectFromFragment) { |
1673 PrerenderTestURL( | 1724 PrerenderTestURL( |
1674 CreateClientRedirect("files/prerender/prerender_fragment.html#fragment"), | 1725 CreateClientRedirect("files/prerender/prerender_fragment.html#fragment"), |
1675 FINAL_STATUS_FRAGMENT_MISMATCH, | 1726 FINAL_STATUS_APP_TERMINATING, |
1676 2); | 1727 2); |
1677 NavigateToURL("files/prerender/prerender_fragment.html"); | 1728 NavigateToURL("files/prerender/prerender_fragment.html"); |
1678 } | 1729 } |
1679 | 1730 |
1680 // Checks that we correctly use a prerendered page when the page uses a client | 1731 // Checks that we correctly use a prerendered page when the page uses a client |
1681 // redirect to refresh to a fragment on the same page. | 1732 // redirect to refresh to a fragment on the same page. |
1682 // DISABLED: http://crbug.com/84154 | 1733 // DISABLED: http://crbug.com/84154 |
1683 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1734 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
dominich
2012/07/03 17:08:39
Can you add a test that prerenders #fragment and n
gavinp
2012/07/03 18:45:40
That sounds like it belongs in the CL that removes
| |
1684 DISABLED_PrerenderClientRedirectToFragment) { | 1735 DISABLED_PrerenderClientRedirectToFragment) { |
1685 PrerenderTestURL( | 1736 PrerenderTestURL( |
1686 CreateClientRedirect("files/prerender/prerender_fragment.html"), | 1737 CreateClientRedirect("files/prerender/prerender_fragment.html"), |
1687 FINAL_STATUS_FRAGMENT_MISMATCH, | 1738 FINAL_STATUS_APP_TERMINATING, |
1688 2); | 1739 2); |
1689 NavigateToURL("files/prerender/prerender_fragment.html#fragment"); | 1740 NavigateToURL("files/prerender/prerender_fragment.html#fragment"); |
1690 } | 1741 } |
1691 | 1742 |
1692 // Checks that we correctly use a prerendered page when the page uses JS to set | 1743 // Checks that we correctly use a prerendered page when the page uses JS to set |
1693 // the window.location.hash to a fragment on the same page. | 1744 // the window.location.hash to a fragment on the same page. |
1694 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1745 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
1695 PrerenderPageChangeFragmentLocationHash) { | 1746 PrerenderPageChangeFragmentLocationHash) { |
1696 PrerenderTestURL("files/prerender/prerender_fragment_location_hash.html", | 1747 PrerenderTestURL("files/prerender/prerender_fragment_location_hash.html", |
1697 FINAL_STATUS_USED, | 1748 FINAL_STATUS_USED, |
1698 1); | 1749 1); |
1699 NavigateToURL("files/prerender/prerender_fragment_location_hash.html"); | 1750 NavigateToURL("files/prerender/prerender_fragment_location_hash.html"); |
1700 } | 1751 } |
1701 | 1752 |
1702 // Checks that prerendering a PNG works correctly. | 1753 // Checks that preren a PNG works correctly. |
dominich
2012/07/02 20:43:03
typo
gavinp
2012/07/03 16:41:02
Done.
| |
1703 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderImagePng) { | 1754 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderImagePng) { |
1704 DisableJavascriptCalls(); | 1755 DisableJavascriptCalls(); |
1705 PrerenderTestURL("files/prerender/image.png", FINAL_STATUS_USED, 1); | 1756 PrerenderTestURL("files/prerender/image.png", FINAL_STATUS_USED, 1); |
1706 NavigateToDestURL(); | 1757 NavigateToDestURL(); |
1707 } | 1758 } |
1708 | 1759 |
1709 // Checks that prerendering a JPG works correctly. | 1760 // Checks that prerendering a JPG works correctly. |
1710 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderImageJpeg) { | 1761 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderImageJpeg) { |
1711 DisableJavascriptCalls(); | 1762 DisableJavascriptCalls(); |
1712 PrerenderTestURL("files/prerender/image.jpeg", FINAL_STATUS_USED, 1); | 1763 PrerenderTestURL("files/prerender/image.jpeg", FINAL_STATUS_USED, 1); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1839 PrerenderTestURL("files/prerender/prerender_print.html", | 1890 PrerenderTestURL("files/prerender/prerender_print.html", |
1840 FINAL_STATUS_WINDOW_PRINT, | 1891 FINAL_STATUS_WINDOW_PRINT, |
1841 1); | 1892 1); |
1842 } | 1893 } |
1843 | 1894 |
1844 // Checks that if a page is opened in a new window by javascript and both the | 1895 // Checks that if a page is opened in a new window by javascript and both the |
1845 // pages are in the same domain, the prerendered page is not used. | 1896 // pages are in the same domain, the prerendered page is not used. |
1846 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1897 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
1847 PrerenderSameDomainWindowOpenerWindowOpen) { | 1898 PrerenderSameDomainWindowOpenerWindowOpen) { |
1848 PrerenderTestURL("files/prerender/prerender_page.html", | 1899 PrerenderTestURL("files/prerender/prerender_page.html", |
1849 FINAL_STATUS_WINDOW_OPENER, | 1900 FINAL_STATUS_APP_TERMINATING, |
1850 1); | 1901 1); |
1851 OpenDestURLViaWindowOpen(); | 1902 OpenDestURLViaWindowOpen(); |
1852 } | 1903 } |
1853 | 1904 |
1854 // Checks that if a page is opened due to click on a href with target="_blank" | 1905 // Checks that if a page is opened due to click on a href with target="_blank" |
1855 // and both pages are in the same domain the prerendered page is not used. | 1906 // and both pages are in the same domain the prerendered page is not used. |
1856 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1907 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
1857 PrerenderSameDomainWindowOpenerClickTarget) { | 1908 PrerenderSameDomainWindowOpenerClickTarget) { |
1858 PrerenderTestURL("files/prerender/prerender_page.html", | 1909 PrerenderTestURL("files/prerender/prerender_page.html", |
1859 FINAL_STATUS_WINDOW_OPENER, | 1910 FINAL_STATUS_APP_TERMINATING, |
1860 1); | 1911 1); |
1861 OpenDestURLViaClickTarget(); | 1912 OpenDestURLViaClickTarget(); |
1862 } | 1913 } |
1863 | 1914 |
1864 // Checks that a top-level page which would normally request an SSL client | 1915 // Checks that a top-level page which would normally request an SSL client |
1865 // certificate will never be seen since it's an https top-level resource. | 1916 // certificate will never be seen since it's an https top-level resource. |
1866 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSSLClientCertTopLevel) { | 1917 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSSLClientCertTopLevel) { |
1867 net::TestServer::HTTPSOptions https_options; | 1918 net::TestServer::HTTPSOptions https_options; |
1868 https_options.request_client_certificate = true; | 1919 https_options.request_client_certificate = true; |
1869 net::TestServer https_server(https_options, | 1920 net::TestServer https_server(https_options, |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2132 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 2183 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
2133 FINAL_STATUS_USED, | 2184 FINAL_STATUS_USED, |
2134 1); | 2185 1); |
2135 OpenDestURLViaClick(); | 2186 OpenDestURLViaClick(); |
2136 NavigateToNextPageAfterPrerender(); | 2187 NavigateToNextPageAfterPrerender(); |
2137 GoBackToPrerender(); | 2188 GoBackToPrerender(); |
2138 } | 2189 } |
2139 | 2190 |
2140 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewWindow) { | 2191 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewWindow) { |
2141 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 2192 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
2142 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH, | 2193 FINAL_STATUS_APP_TERMINATING, |
dominich
2012/07/03 17:08:39
If this isn't used because the Session Storage Nam
gavinp
2012/07/03 18:45:40
I disagree; I'm happy to throw out that result cod
| |
2143 1); | 2194 1); |
2144 OpenDestURLViaClickNewWindow(); | 2195 OpenDestURLViaClickNewWindow(); |
2145 } | 2196 } |
2146 | 2197 |
2147 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewForegroundTab) { | 2198 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewForegroundTab) { |
2148 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 2199 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
2149 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH, | 2200 FINAL_STATUS_APP_TERMINATING, |
2150 1); | 2201 1); |
2151 OpenDestURLViaClickNewForegroundTab(); | 2202 OpenDestURLViaClickNewForegroundTab(); |
2152 } | 2203 } |
2153 | 2204 |
2154 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewBackgroundTab) { | 2205 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewBackgroundTab) { |
2155 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 2206 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
2156 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH, | 2207 FINAL_STATUS_APP_TERMINATING, |
2157 1); | 2208 1); |
2158 OpenDestURLViaClickNewBackgroundTab(); | 2209 OpenDestURLViaClickNewBackgroundTab(); |
2159 } | 2210 } |
2160 | 2211 |
2161 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 2212 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
2162 NavigateToPrerenderedPageWhenDevToolsAttached) { | 2213 NavigateToPrerenderedPageWhenDevToolsAttached) { |
2163 DisableJavascriptCalls(); | 2214 DisableJavascriptCalls(); |
2164 WebContents* web_contents = chrome::GetActiveWebContents(current_browser()); | 2215 WebContents* web_contents = chrome::GetActiveWebContents(current_browser()); |
2165 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 2216 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
2166 web_contents->GetRenderViewHost()); | 2217 web_contents->GetRenderViewHost()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2251 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSSLReferrerPolicy) { | 2302 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSSLReferrerPolicy) { |
2252 set_use_https_src(true); | 2303 set_use_https_src(true); |
2253 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html"); | 2304 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html"); |
2254 PrerenderTestURL("files/prerender/prerender_referrer_policy.html", | 2305 PrerenderTestURL("files/prerender/prerender_referrer_policy.html", |
2255 FINAL_STATUS_USED, | 2306 FINAL_STATUS_USED, |
2256 1); | 2307 1); |
2257 NavigateToDestURL(); | 2308 NavigateToDestURL(); |
2258 } | 2309 } |
2259 | 2310 |
2260 } // namespace prerender | 2311 } // namespace prerender |
OLD | NEW |