2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2010 Pawel Hajdan (phajdan.jr@chromium.org)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 LayoutTestController class:
34 Bound to a JavaScript window.layoutTestController object using the
35 CppBoundClass::bindToJavascript(), this allows layout tests that are run in
36 the test_shell (or, in principle, any web page loaded into a client app built
37 with this class) to control various aspects of how the tests are run and what
38 sort of output they produce.
41 #ifndef LayoutTestController_h
42 #define LayoutTestController_h
44 #include "CppBoundClass.h"
46 #include "WebString.h"
48 #include <wtf/Deque.h>
49 #include <wtf/OwnPtr.h>
52 class WebGeolocationClientMock;
53 class WebSpeechInputController;
54 class WebSpeechInputControllerMock;
55 class WebSpeechInputListener;
60 class LayoutTestController : public CppBoundClass {
62 // Builds the property and method lists needed to bind this class to a JS
64 LayoutTestController(TestShell*);
66 ~LayoutTestController();
68 // This function sets a flag that tells the test_shell to dump pages as
69 // plain text, rather than as a text representation of the renderer's state.
70 // It takes an optional argument, whether to dump pixels results or not.
71 void dumpAsText(const CppArgumentList&, CppVariant*);
73 // This function should set a flag that tells the test_shell to print a line
74 // of descriptive text for each database command. It should take no
75 // arguments, and ignore any that may be present. However, at the moment, we
76 // don't have any DB function that prints messages, so for now this function
77 // doesn't do anything.
78 void dumpDatabaseCallbacks(const CppArgumentList&, CppVariant*);
80 // This function sets a flag that tells the test_shell to print a line of
81 // descriptive text for each editing command. It takes no arguments, and
82 // ignores any that may be present.
83 void dumpEditingCallbacks(const CppArgumentList&, CppVariant*);
85 // This function sets a flag that tells the test_shell to print a line of
86 // descriptive text for each frame load callback. It takes no arguments, and
87 // ignores any that may be present.
88 void dumpFrameLoadCallbacks(const CppArgumentList&, CppVariant*);
90 // This function sets a flag that tells the test_shell to print a line of
91 // user gesture status text for some frame load callbacks. It takes no
92 // arguments, and ignores any that may be present.
93 void dumpUserGestureInFrameLoadCallbacks(const CppArgumentList&, CppVariant*);
95 // This function sets a flag that tells the test_shell to print out a text
96 // representation of the back/forward list. It ignores all arguments.
97 void dumpBackForwardList(const CppArgumentList&, CppVariant*);
99 // This function sets a flag that tells the test_shell to print out the
100 // scroll offsets of the child frames. It ignores all.
101 void dumpChildFrameScrollPositions(const CppArgumentList&, CppVariant*);
103 // This function sets a flag that tells the test_shell to recursively
104 // dump all frames as plain text if the dumpAsText flag is set.
105 // It takes no arguments, and ignores any that may be present.
106 void dumpChildFramesAsText(const CppArgumentList&, CppVariant*);
108 // This function sets a flag that tells the test_shell to dump a descriptive
109 // line for each resource load callback. It takes no arguments, and ignores
110 // any that may be present.
111 void dumpResourceLoadCallbacks(const CppArgumentList&, CppVariant*);
113 // This function sets a flag that tells the test_shell to dump the MIME type
114 // for each resource that was loaded. It takes no arguments, and ignores any
115 // that may be present.
116 void dumpResourceResponseMIMETypes(const CppArgumentList&, CppVariant*);
118 // This function sets a flag that tells the test_shell to dump all calls
119 // to window.status().
120 // It takes no arguments, and ignores any that may be present.
121 void dumpWindowStatusChanges(const CppArgumentList&, CppVariant*);
123 // When called with a boolean argument, this sets a flag that controls
124 // whether content-editable elements accept editing focus when an editing
125 // attempt is made. It ignores any additional arguments.
126 void setAcceptsEditing(const CppArgumentList&, CppVariant*);
128 // Functions for dealing with windows. By default we block all new windows.
129 void windowCount(const CppArgumentList&, CppVariant*);
130 void setCanOpenWindows(const CppArgumentList&, CppVariant*);
131 void setCloseRemainingWindowsWhenComplete(const CppArgumentList&, CppVariant*);
133 // By default, tests end when page load is complete. These methods are used
134 // to delay the completion of the test until notifyDone is called.
135 void waitUntilDone(const CppArgumentList&, CppVariant*);
136 void notifyDone(const CppArgumentList&, CppVariant*);
138 // Methods for adding actions to the work queue. Used in conjunction with
139 // waitUntilDone/notifyDone above.
140 void queueBackNavigation(const CppArgumentList&, CppVariant*);
141 void queueForwardNavigation(const CppArgumentList&, CppVariant*);
142 void queueReload(const CppArgumentList&, CppVariant*);
143 void queueLoadingScript(const CppArgumentList&, CppVariant*);
144 void queueNonLoadingScript(const CppArgumentList&, CppVariant*);
145 void queueLoad(const CppArgumentList&, CppVariant*);
146 void queueLoadHTMLString(const CppArgumentList&, CppVariant*);
148 // Although this is named "objC" to match the Mac version, it actually tests
149 // the identity of its two arguments in C++.
150 void objCIdentityIsEqual(const CppArgumentList&, CppVariant*);
152 // Changes the cookie policy from the default to allow all cookies.
153 void setAlwaysAcceptCookies(const CppArgumentList&, CppVariant*);
155 // Changes asynchronous spellchecking flag on the settings.
156 void setAsynchronousSpellCheckingEnabled(const CppArgumentList&, CppVariant*);
158 // Shows DevTools window.
159 void showWebInspector(const CppArgumentList&, CppVariant*);
160 void closeWebInspector(const CppArgumentList&, CppVariant*);
162 // Gives focus to the window.
163 void setWindowIsKey(const CppArgumentList&, CppVariant*);
165 // Method that controls whether pressing Tab key cycles through page elements
166 // or inserts a '\t' char in text area
167 void setTabKeyCyclesThroughElements(const CppArgumentList&, CppVariant*);
169 // Passes through to WebPreferences which allows the user to have a custom
171 void setUserStyleSheetEnabled(const CppArgumentList&, CppVariant*);
172 void setUserStyleSheetLocation(const CppArgumentList&, CppVariant*);
174 // Passes this preference through to WebSettings.
175 void setAuthorAndUserStylesEnabled(const CppArgumentList&, CppVariant*);
177 // Puts Webkit in "dashboard compatibility mode", which is used in obscure
178 // Mac-only circumstances. It's not really necessary, and will most likely
179 // never be used by Chrome, but some layout tests depend on its presence.
180 void setUseDashboardCompatibilityMode(const CppArgumentList&, CppVariant*);
182 void setScrollbarPolicy(const CppArgumentList&, CppVariant*);
184 // Causes navigation actions just printout the intended navigation instead
185 // of taking you to the page. This is used for cases like mailto, where you
186 // don't actually want to open the mail program.
187 void setCustomPolicyDelegate(const CppArgumentList&, CppVariant*);
189 // Delays completion of the test until the policy delegate runs.
190 void waitForPolicyDelegate(const CppArgumentList&, CppVariant*);
192 // Causes WillSendRequest to clear certain headers.
193 void setWillSendRequestClearHeader(const CppArgumentList&, CppVariant*);
195 // Causes WillSendRequest to block redirects.
196 void setWillSendRequestReturnsNullOnRedirect(const CppArgumentList&, CppVariant*);
198 // Causes WillSendRequest to return an empty request.
199 void setWillSendRequestReturnsNull(const CppArgumentList&, CppVariant*);
201 // Converts a URL starting with file:///tmp/ to the local mapping.
202 void pathToLocalResource(const CppArgumentList&, CppVariant*);
204 // Sets a bool such that when a drag is started, we fill the drag clipboard
205 // with a fake file object.
206 void addFileToPasteboardOnDrag(const CppArgumentList&, CppVariant*);
208 // Executes an internal command (superset of document.execCommand() commands).
209 void execCommand(const CppArgumentList&, CppVariant*);
211 // Checks if an internal command is currently available.
212 void isCommandEnabled(const CppArgumentList&, CppVariant*);
214 // Set the WebPreference that controls webkit's popup blocking.
215 void setPopupBlockingEnabled(const CppArgumentList&, CppVariant*);
217 // If true, causes provisional frame loads to be stopped for the remainder of
219 void setStopProvisionalFrameLoads(const CppArgumentList&, CppVariant*);
221 // Enable or disable smart insert/delete. This is enabled by default.
222 void setSmartInsertDeleteEnabled(const CppArgumentList&, CppVariant*);
224 // Enable or disable trailing whitespace selection on double click.
225 void setSelectTrailingWhitespaceEnabled(const CppArgumentList&, CppVariant*);
227 void pauseAnimationAtTimeOnElementWithId(const CppArgumentList&, CppVariant*);
228 void pauseTransitionAtTimeOnElementWithId(const CppArgumentList&, CppVariant*);
229 void elementDoesAutoCompleteForElementWithId(const CppArgumentList&, CppVariant*);
230 void numberOfActiveAnimations(const CppArgumentList&, CppVariant*);
231 void suspendAnimations(const CppArgumentList&, CppVariant*);
232 void resumeAnimations(const CppArgumentList&, CppVariant*);
233 void sampleSVGAnimationForElementAtTime(const CppArgumentList&, CppVariant*);
234 void disableImageLoading(const CppArgumentList&, CppVariant*);
235 void setIconDatabaseEnabled(const CppArgumentList&, CppVariant*);
236 void dumpSelectionRect(const CppArgumentList&, CppVariant*);
238 // Grants permission for desktop notifications to an origin
239 void grantDesktopNotificationPermission(const CppArgumentList&, CppVariant*);
240 // Simulates a click on a desktop notification.
241 void simulateDesktopNotificationClick(const CppArgumentList&, CppVariant*);
243 void setDomainRelaxationForbiddenForURLScheme(const CppArgumentList&, CppVariant*);
244 void setDeferMainResourceDataLoad(const CppArgumentList&, CppVariant*);
245 void setEditingBehavior(const CppArgumentList&, CppVariant*);
247 // The following are only stubs. TODO(pamg): Implement any of these that
248 // are needed to pass the layout tests.
249 void dumpAsWebArchive(const CppArgumentList&, CppVariant*);
250 void dumpTitleChanges(const CppArgumentList&, CppVariant*);
251 void setMainFrameIsFirstResponder(const CppArgumentList&, CppVariant*);
252 void display(const CppArgumentList&, CppVariant*);
253 void displayInvalidatedRegion(const CppArgumentList&, CppVariant*);
254 void testRepaint(const CppArgumentList&, CppVariant*);
255 void repaintSweepHorizontally(const CppArgumentList&, CppVariant*);
256 void clearBackForwardList(const CppArgumentList&, CppVariant*);
257 void keepWebHistory(const CppArgumentList&, CppVariant*);
258 void storeWebScriptObject(const CppArgumentList&, CppVariant*);
259 void accessStoredWebScriptObject(const CppArgumentList&, CppVariant*);
260 void objCClassNameOf(const CppArgumentList&, CppVariant*);
261 void addDisallowedURL(const CppArgumentList&, CppVariant*);
262 void callShouldCloseOnWebView(const CppArgumentList&, CppVariant*);
263 void setCallCloseOnWebViews(const CppArgumentList&, CppVariant*);
264 void setPrivateBrowsingEnabled(const CppArgumentList&, CppVariant*);
266 void setJavaScriptCanAccessClipboard(const CppArgumentList&, CppVariant*);
267 void setXSSAuditorEnabled(const CppArgumentList&, CppVariant*);
268 void evaluateScriptInIsolatedWorld(const CppArgumentList&, CppVariant*);
269 void overridePreference(const CppArgumentList&, CppVariant*);
270 void setAllowUniversalAccessFromFileURLs(const CppArgumentList&, CppVariant*);
271 void setAllowFileAccessFromFileURLs(const CppArgumentList&, CppVariant*);
274 // The fallback method is called when a nonexistent method is called on
275 // the layout test controller object.
276 // It is usefull to catch typos in the JavaScript code (a few layout tests
277 // do have typos in them) and it allows the script to continue running in
278 // that case (as the Mac does).
279 void fallbackMethod(const CppArgumentList&, CppVariant*);
281 // Allows layout tests to manage origins' whitelisting.
282 void addOriginAccessWhitelistEntry(const CppArgumentList&, CppVariant*);
283 void removeOriginAccessWhitelistEntry(const CppArgumentList&, CppVariant*);
285 // Clears all Application Caches.
286 void clearAllApplicationCaches(const CppArgumentList&, CppVariant*);
287 // Sets the Application Quota for the localhost origin.
288 void setApplicationCacheOriginQuota(const CppArgumentList&, CppVariant*);
290 // Clears all databases.
291 void clearAllDatabases(const CppArgumentList&, CppVariant*);
292 // Sets the default quota for all origins
293 void setDatabaseQuota(const CppArgumentList&, CppVariant*);
295 // Calls setlocale(LC_ALL, ...) for a specified locale.
296 // Resets between tests.
297 void setPOSIXLocale(const CppArgumentList&, CppVariant*);
299 // Gets the value of the counter in the element specified by its ID.
300 void counterValueForElementById(const CppArgumentList&, CppVariant*);
302 // Gets the number of page where the specified element will be put.
303 void pageNumberForElementById(const CppArgumentList&, CppVariant*);
305 // Gets the number of pages to be printed.
306 void numberOfPages(const CppArgumentList&, CppVariant*);
309 // Allows layout tests to start Timeline profiling.
310 void setTimelineProfilingEnabled(const CppArgumentList&, CppVariant*);
312 // Allows layout tests to exec scripts at WebInspector side.
313 void evaluateInWebInspector(const CppArgumentList&, CppVariant*);
315 // Adds a user script or user style sheet to be injected into new documents.
316 void addUserScript(const CppArgumentList&, CppVariant*);
317 void addUserStyleSheet(const CppArgumentList&, CppVariant*);
319 // DeviceOrientation related functions
320 void setMockDeviceOrientation(const CppArgumentList&, CppVariant*);
322 // Geolocation related functions.
323 void setGeolocationPermission(const CppArgumentList&, CppVariant*);
324 void setMockGeolocationPosition(const CppArgumentList&, CppVariant*);
325 void setMockGeolocationError(const CppArgumentList&, CppVariant*);
327 // Empty stub method to keep parity with object model exposed by global LayoutTestController.
328 void abortModal(const CppArgumentList&, CppVariant*);
330 // Speech input related functions.
331 void addMockSpeechInputResult(const CppArgumentList&, CppVariant*);
333 void layerTreeAsText(const CppArgumentList& args, CppVariant* result);
335 void markerTextForListItem(const CppArgumentList&, CppVariant*);
336 void hasSpellingMarker(const CppArgumentList&, CppVariant*);
339 // The following methods are not exposed to JavaScript.
340 void setWorkQueueFrozen(bool frozen) { m_workQueue.setFrozen(frozen); }
342 WebKit::WebSpeechInputController* speechInputController(WebKit::WebSpeechInputListener*);
343 bool shouldDumpAsText() { return m_dumpAsText; }
344 bool shouldDumpEditingCallbacks() { return m_dumpEditingCallbacks; }
345 bool shouldDumpFrameLoadCallbacks() { return m_dumpFrameLoadCallbacks; }
346 void setShouldDumpFrameLoadCallbacks(bool value) { m_dumpFrameLoadCallbacks = value; }
347 bool shouldDumpUserGestureInFrameLoadCallbacks() { return m_dumpUserGestureInFrameLoadCallbacks; }
348 void setShouldDumpUserGestureInFrameLoadCallbacks(bool value) { m_dumpUserGestureInFrameLoadCallbacks = value; }
349 bool shouldDumpResourceLoadCallbacks() {return m_dumpResourceLoadCallbacks; }
350 void setShouldDumpResourceResponseMIMETypes(bool value) { m_dumpResourceResponseMIMETypes = value; }
351 bool shouldDumpResourceResponseMIMETypes() {return m_dumpResourceResponseMIMETypes; }
352 bool shouldDumpStatusCallbacks() { return m_dumpWindowStatusChanges; }
353 bool shouldDumpSelectionRect() { return m_dumpSelectionRect; }
354 bool shouldDumpBackForwardList() { return m_dumpBackForwardList; }
355 bool shouldDumpTitleChanges() { return m_dumpTitleChanges; }
356 bool shouldDumpChildFrameScrollPositions() { return m_dumpChildFrameScrollPositions; }
357 bool shouldDumpChildFramesAsText() { return m_dumpChildFramesAsText; }
358 bool shouldGeneratePixelResults() { return m_generatePixelResults; }
359 bool acceptsEditing() { return m_acceptsEditing; }
360 bool canOpenWindows() { return m_canOpenWindows; }
361 bool shouldAddFileToPasteboard() { return m_shouldAddFileToPasteboard; }
362 bool stopProvisionalFrameLoads() { return m_stopProvisionalFrameLoads; }
363 bool deferMainResourceDataLoad() { return m_deferMainResourceDataLoad; }
365 bool testRepaint() const { return m_testRepaint; }
366 bool sweepHorizontally() const { return m_sweepHorizontally; }
368 // Called by the webview delegate when the toplevel frame load is done.
369 void locationChangeDone();
371 // Called by the webview delegate when the policy delegate runs if the
372 // waitForPolicyDelegate was called.
373 void policyDelegateDone();
375 // Reinitializes all static values. The reset() method should be called
376 // before the start of each test (currently from
377 // TestShell::runFileTest).
380 // A single item in the work queue.
383 virtual ~WorkItem() {}
385 // Returns true if this started a load.
386 virtual bool run(TestShell* shell) = 0;
389 TaskList* taskList() { return &m_taskList; }
392 friend class WorkItem;
393 friend class WorkQueue;
395 // Helper class for managing events queued by methods like queueLoad or
399 WorkQueue(LayoutTestController* controller) : m_frozen(false), m_controller(controller) {}
400 virtual ~WorkQueue();
401 void processWorkSoon();
403 // Reset the state of the class between tests.
406 void addWork(WorkItem* work);
408 void setFrozen(bool frozen) { m_frozen = frozen; }
409 bool isEmpty() { return m_queue.isEmpty(); }
410 TaskList* taskList() { return &m_taskList; }
414 class WorkQueueTask: public MethodTask<WorkQueue> {
416 WorkQueueTask(WorkQueue* object): MethodTask<WorkQueue>(object) {}
417 virtual void runIfValid() { m_object->processWork(); }
421 Deque<WorkItem*> m_queue;
423 LayoutTestController* m_controller;
426 // Support for overridePreference.
427 bool cppVariantToBool(const CppVariant&);
428 int32_t cppVariantToInt32(const CppVariant&);
429 WebKit::WebString cppVariantToWebString(const CppVariant&);
431 void logErrorToConsole(const std::string&);
432 void completeNotifyDone(bool isTimeout);
433 class NotifyDoneTimedOutTask: public MethodTask<LayoutTestController> {
435 NotifyDoneTimedOutTask(LayoutTestController* object): MethodTask<LayoutTestController>(object) {}
436 virtual void runIfValid() { m_object->completeNotifyDone(true); }
440 bool pauseAnimationAtTimeOnElementWithId(const WebKit::WebString& animationName, double time, const WebKit::WebString& elementId);
441 bool pauseTransitionAtTimeOnElementWithId(const WebKit::WebString& propertyName, double time, const WebKit::WebString& elementId);
442 bool elementDoesAutoCompleteForElementWithId(const WebKit::WebString&);
443 int numberOfActiveAnimations();
444 void suspendAnimations();
445 void resumeAnimations();
447 // Used for test timeouts.
450 // Non-owning pointer. The LayoutTestController is owned by the host.
453 // If true, the test_shell will produce a plain text dump rather than a
454 // text representation of the renderer.
457 // If true, the test_shell will write a descriptive line for each editing
459 bool m_dumpEditingCallbacks;
461 // If true, the test_shell will draw the bounds of the current selection rect
462 // taking possible transforms of the selection rect into account.
463 bool m_dumpSelectionRect;
465 // If true, the test_shell will output a descriptive line for each frame
467 bool m_dumpFrameLoadCallbacks;
469 // If true, the test_shell will output a line of the user gesture status
470 // text for some frame load callbacks.
471 bool m_dumpUserGestureInFrameLoadCallbacks;
473 // If true, the test_shell will output a descriptive line for each resource
475 bool m_dumpResourceLoadCallbacks;
477 // If true, the test_shell will output the MIME type for each resource that
479 bool m_dumpResourceResponseMIMETypes;
481 // If true, the test_shell will produce a dump of the back forward list as
483 bool m_dumpBackForwardList;
485 // If true, the test_shell will print out the child frame scroll offsets as
487 bool m_dumpChildFrameScrollPositions;
489 // If true and if dump_as_text_ is true, the test_shell will recursively
490 // dump all frames as plain text.
491 bool m_dumpChildFramesAsText;
493 // If true, the test_shell will dump all changes to window.status.
494 bool m_dumpWindowStatusChanges;
496 // If true, output a message when the page title is changed.
497 bool m_dumpTitleChanges;
499 // If true, the test_shell will generate pixel results in dumpAsText mode
500 bool m_generatePixelResults;
502 // If true, the element will be treated as editable. This value is returned
503 // from various editing callbacks that are called just before edit operations
505 bool m_acceptsEditing;
507 // If true, new windows can be opened via javascript or by plugins. By
508 // default, set to false and can be toggled to true using
509 // setCanOpenWindows().
510 bool m_canOpenWindows;
512 // When reset is called, go through and close all but the main test shell
513 // window. By default, set to true but toggled to false using
514 // setCloseRemainingWindowsWhenComplete().
515 bool m_closeRemainingWindows;
517 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
518 // individual paints over the height of the view.
520 // If true and test_repaint_ is true as well, pixel dump will be produced as
521 // a series of 1px-wide, view-tall paints across the width of the view.
522 bool m_sweepHorizontally;
524 // If true and a drag starts, adds a file to the drag&drop clipboard.
525 bool m_shouldAddFileToPasteboard;
527 // If true, stops provisional frame loads during the
528 // DidStartProvisionalLoadForFrame callback.
529 bool m_stopProvisionalFrameLoads;
531 // If true, don't dump output until notifyDone is called.
532 bool m_waitUntilDone;
534 // If false, all new requests will not defer the main resource data load.
535 bool m_deferMainResourceDataLoad;
537 WorkQueue m_workQueue;
539 CppVariant m_globalFlag;
541 // Bound variable counting the number of top URLs visited.
542 CppVariant m_webHistoryItemCount;
544 WebKit::WebURL m_userStyleSheetLocation;
546 OwnPtr<WebKit::WebSpeechInputControllerMock> m_speechInputControllerMock;
549 #endif // LayoutTestController_h