layoutTestController.setBackingScaleFactor is redundant with (and less awesome than...
[WebKit-https.git] / Tools / WebKitTestRunner / InjectedBundle / InjectedBundle.h
1 /*
2  * Copyright (C) 2010, 2011, 2012 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 InjectedBundle_h
27 #define InjectedBundle_h
28
29 #include "AccessibilityController.h"
30 #include "EventSendingController.h"
31 #include "GCController.h"
32 #include "LayoutTestController.h"
33 #include "TextInputController.h"
34 #include <WebKit2/WKBase.h>
35 #include <WebKit2/WKRetainPtr.h>
36 #include <wtf/OwnPtr.h>
37 #include <wtf/RefPtr.h>
38 #include <wtf/Vector.h>
39
40 #include <sstream>
41
42 namespace WTF {
43 class StringBuilder;
44 }
45
46 namespace WTR {
47
48 class InjectedBundlePage;
49
50 class InjectedBundle {
51 public:
52     static InjectedBundle& shared();
53
54     // Initialize the InjectedBundle.
55     void initialize(WKBundleRef, WKTypeRef initializationUserData);
56
57     WKBundleRef bundle() const { return m_bundle; }
58     WKBundlePageGroupRef pageGroup() const { return m_pageGroup; }
59
60     LayoutTestController* layoutTestController() { return m_layoutTestController.get(); }
61     GCController* gcController() { return m_gcController.get(); }
62     EventSendingController* eventSendingController() { return m_eventSendingController.get(); }
63     TextInputController* textInputController() { return m_textInputController.get(); }
64     AccessibilityController* accessibilityController() { return m_accessibilityController.get(); }
65
66     InjectedBundlePage* page() const;
67     size_t pageCount() const { return m_pages.size(); }
68     void closeOtherPages();
69
70     void dumpBackForwardListsForAllPages();
71
72     void done();
73     WTF::StringBuilder* stringBuilder() { return m_stringBuilder.get(); }
74     void setPixelResult(WKImageRef image) { m_pixelResult = image; }
75     void setRepaintRects(WKArrayRef rects) { m_repaintRects = rects; }
76
77     bool isTestRunning() { return m_state == Testing; }
78
79     WKBundleFrameRef topLoadingFrame() { return m_topLoadingFrame; }
80     void setTopLoadingFrame(WKBundleFrameRef frame) { m_topLoadingFrame = frame; }
81
82     bool shouldDumpPixels() const { return m_dumpPixels; }
83     bool useWaitToDumpWatchdogTimer() const { return m_useWaitToDumpWatchdogTimer; }
84     
85     void postNewBeforeUnloadReturnValue(bool);
86     void postAddChromeInputField();
87     void postRemoveChromeInputField();
88     void postFocusWebView();
89     void postSetWindowIsKey(bool);
90
91 private:
92     InjectedBundle();
93     ~InjectedBundle();
94
95     static void didCreatePage(WKBundleRef, WKBundlePageRef, const void* clientInfo);
96     static void willDestroyPage(WKBundleRef, WKBundlePageRef, const void* clientInfo);
97     static void didInitializePageGroup(WKBundleRef, WKBundlePageGroupRef, const void* clientInfo);
98     static void didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo);
99
100     void didCreatePage(WKBundlePageRef);
101     void willDestroyPage(WKBundlePageRef);
102     void didInitializePageGroup(WKBundlePageGroupRef);
103     void didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody);
104
105     void platformInitialize(WKTypeRef initializationUserData);
106     void resetLocalSettings();
107
108     void beginTesting(WKDictionaryRef initialSettings);
109
110     bool booleanForKey(WKDictionaryRef, const char* key);
111
112     WKBundleRef m_bundle;
113     WKBundlePageGroupRef m_pageGroup;
114     Vector<OwnPtr<InjectedBundlePage> > m_pages;
115
116     RefPtr<AccessibilityController> m_accessibilityController;
117     RefPtr<LayoutTestController> m_layoutTestController;
118     RefPtr<GCController> m_gcController;
119     RefPtr<EventSendingController> m_eventSendingController;
120     RefPtr<TextInputController> m_textInputController;
121
122     WKBundleFrameRef m_topLoadingFrame;
123
124     OwnPtr<WTF::StringBuilder> m_stringBuilder;
125     
126     enum State {
127         Idle,
128         Testing,
129         Stopping
130     };
131     State m_state;
132
133     bool m_dumpPixels;
134     bool m_useWaitToDumpWatchdogTimer;
135
136     WKRetainPtr<WKImageRef> m_pixelResult;
137     WKRetainPtr<WKArrayRef> m_repaintRects;
138 };
139
140 } // namespace WTR
141
142 #endif // InjectedBundle_h