content: Add RendererScheduler.
[chromium-blink-merge.git] / content / public / test / render_view_test.h
blobbaab05aa9ca26026b57f95962c775bc0b5f0ad85
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.
5 #ifndef CONTENT_PUBLIC_TEST_RENDER_VIEW_TEST_H_
6 #define CONTENT_PUBLIC_TEST_RENDER_VIEW_TEST_H_
8 #include <string>
10 #include "base/command_line.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string16.h"
14 #include "content/public/browser/native_web_keyboard_event.h"
15 #include "content/public/common/main_function_params.h"
16 #include "content/public/common/page_state.h"
17 #include "content/public/test/mock_render_thread.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/platform/Platform.h"
20 #include "third_party/WebKit/public/web/WebFrame.h"
22 namespace blink {
23 class WebWidget;
26 namespace gfx {
27 class Rect;
30 namespace content {
31 class ContentBrowserClient;
32 class ContentClient;
33 class ContentRendererClient;
34 class MockRenderProcess;
35 class PageState;
36 class RendererMainPlatformDelegate;
37 class RendererBlinkPlatformImplNoSandboxImpl;
38 class RendererScheduler;
39 class RenderView;
41 class RenderViewTest : public testing::Test {
42 public:
43 // A special BlinkPlatformImpl class for getting rid off the dependency to the
44 // sandbox, which is not available in RenderViewTest.
45 class RendererBlinkPlatformImplNoSandbox {
46 public:
47 RendererBlinkPlatformImplNoSandbox();
48 ~RendererBlinkPlatformImplNoSandbox();
49 blink::Platform* Get();
51 private:
52 scoped_ptr<RendererScheduler> renderer_scheduler_;
53 scoped_ptr<RendererBlinkPlatformImplNoSandboxImpl> blink_platform_impl_;
56 RenderViewTest();
57 ~RenderViewTest() override;
59 protected:
60 // Spins the message loop to process all messages that are currently pending.
61 void ProcessPendingMessages();
63 // Returns a pointer to the main frame.
64 blink::WebLocalFrame* GetMainFrame();
66 // Executes the given JavaScript in the context of the main frame. The input
67 // is a NULL-terminated UTF-8 string.
68 void ExecuteJavaScript(const char* js);
70 // Executes the given JavaScript and sets the int value it evaluates to in
71 // |result|.
72 // Returns true if the JavaScript was evaluated correctly to an int value,
73 // false otherwise.
74 bool ExecuteJavaScriptAndReturnIntValue(const base::string16& script,
75 int* result);
77 // Loads the given HTML into the main frame as a data: URL and blocks until
78 // the navigation is committed.
79 void LoadHTML(const char* html);
81 // Returns the current PageState.
82 PageState GetCurrentPageState();
84 // Navigates the main frame back or forward in session history and commits.
85 // The caller must capture a PageState for the target page.
86 void GoBack(const PageState& state);
87 void GoForward(const PageState& state);
89 // Sends one native key event over IPC.
90 void SendNativeKeyEvent(const NativeWebKeyboardEvent& key_event);
92 // Send a raw keyboard event to the renderer.
93 void SendWebKeyboardEvent(const blink::WebKeyboardEvent& key_event);
95 // Send a raw mouse event to the renderer.
96 void SendWebMouseEvent(const blink::WebMouseEvent& key_event);
98 // Returns the bounds (coordinates and size) of the element with id
99 // |element_id|. Returns an empty rect if such an element was not found.
100 gfx::Rect GetElementBounds(const std::string& element_id);
102 // Sends a left mouse click in the middle of the element with id |element_id|.
103 // Returns true if the event was sent, false otherwise (typically because
104 // the element was not found).
105 bool SimulateElementClick(const std::string& element_id);
107 // Simulates |node| being focused.
108 void SetFocused(const blink::WebNode& node);
110 // Clears anything associated with the browsing history.
111 void ClearHistory();
113 // Simulates a navigation with a type of reload to the given url.
114 void Reload(const GURL& url);
116 // Returns the IPC message ID of the navigation message.
117 uint32 GetNavigationIPCType();
119 // Resize the view.
120 void Resize(gfx::Size new_size,
121 gfx::Rect resizer_rect,
122 bool is_fullscreen);
124 // These are all methods from RenderViewImpl that we expose to testing code.
125 bool OnMessageReceived(const IPC::Message& msg);
126 void DidNavigateWithinPage(blink::WebLocalFrame* frame,
127 bool is_new_navigation);
128 void SendContentStateImmediately();
129 blink::WebWidget* GetWebWidget();
131 // Allows a subclass to override the various content client implementations.
132 virtual ContentClient* CreateContentClient();
133 virtual ContentBrowserClient* CreateContentBrowserClient();
134 virtual ContentRendererClient* CreateContentRendererClient();
136 // testing::Test
137 void SetUp() override;
139 void TearDown() override;
141 base::MessageLoop msg_loop_;
142 scoped_ptr<MockRenderProcess> mock_process_;
143 // We use a naked pointer because we don't want to expose RenderViewImpl in
144 // the embedder's namespace.
145 RenderView* view_;
146 RendererBlinkPlatformImplNoSandbox blink_platform_impl_;
147 scoped_ptr<ContentClient> content_client_;
148 scoped_ptr<ContentBrowserClient> content_browser_client_;
149 scoped_ptr<ContentRendererClient> content_renderer_client_;
150 scoped_ptr<MockRenderThread> render_thread_;
152 // Used to setup the process so renderers can run.
153 scoped_ptr<RendererMainPlatformDelegate> platform_;
154 scoped_ptr<MainFunctionParams> params_;
155 scoped_ptr<base::CommandLine> command_line_;
157 #if defined(OS_MACOSX)
158 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_;
159 #endif
161 private:
162 void GoToOffset(int offset, const PageState& state);
165 } // namespace content
167 #endif // CONTENT_PUBLIC_TEST_RENDER_VIEW_TEST_H_