blob: d4f79189dc3c79c73231e54b8376de0f7672e5d9 [file] [log] [blame]
[email protected]80e776ae2012-03-23 16:17:201// 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
3// found in the LICENSE file.
4
[email protected]0c4e92e62012-04-11 15:19:005#ifndef CONTENT_BROWSER_WEB_CONTENTS_TEST_WEB_CONTENTS_H_
6#define CONTENT_BROWSER_WEB_CONTENTS_TEST_WEB_CONTENTS_H_
[email protected]80e776ae2012-03-23 16:17:207
[email protected]93ddb3c2012-04-11 21:44:298#include "content/browser/web_contents/web_contents_impl.h"
[email protected]80e776ae2012-03-23 16:17:209#include "content/public/common/page_transition_types.h"
[email protected]b1e3f202012-06-04 14:45:5010#include "content/public/test/web_contents_tester.h"
[email protected]80e776ae2012-03-23 16:17:2011#include "webkit/glue/webpreferences.h"
12
13class SiteInstanceImpl;
14
15namespace content {
16
17class RenderViewHost;
18class TestRenderViewHost;
19class WebContentsTester;
20
[email protected]2db9bd72012-04-13 20:20:5621// Subclass WebContentsImpl to ensure it creates TestRenderViewHosts
[email protected]80e776ae2012-03-23 16:17:2022// and does not do anything involving views.
[email protected]2db9bd72012-04-13 20:20:5623class TestWebContents : public WebContentsImpl, public WebContentsTester {
[email protected]80e776ae2012-03-23 16:17:2024 public:
[email protected]80e776ae2012-03-23 16:17:2025 virtual ~TestWebContents();
26
[email protected]d1198fd2012-08-13 22:50:1927 static TestWebContents* Create(BrowserContext* browser_context,
28 SiteInstance* instance);
29
[email protected]80e776ae2012-03-23 16:17:2030 // WebContentsTester implementation.
31 virtual void CommitPendingNavigation() OVERRIDE;
32 virtual int GetNumberOfFocusCalls() OVERRIDE;
33 virtual RenderViewHost* GetPendingRenderViewHost() const OVERRIDE;
34 virtual void NavigateAndCommit(const GURL& url) OVERRIDE;
[email protected]9565b0c2012-05-15 21:12:2635 virtual void TestSetIsLoading(bool value) OVERRIDE;
[email protected]80e776ae2012-03-23 16:17:2036 virtual void ProceedWithCrossSiteNavigation() OVERRIDE;
37 virtual void TestDidNavigate(RenderViewHost* render_view_host,
38 int page_id,
39 const GURL& url,
40 PageTransition transition) OVERRIDE;
41 virtual void TestDidNavigateWithReferrer(RenderViewHost* render_view_host,
42 int page_id,
43 const GURL& url,
44 const Referrer& referrer,
45 PageTransition transition) OVERRIDE;
[email protected]6717bf272012-05-11 23:31:2546 virtual webkit_glue::WebPreferences TestGetWebkitPrefs() OVERRIDE;
[email protected]80e776ae2012-03-23 16:17:2047
48 TestRenderViewHost* pending_test_rvh() const;
49
50 // State accessor.
51 bool cross_navigation_pending() {
52 return render_manager_.cross_navigation_pending_;
53 }
54
[email protected]2db9bd72012-04-13 20:20:5655 // Overrides WebContentsImpl::ShouldTransitionCrossSite so that we can test
56 // both alternatives without using command-line switches.
[email protected]80e776ae2012-03-23 16:17:2057 bool ShouldTransitionCrossSite() { return transition_cross_site; }
58
59 // Prevent interaction with views.
60 virtual bool CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:4461 RenderViewHost* render_view_host, int opener_route_id) OVERRIDE;
[email protected]80e776ae2012-03-23 16:17:2062 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE {}
63
64 // Returns a clone of this TestWebContents. The returned object is also a
65 // TestWebContents. The caller owns the returned object.
66 virtual WebContents* Clone() OVERRIDE;
67
68 // Set by individual tests.
69 bool transition_cross_site;
70
[email protected]5a3bdf52012-05-24 15:12:5771 // Allow mocking of the RenderViewHostDelegateView.
72 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE;
73 void set_delegate_view(RenderViewHostDelegateView* view) {
[email protected]80e776ae2012-03-23 16:17:2074 delegate_view_override_ = view;
75 }
76
[email protected]14392a52012-05-02 20:28:4477 // Allows us to simulate this tab having an opener.
78 void SetOpener(TestWebContents* opener);
79
[email protected]80e776ae2012-03-23 16:17:2080 // Establish expected arguments for |SetHistoryLengthAndPrune()|. When
81 // |SetHistoryLengthAndPrune()| is called, the arguments are compared
82 // with the expected arguments specified here.
83 void ExpectSetHistoryLengthAndPrune(const SiteInstance* site_instance,
84 int history_length,
85 int32 min_page_id);
86
87 // Compares the arguments passed in with the expected arguments passed in
88 // to |ExpectSetHistoryLengthAndPrune()|.
89 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
90 int history_length,
91 int32 min_page_id) OVERRIDE;
92
[email protected]d1198fd2012-08-13 22:50:1993 protected:
94 // The deprecated WebContentsTester still needs to subclass this.
95 explicit TestWebContents(BrowserContext* browser_context);
96
[email protected]80e776ae2012-03-23 16:17:2097 private:
[email protected]bafe6cd2012-05-23 23:09:5098 // WebContentsImpl overrides
99 virtual void CreateNewWindow(
100 int route_id,
[email protected]97714c82012-06-06 10:15:13101 const ViewHostMsg_CreateWindow_Params& params,
102 SessionStorageNamespace* session_storage_namespace) OVERRIDE;
[email protected]bafe6cd2012-05-23 23:09:50103 virtual void CreateNewWidget(int route_id,
104 WebKit::WebPopupType popup_type) OVERRIDE;
105 virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE;
106 virtual void ShowCreatedWindow(int route_id,
107 WindowOpenDisposition disposition,
108 const gfx::Rect& initial_pos,
109 bool user_gesture) OVERRIDE;
110 virtual void ShowCreatedWidget(int route_id,
111 const gfx::Rect& initial_pos) OVERRIDE;
112 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE;
113
114
[email protected]5a3bdf52012-05-24 15:12:57115 RenderViewHostDelegateView* delegate_view_override_;
[email protected]80e776ae2012-03-23 16:17:20116
117 // Expectations for arguments of |SetHistoryLengthAndPrune()|.
118 bool expect_set_history_length_and_prune_;
119 scoped_refptr<const SiteInstanceImpl>
120 expect_set_history_length_and_prune_site_instance_;
121 int expect_set_history_length_and_prune_history_length_;
122 int32 expect_set_history_length_and_prune_min_page_id_;
123};
124
125} // namespace content
126
[email protected]0c4e92e62012-04-11 15:19:00127#endif // CONTENT_BROWSER_WEB_CONTENTS_TEST_WEB_CONTENTS_H_