Home | History | Annotate | Download | only in test
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_
      6 #define CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/basictypes.h"
     11 #include "content/browser/frame_host/render_frame_host_impl.h"
     12 #include "content/public/browser/web_contents_observer.h"
     13 #include "content/public/test/test_renderer_host.h"
     14 #include "content/test/test_render_view_host.h"
     15 #include "ui/base/page_transition_types.h"
     16 
     17 struct FrameHostMsg_DidCommitProvisionalLoad_Params;
     18 
     19 namespace content {
     20 
     21 class TestRenderFrameHostCreationObserver : public WebContentsObserver {
     22  public:
     23   explicit TestRenderFrameHostCreationObserver(WebContents* web_contents);
     24   virtual ~TestRenderFrameHostCreationObserver();
     25 
     26   // WebContentsObserver implementation.
     27   virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) OVERRIDE;
     28 
     29   RenderFrameHost* last_created_frame() const { return last_created_frame_; }
     30 
     31  private:
     32   RenderFrameHost* last_created_frame_;
     33 };
     34 
     35 class TestRenderFrameHost : public RenderFrameHostImpl,
     36                             public RenderFrameHostTester {
     37  public:
     38   TestRenderFrameHost(RenderViewHostImpl* render_view_host,
     39                       RenderFrameHostDelegate* delegate,
     40                       FrameTree* frame_tree,
     41                       FrameTreeNode* frame_tree_node,
     42                       int routing_id,
     43                       bool is_swapped_out);
     44   virtual ~TestRenderFrameHost();
     45 
     46   // RenderFrameHostImpl overrides (same values, but in Test* types)
     47   virtual TestRenderViewHost* GetRenderViewHost() OVERRIDE;
     48 
     49   // RenderFrameHostTester implementation.
     50   virtual TestRenderFrameHost* AppendChild(
     51       const std::string& frame_name) OVERRIDE;
     52   virtual void SendNavigateWithTransition(
     53       int page_id,
     54       const GURL& url,
     55       ui::PageTransition transition) OVERRIDE;
     56 
     57   void SendNavigate(int page_id, const GURL& url);
     58   void SendFailedNavigate(int page_id, const GURL& url);
     59   void SendNavigateWithTransitionAndResponseCode(
     60       int page_id,
     61       const GURL& url, ui::PageTransition transition,
     62       int response_code);
     63   void SendNavigateWithOriginalRequestURL(
     64       int page_id,
     65       const GURL& url,
     66       const GURL& original_request_url);
     67   void SendNavigateWithFile(
     68       int page_id,
     69       const GURL& url,
     70       const base::FilePath& file_path);
     71   void SendNavigateWithParams(
     72       FrameHostMsg_DidCommitProvisionalLoad_Params* params);
     73   void SendNavigateWithRedirects(
     74       int page_id,
     75       const GURL& url,
     76       const std::vector<GURL>& redirects);
     77   void SendNavigateWithParameters(
     78       int page_id,
     79       const GURL& url,
     80       ui::PageTransition transition,
     81       const GURL& original_request_url,
     82       int response_code,
     83       const base::FilePath* file_path_for_history_item,
     84       const std::vector<GURL>& redirects);
     85   void SendBeginNavigationWithURL(const GURL& url);
     86 
     87   void DidDisownOpener();
     88 
     89   void set_contents_mime_type(const std::string& mime_type) {
     90     contents_mime_type_ = mime_type;
     91   }
     92 
     93   // If set, navigations will appear to have cleared the history list in the
     94   // RenderFrame
     95   // (FrameHostMsg_DidCommitProvisionalLoad_Params::history_list_was_cleared).
     96   // False by default.
     97   void set_simulate_history_list_was_cleared(bool cleared) {
     98     simulate_history_list_was_cleared_ = cleared;
     99   }
    100 
    101   // TODO(nick): As necessary for testing, override behavior of RenderFrameHost
    102   // here.
    103 
    104  private:
    105   TestRenderFrameHostCreationObserver child_creation_observer_;
    106 
    107   std::string contents_mime_type_;
    108 
    109   // See set_simulate_history_list_was_cleared() above.
    110   bool simulate_history_list_was_cleared_;
    111 
    112   DISALLOW_COPY_AND_ASSIGN(TestRenderFrameHost);
    113 };
    114 
    115 }  // namespace content
    116 
    117 #endif  // CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_
    118