2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef LayoutTestController_h
27 #define LayoutTestController_h
29 #include "JSWrappable.h"
30 #include <JavaScriptCore/JSRetainPtr.h>
31 #include <WebKit2/WKBundleScriptWorld.h>
33 #include <wtf/PassRefPtr.h>
36 #include <wtf/RetainPtr.h>
37 typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
39 typedef UINT_PTR PlatformTimerRef;
42 typedef QTimer PlatformTimerRef;
47 class LayoutTestController : public JSWrappable {
49 static PassRefPtr<LayoutTestController> create();
50 virtual ~LayoutTestController();
53 virtual JSClassRef wrapperClass();
55 void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
58 void dumpAsText() { m_whatToDump = MainFrameText; }
59 void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
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; }
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);
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();
88 void testRepaint() { m_testRepaint = true; }
89 void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
93 unsigned numberOfActiveAnimations() const;
94 bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
95 void suspendAnimations();
96 void resumeAnimations();
98 // Compositing testing.
99 JSRetainPtr<JSStringRef> layerTreeAsText() const;
101 // UserContent testing.
102 void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
103 void addUserStyleSheet(JSStringRef source, bool allFrames);
105 // Text search testing.
106 bool findString(JSStringRef, JSValueRef optionsArray);
108 enum WhatToDump { RenderTree, MainFrameText, AllFramesText };
109 WhatToDump whatToDump() const { return m_whatToDump; }
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; }
118 bool waitToDump() const { return m_waitToDump; }
119 void waitToDumpWatchdogTimerFired();
120 void invalidateWaitToDumpWatchdogTimer();
122 bool shouldAllowEditing() const { return m_shouldAllowEditing; }
124 bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
126 void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
127 static unsigned worldIDForWorld(WKBundleScriptWorldRef);
129 void showWebInspector();
130 void closeWebInspector();
131 void evaluateInWebInspector(long callId, JSStringRef script);
132 void setTimelineProfilingEnabled(bool);
134 void setPOSIXLocale(JSStringRef);
136 bool willSendRequestReturnsNull() { return m_willSendRequestReturnsNull; }
137 void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
140 static const double waitToDumpWatchdogTimerInterval;
142 LayoutTestController();
144 void platformInitialize();
145 void initializeWaitToDumpWatchdogTimerIfNeeded();
147 WhatToDump m_whatToDump;
148 bool m_shouldDumpAllFrameScrollPositions;
149 bool m_shouldDumpBackForwardListsForAllWindows;
151 bool m_shouldAllowEditing;
152 bool m_shouldCloseExtraWindows;
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.
159 bool m_testRepaintSweepHorizontally;
161 bool m_willSendRequestReturnsNull;
163 PlatformTimerRef m_waitToDumpWatchdogTimer;
168 #endif // LayoutTestController_h