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
|
// Copyright (c) 2009 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_render_view_host.h"
#include "chrome/browser/tab_contents/test_web_contents.h"
#include "chrome/common/render_messages.h"
TestRenderViewHost::TestRenderViewHost(SiteInstance* instance,
RenderViewHostDelegate* delegate,
int routing_id,
base::WaitableEvent* modal_dialog_event)
: RenderViewHost(instance, delegate, routing_id, modal_dialog_event),
render_view_created_(false),
delete_counter_(NULL) {
set_view(new TestRenderWidgetHostView());
}
TestRenderViewHost::~TestRenderViewHost() {
if (delete_counter_)
++*delete_counter_;
// Since this isn't a traditional view, we have to delete it.
delete view();
}
bool TestRenderViewHost::CreateRenderView() {
DCHECK(!render_view_created_);
render_view_created_ = true;
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::EmptyGURL();
params.transition = PageTransition::LINK;
params.redirects = std::vector<GURL>();
params.should_update_history = true;
params.searchable_form_url = GURL::EmptyGURL();
params.searchable_form_element_name = std::wstring();
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);
}
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 WebContents goes away.
SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get());
contents_ = new TestWebContents(profile_.get(), instance, &rvh_factory_);
controller_ = new NavigationController(contents_, profile_.get());
}
void RenderViewHostTestHarness::TearDown() {
if (contents_) {
contents_->CloseContents();
contents_ = NULL;
}
controller_ = NULL;
// Make sure that we flush any messages related to WebContents destruction
// before we destroy the profile.
MessageLoop::current()->RunAllPending();
}
|