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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
// Copyright (c) 2010 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 "base/timer.h"
#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 should set a flag that tells the test_shell to print a line
// of descriptive text for each database command. It should take no
// arguments, and ignore any that may be present. However, at the moment, we
// don't have any DB function that prints messages, so for now this function
// doesn't do anything.
void dumpDatabaseCallbacks(const CppArgumentList& args, CppVariant* result);
// This function sets a flag that tells the test_shell to print a line of
// descriptive text 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 text 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);
// This function sets a flag that tells the test_shell to dump all calls
// to window.status().
// It takes no arguments, and ignores any that may be present.
void dumpWindowStatusChanges(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);
void notifyDoneTimedOut();
// 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 queueLoadingScript(const CppArgumentList& args, CppVariant* result);
void queueNonLoadingScript(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);
// Changes the cookie policy from the default to allow all cookies.
void setAlwaysAcceptCookies(const CppArgumentList& args, CppVariant* result);
// Shows DevTools window.
void showWebInspector(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);
// Passes this preference through to WebPreferences.
void setAuthorAndUserStylesEnabled(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);
void setScrollbarPolicy(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);
// Delays completion of the test until the policy delegate runs.
void waitForPolicyDelegate(const CppArgumentList& args, CppVariant* result);
// Causes WillSendRequest to clear certain headers.
void setWillSendRequestClearHeader(const CppArgumentList& args,
CppVariant* result);
// Causes WillSendRequest to block redirects.
void setWillSendRequestReturnsNullOnRedirect(const CppArgumentList& args,
CppVariant* result);
// Causes WillSendRequest to return an empty request.
void setWillSendRequestReturnsNull(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);
// Checks if an internal command is currently available.
void isCommandEnabled(const CppArgumentList& args, CppVariant* result);
// Set the WebPreference that controls webkit's popup blocking.
void setPopupBlockingEnabled(const CppArgumentList& args, CppVariant* result);
// If true, causes provisional frame loads to be stopped for the remainder of
// the test.
void setStopProvisionalFrameLoads(const CppArgumentList& args,
CppVariant* result);
// Enable or disable smart insert/delete. This is enabled by default.
void setSmartInsertDeleteEnabled(const CppArgumentList& args,
CppVariant* result);
// Enable or disable trailing whitespace selection on double click.
void setSelectTrailingWhitespaceEnabled(const CppArgumentList& args,
CppVariant* result);
void pauseAnimationAtTimeOnElementWithId(const CppArgumentList& args,
CppVariant* result);
void pauseTransitionAtTimeOnElementWithId(const CppArgumentList& args,
CppVariant* result);
void elementDoesAutoCompleteForElementWithId(const CppArgumentList& args,
CppVariant* result);
void numberOfActiveAnimations(const CppArgumentList& args,
CppVariant* result);
void disableImageLoading(const CppArgumentList& args,
CppVariant* result);
void setIconDatabaseEnabled(const CppArgumentList& args,
CppVariant* result);
void dumpSelectionRect(const CppArgumentList& args, CppVariant* result);
// Grants permission for desktop notifications to an origin
void grantDesktopNotificationPermission(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 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 callShouldCloseOnWebView(const CppArgumentList& args, CppVariant* result);
void setCallCloseOnWebViews(const CppArgumentList& args, CppVariant* result);
void setPrivateBrowsingEnabled(const CppArgumentList& args, CppVariant* result);
void setJavaScriptCanAccessClipboard(const CppArgumentList& args, CppVariant* result);
void setXSSAuditorEnabled(const CppArgumentList& args, CppVariant* result);
void evaluateScriptInIsolatedWorld(const CppArgumentList& args, CppVariant* result);
void overridePreference(const CppArgumentList& args, CppVariant* result);
void setAllowUniversalAccessFromFileURLs(const CppArgumentList& args, CppVariant* result);
void setAllowFileAccessFromFileURLs(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);
// Allows layout tests to manage origins' whitelisting.
void addOriginAccessWhitelistEntry(
const CppArgumentList& args, CppVariant* result);
void removeOriginAccessWhitelistEntry(
const CppArgumentList& args, CppVariant* result);
// Clears all databases.
void clearAllDatabases(const CppArgumentList& args, CppVariant* result);
// Sets the default quota for all origins
void setDatabaseQuota(const CppArgumentList& args, CppVariant* result);
// Calls setlocale(LC_ALL, ...) for a specified locale.
// Resets between tests.
void setPOSIXLocale(const CppArgumentList& args, CppVariant* result);
// Gets the value of the counter in the element specified by its ID.
void counterValueForElementById(
const CppArgumentList& args, CppVariant* result);
// Gets the number of page where the specified element will be put.
void pageNumberForElementById(
const CppArgumentList& args, CppVariant* result);
// Gets the number of pages to be printed.
void numberOfPages(const CppArgumentList& args, CppVariant* result);
// Allows layout tests to start Timeline profiling.
void setTimelineProfilingEnabled(const CppArgumentList& args,
CppVariant* result);
// Allows layout tests to exec scripts at WebInspector side.
void evaluateInWebInspector(const CppArgumentList& args, CppVariant* result);
// Forces the selection colors for testing under Linux.
void forceRedSelectionColors(const CppArgumentList& args,
CppVariant* result);
// Adds a user script or user style sheet to be injected into new documents.
void addUserScript(const CppArgumentList& args, CppVariant* result);
void addUserStyleSheet(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 ShouldDumpStatusCallbacks() {
return dump_window_status_changes_;
}
bool ShouldDumpSelectionRect() {
return dump_selection_rect_;
}
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_; }
bool StopProvisionalFrameLoads() { return stop_provisional_frame_loads_; }
bool test_repaint() const { return test_repaint_; }
bool sweep_horizontally() const { return sweep_horizontally_; }
// Called by the webview delegate when the toplevel frame load is done.
void LocationChangeDone();
// Called by the webview delegate when the policy delegate runs if the
// waitForPolicyDelegate was called.
void PolicyDelegateDone();
// 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() {}
// Returns true if this started a load.
virtual bool 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 ProcessWorkSoon();
// 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:
void ProcessWork();
base::OneShotTimer<WorkQueue> timer_;
std::queue<WorkItem*> queue_;
bool frozen_;
};
// Support for overridePreference.
bool CppVariantToBool(const CppVariant&);
int32 CppVariantToInt32(const CppVariant&);
std::wstring CppVariantToWstring(const CppVariant&);
void LogErrorToConsole(const std::string& text);
void completeNotifyDone(bool is_timeout);
// Used for test timeouts.
// TODO(ojan): Use base::OneShotTimer.
ScopedRunnableMethodFactory<LayoutTestController> timeout_factory_;
// 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 draw the bounds of the current selection rect
// taking possible transforms of the selection rect into account.
static bool dump_selection_rect_;
// 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, the test_shell will dump all changes to window.status.
static bool dump_window_status_changes_;
// 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, pixel dump will be produced as a series of 1px-tall, view-wide
// individual paints over the height of the view.
static bool test_repaint_;
// If true and test_repaint_ is true as well, pixel dump will be produced as
// a series of 1px-wide, view-tall paints across the width of the view.
static bool sweep_horizontally_;
// If true and a drag starts, adds a file to the drag&drop clipboard.
static bool should_add_file_to_pasteboard_;
// If true, stops provisional frame loads during the
// DidStartProvisionalLoadForFrame callback.
static bool stop_provisional_frame_loads_;
// 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_;
// Bound variable counting the number of top URLs visited.
static CppVariant webHistoryItemCount_;
};
#endif // WEBKIT_TOOLS_TEST_SHELL_LAYOUT_TEST_CONTROLLER_H_
|