1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
#include "base/gfx/rect.h"
#include "chrome/browser/renderer_host/test/test_backing_store.h"
#include "chrome/browser/tab_contents/test_tab_contents.h"
#include "chrome/common/dom_storage_common.h"
#include "chrome/common/render_messages.h"
using webkit_glue::PasswordForm;
TestRenderViewHost::TestRenderViewHost(SiteInstance* instance,
RenderViewHostDelegate* delegate,
int routing_id)
: RenderViewHost(instance, delegate, routing_id,
kInvalidSessionStorageNamespaceId),
render_view_created_(false),
delete_counter_(NULL) {
set_view(new TestRenderWidgetHostView(this));
}
TestRenderViewHost::~TestRenderViewHost() {
if (delete_counter_)
++*delete_counter_;
// Since this isn't a traditional view, we have to delete it.
delete view();
}
bool TestRenderViewHost::CreateRenderView(
URLRequestContextGetter* request_context) {
DCHECK(!render_view_created_);
render_view_created_ = true;
process()->ViewCreated();
return true;
}
bool TestRenderViewHost::IsRenderViewLive() const {
return render_view_created_;
}
void TestRenderViewHost::TestOnMessageReceived(const IPC::Message& msg) {
OnMessageReceived(msg);
}
void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
ViewHostMsg_FrameNavigate_Params params;
params.page_id = page_id;
params.url = url;
params.referrer = GURL();
params.transition = PageTransition::LINK;
params.redirects = std::vector<GURL>();
params.should_update_history = true;
params.searchable_form_url = GURL();
params.searchable_form_encoding = std::string();
params.password_form = PasswordForm();
params.security_info = std::string();
params.gesture = NavigationGestureUser;
params.contents_mime_type = std::string();
params.is_post = false;
params.is_content_filtered = false;
params.http_status_code = 0;
ViewHostMsg_FrameNavigate msg(1, params);
OnMsgNavigate(msg);
}
TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh)
: rwh_(rwh),
is_showing_(false) {
}
BackingStore* TestRenderWidgetHostView::AllocBackingStore(
const gfx::Size& size) {
return new TestBackingStore(rwh_, size);
}
#if defined(OS_MACOSX)
gfx::Rect TestRenderWidgetHostView::GetWindowRect() {
return gfx::Rect();
}
gfx::Rect TestRenderWidgetHostView::GetRootWindowRect() {
return gfx::Rect();
}
void TestRenderWidgetHostView::SetActive(bool active) {
// <viettrungluu@gmail.com>: Do I need to do anything here?
}
#endif
void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) {
controller().LoadURL(url, GURL(), 0);
rvh()->SendNavigate(process()->max_page_id() + 1, url);
}
void RenderViewHostTestHarness::SetUp() {
// See comment above profile_ decl for why we check for NULL here.
if (!profile_.get())
profile_.reset(new TestingProfile());
// This will be deleted when the TabContents goes away.
SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get());
contents_.reset(new TestTabContents(profile_.get(), instance));
user_data_manager_.reset(UserDataManager::Create());
}
void RenderViewHostTestHarness::TearDown() {
contents_.reset();
// Make sure that we flush any messages related to TabContents destruction
// before we destroy the profile.
MessageLoop::current()->RunAllPending();
}
|