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);
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);
77 void setAllowUniversalAccessFromFileURLs(bool);
78 void setAllowFileAccessFromFileURLs(bool);
80 // Special DOM functions.
81 JSValueRef computedStyleIncludingVisitedInfo(JSValueRef element);
82 JSRetainPtr<JSStringRef> counterValueForElementById(JSStringRef elementId);
83 void clearBackForwardList();
84 void execCommand(JSStringRef name, JSStringRef argument);
85 bool isCommandEnabled(JSStringRef name);
86 JSRetainPtr<JSStringRef> markerTextForListItem(JSValueRef element);
87 unsigned windowCount();
88 JSValueRef shadowRoot(JSValueRef element);
91 void testRepaint() { m_testRepaint = true; }
92 void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
96 unsigned numberOfActiveAnimations() const;
97 bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
98 void suspendAnimations();
99 void resumeAnimations();
101 // Compositing testing.
102 JSRetainPtr<JSStringRef> layerTreeAsText() const;
104 // UserContent testing.
105 void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
106 void addUserStyleSheet(JSStringRef source, bool allFrames);
108 // Text search testing.
109 bool findString(JSStringRef, JSValueRef optionsArray);
112 void clearAllDatabases();
113 void setDatabaseQuota(uint64_t);
116 int numberOfPages(double pageWidthInPixels, double pageHeightInPixels);
117 int pageNumberForElementById(JSStringRef, double pageWidthInPixels, double pageHeightInPixels);
118 JSRetainPtr<JSStringRef> pageSizeAndMarginsInPixels(int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
120 enum WhatToDump { RenderTree, MainFrameText, AllFramesText };
121 WhatToDump whatToDump() const { return m_whatToDump; }
123 bool shouldDumpAllFrameScrollPositions() const { return m_shouldDumpAllFrameScrollPositions; }
124 bool shouldDumpBackForwardListsForAllWindows() const { return m_shouldDumpBackForwardListsForAllWindows; }
125 bool shouldDumpEditingCallbacks() const { return m_dumpEditingCallbacks; }
126 bool shouldDumpMainFrameScrollPosition() const { return m_whatToDump == RenderTree; }
127 bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
128 bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
129 bool shouldDumpPixels() const { return m_dumpPixels; }
131 bool waitToDump() const { return m_waitToDump; }
132 void waitToDumpWatchdogTimerFired();
133 void invalidateWaitToDumpWatchdogTimer();
135 bool shouldAllowEditing() const { return m_shouldAllowEditing; }
137 bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
139 void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
140 static unsigned worldIDForWorld(WKBundleScriptWorldRef);
142 void showWebInspector();
143 void closeWebInspector();
144 void evaluateInWebInspector(long callId, JSStringRef script);
145 void setTimelineProfilingEnabled(bool);
147 void setPOSIXLocale(JSStringRef);
149 bool willSendRequestReturnsNull() { return m_willSendRequestReturnsNull; }
150 void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
153 static const double waitToDumpWatchdogTimerInterval;
155 LayoutTestController();
157 void platformInitialize();
158 void initializeWaitToDumpWatchdogTimerIfNeeded();
160 WhatToDump m_whatToDump;
161 bool m_shouldDumpAllFrameScrollPositions;
162 bool m_shouldDumpBackForwardListsForAllWindows;
164 bool m_shouldAllowEditing;
165 bool m_shouldCloseExtraWindows;
167 bool m_dumpEditingCallbacks;
168 bool m_dumpStatusCallbacks;
169 bool m_dumpTitleChanges;
171 bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
173 bool m_testRepaintSweepHorizontally;
175 bool m_willSendRequestReturnsNull;
177 PlatformTimerRef m_waitToDumpWatchdogTimer;
182 #endif // LayoutTestController_h