blob: 583fff6913fcd78183c51acbc5146275704e4e75 (
plain)
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
|
// 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/test/render_view_test.h"
#include "chrome/common/render_messages.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/renderer/extensions/event_bindings.h"
#include "chrome/renderer/extensions/extension_process_bindings.h"
#include "chrome/renderer/extensions/renderer_extension_bindings.h"
#include "chrome/renderer/js_only_v8_extensions.h"
#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
#include "webkit/glue/weburlrequest.h"
#include "webkit/glue/webview.h"
using WebKit::WebScriptSource;
using WebKit::WebString;
namespace {
const int32 kRouteId = 5;
const int32 kOpenerId = 7;
};
void RenderViewTest::ProcessPendingMessages() {
msg_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask());
msg_loop_.Run();
}
WebFrame* RenderViewTest::GetMainFrame() {
return view_->webview()->GetMainFrame();
}
void RenderViewTest::ExecuteJavaScript(const char* js) {
GetMainFrame()->ExecuteScript(WebScriptSource(WebString::fromUTF8(js)));
}
void RenderViewTest::LoadHTML(const char* html) {
std::string url_str = "data:text/html;charset=utf-8,";
url_str.append(html);
GURL url(url_str);
scoped_ptr<WebRequest> request(WebRequest::Create(url));
GetMainFrame()->LoadRequest(request.get());
// The load actually happens asynchronously, so we pump messages to process
// the pending continuation.
ProcessPendingMessages();
}
void RenderViewTest::SetUp() {
WebKit::initialize(&webkitclient_);
WebKit::registerExtension(BaseJsV8Extension::Get());
WebKit::registerExtension(JsonJsV8Extension::Get());
WebKit::registerExtension(JsonSchemaJsV8Extension::Get());
WebKit::registerExtension(EventBindings::Get());
WebKit::registerExtension(ExtensionProcessBindings::Get());
WebKit::registerExtension(RendererExtensionBindings::Get());
EventBindings::SetRenderThread(&render_thread_);
// TODO(aa): Should some of this go to some other inheriting class?
std::vector<std::string> names;
ExtensionFunctionDispatcher::GetAllFunctionNames(&names);
ExtensionProcessBindings::SetFunctionNames(names);
mock_process_.reset(new MockProcess());
render_thread_.set_routing_id(kRouteId);
// This needs to pass the mock render thread to the view.
view_ = RenderView::Create(&render_thread_, NULL, NULL, kOpenerId,
WebPreferences(),
new SharedRenderViewCounter(0), kRouteId);
}
void RenderViewTest::TearDown() {
render_thread_.SendCloseMessage();
// Run the loop so the release task from the renderwidget executes.
ProcessPendingMessages();
EventBindings::SetRenderThread(NULL);
view_ = NULL;
mock_process_.reset();
WebKit::shutdown();
msg_loop_.RunAllPending();
}
|