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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
// Copyright (c) 2006-2008 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.
/*
LayoutTestController class:
Bound to a JavaScript window.layoutTestController object using the
CppBoundClass::BindToJavascript(), this allows layout tests that are run in
the test_shell (or, in principle, any web page loaded into a client app built
with this class) to control various aspects of how the tests are run and what
sort of output they produce.
*/
#ifndef WEBKIT_TOOLS_TEST_SHELL_LAYOUT_TEST_CONTROLLER_H__
#define WEBKIT_TOOLS_TEST_SHELL_LAYOUT_TEST_CONTROLLER_H__
#include <queue>
#include "webkit/glue/cpp_bound_class.h"
class TestShell;
class LayoutTestController : public CppBoundClass {
public:
// Builds the property and method lists needed to bind this class to a JS
// object.
LayoutTestController(TestShell* shell);
// This function sets a flag that tells the test_shell to dump pages as
// plain text, rather than as a text representation of the renderer's state.
// It takes no arguments, and ignores any that may be present.
void dumpAsText(const CppArgumentList& args, CppVariant* result);
// This function sets a flag that tells the test_shell to print a line of
// descriptive test for each editing command. It takes no arguments, and
// ignores any that may be present.
void dumpEditingCallbacks(const CppArgumentList& args, CppVariant* result);
// This function sets a flag that tells the test_shell to print a line of
// descriptive test for each frame load callback. It takes no arguments, and
// ignores any that may be present.
void dumpFrameLoadCallbacks(const CppArgumentList& args, CppVariant* result);
// This function sets a flag that tells the test_shell to print out a text
// representation of the back/forward list. It ignores all args.
void dumpBackForwardList(const CppArgumentList& args, CppVariant* result);
// This function sets a flag that tells the test_shell to print out the
// scroll offsets of the child frames. It ignores all args.
void dumpChildFrameScrollPositions(const CppArgumentList& args, CppVariant* result);
// This function sets a flag that tells the test_shell to recursively
// dump all frames as plain text if the dumpAsText flag is set.
// It takes no arguments, and ignores any that may be present.
void dumpChildFramesAsText(const CppArgumentList& args, CppVariant* result);
// When called with a boolean argument, this sets a flag that controls
// whether content-editable elements accept editing focus when an editing
// attempt is made. It ignores any additional arguments.
void setAcceptsEditing(const CppArgumentList& args, CppVariant* result);
// Functions for dealing with windows. By default we block all new windows.
void windowCount(const CppArgumentList& args, CppVariant* result);
void setCanOpenWindows(const CppArgumentList& args, CppVariant* result);
void setCloseRemainingWindowsWhenComplete(const CppArgumentList& args, CppVariant* result);
// By default, tests end when page load is complete. These methods are used
// to delay the completion of the test until notifyDone is called.
void waitUntilDone(const CppArgumentList& args, CppVariant* result);
void notifyDone(const CppArgumentList& args, CppVariant* result);
// Methods for adding actions to the work queue. Used in conjunction with
// waitUntilDone/notifyDone above.
void queueBackNavigation(const CppArgumentList& args, CppVariant* result);
void queueForwardNavigation(const CppArgumentList& args, CppVariant* result);
void queueReload(const CppArgumentList& args, CppVariant* result);
void queueScript(const CppArgumentList& args, CppVariant* result);
void queueLoad(const CppArgumentList& args, CppVariant* result);
// Although this is named "objC" to match the Mac version, it actually tests
// the identity of its two arguments in C++.
void objCIdentityIsEqual(const CppArgumentList& args, CppVariant* result);
// Gives focus to the window.
void setWindowIsKey(const CppArgumentList& args, CppVariant* result);
// Method that controls whether pressing Tab key cycles through page elements
// or inserts a '\t' char in text area
void setTabKeyCyclesThroughElements(const CppArgumentList& args, CppVariant* result);
// Passes through to WebPreferences which allows the user to have a custom
// style sheet.
void setUserStyleSheetEnabled(const CppArgumentList& args, CppVariant* result);
void setUserStyleSheetLocation(const CppArgumentList& args, CppVariant* result);
// Puts Webkit in "dashboard compatibility mode", which is used in obscure
// Mac-only circumstances. It's not really necessary, and will most likely
// never be used by Chrome, but some layout tests depend on its presence.
void setUseDashboardCompatibilityMode(const CppArgumentList& args, CppVariant* result);
// Causes navigation actions just printout the intended navigation instead
// of taking you to the page. This is used for cases like mailto, where you
// don't actually want to open the mail program.
void setCustomPolicyDelegate(const CppArgumentList& args, CppVariant* result);
// Converts a URL starting with file:///tmp/ to the local mapping.
void pathToLocalResource(const CppArgumentList& args, CppVariant* result);
// Sets a bool such that when a drag is started, we fill the drag clipboard
// with a fake file object.
void addFileToPasteboardOnDrag(const CppArgumentList& args, CppVariant* result);
// Executes an internal command (superset of document.execCommand() commands)
void execCommand(const CppArgumentList& args, CppVariant* result);
// Set the WebPreference that controls webkit's popup blocking.
void setPopupBlockingEnabled(const CppArgumentList& args, CppVariant* result);
// The following are only stubs. TODO(pamg): Implement any of these that
// are needed to pass the layout tests.
void dumpAsWebArchive(const CppArgumentList& args, CppVariant* result);
void dumpTitleChanges(const CppArgumentList& args, CppVariant* result);
void dumpResourceLoadCallbacks(const CppArgumentList& args, CppVariant* result);
void setMainFrameIsFirstResponder(const CppArgumentList& args, CppVariant* result);
void dumpSelectionRect(const CppArgumentList& args, CppVariant* result);
void display(const CppArgumentList& args, CppVariant* result);
void testRepaint(const CppArgumentList& args, CppVariant* result);
void repaintSweepHorizontally(const CppArgumentList& args, CppVariant* result);
void clearBackForwardList(const CppArgumentList& args, CppVariant* result);
void keepWebHistory(const CppArgumentList& args, CppVariant* result);
void storeWebScriptObject(const CppArgumentList& args, CppVariant* result);
void accessStoredWebScriptObject(const CppArgumentList& args, CppVariant* result);
void objCClassNameOf(const CppArgumentList& args, CppVariant* result);
void addDisallowedURL(const CppArgumentList& args, CppVariant* result);
void setCallCloseOnWebViews(const CppArgumentList& args, CppVariant* result);
void setPrivateBrowsingEnabled(const CppArgumentList& args, CppVariant* result);
// The fallback method is called when a nonexistent method is called on
// the layout test controller object.
// It is usefull to catch typos in the JavaScript code (a few layout tests
// do have typos in them) and it allows the script to continue running in
// that case (as the Mac does).
void fallbackMethod(const CppArgumentList& args, CppVariant* result);
public:
// The following methods are not exposed to JavaScript.
void SetWorkQueueFrozen(bool frozen) { work_queue_.set_frozen(frozen); }
bool ShouldDumpAsText() { return dump_as_text_; }
bool ShouldDumpEditingCallbacks() { return dump_editing_callbacks_; }
bool ShouldDumpFrameLoadCallbacks() { return dump_frame_load_callbacks_; }
void SetShouldDumpFrameLoadCallbacks(bool value) {
dump_frame_load_callbacks_ = value;
}
bool ShouldDumpResourceLoadCallbacks() {
return dump_resource_load_callbacks_;
}
bool ShouldDumpBackForwardList() { return dump_back_forward_list_; }
bool ShouldDumpTitleChanges() { return dump_title_changes_; }
bool ShouldDumpChildFrameScrollPositions() {
return dump_child_frame_scroll_positions_;
}
bool ShouldDumpChildFramesAsText() {
return dump_child_frames_as_text_;
}
bool AcceptsEditing() { return accepts_editing_; }
bool CanOpenWindows() { return can_open_windows_; }
bool ShouldAddFileToPasteboard() { return should_add_file_to_pasteboard_; }
// If we have queued events, fire them and then dump the test output.
// Otherwise, just dump the test output.
// Used by the layout tests for tests that span more than a single load.
// This is called by the test webview delegate when a page finishes
// loading (successful or not). Once all the work has been processed, we
// dump the test output.
void ProcessWork() { work_queue_.ProcessWork(); }
// Called by the webview delegate when the toplevel frame load is done.
void LocationChangeDone();
// Reinitializes all static values. The Reset() method should be called
// before the start of each test (currently from
// TestShell::RunFileTest).
void Reset();
// A single item in the work queue.
class WorkItem {
public:
virtual ~WorkItem() {};
virtual void Run(TestShell* shell) = 0;
};
// Used to clear the value of shell_ from test_shell_tests.
static void ClearShell() { shell_ = NULL; }
private:
friend class WorkItem;
// Helper class for managing events queued by methods like queueLoad or
// queueScript.
class WorkQueue {
public:
virtual ~WorkQueue();
void ProcessWork();
// Reset the state of the class between tests.
void Reset();
void AddWork(WorkItem* work);
void set_frozen(bool frozen) { frozen_ = frozen; }
bool empty() { return queue_.empty(); }
private:
std::queue<WorkItem*> queue_;
bool frozen_;
};
// Non-owning pointer. The LayoutTestController is owned by the host.
static TestShell* shell_;
// If true, the test_shell will produce a plain text dump rather than a
// text representation of the renderer.
static bool dump_as_text_;
// If true, the test_shell will write a descriptive line for each editing
// command.
static bool dump_editing_callbacks_;
// If true, the test_shell will output a descriptive line for each frame
// load callback.
static bool dump_frame_load_callbacks_;
// If true, the test_shell will output a descriptive line for each resource
// load callback.
static bool dump_resource_load_callbacks_;
// If true, the test_shell will produce a dump of the back forward list as
// well.
static bool dump_back_forward_list_;
// If true, the test_shell will print out the child frame scroll offsets as
// well.
static bool dump_child_frame_scroll_positions_;
// If true and if dump_as_text_ is true, the test_shell will recursively
// dump all frames as plain text.
static bool dump_child_frames_as_text_;
// If true, output a message when the page title is changed.
static bool dump_title_changes_;
// If true, the element will be treated as editable. This value is returned
// from various editing callbacks that are called just before edit operations
// are allowed.
static bool accepts_editing_;
// If true, new windows can be opened via javascript or by plugins. By
// default, set to false and can be toggled to true using
// setCanOpenWindows().
static bool can_open_windows_;
// When reset is called, go through and close all but the main test shell
// window. By default, set to true but toggled to false using
// setCloseRemainingWindowsWhenComplete().
static bool close_remaining_windows_;
// If true and a drag starts, adds a file to the drag&drop clipboard.
static bool should_add_file_to_pasteboard_;
// If true, don't dump output until notifyDone is called.
static bool wait_until_done_;
// To prevent infinite loops, only the first page of a test can add to a
// work queue (since we may well come back to that same page).
static bool work_queue_frozen_;
static WorkQueue work_queue_;
static CppVariant globalFlag_;
};
#endif // WEBKIT_TOOLS_TEST_SHELL_LAYOUT_TEST_CONTROLLER_H__
|