Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / content / public / test / render_view_test.h
blobba225d55c590572e95639daef8c73a9c92d004a3
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 WebInputElement;
26 class WebWidget;
29 namespace gfx {
30 class Rect;
33 namespace scheduler {
34 class RendererScheduler;
37 namespace content {
38 class ContentBrowserClient;
39 class ContentClient;
40 class ContentRendererClient;
41 class FakeCompositorDependencies;
42 class MockRenderProcess;
43 class PageState;
44 class RendererMainPlatformDelegate;
45 class RendererBlinkPlatformImplNoSandboxImpl;
46 class RenderView;
48 class RenderViewTest : public testing::Test {
49 public:
50 // A special BlinkPlatformImpl class for getting rid off the dependency to the
51 // sandbox, which is not available in RenderViewTest.
52 class RendererBlinkPlatformImplNoSandbox {
53 public:
54 RendererBlinkPlatformImplNoSandbox();
55 ~RendererBlinkPlatformImplNoSandbox();
56 blink::Platform* Get() const;
57 scheduler::RendererScheduler* Scheduler() const;
59 private:
60 scoped_ptr<scheduler::RendererScheduler> renderer_scheduler_;
61 scoped_ptr<RendererBlinkPlatformImplNoSandboxImpl> blink_platform_impl_;
64 RenderViewTest();
65 ~RenderViewTest() override;
67 protected:
68 // Spins the message loop to process all messages that are currently pending.
69 void ProcessPendingMessages();
71 // Returns a pointer to the main frame.
72 blink::WebLocalFrame* GetMainFrame();
74 // Executes the given JavaScript in the context of the main frame. The input
75 // is a NULL-terminated UTF-8 string.
76 void ExecuteJavaScriptForTests(const char* js);
78 // Executes the given JavaScript and sets the int value it evaluates to in
79 // |result|.
80 // Returns true if the JavaScript was evaluated correctly to an int value,
81 // false otherwise.
82 bool ExecuteJavaScriptAndReturnIntValue(const base::string16& script,
83 int* result);
85 // Loads the given HTML into the main frame as a data: URL and blocks until
86 // the navigation is committed.
87 void LoadHTML(const char* html);
89 // Returns the current PageState.
90 PageState GetCurrentPageState();
92 // Navigates the main frame back or forward in session history and commits.
93 // The caller must capture a PageState for the target page.
94 void GoBack(const PageState& state);
95 void GoForward(const PageState& state);
97 // Sends one native key event over IPC.
98 void SendNativeKeyEvent(const NativeWebKeyboardEvent& key_event);
100 // Send a raw keyboard event to the renderer.
101 void SendWebKeyboardEvent(const blink::WebKeyboardEvent& key_event);
103 // Send a raw mouse event to the renderer.
104 void SendWebMouseEvent(const blink::WebMouseEvent& mouse_event);
106 // Returns the bounds (coordinates and size) of the element with id
107 // |element_id|. Returns an empty rect if such an element was not found.
108 gfx::Rect GetElementBounds(const std::string& element_id);
110 // Sends a left mouse click in the middle of the element with id |element_id|.
111 // Returns true if the event was sent, false otherwise (typically because
112 // the element was not found).
113 bool SimulateElementClick(const std::string& element_id);
115 // Sends a left mouse click at the |point|.
116 void SimulatePointClick(const gfx::Point& point);
118 // Sends a right mouse click in the middle of the element with id
119 // |element_id|. Returns true if the event was sent, false otherwise
120 // (typically because the element was not found).
121 bool SimulateElementRightClick(const std::string& element_id);
123 // Sends a right mouse click at the |point|.
124 void SimulatePointRightClick(const gfx::Point& point);
126 // Sends a tap at the |rect|.
127 void SimulateRectTap(const gfx::Rect& rect);
129 // Simulates |node| being focused.
130 void SetFocused(const blink::WebNode& node);
132 // Simulates a navigation with a type of reload to the given url.
133 void Reload(const GURL& url);
135 // Returns the IPC message ID of the navigation message.
136 uint32 GetNavigationIPCType();
138 // Resize the view.
139 void Resize(gfx::Size new_size,
140 gfx::Rect resizer_rect,
141 bool is_fullscreen);
143 // Simulates typing the |ascii_character| into this render view. Also accepts
144 // ui::VKEY_BACK for backspace. Will flush the message loop if
145 // |flush_message_loop| is true.
146 void SimulateUserTypingASCIICharacter(char ascii_character,
147 bool flush_message_loop);
149 // Simulates user focusing |input|, erasing all text, and typing the
150 // |new_value| instead. Will process input events for autofill. This is a user
151 // gesture.
152 void SimulateUserInputChangeForElement(blink::WebInputElement* input,
153 const std::string& new_value);
155 // These are all methods from RenderViewImpl that we expose to testing code.
156 bool OnMessageReceived(const IPC::Message& msg);
157 void DidNavigateWithinPage(blink::WebLocalFrame* frame,
158 bool is_new_navigation);
159 void SendContentStateImmediately();
160 blink::WebWidget* GetWebWidget();
162 // Allows a subclass to override the various content client implementations.
163 virtual ContentClient* CreateContentClient();
164 virtual ContentBrowserClient* CreateContentBrowserClient();
165 virtual ContentRendererClient* CreateContentRendererClient();
167 // Allows a subclass to customize the initial size of the RenderView.
168 virtual scoped_ptr<ViewMsg_Resize_Params> InitialSizeParams();
170 // testing::Test
171 void SetUp() override;
173 void TearDown() override;
175 base::MessageLoop msg_loop_;
176 scoped_ptr<FakeCompositorDependencies> compositor_deps_;
177 scoped_ptr<MockRenderProcess> mock_process_;
178 // We use a naked pointer because we don't want to expose RenderViewImpl in
179 // the embedder's namespace.
180 RenderView* view_;
181 RendererBlinkPlatformImplNoSandbox blink_platform_impl_;
182 scoped_ptr<ContentClient> content_client_;
183 scoped_ptr<ContentBrowserClient> content_browser_client_;
184 scoped_ptr<ContentRendererClient> content_renderer_client_;
185 scoped_ptr<MockRenderThread> render_thread_;
187 // Used to setup the process so renderers can run.
188 scoped_ptr<RendererMainPlatformDelegate> platform_;
189 scoped_ptr<MainFunctionParams> params_;
190 scoped_ptr<base::CommandLine> command_line_;
192 #if defined(OS_MACOSX)
193 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_;
194 #endif
196 private:
197 void GoToOffset(int offset, const PageState& state);
200 } // namespace content
202 #endif // CONTENT_PUBLIC_TEST_RENDER_VIEW_TEST_H_