Add and remove cookie partition accordingly in intermediary redirect requests
[WebKit-https.git] / Tools / WebKitTestRunner / InjectedBundle / InjectedBundle.h
1 /*
2  * Copyright (C) 2010-2016 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 #pragma once
27
28 #include "EventSendingController.h"
29 #include "GCController.h"
30 #include "TestRunner.h"
31 #include "TextInputController.h"
32 #include <WebKit/WKBase.h>
33 #include <WebKit/WKRetainPtr.h>
34 #include <sstream>
35 #include <wtf/Forward.h>
36 #include <wtf/RefPtr.h>
37 #include <wtf/Vector.h>
38
39 #if HAVE(ACCESSIBILITY)
40 #include "AccessibilityController.h"
41 #endif
42
43 namespace WTR {
44
45 class InjectedBundlePage;
46
47 class InjectedBundle {
48 public:
49     static InjectedBundle& singleton();
50
51     // Initialize the InjectedBundle.
52     void initialize(WKBundleRef, WKTypeRef initializationUserData);
53
54     WKBundleRef bundle() const { return m_bundle; }
55     WKBundlePageGroupRef pageGroup() const { return m_pageGroup; }
56
57     TestRunner* testRunner() { return m_testRunner.get(); }
58     GCController* gcController() { return m_gcController.get(); }
59     EventSendingController* eventSendingController() { return m_eventSendingController.get(); }
60     TextInputController* textInputController() { return m_textInputController.get(); }
61 #if HAVE(ACCESSIBILITY)
62     AccessibilityController* accessibilityController() { return m_accessibilityController.get(); }
63 #endif
64
65     InjectedBundlePage* page() const;
66     size_t pageCount() const { return m_pages.size(); }
67     void closeOtherPages();
68
69     void dumpBackForwardListsForAllPages(StringBuilder&);
70
71     void done();
72     void setAudioResult(WKDataRef audioData) { m_audioResult = audioData; }
73     void setPixelResult(WKImageRef image) { m_pixelResult = image; m_pixelResultIsPending = false; }
74     void setPixelResultIsPending(bool isPending) { m_pixelResultIsPending = isPending; }
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     bool dumpJSConsoleLogInStdErr() const { return m_dumpJSConsoleLogInStdErr; };
85
86     void outputText(const String&);
87     void dumpToStdErr(const String&);
88     void postNewBeforeUnloadReturnValue(bool);
89     void postAddChromeInputField();
90     void postRemoveChromeInputField();
91     void postFocusWebView();
92     void postSetBackingScaleFactor(double);
93     void postSetWindowIsKey(bool);
94     void postSetViewSize(double width, double height);
95     void postSimulateWebNotificationClick(uint64_t notificationID);
96     void postSetAddsVisitedLinks(bool);
97
98     // Geolocation.
99     void setGeolocationPermission(bool);
100     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, bool providesFloorLevel, double floorLevel);
101     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
102     bool isGeolocationProviderActive() const;
103
104     // MediaStream.
105     void setUserMediaPermission(bool);
106     void resetUserMediaPermission();
107     void setUserMediaPersistentPermissionForOrigin(bool permission, WKStringRef origin, WKStringRef parentOrigin);
108     unsigned userMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin) const;
109     void resetUserMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin);
110
111     // Policy delegate.
112     void setCustomPolicyDelegate(bool enabled, bool permissive);
113
114     // Page Visibility.
115     void setHidden(bool);
116
117     // Cache.
118     void setCacheModel(int);
119
120     // Work queue.
121     bool shouldProcessWorkQueue() const;
122     void processWorkQueue();
123     void queueBackNavigation(unsigned howFarBackward);
124     void queueForwardNavigation(unsigned howFarForward);
125     void queueLoad(WKStringRef url, WKStringRef target, bool shouldOpenExternalURLs = false);
126     void queueLoadHTMLString(WKStringRef content, WKStringRef baseURL = 0, WKStringRef unreachableURL = 0);
127     void queueReload();
128     void queueLoadingScript(WKStringRef script);
129     void queueNonLoadingScript(WKStringRef script);
130
131     bool isAllowedHost(WKStringRef);
132
133     unsigned imageCountInGeneralPasteboard() const;
134
135     void setAllowsAnySSLCertificate(bool);
136
137     void statisticsNotifyObserver();
138
139 private:
140     InjectedBundle();
141     ~InjectedBundle();
142
143     static void didCreatePage(WKBundleRef, WKBundlePageRef, const void* clientInfo);
144     static void willDestroyPage(WKBundleRef, WKBundlePageRef, const void* clientInfo);
145     static void didInitializePageGroup(WKBundleRef, WKBundlePageGroupRef, const void* clientInfo);
146     static void didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo);
147     static void didReceiveMessageToPage(WKBundleRef, WKBundlePageRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo);
148
149     void didCreatePage(WKBundlePageRef);
150     void willDestroyPage(WKBundlePageRef);
151     void didInitializePageGroup(WKBundlePageGroupRef);
152     void didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody);
153     void didReceiveMessageToPage(WKBundlePageRef, WKStringRef messageName, WKTypeRef messageBody);
154
155     void platformInitialize(WKTypeRef initializationUserData);
156     void resetLocalSettings();
157
158     void beginTesting(WKDictionaryRef initialSettings);
159
160     bool booleanForKey(WKDictionaryRef, const char* key);
161
162     WKBundleRef m_bundle;
163     WKBundlePageGroupRef m_pageGroup;
164     Vector<std::unique_ptr<InjectedBundlePage>> m_pages;
165
166 #if HAVE(ACCESSIBILITY)
167     RefPtr<AccessibilityController> m_accessibilityController;
168 #endif
169     RefPtr<TestRunner> m_testRunner;
170     RefPtr<GCController> m_gcController;
171     RefPtr<EventSendingController> m_eventSendingController;
172     RefPtr<TextInputController> m_textInputController;
173
174     WKBundleFrameRef m_topLoadingFrame;
175
176     enum State {
177         Idle,
178         Testing,
179         Stopping
180     };
181     State m_state;
182
183     bool m_dumpPixels;
184     bool m_useWaitToDumpWatchdogTimer;
185     bool m_useWorkQueue;
186     int m_timeout;
187     bool m_pixelResultIsPending { false };
188     bool m_dumpJSConsoleLogInStdErr { false };
189
190     WKRetainPtr<WKDataRef> m_audioResult;
191     WKRetainPtr<WKImageRef> m_pixelResult;
192     WKRetainPtr<WKArrayRef> m_repaintRects;
193
194     Vector<String> m_allowedHosts;
195 };
196
197 } // namespace WTR