diff options
Diffstat (limited to 'content/test')
-rw-r--r-- | content/test/test_render_frame_host.cc | 101 | ||||
-rw-r--r-- | content/test/test_render_frame_host.h | 48 | ||||
-rw-r--r-- | content/test/test_render_view_host.cc | 91 | ||||
-rw-r--r-- | content/test/test_render_view_host.h | 21 | ||||
-rw-r--r-- | content/test/test_web_contents.cc | 8 |
5 files changed, 201 insertions, 68 deletions
diff --git a/content/test/test_render_frame_host.cc b/content/test/test_render_frame_host.cc index e9a3bc8..ec6a349 100644 --- a/content/test/test_render_frame_host.cc +++ b/content/test/test_render_frame_host.cc @@ -5,8 +5,15 @@ #include "content/test/test_render_frame_host.h" #include "content/browser/frame_host/frame_tree.h" +#include "content/common/frame_messages.h" #include "content/test/test_render_view_host.h" +namespace { + +const int64 kFrameId = 13UL; + +} // namespace + namespace content { TestRenderFrameHost::TestRenderFrameHost(RenderViewHostImpl* render_view_host, @@ -20,7 +27,9 @@ TestRenderFrameHost::TestRenderFrameHost(RenderViewHostImpl* render_view_host, frame_tree, frame_tree_node, routing_id, - is_swapped_out) { + is_swapped_out), + contents_mime_type_("text/html"), + simulate_history_list_was_cleared_(false) { // Allow TestRenderViewHosts to easily access their main frame RFH. if (frame_tree_node == frame_tree->root()) { static_cast<TestRenderViewHost*>(render_view_host)-> @@ -30,4 +39,94 @@ TestRenderFrameHost::TestRenderFrameHost(RenderViewHostImpl* render_view_host, TestRenderFrameHost::~TestRenderFrameHost() {} +void TestRenderFrameHost::SendNavigate(int page_id, const GURL& url) { + SendNavigateWithTransition(page_id, url, PAGE_TRANSITION_LINK); +} + +void TestRenderFrameHost::SendNavigateWithTransition( + int page_id, + const GURL& url, + PageTransition transition) { + SendNavigateWithTransitionAndResponseCode(page_id, url, transition, 200); +} + +void TestRenderFrameHost::SendFailedNavigate(int page_id, const GURL& url) { + SendNavigateWithTransitionAndResponseCode( + page_id, url, PAGE_TRANSITION_LINK, 500); +} + +void TestRenderFrameHost::SendNavigateWithTransitionAndResponseCode( + int page_id, + const GURL& url, PageTransition transition, + int response_code) { + // DidStartProvisionalLoad may delete the pending entry that holds |url|, + // so we keep a copy of it to use in SendNavigateWithParameters. + GURL url_copy(url); + OnDidStartProvisionalLoadForFrame(kFrameId, -1, true, url_copy); + SendNavigateWithParameters( + page_id, url_copy, transition, url_copy, response_code, 0); +} + +void TestRenderFrameHost::SendNavigateWithOriginalRequestURL( + int page_id, + const GURL& url, + const GURL& original_request_url) { + OnDidStartProvisionalLoadForFrame(kFrameId, -1, true, url); + SendNavigateWithParameters( + page_id, url, PAGE_TRANSITION_LINK, original_request_url, 200, 0); +} + +void TestRenderFrameHost::SendNavigateWithFile( + int page_id, + const GURL& url, + const base::FilePath& file_path) { + SendNavigateWithParameters( + page_id, url, PAGE_TRANSITION_LINK, url, 200, &file_path); +} + +void TestRenderFrameHost::SendNavigateWithParams( + FrameHostMsg_DidCommitProvisionalLoad_Params* params) { + params->frame_id = kFrameId; + FrameHostMsg_DidCommitProvisionalLoad msg(1, *params); + OnNavigate(msg); +} + +void TestRenderFrameHost::SendNavigateWithParameters( + int page_id, + const GURL& url, + PageTransition transition, + const GURL& original_request_url, + int response_code, + const base::FilePath* file_path_for_history_item) { + FrameHostMsg_DidCommitProvisionalLoad_Params params; + params.page_id = page_id; + params.frame_id = kFrameId; + params.url = url; + params.referrer = Referrer(); + params.transition = transition; + params.redirects = std::vector<GURL>(); + params.should_update_history = true; + params.searchable_form_url = GURL(); + params.searchable_form_encoding = std::string(); + params.security_info = std::string(); + params.gesture = NavigationGestureUser; + params.contents_mime_type = contents_mime_type_; + params.is_post = false; + params.was_within_same_page = false; + params.http_status_code = response_code; + params.socket_address.set_host("2001:db8::1"); + params.socket_address.set_port(80); + params.history_list_was_cleared = simulate_history_list_was_cleared_; + params.original_request_url = original_request_url; + + params.page_state = PageState::CreateForTesting( + url, + false, + file_path_for_history_item ? "data" : NULL, + file_path_for_history_item); + + FrameHostMsg_DidCommitProvisionalLoad msg(1, params); + OnNavigate(msg); +} + } // namespace content diff --git a/content/test/test_render_frame_host.h b/content/test/test_render_frame_host.h index 7668b25..25caa87 100644 --- a/content/test/test_render_frame_host.h +++ b/content/test/test_render_frame_host.h @@ -7,6 +7,9 @@ #include "base/basictypes.h" #include "content/browser/frame_host/render_frame_host_impl.h" +#include "content/public/common/page_transition_types.h" + +struct FrameHostMsg_DidCommitProvisionalLoad_Params; namespace content { @@ -20,10 +23,55 @@ class TestRenderFrameHost : public RenderFrameHostImpl { bool is_swapped_out); virtual ~TestRenderFrameHost(); + void SendNavigate(int page_id, const GURL& url); + void SendNavigateWithTransition( + int page_id, + const GURL& url, + PageTransition transition); + void SendFailedNavigate(int page_id, const GURL& url); + void SendNavigateWithTransitionAndResponseCode( + int page_id, + const GURL& url, PageTransition transition, + int response_code); + void SendNavigateWithOriginalRequestURL( + int page_id, + const GURL& url, + const GURL& original_request_url); + void SendNavigateWithFile( + int page_id, + const GURL& url, + const base::FilePath& file_path); + void SendNavigateWithParams( + FrameHostMsg_DidCommitProvisionalLoad_Params* params); + void SendNavigateWithParameters( + int page_id, + const GURL& url, + PageTransition transition, + const GURL& original_request_url, + int response_code, + const base::FilePath* file_path_for_history_item); + + void set_contents_mime_type(const std::string& mime_type) { + contents_mime_type_ = mime_type; + } + + // If set, navigations will appear to have cleared the history list in the + // RenderFrame + // (FrameHostMsg_DidCommitProvisionalLoad_Params::history_list_was_cleared). + // False by default. + void set_simulate_history_list_was_cleared(bool cleared) { + simulate_history_list_was_cleared_ = cleared; + } + // TODO(nick): As necessary for testing, override behavior of RenderFrameHost // here. private: + std::string contents_mime_type_; + + // See set_simulate_history_list_was_cleared() above. + bool simulate_history_list_was_cleared_; + DISALLOW_COPY_AND_ASSIGN(TestRenderFrameHost); }; diff --git a/content/test/test_render_view_host.cc b/content/test/test_render_view_host.cc index 1945e9f..38facdb 100644 --- a/content/test/test_render_view_host.cc +++ b/content/test/test_render_view_host.cc @@ -9,6 +9,7 @@ #include "content/browser/dom_storage/session_storage_namespace_impl.h" #include "content/browser/site_instance_impl.h" #include "content/common/dom_storage/dom_storage_types.h" +#include "content/common/frame_messages.h" #include "content/common/view_messages.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/navigation_controller.h" @@ -30,7 +31,7 @@ const int64 kFrameId = 13UL; } // namespace -void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, +void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params* params, int page_id, const GURL& url, PageTransition transition) { @@ -274,86 +275,60 @@ bool TestRenderViewHost::IsRenderViewLive() const { } void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) { - SendNavigateWithTransition(page_id, url, PAGE_TRANSITION_LINK); + main_render_frame_host_->SendNavigate(page_id, url); } void TestRenderViewHost::SendFailedNavigate(int page_id, const GURL& url) { - SendNavigateWithTransitionAndResponseCode( - page_id, url, PAGE_TRANSITION_LINK, 500); + main_render_frame_host_->SendFailedNavigate(page_id, url); } void TestRenderViewHost::SendNavigateWithTransition( - int page_id, const GURL& url, PageTransition transition) { - SendNavigateWithTransitionAndResponseCode(page_id, url, transition, 200); + int page_id, + const GURL& url, + PageTransition transition) { + main_render_frame_host_->SendNavigateWithTransition(page_id, url, transition); } void TestRenderViewHost::SendNavigateWithOriginalRequestURL( - int page_id, const GURL& url, const GURL& original_request_url) { - main_render_frame_host()->OnDidStartProvisionalLoadForFrame( - kFrameId, -1, true, url); - SendNavigateWithParameters(page_id, url, PAGE_TRANSITION_LINK, - original_request_url, 200, 0); + int page_id, + const GURL& url, + const GURL& original_request_url) { + main_render_frame_host_->SendNavigateWithOriginalRequestURL( + page_id, url, original_request_url); } void TestRenderViewHost::SendNavigateWithFile( - int page_id, const GURL& url, const base::FilePath& file_path) { - SendNavigateWithParameters(page_id, url, PAGE_TRANSITION_LINK, - url, 200, &file_path); + int page_id, + const GURL& url, + const base::FilePath& file_path) { + main_render_frame_host_->SendNavigateWithFile(page_id, url, file_path); } void TestRenderViewHost::SendNavigateWithParams( - ViewHostMsg_FrameNavigate_Params* params) { - params->frame_id = kFrameId; - ViewHostMsg_FrameNavigate msg(1, *params); - OnNavigate(msg); + FrameHostMsg_DidCommitProvisionalLoad_Params* params) { + main_render_frame_host_->SendNavigateWithParams(params); } void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode( - int page_id, const GURL& url, PageTransition transition, + int page_id, + const GURL& url, + PageTransition transition, int response_code) { - // DidStartProvisionalLoad may delete the pending entry that holds |url|, - // so we keep a copy of it to use in SendNavigateWithParameters. - GURL url_copy(url); - main_render_frame_host()->OnDidStartProvisionalLoadForFrame( - kFrameId, -1, true, url_copy); - SendNavigateWithParameters(page_id, url_copy, transition, url_copy, - response_code, 0); + main_render_frame_host_->SendNavigateWithTransitionAndResponseCode( + page_id, url, transition, response_code); } void TestRenderViewHost::SendNavigateWithParameters( - int page_id, const GURL& url, PageTransition transition, - const GURL& original_request_url, int response_code, + int page_id, + const GURL& url, + PageTransition transition, + const GURL& original_request_url, + int response_code, const base::FilePath* file_path_for_history_item) { - ViewHostMsg_FrameNavigate_Params params; - params.page_id = page_id; - params.frame_id = kFrameId; - params.url = url; - params.referrer = Referrer(); - params.transition = transition; - params.redirects = std::vector<GURL>(); - params.should_update_history = true; - params.searchable_form_url = GURL(); - params.searchable_form_encoding = std::string(); - params.security_info = std::string(); - params.gesture = NavigationGestureUser; - params.contents_mime_type = contents_mime_type_; - params.is_post = false; - params.was_within_same_page = false; - params.http_status_code = response_code; - params.socket_address.set_host("2001:db8::1"); - params.socket_address.set_port(80); - params.was_fetched_via_proxy = simulate_fetch_via_proxy_; - params.history_list_was_cleared = simulate_history_list_was_cleared_; - params.original_request_url = original_request_url; - - params.page_state = PageState::CreateForTesting( - url, - false, - file_path_for_history_item ? "data" : NULL, - file_path_for_history_item); - ViewHostMsg_FrameNavigate msg(1, params); - OnNavigate(msg); + main_render_frame_host_->SendNavigateWithParameters( + page_id, url, transition, original_request_url, response_code, + file_path_for_history_item); } void TestRenderViewHost::SendShouldCloseACK(bool proceed) { @@ -363,6 +338,7 @@ void TestRenderViewHost::SendShouldCloseACK(bool proceed) { void TestRenderViewHost::SetContentsMimeType(const std::string& mime_type) { contents_mime_type_ = mime_type; + main_render_frame_host_->set_contents_mime_type(mime_type); } void TestRenderViewHost::SimulateSwapOutACK() { @@ -401,6 +377,7 @@ void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) { void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared) { simulate_history_list_was_cleared_ = cleared; + main_render_frame_host_->set_simulate_history_list_was_cleared(cleared); } RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() { diff --git a/content/test/test_render_view_host.h b/content/test/test_render_view_host.h index eba1d1f..985b4d9 100644 --- a/content/test/test_render_view_host.h +++ b/content/test/test_render_view_host.h @@ -26,7 +26,7 @@ // // To use, derive your test base class from RenderViewHostImplTestHarness. -struct ViewHostMsg_FrameNavigate_Params; +struct FrameHostMsg_DidCommitProvisionalLoad_Params; namespace gfx { class Rect; @@ -40,7 +40,7 @@ class TestWebContents; // Utility function to initialize ViewHostMsg_NavigateParams_Params // with given |page_id|, |url| and |transition_type|. -void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, +void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params* params, int page_id, const GURL& url, PageTransition transition_type); @@ -236,16 +236,19 @@ class TestRenderViewHost // RenderViewHostTester implementation. Note that CreateRenderView // is not specified since it is synonymous with the one from // RenderViewHostImpl, see below. - virtual void SendNavigate(int page_id, const GURL& url) OVERRIDE; - virtual void SendFailedNavigate(int page_id, const GURL& url) OVERRIDE; - virtual void SendNavigateWithTransition(int page_id, const GURL& url, - PageTransition transition) OVERRIDE; virtual void SendShouldCloseACK(bool proceed) OVERRIDE; virtual void SetContentsMimeType(const std::string& mime_type) OVERRIDE; virtual void SimulateSwapOutACK() OVERRIDE; virtual void SimulateWasHidden() OVERRIDE; virtual void SimulateWasShown() OVERRIDE; + // NOTE: These methods are deprecated and the equivalents in + // TestRenderFrameHost should be used. + virtual void SendNavigate(int page_id, const GURL& url) OVERRIDE; + virtual void SendFailedNavigate(int page_id, const GURL& url) OVERRIDE; + virtual void SendNavigateWithTransition(int page_id, const GURL& url, + PageTransition transition) OVERRIDE; + // Calls OnNavigate on the RenderViewHost with the given information, // including a custom original request URL. Sets the rest of the // parameters in the message to the "typical" values. This is a helper @@ -256,7 +259,8 @@ class TestRenderViewHost void SendNavigateWithFile( int page_id, const GURL& url, const base::FilePath& file_path); - void SendNavigateWithParams(ViewHostMsg_FrameNavigate_Params* params); + void SendNavigateWithParams( + FrameHostMsg_DidCommitProvisionalLoad_Params* params); void TestOnUpdateStateWithFile( int process_id, const base::FilePath& file_path); @@ -293,7 +297,8 @@ class TestRenderViewHost void set_simulate_fetch_via_proxy(bool proxy); // If set, navigations will appear to have cleared the history list in the - // RenderView (ViewHostMsg_FrameNavigate_Params::history_list_was_cleared). + // RenderView + // (FrameHostMsg_DidCommitProvisionalLoad_Params::history_list_was_cleared). // False by default. void set_simulate_history_list_was_cleared(bool cleared); diff --git a/content/test/test_web_contents.cc b/content/test/test_web_contents.cc index ff78a18..d96458b 100644 --- a/content/test/test_web_contents.cc +++ b/content/test/test_web_contents.cc @@ -9,6 +9,7 @@ #include "content/browser/browser_url_handler_impl.h" #include "content/browser/frame_host/cross_process_frame_connector.h" #include "content/browser/frame_host/navigation_entry_impl.h" +#include "content/browser/frame_host/navigator.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/site_instance_impl.h" #include "content/common/frame_messages.h" @@ -69,7 +70,7 @@ void TestWebContents::TestDidNavigateWithReferrer( const GURL& url, const Referrer& referrer, PageTransition transition) { - ViewHostMsg_FrameNavigate_Params params; + FrameHostMsg_DidCommitProvisionalLoad_Params params; params.page_id = page_id; params.url = url; @@ -85,7 +86,10 @@ void TestWebContents::TestDidNavigateWithReferrer( params.is_post = false; params.page_state = PageState::CreateFromURL(url); - DidNavigate(render_view_host, params); + RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(render_view_host); + RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID( + rvh->GetProcess()->GetID(), rvh->main_frame_routing_id()); + frame_tree_.root()->navigator()->DidNavigate(rfh, params); } WebPreferences TestWebContents::TestGetWebkitPrefs() { |