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 #include "LayoutTestController.h"
28 #include "InjectedBundle.h"
29 #include "InjectedBundlePage.h"
30 #include "JSLayoutTestController.h"
31 #include <JavaScriptCore/JSRetainPtr.h>
32 #include <WebKit2/WKBundleFrame.h>
33 #include <WebKit2/WKRetainPtr.h>
34 #include <WebKit2/WKStringCF.h>
35 #include <WebKit2/WebKit2.h>
39 PassRefPtr<LayoutTestController> LayoutTestController::create(const std::string& testPathOrURL)
41 return adoptRef(new LayoutTestController(testPathOrURL));
44 LayoutTestController::LayoutTestController(const std::string& testPathOrURL)
46 , m_dumpStatusCallbacks(false)
48 , m_testRepaint(false)
49 , m_testRepaintSweepHorizontally(false)
50 , m_testPathOrURL(testPathOrURL)
54 LayoutTestController::~LayoutTestController()
58 JSClassRef LayoutTestController::wrapperClass()
60 return JSLayoutTestController::layoutTestControllerClass();
63 // This is lower than DumpRenderTree's timeout, to make it easier to work through the failures
64 // Eventually it should be changed to match.
65 static const CFTimeInterval waitToDumpWatchdogInterval = 6.0;
67 void LayoutTestController::display()
69 // FIXME: actually implement, once we want pixel tests
72 void LayoutTestController::invalidateWaitToDumpWatchdog()
74 if (m_waitToDumpWatchdog) {
75 CFRunLoopTimerInvalidate(m_waitToDumpWatchdog.get());
76 m_waitToDumpWatchdog = 0;
80 static void waitUntilDoneWatchdogFired(CFRunLoopTimerRef timer, void* info)
82 InjectedBundle::shared().layoutTestController()->waitToDumpWatchdogTimerFired();
85 void LayoutTestController::waitUntilDone()
88 if (!m_waitToDumpWatchdog) {
89 m_waitToDumpWatchdog.adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + waitToDumpWatchdogInterval,
90 0, 0, 0, waitUntilDoneWatchdogFired, NULL));
91 CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_waitToDumpWatchdog.get(), kCFRunLoopCommonModes);
95 void LayoutTestController::waitToDumpWatchdogTimerFired()
97 invalidateWaitToDumpWatchdog();
98 const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
99 InjectedBundle::shared().os() << message << "\n";
100 InjectedBundle::shared().done();
103 void LayoutTestController::notifyDone()
105 if (m_waitToDump && !InjectedBundle::shared().page()->isLoading())
106 InjectedBundle::shared().page()->dump();
107 m_waitToDump = false;
110 unsigned LayoutTestController::numberOfActiveAnimations() const
112 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
113 return WKBundleFrameGetNumberOfActiveAnimations(mainFrame);
116 bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId)
118 RetainPtr<CFStringRef> idCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, elementId));
119 WKRetainPtr<WKStringRef> idWK(AdoptWK, WKStringCreateWithCFString(idCF.get()));
120 RetainPtr<CFStringRef> nameCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, animationName));
121 WKRetainPtr<WKStringRef> nameWK(AdoptWK, WKStringCreateWithCFString(nameCF.get()));
123 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
124 return WKBundleFramePauseAnimationOnElementWithId(mainFrame, nameWK.get(), idWK.get(), time);
129 void LayoutTestController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
131 JSRetainPtr<JSStringRef> layoutTestContollerStr(Adopt, JSStringCreateWithUTF8CString("layoutTestController"));
132 JSObjectSetProperty(context, windowObject, layoutTestContollerStr.get(), JSWrapper::wrap(context, this), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);