OSDN Git Service

am 71d8d800: (-s ours) am 1441f89d: Do not merge -- restrict text selection to the...
[android-x86/external-webkit.git] / WebKitTools / DumpRenderTree / chromium / LayoutTestController.h
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  * Copyright (C) 2010 Pawel Hajdan (phajdan.jr@chromium.org)
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
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
14  * distribution.
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.
18  *
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.
30  */
31
32 /*
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.
39 */
40
41 #ifndef LayoutTestController_h
42 #define LayoutTestController_h
43
44 #include "CppBoundClass.h"
45 #include "base/timer.h" // FIXME: Remove this.
46 #include "public/WebString.h"
47 #include "public/WebURL.h"
48 #include <wtf/Deque.h>
49 #include <wtf/OwnPtr.h>
50
51 namespace WebKit {
52 class WebSpeechInputController;
53 class WebSpeechInputControllerMock;
54 class WebSpeechInputListener;
55 }
56
57 class TestShell;
58
59 class LayoutTestController : public CppBoundClass {
60 public:
61     // Builds the property and method lists needed to bind this class to a JS
62     // object.
63     LayoutTestController(TestShell*);
64
65     // This function sets a flag that tells the test_shell to dump pages as
66     // plain text, rather than as a text representation of the renderer's state.
67     // It takes an optional argument, whether to dump pixels results or not.
68     void dumpAsText(const CppArgumentList&, CppVariant*);
69
70     // This function should set a flag that tells the test_shell to print a line
71     // of descriptive text for each database command.  It should take no
72     // arguments, and ignore any that may be present. However, at the moment, we
73     // don't have any DB function that prints messages, so for now this function
74     // doesn't do anything.
75     void dumpDatabaseCallbacks(const CppArgumentList&, CppVariant*);
76
77     // This function sets a flag that tells the test_shell to print a line of
78     // descriptive text for each editing command.  It takes no arguments, and
79     // ignores any that may be present.
80     void dumpEditingCallbacks(const CppArgumentList&, CppVariant*);
81
82     // This function sets a flag that tells the test_shell to print a line of
83     // descriptive text for each frame load callback.  It takes no arguments, and
84     // ignores any that may be present.
85     void dumpFrameLoadCallbacks(const CppArgumentList&, CppVariant*);
86
87     // This function sets a flag that tells the test_shell to print out a text
88     // representation of the back/forward list.  It ignores all arguments.
89     void dumpBackForwardList(const CppArgumentList&, CppVariant*);
90
91     // This function sets a flag that tells the test_shell to print out the
92     // scroll offsets of the child frames.  It ignores all.
93     void dumpChildFrameScrollPositions(const CppArgumentList&, CppVariant*);
94
95     // This function sets a flag that tells the test_shell to recursively
96     // dump all frames as plain text if the dumpAsText flag is set.
97     // It takes no arguments, and ignores any that may be present.
98     void dumpChildFramesAsText(const CppArgumentList&, CppVariant*);
99
100     // This function sets a flag that tells the test_shell to dump all calls
101     // to window.status().
102     // It takes no arguments, and ignores any that may be present.
103     void dumpWindowStatusChanges(const CppArgumentList&, CppVariant*);
104
105     // When called with a boolean argument, this sets a flag that controls
106     // whether content-editable elements accept editing focus when an editing
107     // attempt is made. It ignores any additional arguments.
108     void setAcceptsEditing(const CppArgumentList&, CppVariant*);
109
110     // Functions for dealing with windows.  By default we block all new windows.
111     void windowCount(const CppArgumentList&, CppVariant*);
112     void setCanOpenWindows(const CppArgumentList&, CppVariant*);
113     void setCloseRemainingWindowsWhenComplete(const CppArgumentList&, CppVariant*);
114
115     // By default, tests end when page load is complete.  These methods are used
116     // to delay the completion of the test until notifyDone is called.
117     void waitUntilDone(const CppArgumentList&, CppVariant*);
118     void notifyDone(const CppArgumentList&, CppVariant*);
119     void notifyDoneTimedOut();
120
121     // Methods for adding actions to the work queue.  Used in conjunction with
122     // waitUntilDone/notifyDone above.
123     void queueBackNavigation(const CppArgumentList&, CppVariant*);
124     void queueForwardNavigation(const CppArgumentList&, CppVariant*);
125     void queueReload(const CppArgumentList&, CppVariant*);
126     void queueLoadingScript(const CppArgumentList&, CppVariant*);
127     void queueNonLoadingScript(const CppArgumentList&, CppVariant*);
128     void queueLoad(const CppArgumentList&, CppVariant*);
129
130     // Although this is named "objC" to match the Mac version, it actually tests
131     // the identity of its two arguments in C++.
132     void objCIdentityIsEqual(const CppArgumentList&, CppVariant*);
133
134     // Changes the cookie policy from the default to allow all cookies.
135     void setAlwaysAcceptCookies(const CppArgumentList&, CppVariant*);
136
137     // Shows DevTools window.
138     void showWebInspector(const CppArgumentList&, CppVariant*);
139     void closeWebInspector(const CppArgumentList&, CppVariant*);
140
141     // Gives focus to the window.
142     void setWindowIsKey(const CppArgumentList&, CppVariant*);
143
144     // Method that controls whether pressing Tab key cycles through page elements
145     // or inserts a '\t' char in text area
146     void setTabKeyCyclesThroughElements(const CppArgumentList&, CppVariant*);
147
148     // Passes through to WebPreferences which allows the user to have a custom
149     // style sheet.
150     void setUserStyleSheetEnabled(const CppArgumentList&, CppVariant*);
151     void setUserStyleSheetLocation(const CppArgumentList&, CppVariant*);
152
153     // Passes this preference through to WebSettings.
154     void setAuthorAndUserStylesEnabled(const CppArgumentList&, CppVariant*);
155
156     // Puts Webkit in "dashboard compatibility mode", which is used in obscure
157     // Mac-only circumstances. It's not really necessary, and will most likely
158     // never be used by Chrome, but some layout tests depend on its presence.
159     void setUseDashboardCompatibilityMode(const CppArgumentList&, CppVariant*);
160
161     void setScrollbarPolicy(const CppArgumentList&, CppVariant*);
162
163     // Causes navigation actions just printout the intended navigation instead
164     // of taking you to the page. This is used for cases like mailto, where you
165     // don't actually want to open the mail program.
166     void setCustomPolicyDelegate(const CppArgumentList&, CppVariant*);
167
168     // Delays completion of the test until the policy delegate runs.
169     void waitForPolicyDelegate(const CppArgumentList&, CppVariant*);
170
171     // Causes WillSendRequest to clear certain headers.
172     void setWillSendRequestClearHeader(const CppArgumentList&, CppVariant*);
173
174     // Causes WillSendRequest to block redirects.
175     void setWillSendRequestReturnsNullOnRedirect(const CppArgumentList&, CppVariant*);
176
177     // Causes WillSendRequest to return an empty request.
178     void setWillSendRequestReturnsNull(const CppArgumentList&, CppVariant*);
179
180     // Converts a URL starting with file:///tmp/ to the local mapping.
181     void pathToLocalResource(const CppArgumentList&, CppVariant*);
182
183     // Sets a bool such that when a drag is started, we fill the drag clipboard
184     // with a fake file object.
185     void addFileToPasteboardOnDrag(const CppArgumentList&, CppVariant*);
186
187     // Executes an internal command (superset of document.execCommand() commands).
188     void execCommand(const CppArgumentList&, CppVariant*);
189
190     // Checks if an internal command is currently available.
191     void isCommandEnabled(const CppArgumentList&, CppVariant*);
192
193     // Set the WebPreference that controls webkit's popup blocking.
194     void setPopupBlockingEnabled(const CppArgumentList&, CppVariant*);
195
196     // If true, causes provisional frame loads to be stopped for the remainder of
197     // the test.
198     void setStopProvisionalFrameLoads(const CppArgumentList&, CppVariant*);
199
200     // Enable or disable smart insert/delete.  This is enabled by default.
201     void setSmartInsertDeleteEnabled(const CppArgumentList&, CppVariant*);
202
203     // Enable or disable trailing whitespace selection on double click.
204     void setSelectTrailingWhitespaceEnabled(const CppArgumentList&, CppVariant*);
205
206     void pauseAnimationAtTimeOnElementWithId(const CppArgumentList&, CppVariant*);
207     void pauseTransitionAtTimeOnElementWithId(const CppArgumentList&, CppVariant*);
208     void elementDoesAutoCompleteForElementWithId(const CppArgumentList&, CppVariant*);
209     void numberOfActiveAnimations(const CppArgumentList&, CppVariant*);
210     void suspendAnimations(const CppArgumentList&, CppVariant*);
211     void resumeAnimations(const CppArgumentList&, CppVariant*);
212
213     void disableImageLoading(const CppArgumentList&, CppVariant*);
214
215     void setIconDatabaseEnabled(const CppArgumentList&, CppVariant*);
216
217     void dumpSelectionRect(const CppArgumentList&, CppVariant*);
218
219     // Grants permission for desktop notifications to an origin
220     void grantDesktopNotificationPermission(const CppArgumentList&, CppVariant*);
221     // Simulates a click on a desktop notification.
222     void simulateDesktopNotificationClick(const CppArgumentList&, CppVariant*);
223
224     void setEditingBehavior(const CppArgumentList&, CppVariant*);
225
226     // The following are only stubs.  TODO(pamg): Implement any of these that
227     // are needed to pass the layout tests.
228     void dumpAsWebArchive(const CppArgumentList&, CppVariant*);
229     void dumpTitleChanges(const CppArgumentList&, CppVariant*);
230     void dumpResourceLoadCallbacks(const CppArgumentList&, CppVariant*);
231     void setMainFrameIsFirstResponder(const CppArgumentList&, CppVariant*);
232     void display(const CppArgumentList&, CppVariant*);
233     void testRepaint(const CppArgumentList&, CppVariant*);
234     void repaintSweepHorizontally(const CppArgumentList&, CppVariant*);
235     void clearBackForwardList(const CppArgumentList&, CppVariant*);
236     void keepWebHistory(const CppArgumentList&, CppVariant*);
237     void storeWebScriptObject(const CppArgumentList&, CppVariant*);
238     void accessStoredWebScriptObject(const CppArgumentList&, CppVariant*);
239     void objCClassNameOf(const CppArgumentList&, CppVariant*);
240     void addDisallowedURL(const CppArgumentList&, CppVariant*);
241     void callShouldCloseOnWebView(const CppArgumentList&, CppVariant*);
242     void setCallCloseOnWebViews(const CppArgumentList&, CppVariant*);
243     void setPrivateBrowsingEnabled(const CppArgumentList&, CppVariant*);
244
245     void setJavaScriptCanAccessClipboard(const CppArgumentList&, CppVariant*);
246     void setXSSAuditorEnabled(const CppArgumentList&, CppVariant*);
247     void evaluateScriptInIsolatedWorld(const CppArgumentList&, CppVariant*);
248     void overridePreference(const CppArgumentList&, CppVariant*);
249     void setAllowUniversalAccessFromFileURLs(const CppArgumentList&, CppVariant*);
250     void setAllowFileAccessFromFileURLs(const CppArgumentList&, CppVariant*);
251
252
253     // The fallback method is called when a nonexistent method is called on
254     // the layout test controller object.
255     // It is usefull to catch typos in the JavaScript code (a few layout tests
256     // do have typos in them) and it allows the script to continue running in
257     // that case (as the Mac does).
258     void fallbackMethod(const CppArgumentList&, CppVariant*);
259
260     // Allows layout tests to manage origins' whitelisting.
261     void addOriginAccessWhitelistEntry(const CppArgumentList&, CppVariant*);
262     void removeOriginAccessWhitelistEntry(const CppArgumentList&, CppVariant*);
263
264     // Clears all Application Caches.
265     void clearAllApplicationCaches(const CppArgumentList&, CppVariant*);
266     // Sets the Application Quota for the localhost origin.
267     void setApplicationCacheOriginQuota(const CppArgumentList&, CppVariant*);
268
269     // Clears all databases.
270     void clearAllDatabases(const CppArgumentList&, CppVariant*);
271     // Sets the default quota for all origins
272     void setDatabaseQuota(const CppArgumentList&, CppVariant*);
273
274     // Calls setlocale(LC_ALL, ...) for a specified locale.
275     // Resets between tests.
276     void setPOSIXLocale(const CppArgumentList&, CppVariant*);
277
278     // Gets the value of the counter in the element specified by its ID.
279     void counterValueForElementById(const CppArgumentList&, CppVariant*);
280
281     // Gets the number of page where the specified element will be put.
282     void pageNumberForElementById(const CppArgumentList&, CppVariant*);
283
284     // Gets the number of pages to be printed.
285     void numberOfPages(const CppArgumentList&, CppVariant*);
286
287
288     // Allows layout tests to start Timeline profiling.
289     void setTimelineProfilingEnabled(const CppArgumentList&, CppVariant*);
290
291     // Allows layout tests to exec scripts at WebInspector side.
292     void evaluateInWebInspector(const CppArgumentList&, CppVariant*);
293
294     // Forces the selection colors for testing under Linux.
295     void forceRedSelectionColors(const CppArgumentList&, CppVariant*);
296
297     // Adds a user script or user style sheet to be injected into new documents.
298     void addUserScript(const CppArgumentList&, CppVariant*);
299     void addUserStyleSheet(const CppArgumentList&, CppVariant*);
300
301     // DeviceOrientation related functions
302     void setMockDeviceOrientation(const CppArgumentList&, CppVariant*);
303
304     // Geolocation related functions.
305     void setGeolocationPermission(const CppArgumentList&, CppVariant*);
306     void setMockGeolocationPosition(const CppArgumentList&, CppVariant*);
307     void setMockGeolocationError(const CppArgumentList&, CppVariant*);
308
309     // Empty stub method to keep parity with object model exposed by global LayoutTestController.
310     void abortModal(const CppArgumentList&, CppVariant*);
311
312     // Speech input related functions.
313     void setMockSpeechInputResult(const CppArgumentList&, CppVariant*);
314
315     void markerTextForListItem(const CppArgumentList&, CppVariant*);
316
317 public:
318     // The following methods are not exposed to JavaScript.
319     void setWorkQueueFrozen(bool frozen) { m_workQueue.setFrozen(frozen); }
320
321     WebKit::WebSpeechInputController* speechInputController(WebKit::WebSpeechInputListener*);
322     bool shouldDumpAsText() { return m_dumpAsText; }
323     bool shouldDumpEditingCallbacks() { return m_dumpEditingCallbacks; }
324     bool shouldDumpFrameLoadCallbacks() { return m_dumpFrameLoadCallbacks; }
325     void setShouldDumpFrameLoadCallbacks(bool value) { m_dumpFrameLoadCallbacks = value; }
326     bool shouldDumpResourceLoadCallbacks() {return m_dumpResourceLoadCallbacks; }
327     bool shouldDumpStatusCallbacks() { return m_dumpWindowStatusChanges; }
328     bool shouldDumpSelectionRect() { return m_dumpSelectionRect; }
329     bool shouldDumpBackForwardList() { return m_dumpBackForwardList; }
330     bool shouldDumpTitleChanges() { return m_dumpTitleChanges; }
331     bool shouldDumpChildFrameScrollPositions() { return m_dumpChildFrameScrollPositions; }
332     bool shouldDumpChildFramesAsText() { return m_dumpChildFramesAsText; }
333     bool shouldGeneratePixelResults() { return m_generatePixelResults; }
334     bool acceptsEditing() { return m_acceptsEditing; }
335     bool canOpenWindows() { return m_canOpenWindows; }
336     bool shouldAddFileToPasteboard() { return m_shouldAddFileToPasteboard; }
337     bool stopProvisionalFrameLoads() { return m_stopProvisionalFrameLoads; }
338
339     bool testRepaint() const { return m_testRepaint; }
340     bool sweepHorizontally() const { return m_sweepHorizontally; }
341
342     // Called by the webview delegate when the toplevel frame load is done.
343     void locationChangeDone();
344
345     // Called by the webview delegate when the policy delegate runs if the
346     // waitForPolicyDelegate was called.
347     void policyDelegateDone();
348
349     // Reinitializes all static values.  The reset() method should be called
350     // before the start of each test (currently from
351     // TestShell::runFileTest).
352     void reset();
353
354     // A single item in the work queue.
355     class WorkItem {
356     public:
357         virtual ~WorkItem() {}
358
359         // Returns true if this started a load.
360         virtual bool run(TestShell* shell) = 0;
361     };
362
363 private:
364     friend class WorkItem;
365     friend class WorkQueue;
366
367     // Helper class for managing events queued by methods like queueLoad or
368     // queueScript.
369     class WorkQueue {
370     public:
371         WorkQueue(LayoutTestController* controller) : m_frozen(false), m_controller(controller) {}
372         virtual ~WorkQueue();
373         void processWorkSoon();
374
375         // Reset the state of the class between tests.
376         void reset();
377
378         void addWork(WorkItem* work);
379
380         void setFrozen(bool frozen) { m_frozen = frozen; }
381         bool isEmpty() { return m_queue.isEmpty(); }
382
383     private:
384         void processWork();
385
386         base::OneShotTimer<WorkQueue> m_timer;
387         Deque<WorkItem*> m_queue;
388         bool m_frozen;
389         LayoutTestController* m_controller;
390     };
391
392     // Support for overridePreference.
393     bool cppVariantToBool(const CppVariant&);
394     int32_t cppVariantToInt32(const CppVariant&);
395     WebKit::WebString cppVariantToWebString(const CppVariant&);
396
397     void logErrorToConsole(const std::string&);
398     void completeNotifyDone(bool isTimeout);
399
400     bool pauseAnimationAtTimeOnElementWithId(const WebKit::WebString& animationName, double time, const WebKit::WebString& elementId);
401     bool pauseTransitionAtTimeOnElementWithId(const WebKit::WebString& propertyName, double time, const WebKit::WebString& elementId);
402     bool elementDoesAutoCompleteForElementWithId(const WebKit::WebString&);
403     int numberOfActiveAnimations();
404     void suspendAnimations();
405     void resumeAnimations();
406
407     // Used for test timeouts.
408     ScopedRunnableMethodFactory<LayoutTestController> m_timeoutFactory;
409
410     // Non-owning pointer.  The LayoutTestController is owned by the host.
411     TestShell* m_shell;
412
413     // If true, the test_shell will produce a plain text dump rather than a
414     // text representation of the renderer.
415     bool m_dumpAsText;
416
417     // If true, the test_shell will write a descriptive line for each editing
418     // command.
419     bool m_dumpEditingCallbacks;
420
421     // If true, the test_shell will draw the bounds of the current selection rect
422     // taking possible transforms of the selection rect into account.
423     bool m_dumpSelectionRect;
424
425     // If true, the test_shell will output a descriptive line for each frame
426     // load callback.
427     bool m_dumpFrameLoadCallbacks;
428
429     // If true, the test_shell will output a descriptive line for each resource
430     // load callback.
431     bool m_dumpResourceLoadCallbacks;
432
433     // If true, the test_shell will produce a dump of the back forward list as
434     // well.
435     bool m_dumpBackForwardList;
436
437     // If true, the test_shell will print out the child frame scroll offsets as
438     // well.
439     bool m_dumpChildFrameScrollPositions;
440
441     // If true and if dump_as_text_ is true, the test_shell will recursively
442     // dump all frames as plain text.
443     bool m_dumpChildFramesAsText;
444
445     // If true, the test_shell will dump all changes to window.status.
446     bool m_dumpWindowStatusChanges;
447
448     // If true, output a message when the page title is changed.
449     bool m_dumpTitleChanges;
450
451     // If true, the test_shell will generate pixel results in dumpAsText mode
452     bool m_generatePixelResults;
453
454     // If true, the element will be treated as editable.  This value is returned
455     // from various editing callbacks that are called just before edit operations
456     // are allowed.
457     bool m_acceptsEditing;
458
459     // If true, new windows can be opened via javascript or by plugins.  By
460     // default, set to false and can be toggled to true using
461     // setCanOpenWindows().
462     bool m_canOpenWindows;
463
464     // When reset is called, go through and close all but the main test shell
465     // window.  By default, set to true but toggled to false using
466     // setCloseRemainingWindowsWhenComplete().
467     bool m_closeRemainingWindows;
468
469     // If true, pixel dump will be produced as a series of 1px-tall, view-wide
470     // individual paints over the height of the view.
471     bool m_testRepaint;
472     // If true and test_repaint_ is true as well, pixel dump will be produced as
473     // a series of 1px-wide, view-tall paints across the width of the view.
474     bool m_sweepHorizontally;
475
476     // If true and a drag starts, adds a file to the drag&drop clipboard.
477     bool m_shouldAddFileToPasteboard;
478
479     // If true, stops provisional frame loads during the
480     // DidStartProvisionalLoadForFrame callback.
481     bool m_stopProvisionalFrameLoads;
482
483     // If true, don't dump output until notifyDone is called.
484     bool m_waitUntilDone;
485
486     WorkQueue m_workQueue;
487
488     CppVariant m_globalFlag;
489
490     // Bound variable counting the number of top URLs visited.
491     CppVariant m_webHistoryItemCount;
492
493     WebKit::WebURL m_userStyleSheetLocation;
494
495     OwnPtr<WebKit::WebSpeechInputControllerMock> m_speechInputControllerMock;
496 };
497
498 #endif // LayoutTestController_h