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 #include <CoreFoundation/CFRunLoop.h>
38 typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
40 typedef UINT_PTR PlatformTimerRef;
43 typedef QTimer PlatformTimerRef;
45 typedef unsigned int PlatformTimerRef;
50 class LayoutTestController : public JSWrappable {
52 static PassRefPtr<LayoutTestController> create();
53 virtual ~LayoutTestController();
56 virtual JSClassRef wrapperClass();
58 void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
61 void dumpAsText(bool dumpPixels);
62 void waitForPolicyDelegate();
63 void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
68 void dumpBackForwardList() { m_shouldDumpBackForwardListsForAllWindows = true; }
69 void dumpChildFrameScrollPositions() { m_shouldDumpAllFrameScrollPositions = true; }
70 void dumpEditingCallbacks() { m_dumpEditingCallbacks = true; }
71 void dumpSelectionRect() { } // Will need to do something when we support pixel tests.
72 void dumpStatusCallbacks() { m_dumpStatusCallbacks = true; }
73 void dumpTitleChanges() { m_dumpTitleChanges = true; }
74 void dumpFullScreenCallbacks() { m_dumpFullScreenCallbacks = true; }
77 void keepWebHistory();
78 void setAcceptsEditing(bool value) { m_shouldAllowEditing = value; }
79 void setCanOpenWindows(bool);
80 void setCloseRemainingWindowsWhenComplete(bool value) { m_shouldCloseExtraWindows = value; }
81 void setXSSAuditorEnabled(bool);
82 void setAllowUniversalAccessFromFileURLs(bool);
83 void setAllowFileAccessFromFileURLs(bool);
84 void setFrameFlatteningEnabled(bool);
85 void setJavaScriptCanAccessClipboard(bool);
86 void setPrivateBrowsingEnabled(bool);
87 void setAuthorAndUserStylesEnabled(bool);
88 void setCustomPolicyDelegate(bool enabled, bool permissive = false);
89 void addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
90 void removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
92 // Special DOM functions.
93 JSValueRef computedStyleIncludingVisitedInfo(JSValueRef element);
94 JSRetainPtr<JSStringRef> counterValueForElementById(JSStringRef elementId);
95 void clearBackForwardList();
96 void execCommand(JSStringRef name, JSStringRef argument);
97 bool isCommandEnabled(JSStringRef name);
98 JSRetainPtr<JSStringRef> markerTextForListItem(JSValueRef element);
99 unsigned windowCount();
102 void testRepaint() { m_testRepaint = true; }
103 void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
106 // Animation testing.
107 unsigned numberOfActiveAnimations() const;
108 bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
109 bool pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId);
110 void suspendAnimations();
111 void resumeAnimations();
113 // Compositing testing.
114 JSRetainPtr<JSStringRef> layerTreeAsText() const;
116 // UserContent testing.
117 void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
118 void addUserStyleSheet(JSStringRef source, bool allFrames);
120 // Text search testing.
121 bool findString(JSStringRef, JSValueRef optionsArray);
124 void clearAllDatabases();
125 void setDatabaseQuota(uint64_t);
126 JSRetainPtr<JSStringRef> pathToLocalResource(JSStringRef);
129 int numberOfPages(double pageWidthInPixels, double pageHeightInPixels);
130 int pageNumberForElementById(JSStringRef, double pageWidthInPixels, double pageHeightInPixels);
131 JSRetainPtr<JSStringRef> pageSizeAndMarginsInPixels(int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
132 bool isPageBoxVisible(int pageIndex);
134 enum WhatToDump { RenderTree, MainFrameText, AllFramesText };
135 WhatToDump whatToDump() const { return m_whatToDump; }
137 bool shouldDumpAllFrameScrollPositions() const { return m_shouldDumpAllFrameScrollPositions; }
138 bool shouldDumpBackForwardListsForAllWindows() const { return m_shouldDumpBackForwardListsForAllWindows; }
139 bool shouldDumpEditingCallbacks() const { return m_dumpEditingCallbacks; }
140 bool shouldDumpMainFrameScrollPosition() const { return m_whatToDump == RenderTree; }
141 bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
142 bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
143 bool shouldDumpPixels() const { return m_dumpPixels; }
144 bool shouldDumpFullScreenCallbacks() const { return m_dumpFullScreenCallbacks; }
145 bool isPolicyDelegateEnabled() const { return m_policyDelegateEnabled; }
146 bool isPolicyDelegatePermissive() const { return m_policyDelegatePermissive; }
148 bool waitToDump() const { return m_waitToDump; }
149 void waitToDumpWatchdogTimerFired();
150 void invalidateWaitToDumpWatchdogTimer();
152 bool shouldAllowEditing() const { return m_shouldAllowEditing; }
154 bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
156 void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
157 static unsigned worldIDForWorld(WKBundleScriptWorldRef);
159 void showWebInspector();
160 void closeWebInspector();
161 void evaluateInWebInspector(long callId, JSStringRef script);
162 void setJavaScriptProfilingEnabled(bool);
164 void setPOSIXLocale(JSStringRef);
166 bool willSendRequestReturnsNull() { return m_willSendRequestReturnsNull; }
167 void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
169 void setTextDirection(JSStringRef);
171 void setShouldStayOnPageAfterHandlingBeforeUnload(bool);
173 bool globalFlag() const { return m_globalFlag; }
174 void setGlobalFlag(bool value) { m_globalFlag = value; }
177 static const double waitToDumpWatchdogTimerInterval;
179 LayoutTestController();
181 void platformInitialize();
182 void initializeWaitToDumpWatchdogTimerIfNeeded();
184 WhatToDump m_whatToDump;
185 bool m_shouldDumpAllFrameScrollPositions;
186 bool m_shouldDumpBackForwardListsForAllWindows;
188 bool m_shouldAllowEditing;
189 bool m_shouldCloseExtraWindows;
191 bool m_dumpEditingCallbacks;
192 bool m_dumpStatusCallbacks;
193 bool m_dumpTitleChanges;
195 bool m_dumpFullScreenCallbacks;
196 bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
198 bool m_testRepaintSweepHorizontally;
200 bool m_willSendRequestReturnsNull;
202 bool m_policyDelegateEnabled;
203 bool m_policyDelegatePermissive;
207 PlatformTimerRef m_waitToDumpWatchdogTimer;
212 #endif // LayoutTestController_h