Fixed somtimes focus ring is shown twice.
[framework/web/webkit-efl.git] / Tools / WebKitTestRunner / TestController.h
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25
26 #ifndef TestController_h
27 #define TestController_h
28
29 #include <WebKit2/WKRetainPtr.h>
30 #include <string>
31 #include <vector>
32 #include <wtf/OwnPtr.h>
33
34 namespace WTR {
35
36 class TestInvocation;
37 class PlatformWebView;
38 class EventSenderProxy;
39
40 // FIXME: Rename this TestRunner?
41 class TestController {
42 public:
43     static TestController& shared();
44
45     TestController(int argc, const char* argv[]);
46     ~TestController();
47
48     bool verbose() const { return m_verbose; }
49
50     WKStringRef injectedBundlePath() { return m_injectedBundlePath.get(); }
51     WKStringRef testPluginDirectory() { return m_testPluginDirectory.get(); }
52
53     PlatformWebView* mainWebView() { return m_mainWebView.get(); }
54     WKContextRef context() { return m_context.get(); }
55
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);
60     void notifyDone();
61     
62     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
63     void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
64
65 private:
66     void initialize(int argc, const char* argv[]);
67     void run();
68
69     void runTestingServerLoop();
70     bool runTest(const char* pathOrURL);
71
72     void platformInitialize();
73     void platformInitializeContext();
74     void platformRunUntil(bool& done, double timeout);
75     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
76     void initializeInjectedBundlePath();
77     void initializeTestPluginDirectory();
78
79     bool resetStateToConsistentValues();
80
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);
86
87     // WKPageLoaderClient
88     static void didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
89     void didCommitLoadForFrame(WKPageRef, WKFrameRef);
90
91     static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
92     void didFinishLoadForFrame(WKPageRef, WKFrameRef);
93
94     static void processDidCrash(WKPageRef, const void* clientInfo);
95     void processDidCrash();
96
97     static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*);
98
99     static void runModal(WKPageRef, const void* clientInfo);
100     static void runModal(PlatformWebView*);
101
102     static const char* libraryPathForTesting();
103     static const char* platformLibraryPathForTesting();
104
105     OwnPtr<TestInvocation> m_currentInvocation;
106
107     bool m_dumpPixelsForAllTests;
108     bool m_verbose;
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;
115
116     OwnPtr<PlatformWebView> m_mainWebView;
117     WKRetainPtr<WKContextRef> m_context;
118     WKRetainPtr<WKPageGroupRef> m_pageGroup;
119
120     enum State {
121         Initial,
122         Resetting,
123         RunningTest
124     };
125     State m_state;
126     bool m_doneResetting;
127
128     double m_longTimeout;
129     double m_shortTimeout;
130     double m_noTimeout;
131     bool m_useWaitToDumpWatchdogTimer;
132     bool m_forceNoTimeout;
133
134     bool m_didPrintWebProcessCrashedMessage;
135     bool m_shouldExitWhenWebProcessCrashes;
136     
137     bool m_beforeUnloadReturnValue;
138
139     EventSenderProxy* m_eventSenderProxy;
140 };
141
142 } // namespace WTR
143
144 #endif // TestController_h