Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1362)

Side by Side Diff: content/test/render_view_test.h

Issue 10497013: Move render_view_test.h header from content\test to content\public\test. This way we can enforce th… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_view_browsertest_mac.mm ('k') | content/test/render_view_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef CONTENT_TEST_RENDER_VIEW_TEST_H_
6 #define CONTENT_TEST_RENDER_VIEW_TEST_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/command_line.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h"
14 #include "base/string16.h"
15 #include "content/public/browser/native_web_keyboard_event.h"
16 #include "content/public/common/main_function_params.h"
17 #include "content/public/test/mock_render_thread.h"
18 #include "content/renderer/mock_content_renderer_client.h"
19 #include "content/renderer/renderer_webkitplatformsupport_impl.h"
20 #include "content/test/mock_keyboard.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
23
24 class MockRenderProcess;
25 class RendererMainPlatformDelegate;
26
27 namespace WebKit {
28 class WebHistoryItem;
29 class WebWidget;
30 }
31
32 namespace content {
33 class RenderView;
34 }
35
36 namespace gfx {
37 class Rect;
38 }
39
40 namespace content {
41
42 class RenderViewTest : public testing::Test {
43 public:
44 // A special WebKitPlatformSupportImpl class for getting rid off the
45 // dependency to the sandbox, which is not available in RenderViewTest.
46 class RendererWebKitPlatformSupportImplNoSandbox :
47 public RendererWebKitPlatformSupportImpl {
48 public:
49 virtual WebKit::WebSandboxSupport* sandboxSupport() {
50 return NULL;
51 }
52 };
53
54 RenderViewTest();
55 virtual ~RenderViewTest();
56
57 protected:
58 // Spins the message loop to process all messages that are currently pending.
59 void ProcessPendingMessages();
60
61 // Returns a pointer to the main frame.
62 WebKit::WebFrame* GetMainFrame();
63
64 // Executes the given JavaScript in the context of the main frame. The input
65 // is a NULL-terminated UTF-8 string.
66 void ExecuteJavaScript(const char* js);
67
68 // Executes the given JavaScript and sets the int value it evaluates to in
69 // |result|.
70 // Returns true if the JavaScript was evaluated correctly to an int value,
71 // false otherwise.
72 bool ExecuteJavaScriptAndReturnIntValue(const string16& script, int* result);
73
74 // Loads the given HTML into the main frame as a data: URL and blocks until
75 // the navigation is committed.
76 void LoadHTML(const char* html);
77
78 // Navigates the main frame back or forward in session history and commits.
79 // The caller must capture a WebHistoryItem for the target page. This is
80 // available from the WebFrame.
81 void GoBack(const WebKit::WebHistoryItem& item);
82 void GoForward(const WebKit::WebHistoryItem& item);
83
84 // Sends IPC messages that emulates a key-press event.
85 int SendKeyEvent(MockKeyboard::Layout layout,
86 int key_code,
87 MockKeyboard::Modifiers key_modifiers,
88 string16* output);
89
90 // Sends one native key event over IPC.
91 void SendNativeKeyEvent(const content::NativeWebKeyboardEvent& key_event);
92
93 // Send a raw keyboard event to the renderer.
94 void SendWebKeyboardEvent(const WebKit::WebKeyboardEvent& key_event);
95
96 // Send a raw mouse event to the renderer.
97 void SendWebMouseEvent(const WebKit::WebMouseEvent& key_event);
98
99 // Returns the bounds (coordinates and size) of the element with id
100 // |element_id|. Returns an empty rect if such an element was not found.
101 gfx::Rect GetElementBounds(const std::string& element_id);
102
103 // Sends a left mouse click in the middle of the element with id |element_id|.
104 // Returns true if the event was sent, false otherwise (typically because
105 // the element was not found).
106 bool SimulateElementClick(const std::string& element_id);
107
108 // Simulates |node| being focused.
109 void SetFocused(const WebKit::WebNode& node);
110
111 // Clears anything associated with the browsing history.
112 void ClearHistory();
113
114 // Simulates a navigation with a type of reload to the given url.
115 void Reload(const GURL& url);
116
117 // Returns the IPC message ID of the navigation message.
118 uint32 GetNavigationIPCType();
119
120 // These are all methods from RenderViewImpl that we expose to testing code.
121 bool OnMessageReceived(const IPC::Message& msg);
122 void DidNavigateWithinPage(WebKit::WebFrame* frame, bool is_new_navigation);
123 void SendContentStateImmediately();
124 WebKit::WebWidget* GetWebWidget();
125
126 // testing::Test
127 virtual void SetUp() OVERRIDE;
128
129 virtual void TearDown() OVERRIDE;
130
131 MessageLoop msg_loop_;
132 scoped_ptr<MockRenderProcess> mock_process_;
133 // We use a naked pointer because we don't want to expose RenderViewImpl in
134 // the embedder's namespace.
135 content::RenderView* view_;
136 RendererWebKitPlatformSupportImplNoSandbox webkit_platform_support_;
137 MockContentRendererClient mock_content_renderer_client_;
138 scoped_ptr<MockKeyboard> mock_keyboard_;
139 scoped_ptr<MockRenderThread> render_thread_;
140
141 // Used to setup the process so renderers can run.
142 scoped_ptr<RendererMainPlatformDelegate> platform_;
143 scoped_ptr<content::MainFunctionParams> params_;
144 scoped_ptr<CommandLine> command_line_;
145
146 private:
147 void GoToOffset(int offset, const WebKit::WebHistoryItem& history_item);
148 };
149
150 } // namespace content
151
152 #endif // CONTENT_TEST_RENDER_VIEW_TEST_H_
OLDNEW
« no previous file with comments | « content/renderer/render_view_browsertest_mac.mm ('k') | content/test/render_view_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698