OSDN Git Service

Merge WebKit at r78450: Initial merge by git.
[android-x86/external-webkit.git] / Tools / WebKitTestRunner / InjectedBundle / LayoutTestController.h
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef LayoutTestController_h
27 #define LayoutTestController_h
28
29 #include "JSWrappable.h"
30 #include <JavaScriptCore/JSRetainPtr.h>
31 #include <WebKit2/WKBundleScriptWorld.h>
32 #include <string>
33 #include <wtf/PassRefPtr.h>
34
35 #if PLATFORM(MAC)
36 #include <wtf/RetainPtr.h>
37 typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
38 #elif PLATFORM(WIN)
39 typedef UINT_PTR PlatformTimerRef;
40 #elif PLATFORM(QT)
41 #include <QTimer>
42 typedef QTimer PlatformTimerRef;
43 #endif
44
45 namespace WTR {
46
47 class LayoutTestController : public JSWrappable {
48 public:
49     static PassRefPtr<LayoutTestController> create();
50     virtual ~LayoutTestController();
51
52     // JSWrappable
53     virtual JSClassRef wrapperClass();
54
55     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
56
57     // The basics.
58     void dumpAsText() { m_whatToDump = MainFrameText; }
59     void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
60     void waitUntilDone();
61     void notifyDone();
62
63     // Other dumping.
64     void dumpBackForwardList() { m_shouldDumpBackForwardListsForAllWindows = true; }
65     void dumpChildFrameScrollPositions() { m_shouldDumpAllFrameScrollPositions = true; }
66     void dumpEditingCallbacks() { m_dumpEditingCallbacks = true; }
67     void dumpSelectionRect() { } // Will need to do something when we support pixel tests.
68     void dumpStatusCallbacks() { m_dumpStatusCallbacks = true; }
69     void dumpTitleChanges() { m_dumpTitleChanges = true; }
70
71     // Special options.
72     void keepWebHistory();
73     void setAcceptsEditing(bool value) { m_shouldAllowEditing = value; }
74     void setCanOpenWindows(bool);
75     void setCloseRemainingWindowsWhenComplete(bool value) { m_shouldCloseExtraWindows = value; }
76     void setXSSAuditorEnabled(bool);
77
78     // Special DOM functions.
79     JSValueRef computedStyleIncludingVisitedInfo(JSValueRef element);
80     JSRetainPtr<JSStringRef> counterValueForElementById(JSStringRef elementId);
81     void clearBackForwardList();
82     void execCommand(JSStringRef name, JSStringRef argument);
83     bool isCommandEnabled(JSStringRef name);
84     JSRetainPtr<JSStringRef> markerTextForListItem(JSValueRef element);
85     unsigned windowCount();
86
87     // Repaint testing.
88     void testRepaint() { m_testRepaint = true; }
89     void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
90     void display();
91
92     // Animation testing.
93     unsigned numberOfActiveAnimations() const;
94     bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
95     void suspendAnimations();
96     void resumeAnimations();
97     
98     // Compositing testing.
99     JSRetainPtr<JSStringRef> layerTreeAsText() const;
100     
101     // UserContent testing.
102     void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
103     void addUserStyleSheet(JSStringRef source, bool allFrames);
104
105     // Text search testing.
106     bool findString(JSStringRef, JSValueRef optionsArray);
107
108     enum WhatToDump { RenderTree, MainFrameText, AllFramesText };
109     WhatToDump whatToDump() const { return m_whatToDump; }
110
111     bool shouldDumpAllFrameScrollPositions() const { return m_shouldDumpAllFrameScrollPositions; }
112     bool shouldDumpBackForwardListsForAllWindows() const { return m_shouldDumpBackForwardListsForAllWindows; }
113     bool shouldDumpEditingCallbacks() const { return m_dumpEditingCallbacks; }
114     bool shouldDumpMainFrameScrollPosition() const { return m_whatToDump == RenderTree; }
115     bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
116     bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
117
118     bool waitToDump() const { return m_waitToDump; }
119     void waitToDumpWatchdogTimerFired();
120     void invalidateWaitToDumpWatchdogTimer();
121
122     bool shouldAllowEditing() const { return m_shouldAllowEditing; }
123
124     bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
125
126     void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
127     static unsigned worldIDForWorld(WKBundleScriptWorldRef);
128
129     void showWebInspector();
130     void closeWebInspector();
131     void evaluateInWebInspector(long callId, JSStringRef script);
132     void setTimelineProfilingEnabled(bool);
133
134     void setPOSIXLocale(JSStringRef);
135
136     bool willSendRequestReturnsNull() { return m_willSendRequestReturnsNull; }
137     void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
138
139 private:
140     static const double waitToDumpWatchdogTimerInterval;
141
142     LayoutTestController();
143
144     void platformInitialize();
145     void initializeWaitToDumpWatchdogTimerIfNeeded();
146
147     WhatToDump m_whatToDump;
148     bool m_shouldDumpAllFrameScrollPositions;
149     bool m_shouldDumpBackForwardListsForAllWindows;
150
151     bool m_shouldAllowEditing;
152     bool m_shouldCloseExtraWindows;
153
154     bool m_dumpEditingCallbacks;
155     bool m_dumpStatusCallbacks;
156     bool m_dumpTitleChanges;
157     bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
158     bool m_testRepaint;
159     bool m_testRepaintSweepHorizontally;
160
161     bool m_willSendRequestReturnsNull;
162
163     PlatformTimerRef m_waitToDumpWatchdogTimer;
164 };
165
166 } // namespace WTR
167
168 #endif // LayoutTestController_h