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);
119 enum WhatToDump { RenderTree, MainFrameText, AllFramesText };
120 WhatToDump whatToDump() const { return m_whatToDump; }
122 bool shouldDumpAllFrameScrollPositions() const { return m_shouldDumpAllFrameScrollPositions; }
123 bool shouldDumpBackForwardListsForAllWindows() const { return m_shouldDumpBackForwardListsForAllWindows; }
124 bool shouldDumpEditingCallbacks() const { return m_dumpEditingCallbacks; }
125 bool shouldDumpMainFrameScrollPosition() const { return m_whatToDump == RenderTree; }
126 bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
127 bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
128 bool shouldDumpPixels() const { return m_dumpPixels; }
130 bool waitToDump() const { return m_waitToDump; }
131 void waitToDumpWatchdogTimerFired();
132 void invalidateWaitToDumpWatchdogTimer();
134 bool shouldAllowEditing() const { return m_shouldAllowEditing; }
136 bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
138 void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
139 static unsigned worldIDForWorld(WKBundleScriptWorldRef);
141 void showWebInspector();
142 void closeWebInspector();
143 void evaluateInWebInspector(long callId, JSStringRef script);
144 void setTimelineProfilingEnabled(bool);
146 void setPOSIXLocale(JSStringRef);
148 bool willSendRequestReturnsNull() { return m_willSendRequestReturnsNull; }
149 void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
152 static const double waitToDumpWatchdogTimerInterval;
154 LayoutTestController();
156 void platformInitialize();
157 void initializeWaitToDumpWatchdogTimerIfNeeded();
159 WhatToDump m_whatToDump;
160 bool m_shouldDumpAllFrameScrollPositions;
161 bool m_shouldDumpBackForwardListsForAllWindows;
163 bool m_shouldAllowEditing;
164 bool m_shouldCloseExtraWindows;
166 bool m_dumpEditingCallbacks;
167 bool m_dumpStatusCallbacks;
168 bool m_dumpTitleChanges;
170 bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
172 bool m_testRepaintSweepHorizontally;
174 bool m_willSendRequestReturnsNull;
176 PlatformTimerRef m_waitToDumpWatchdogTimer;
181 #endif // LayoutTestController_h