tuple: update to make use of C++11
[chromium-blink-merge.git] / content / public / test / render_view_test.h
blob67442d0dcb00e9451bb233f3257c1d1bd06d2338
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 struct ViewMsg_Resize_Params;
24 namespace blink {
25 class WebWidget;
28 namespace gfx {
29 class Rect;
32 namespace content {
33 class ContentBrowserClient;
34 class ContentClient;
35 class ContentRendererClient;
36 class MockRenderProcess;
37 class PageState;
38 class RendererMainPlatformDelegate;
39 class RendererBlinkPlatformImplNoSandboxImpl;
40 class RendererScheduler;
41 class RenderView;
43 class RenderViewTest : public testing::Test {
44 public:
45 // A special BlinkPlatformImpl class for getting rid off the dependency to the
46 // sandbox, which is not available in RenderViewTest.
47 class RendererBlinkPlatformImplNoSandbox {
48 public:
49 RendererBlinkPlatformImplNoSandbox();
50 ~RendererBlinkPlatformImplNoSandbox();
51 blink::Platform* Get();
53 private:
54 scoped_ptr<RendererScheduler> renderer_scheduler_;
55 scoped_ptr<RendererBlinkPlatformImplNoSandboxImpl> blink_platform_impl_;
58 RenderViewTest();
59 ~RenderViewTest() override;
61 protected:
62 // Spins the message loop to process all messages that are currently pending.
63 void ProcessPendingMessages();
65 // Returns a pointer to the main frame.
66 blink::WebLocalFrame* GetMainFrame();
68 // Executes the given JavaScript in the context of the main frame. The input
69 // is a NULL-terminated UTF-8 string.
70 void ExecuteJavaScript(const char* js);
72 // Executes the given JavaScript and sets the int value it evaluates to in
73 // |result|.
74 // Returns true if the JavaScript was evaluated correctly to an int value,
75 // false otherwise.
76 bool ExecuteJavaScriptAndReturnIntValue(const base::string16& script,
77 int* result);
79 // Loads the given HTML into the main frame as a data: URL and blocks until
80 // the navigation is committed.
81 void LoadHTML(const char* html);
83 // Returns the current PageState.
84 PageState GetCurrentPageState();
86 // Navigates the main frame back or forward in session history and commits.
87 // The caller must capture a PageState for the target page.
88 void GoBack(const PageState& state);
89 void GoForward(const PageState& state);
91 // Sends one native key event over IPC.
92 void SendNativeKeyEvent(const NativeWebKeyboardEvent& key_event);
94 // Send a raw keyboard event to the renderer.
95 void SendWebKeyboardEvent(const blink::WebKeyboardEvent& key_event);
97 // Send a raw mouse event to the renderer.
98 void SendWebMouseEvent(const blink::WebMouseEvent& key_event);
100 // Returns the bounds (coordinates and size) of the element with id
101 // |element_id|. Returns an empty rect if such an element was not found.
102 gfx::Rect GetElementBounds(const std::string& element_id);
104 // Sends a left mouse click in the middle of the element with id |element_id|.
105 // Returns true if the event was sent, false otherwise (typically because
106 // the element was not found).
107 bool SimulateElementClick(const std::string& element_id);
109 // Simulates |node| being focused.
110 void SetFocused(const blink::WebNode& node);
112 // Simulates a navigation with a type of reload to the given url.
113 void Reload(const GURL& url);
115 // Returns the IPC message ID of the navigation message.
116 uint32 GetNavigationIPCType();
118 // Resize the view.
119 void Resize(gfx::Size new_size,
120 gfx::Rect resizer_rect,
121 bool is_fullscreen);
123 // These are all methods from RenderViewImpl that we expose to testing code.
124 bool OnMessageReceived(const IPC::Message& msg);
125 void DidNavigateWithinPage(blink::WebLocalFrame* frame,
126 bool is_new_navigation);
127 void SendContentStateImmediately();
128 blink::WebWidget* GetWebWidget();
130 // Allows a subclass to override the various content client implementations.
131 virtual ContentClient* CreateContentClient();
132 virtual ContentBrowserClient* CreateContentBrowserClient();
133 virtual ContentRendererClient* CreateContentRendererClient();
135 // Allows a subclass to customize the initial size of the RenderView.
136 virtual scoped_ptr<ViewMsg_Resize_Params> InitialSizeParams();
138 // testing::Test
139 void SetUp() override;
141 void TearDown() override;
143 base::MessageLoop msg_loop_;
144 scoped_ptr<MockRenderProcess> mock_process_;
145 // We use a naked pointer because we don't want to expose RenderViewImpl in
146 // the embedder's namespace.
147 RenderView* view_;
148 RendererBlinkPlatformImplNoSandbox blink_platform_impl_;
149 scoped_ptr<ContentClient> content_client_;
150 scoped_ptr<ContentBrowserClient> content_browser_client_;
151 scoped_ptr<ContentRendererClient> content_renderer_client_;
152 scoped_ptr<MockRenderThread> render_thread_;
154 // Used to setup the process so renderers can run.
155 scoped_ptr<RendererMainPlatformDelegate> platform_;
156 scoped_ptr<MainFunctionParams> params_;
157 scoped_ptr<base::CommandLine> command_line_;
159 #if defined(OS_MACOSX)
160 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_;
161 #endif
163 private:
164 void GoToOffset(int offset, const PageState& state);
167 } // namespace content
169 #endif // CONTENT_PUBLIC_TEST_RENDER_VIEW_TEST_H_