Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: content/browser/tab_contents/test_web_contents.cc

Issue 10024066: TabContents -> WebContentsImpl, part 4. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/tab_contents/test_web_contents.h"
6
7 #include <utility>
8
9 #include "content/browser/browser_url_handler_impl.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h"
11 #include "content/browser/renderer_host/test_render_view_host.h"
12 #include "content/browser/site_instance_impl.h"
13 #include "content/browser/web_contents/navigation_entry_impl.h"
14 #include "content/common/view_messages.h"
15 #include "content/public/common/page_transition_types.h"
16 #include "content/test/mock_render_process_host.h"
17 #include "webkit/forms/password_form.h"
18 #include "webkit/glue/webkit_glue.h"
19
20 namespace content {
21
22 TestWebContents::TestWebContents(BrowserContext* browser_context,
23 SiteInstance* instance)
24 : TabContents(browser_context, instance, MSG_ROUTING_NONE, NULL, NULL),
25 transition_cross_site(false),
26 delegate_view_override_(NULL),
27 expect_set_history_length_and_prune_(false),
28 expect_set_history_length_and_prune_site_instance_(NULL),
29 expect_set_history_length_and_prune_history_length_(0),
30 expect_set_history_length_and_prune_min_page_id_(-1) {
31 }
32
33 TestWebContents::~TestWebContents() {
34 }
35
36 RenderViewHost* TestWebContents::GetPendingRenderViewHost() const {
37 return render_manager_.pending_render_view_host_;
38 }
39
40 TestRenderViewHost* TestWebContents::pending_test_rvh() const {
41 return static_cast<TestRenderViewHost*>(GetPendingRenderViewHost());
42 }
43
44 void TestWebContents::TestDidNavigate(RenderViewHost* render_view_host,
45 int page_id,
46 const GURL& url,
47 PageTransition transition) {
48 TestDidNavigateWithReferrer(render_view_host,
49 page_id,
50 url,
51 Referrer(),
52 transition);
53 }
54
55 void TestWebContents::TestDidNavigateWithReferrer(
56 RenderViewHost* render_view_host,
57 int page_id,
58 const GURL& url,
59 const Referrer& referrer,
60 PageTransition transition) {
61 ViewHostMsg_FrameNavigate_Params params;
62
63 params.page_id = page_id;
64 params.url = url;
65 params.referrer = referrer;
66 params.transition = transition;
67 params.redirects = std::vector<GURL>();
68 params.should_update_history = false;
69 params.searchable_form_url = GURL();
70 params.searchable_form_encoding = std::string();
71 params.password_form = webkit::forms::PasswordForm();
72 params.security_info = std::string();
73 params.gesture = NavigationGestureUser;
74 params.was_within_same_page = false;
75 params.is_post = false;
76 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url));
77
78 DidNavigate(render_view_host, params);
79 }
80
81 WebPreferences TestWebContents::TestGetWebkitPrefs() {
82 return GetWebkitPrefs();
83 }
84
85 bool TestWebContents::CreateRenderViewForRenderManager(
86 RenderViewHost* render_view_host) {
87 // This will go to a TestRenderViewHost.
88 static_cast<RenderViewHostImpl*>(
89 render_view_host)->CreateRenderView(string16(), -1);
90 return true;
91 }
92
93 WebContents* TestWebContents::Clone() {
94 TabContents* tc = new TestWebContents(
95 GetBrowserContext(),
96 SiteInstance::Create(GetBrowserContext()));
97 tc->GetControllerImpl().CopyStateFrom(controller_);
98 return tc;
99 }
100
101 void TestWebContents::NavigateAndCommit(const GURL& url) {
102 GetController().LoadURL(
103 url, Referrer(), PAGE_TRANSITION_LINK, std::string());
104 GURL loaded_url(url);
105 bool reverse_on_redirect = false;
106 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
107 &loaded_url, GetBrowserContext(), &reverse_on_redirect);
108
109 // LoadURL created a navigation entry, now simulate the RenderView sending
110 // a notification that it actually navigated.
111 CommitPendingNavigation();
112 }
113
114 void TestWebContents::CommitPendingNavigation() {
115 // If we are doing a cross-site navigation, this simulates the current RVH
116 // notifying that it has unloaded so the pending RVH is resumed and can
117 // navigate.
118 ProceedWithCrossSiteNavigation();
119 RenderViewHost* old_rvh = render_manager_.current_host();
120 TestRenderViewHost* rvh =
121 static_cast<TestRenderViewHost*>(GetPendingRenderViewHost());
122 if (!rvh)
123 rvh = static_cast<TestRenderViewHost*>(old_rvh);
124
125 const NavigationEntry* entry = GetController().GetPendingEntry();
126 DCHECK(entry);
127 int page_id = entry->GetPageID();
128 if (page_id == -1) {
129 // It's a new navigation, assign a never-seen page id to it.
130 page_id = GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()) + 1;
131 }
132 rvh->SendNavigate(page_id, entry->GetURL());
133
134 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation
135 // without making any network requests.
136 if (old_rvh != rvh)
137 static_cast<RenderViewHostImpl*>(old_rvh)->OnSwapOutACK();
138 }
139
140 int TestWebContents::GetNumberOfFocusCalls() {
141 NOTREACHED();
142 return 0;
143 }
144
145 void TestWebContents::ProceedWithCrossSiteNavigation() {
146 if (!GetPendingRenderViewHost())
147 return;
148 TestRenderViewHost* rvh = static_cast<TestRenderViewHost*>(
149 render_manager_.current_host());
150 rvh->SendShouldCloseACK(true);
151 }
152
153 RenderViewHostDelegate::View* TestWebContents::GetViewDelegate() {
154 if (delegate_view_override_)
155 return delegate_view_override_;
156 return TabContents::GetViewDelegate();
157 }
158
159 void TestWebContents::ExpectSetHistoryLengthAndPrune(
160 const SiteInstance* site_instance,
161 int history_length,
162 int32 min_page_id) {
163 expect_set_history_length_and_prune_ = true;
164 expect_set_history_length_and_prune_site_instance_ =
165 static_cast<const SiteInstanceImpl*>(site_instance);
166 expect_set_history_length_and_prune_history_length_ = history_length;
167 expect_set_history_length_and_prune_min_page_id_ = min_page_id;
168 }
169
170 void TestWebContents::SetHistoryLengthAndPrune(
171 const SiteInstance* site_instance, int history_length,
172 int32 min_page_id) {
173 EXPECT_TRUE(expect_set_history_length_and_prune_);
174 expect_set_history_length_and_prune_ = false;
175 EXPECT_EQ(expect_set_history_length_and_prune_site_instance_, site_instance);
176 EXPECT_EQ(expect_set_history_length_and_prune_history_length_,
177 history_length);
178 EXPECT_EQ(expect_set_history_length_and_prune_min_page_id_, min_page_id);
179 }
180
181 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tab_contents/test_web_contents.h ('k') | content/browser/tab_contents/web_contents_drag_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698