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 TestController_h
27 #define TestController_h
29 #include <WebKit2/WKRetainPtr.h>
32 #include <wtf/OwnPtr.h>
37 class PlatformWebView;
38 class EventSenderProxy;
40 // FIXME: Rename this TestRunner?
41 class TestController {
43 static TestController& shared();
45 TestController(int argc, const char* argv[]);
48 bool verbose() const { return m_verbose; }
50 WKStringRef injectedBundlePath() { return m_injectedBundlePath.get(); }
51 WKStringRef testPluginDirectory() { return m_testPluginDirectory.get(); }
53 PlatformWebView* mainWebView() { return m_mainWebView.get(); }
54 WKContextRef context() { return m_context.get(); }
56 // Runs the run loop until `done` is true or the timeout elapses.
57 enum TimeoutDuration { ShortTimeout, LongTimeout, NoTimeout };
58 bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
59 void runUntil(bool& done, TimeoutDuration);
62 bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
63 void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
66 void initialize(int argc, const char* argv[]);
69 void runTestingServerLoop();
70 bool runTest(const char* pathOrURL);
72 void platformInitialize();
73 void platformInitializeContext();
74 void platformRunUntil(bool& done, double timeout);
75 void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
76 void initializeInjectedBundlePath();
77 void initializeTestPluginDirectory();
79 bool resetStateToConsistentValues();
81 // WKContextInjectedBundleClient
82 static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
83 static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
84 void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
85 WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
88 static void didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
89 void didCommitLoadForFrame(WKPageRef, WKFrameRef);
91 static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
92 void didFinishLoadForFrame(WKPageRef, WKFrameRef);
94 static void processDidCrash(WKPageRef, const void* clientInfo);
95 void processDidCrash();
97 static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*);
99 static void runModal(WKPageRef, const void* clientInfo);
100 static void runModal(PlatformWebView*);
102 static const char* libraryPathForTesting();
103 static const char* platformLibraryPathForTesting();
105 OwnPtr<TestInvocation> m_currentInvocation;
107 bool m_dumpPixelsForAllTests;
109 bool m_printSeparators;
110 bool m_usingServerMode;
111 bool m_gcBetweenTests;
112 std::vector<std::string> m_paths;
113 WKRetainPtr<WKStringRef> m_injectedBundlePath;
114 WKRetainPtr<WKStringRef> m_testPluginDirectory;
116 OwnPtr<PlatformWebView> m_mainWebView;
117 WKRetainPtr<WKContextRef> m_context;
118 WKRetainPtr<WKPageGroupRef> m_pageGroup;
126 bool m_doneResetting;
128 double m_longTimeout;
129 double m_shortTimeout;
131 bool m_useWaitToDumpWatchdogTimer;
132 bool m_forceNoTimeout;
134 bool m_didPrintWebProcessCrashedMessage;
135 bool m_shouldExitWhenWebProcessCrashes;
137 bool m_beforeUnloadReturnValue;
139 EventSenderProxy* m_eventSenderProxy;
144 #endif // TestController_h