REGRESSION (r230523): Caps lock indicator not shown in password field
[WebKit-https.git] / Tools / WebKitTestRunner / TestInvocation.cpp
1 /*
2  * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
3  * Copyright (C) 2012 Intel Corporation. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24  * THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "TestInvocation.h"
29
30 #include "PlatformWebView.h"
31 #include "StringFunctions.h"
32 #include "TestController.h"
33 #include "UIScriptController.h"
34 #include "WebCoreTestSupport.h"
35 #include <WebKit/WKContextPrivate.h>
36 #include <WebKit/WKCookieManager.h>
37 #include <WebKit/WKData.h>
38 #include <WebKit/WKDictionary.h>
39 #include <WebKit/WKInspector.h>
40 #include <WebKit/WKPagePrivate.h>
41 #include <WebKit/WKRetainPtr.h>
42 #include <WebKit/WKWebsiteDataStoreRef.h>
43 #include <climits>
44 #include <cstdio>
45 #include <unistd.h>
46 #include <wtf/StdLibExtras.h>
47 #include <wtf/text/CString.h>
48
49 #if PLATFORM(MAC) && !PLATFORM(IOS_FAMILY)
50 #include <Carbon/Carbon.h>
51 #endif
52
53 #if PLATFORM(COCOA)
54 #include <WebKit/WKPagePrivateMac.h>
55 #endif
56
57 using namespace JSC;
58 using namespace WebKit;
59 using namespace std;
60
61 namespace WTR {
62
63 TestInvocation::TestInvocation(WKURLRef url, const TestOptions& options)
64     : m_options(options)
65     , m_url(url)
66 {
67     WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyString(m_url.get()));
68
69     size_t stringLength = WKStringGetLength(urlString.get());
70
71     Vector<char> urlVector;
72     urlVector.resize(stringLength + 1);
73
74     WKStringGetUTF8CString(urlString.get(), urlVector.data(), stringLength + 1);
75
76     m_urlString = String(urlVector.data(), stringLength);
77
78     // FIXME: Avoid mutating the setting via a test directory like this.
79     m_dumpFrameLoadCallbacks = urlContains("loading/");
80 }
81
82 TestInvocation::~TestInvocation()
83 {
84     if (m_pendingUIScriptInvocationData)
85         m_pendingUIScriptInvocationData->testInvocation = nullptr;
86 }
87
88 WKURLRef TestInvocation::url() const
89 {
90     return m_url.get();
91 }
92
93 bool TestInvocation::urlContains(const char* searchString) const
94 {
95     return m_urlString.containsIgnoringASCIICase(searchString);
96 }
97
98 void TestInvocation::setIsPixelTest(const std::string& expectedPixelHash)
99 {
100     m_dumpPixels = true;
101     m_expectedPixelHash = expectedPixelHash;
102 }
103
104 WTF::Seconds TestInvocation::shortTimeout() const
105 {
106     if (!m_timeout) {
107         // Running WKTR directly, without webkitpy.
108         return TestController::defaultShortTimeout;
109     }
110
111     // This is not exactly correct for the way short timeout is used - it should not depend on whether a test is "slow",
112     // but it currently does. There is no way to know what a normal test's timeout is, as webkitpy only passes timeouts
113     // for each test individually.
114     // But there shouldn't be any observable negative consequences from this.
115     return m_timeout / 4;
116 }
117
118 bool TestInvocation::shouldLogHistoryClientCallbacks() const
119 {
120     return urlContains("globalhistory/");
121 }
122
123 WKRetainPtr<WKMutableDictionaryRef> TestInvocation::createTestSettingsDictionary()
124 {
125     WKRetainPtr<WKMutableDictionaryRef> beginTestMessageBody = adoptWK(WKMutableDictionaryCreate());
126
127     WKRetainPtr<WKStringRef> useFlexibleViewportKey = adoptWK(WKStringCreateWithUTF8CString("UseFlexibleViewport"));
128     WKRetainPtr<WKBooleanRef> useFlexibleViewportValue = adoptWK(WKBooleanCreate(options().useFlexibleViewport));
129     WKDictionarySetItem(beginTestMessageBody.get(), useFlexibleViewportKey.get(), useFlexibleViewportValue.get());
130
131     WKRetainPtr<WKStringRef> dumpPixelsKey = adoptWK(WKStringCreateWithUTF8CString("DumpPixels"));
132     WKRetainPtr<WKBooleanRef> dumpPixelsValue = adoptWK(WKBooleanCreate(m_dumpPixels));
133     WKDictionarySetItem(beginTestMessageBody.get(), dumpPixelsKey.get(), dumpPixelsValue.get());
134
135     WKRetainPtr<WKStringRef> useWaitToDumpWatchdogTimerKey = adoptWK(WKStringCreateWithUTF8CString("UseWaitToDumpWatchdogTimer"));
136     WKRetainPtr<WKBooleanRef> useWaitToDumpWatchdogTimerValue = adoptWK(WKBooleanCreate(TestController::singleton().useWaitToDumpWatchdogTimer()));
137     WKDictionarySetItem(beginTestMessageBody.get(), useWaitToDumpWatchdogTimerKey.get(), useWaitToDumpWatchdogTimerValue.get());
138
139     WKRetainPtr<WKStringRef> timeoutKey = adoptWK(WKStringCreateWithUTF8CString("Timeout"));
140     WKRetainPtr<WKUInt64Ref> timeoutValue = adoptWK(WKUInt64Create(m_timeout.milliseconds()));
141     WKDictionarySetItem(beginTestMessageBody.get(), timeoutKey.get(), timeoutValue.get());
142
143     WKRetainPtr<WKStringRef> dumpJSConsoleLogInStdErrKey = adoptWK(WKStringCreateWithUTF8CString("DumpJSConsoleLogInStdErr"));
144     WKRetainPtr<WKBooleanRef> dumpJSConsoleLogInStdErrValue = adoptWK(WKBooleanCreate(m_dumpJSConsoleLogInStdErr));
145     WKDictionarySetItem(beginTestMessageBody.get(), dumpJSConsoleLogInStdErrKey.get(), dumpJSConsoleLogInStdErrValue.get());
146     
147     return beginTestMessageBody;
148 }
149
150 void TestInvocation::invoke()
151 {
152     TestController::singleton().configureViewForTest(*this);
153
154     WKPageSetAddsVisitedLinks(TestController::singleton().mainWebView()->page(), false);
155
156     m_textOutput.clear();
157
158     TestController::singleton().setShouldLogHistoryClientCallbacks(shouldLogHistoryClientCallbacks());
159
160     WKCookieManagerSetHTTPCookieAcceptPolicy(WKContextGetCookieManager(TestController::singleton().context()), kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain);
161
162     // FIXME: We should clear out visited links here.
163
164     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("BeginTest"));
165     auto beginTestMessageBody = createTestSettingsDictionary();
166     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), beginTestMessageBody.get());
167
168     m_startedTesting = true;
169
170     bool shouldOpenExternalURLs = false;
171
172     TestController::singleton().runUntil(m_gotInitialResponse, TestController::noTimeout);
173     if (m_error)
174         goto end;
175
176     WKPageLoadURLWithShouldOpenExternalURLsPolicy(TestController::singleton().mainWebView()->page(), m_url.get(), shouldOpenExternalURLs);
177
178     TestController::singleton().runUntil(m_gotFinalMessage, TestController::noTimeout);
179     if (m_error)
180         goto end;
181
182     dumpResults();
183
184 end:
185 #if !PLATFORM(IOS_FAMILY)
186     if (m_gotInitialResponse)
187         WKInspectorClose(WKPageGetInspector(TestController::singleton().mainWebView()->page()));
188 #endif // !PLATFORM(IOS_FAMILY)
189
190     if (TestController::singleton().resetStateToConsistentValues(m_options, TestController::ResetStage::AfterTest))
191         return;
192
193     // The process is unresponsive, so let's start a new one.
194     TestController::singleton().terminateWebContentProcess();
195     // Make sure that we have a process, as invoke() will need one to send bundle messages for the next test.
196     TestController::singleton().reattachPageToWebProcess();
197 }
198
199 void TestInvocation::dumpWebProcessUnresponsiveness(const char* errorMessage)
200 {
201     fprintf(stderr, "%s", errorMessage);
202     char buffer[1024] = { };
203 #if PLATFORM(COCOA)
204     pid_t pid = WKPageGetProcessIdentifier(TestController::singleton().mainWebView()->page());
205     snprintf(buffer, sizeof(buffer), "#PROCESS UNRESPONSIVE - %s (pid %ld)\n", TestController::webProcessName(), static_cast<long>(pid));
206 #else
207     snprintf(buffer, sizeof(buffer), "#PROCESS UNRESPONSIVE - %s\n", TestController::webProcessName());
208 #endif
209
210     dump(errorMessage, buffer, true);
211     
212     if (!TestController::singleton().usingServerMode())
213         return;
214     
215     if (isatty(fileno(stdin)) || isatty(fileno(stderr)))
216         fputs("Grab an image of the stack, then hit enter...\n", stderr);
217     
218     if (!fgets(buffer, sizeof(buffer), stdin) || strcmp(buffer, "#SAMPLE FINISHED\n"))
219         fprintf(stderr, "Failed receive expected sample response, got:\n\t\"%s\"\nContinuing...\n", buffer);
220 }
221
222 void TestInvocation::dump(const char* textToStdout, const char* textToStderr, bool seenError)
223 {
224     printf("Content-Type: text/plain\n");
225     if (textToStdout)
226         fputs(textToStdout, stdout);
227     if (textToStderr)
228         fputs(textToStderr, stderr);
229
230     fputs("#EOF\n", stdout);
231     fputs("#EOF\n", stderr);
232     if (seenError)
233         fputs("#EOF\n", stdout);
234     fflush(stdout);
235     fflush(stderr);
236 }
237
238 void TestInvocation::forceRepaintDoneCallback(WKErrorRef error, void* context)
239 {
240     // The context may not be valid any more, e.g. if WebKit is invalidating callbacks at process exit.
241     if (error)
242         return;
243
244     TestInvocation* testInvocation = static_cast<TestInvocation*>(context);
245     RELEASE_ASSERT(TestController::singleton().isCurrentInvocation(testInvocation));
246
247     testInvocation->m_gotRepaint = true;
248     TestController::singleton().notifyDone();
249 }
250
251 void TestInvocation::dumpResults()
252 {
253     if (m_shouldDumpResourceLoadStatistics)
254         m_textOutput.append(m_savedResourceLoadStatistics.isNull() ? TestController::singleton().dumpResourceLoadStatistics() : m_savedResourceLoadStatistics);
255
256     if (m_textOutput.length() || !m_audioResult)
257         dump(m_textOutput.toString().utf8().data());
258     else
259         dumpAudio(m_audioResult.get());
260
261     if (m_dumpPixels) {
262         if (m_pixelResult)
263             dumpPixelsAndCompareWithExpected(SnapshotResultType::WebContents, m_repaintRects.get(), m_pixelResult.get());
264         else if (m_pixelResultIsPending) {
265             m_gotRepaint = false;
266             WKPageForceRepaint(TestController::singleton().mainWebView()->page(), this, TestInvocation::forceRepaintDoneCallback);
267             TestController::singleton().runUntil(m_gotRepaint, TestController::noTimeout);
268             dumpPixelsAndCompareWithExpected(SnapshotResultType::WebView, m_repaintRects.get());
269         }
270     }
271
272     fputs("#EOF\n", stdout);
273     fflush(stdout);
274     fflush(stderr);
275 }
276
277 void TestInvocation::dumpAudio(WKDataRef audioData)
278 {
279     size_t length = WKDataGetSize(audioData);
280     if (!length)
281         return;
282
283     const unsigned char* data = WKDataGetBytes(audioData);
284
285     printf("Content-Type: audio/wav\n");
286     printf("Content-Length: %lu\n", static_cast<unsigned long>(length));
287
288     fwrite(data, 1, length, stdout);
289     printf("#EOF\n");
290     fprintf(stderr, "#EOF\n");
291 }
292
293 bool TestInvocation::compareActualHashToExpectedAndDumpResults(const char actualHash[33])
294 {
295     // Compute the hash of the bitmap context pixels
296     fprintf(stdout, "\nActualHash: %s\n", actualHash);
297
298     if (!m_expectedPixelHash.length())
299         return false;
300
301     ASSERT(m_expectedPixelHash.length() == 32);
302     fprintf(stdout, "\nExpectedHash: %s\n", m_expectedPixelHash.c_str());
303
304     // FIXME: Do case insensitive compare.
305     return m_expectedPixelHash == actualHash;
306 }
307
308 void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
309 {
310     if (WKStringIsEqualToUTF8CString(messageName, "Error")) {
311         // Set all states to true to stop spinning the runloop.
312         m_gotInitialResponse = true;
313         m_gotFinalMessage = true;
314         m_error = true;
315         TestController::singleton().notifyDone();
316         return;
317     }
318
319     if (WKStringIsEqualToUTF8CString(messageName, "Ack")) {
320         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
321         WKStringRef messageBodyString = static_cast<WKStringRef>(messageBody);
322         if (WKStringIsEqualToUTF8CString(messageBodyString, "BeginTest")) {
323             m_gotInitialResponse = true;
324             TestController::singleton().notifyDone();
325             return;
326         }
327
328         ASSERT_NOT_REACHED();
329     }
330
331     if (WKStringIsEqualToUTF8CString(messageName, "Done")) {
332         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
333         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
334
335         WKRetainPtr<WKStringRef> pixelResultIsPendingKey = adoptWK(WKStringCreateWithUTF8CString("PixelResultIsPending"));
336         WKBooleanRef pixelResultIsPending = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultIsPendingKey.get()));
337         m_pixelResultIsPending = WKBooleanGetValue(pixelResultIsPending);
338
339         if (!m_pixelResultIsPending) {
340             WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult"));
341             m_pixelResult = static_cast<WKImageRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultKey.get()));
342             ASSERT(!m_pixelResult || m_dumpPixels);
343         }
344
345         WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects"));
346         m_repaintRects = static_cast<WKArrayRef>(WKDictionaryGetItemForKey(messageBodyDictionary, repaintRectsKey.get()));
347
348         WKRetainPtr<WKStringRef> audioResultKey =  adoptWK(WKStringCreateWithUTF8CString("AudioResult"));
349         m_audioResult = static_cast<WKDataRef>(WKDictionaryGetItemForKey(messageBodyDictionary, audioResultKey.get()));
350
351         m_gotFinalMessage = true;
352         TestController::singleton().notifyDone();
353         return;
354     }
355
356     if (WKStringIsEqualToUTF8CString(messageName, "TextOutput")) {
357         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
358         WKStringRef textOutput = static_cast<WKStringRef>(messageBody);
359         m_textOutput.append(toWTFString(textOutput));
360         return;
361     }
362
363     if (WKStringIsEqualToUTF8CString(messageName, "DumpToStdErr")) {
364         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
365         WKStringRef textOutput = static_cast<WKStringRef>(messageBody);
366         fprintf(stderr, "%s", toWTFString(textOutput).utf8().data());
367         return;
368     }
369
370     if (WKStringIsEqualToUTF8CString(messageName, "BeforeUnloadReturnValue")) {
371         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
372         WKBooleanRef beforeUnloadReturnValue = static_cast<WKBooleanRef>(messageBody);
373         TestController::singleton().setBeforeUnloadReturnValue(WKBooleanGetValue(beforeUnloadReturnValue));
374         return;
375     }
376     
377     if (WKStringIsEqualToUTF8CString(messageName, "AddChromeInputField")) {
378         TestController::singleton().mainWebView()->addChromeInputField();
379         WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallAddChromeInputFieldCallback"));
380         WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
381         return;
382     }
383
384     if (WKStringIsEqualToUTF8CString(messageName, "RemoveChromeInputField")) {
385         TestController::singleton().mainWebView()->removeChromeInputField();
386         WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallRemoveChromeInputFieldCallback"));
387         WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
388         return;
389     }
390     
391     if (WKStringIsEqualToUTF8CString(messageName, "FocusWebView")) {
392         TestController::singleton().mainWebView()->makeWebViewFirstResponder();
393         WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallFocusWebViewCallback"));
394         WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
395         return;
396     }
397
398     if (WKStringIsEqualToUTF8CString(messageName, "SetBackingScaleFactor")) {
399         ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID());
400         double backingScaleFactor = WKDoubleGetValue(static_cast<WKDoubleRef>(messageBody));
401         WKPageSetCustomBackingScaleFactor(TestController::singleton().mainWebView()->page(), backingScaleFactor);
402
403         WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallSetBackingScaleFactorCallback"));
404         WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
405         return;
406     }
407
408     if (WKStringIsEqualToUTF8CString(messageName, "SimulateWebNotificationClick")) {
409         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
410         uint64_t notificationID = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
411         TestController::singleton().simulateWebNotificationClick(notificationID);
412         return;
413     }
414
415     if (WKStringIsEqualToUTF8CString(messageName, "SetAddsVisitedLinks")) {
416         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
417         WKBooleanRef enabledWK = static_cast<WKBooleanRef>(messageBody);
418         WKPageSetAddsVisitedLinks(TestController::singleton().mainWebView()->page(), WKBooleanGetValue(enabledWK));
419         return;
420     }
421
422     if (WKStringIsEqualToUTF8CString(messageName, "SetGeolocationPermission")) {
423         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
424         WKBooleanRef enabledWK = static_cast<WKBooleanRef>(messageBody);
425         TestController::singleton().setGeolocationPermission(WKBooleanGetValue(enabledWK));
426         return;
427     }
428
429     if (WKStringIsEqualToUTF8CString(messageName, "SetMockGeolocationPosition")) {
430         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
431         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
432
433         WKRetainPtr<WKStringRef> latitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("latitude"));
434         WKDoubleRef latitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, latitudeKeyWK.get()));
435         double latitude = WKDoubleGetValue(latitudeWK);
436
437         WKRetainPtr<WKStringRef> longitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("longitude"));
438         WKDoubleRef longitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, longitudeKeyWK.get()));
439         double longitude = WKDoubleGetValue(longitudeWK);
440
441         WKRetainPtr<WKStringRef> accuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("accuracy"));
442         WKDoubleRef accuracyWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, accuracyKeyWK.get()));
443         double accuracy = WKDoubleGetValue(accuracyWK);
444
445         WKRetainPtr<WKStringRef> providesAltitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitude"));
446         WKBooleanRef providesAltitudeWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesAltitudeKeyWK.get()));
447         bool providesAltitude = WKBooleanGetValue(providesAltitudeWK);
448
449         WKRetainPtr<WKStringRef> altitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitude"));
450         WKDoubleRef altitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, altitudeKeyWK.get()));
451         double altitude = WKDoubleGetValue(altitudeWK);
452
453         WKRetainPtr<WKStringRef> providesAltitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitudeAccuracy"));
454         WKBooleanRef providesAltitudeAccuracyWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesAltitudeAccuracyKeyWK.get()));
455         bool providesAltitudeAccuracy = WKBooleanGetValue(providesAltitudeAccuracyWK);
456
457         WKRetainPtr<WKStringRef> altitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitudeAccuracy"));
458         WKDoubleRef altitudeAccuracyWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, altitudeAccuracyKeyWK.get()));
459         double altitudeAccuracy = WKDoubleGetValue(altitudeAccuracyWK);
460
461         WKRetainPtr<WKStringRef> providesHeadingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesHeading"));
462         WKBooleanRef providesHeadingWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesHeadingKeyWK.get()));
463         bool providesHeading = WKBooleanGetValue(providesHeadingWK);
464
465         WKRetainPtr<WKStringRef> headingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("heading"));
466         WKDoubleRef headingWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, headingKeyWK.get()));
467         double heading = WKDoubleGetValue(headingWK);
468
469         WKRetainPtr<WKStringRef> providesSpeedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesSpeed"));
470         WKBooleanRef providesSpeedWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesSpeedKeyWK.get()));
471         bool providesSpeed = WKBooleanGetValue(providesSpeedWK);
472
473         WKRetainPtr<WKStringRef> speedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("speed"));
474         WKDoubleRef speedWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, speedKeyWK.get()));
475         double speed = WKDoubleGetValue(speedWK);
476
477         WKRetainPtr<WKStringRef> providesFloorLevelKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesFloorLevel"));
478         WKBooleanRef providesFloorLevelWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesFloorLevelKeyWK.get()));
479         bool providesFloorLevel = WKBooleanGetValue(providesFloorLevelWK);
480
481         WKRetainPtr<WKStringRef> floorLevelKeyWK(AdoptWK, WKStringCreateWithUTF8CString("floorLevel"));
482         WKDoubleRef floorLevelWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, floorLevelKeyWK.get()));
483         double floorLevel = WKDoubleGetValue(floorLevelWK);
484
485         TestController::singleton().setMockGeolocationPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed, providesFloorLevel, floorLevel);
486         return;
487     }
488
489     if (WKStringIsEqualToUTF8CString(messageName, "SetMockGeolocationPositionUnavailableError")) {
490         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
491         WKStringRef errorMessage = static_cast<WKStringRef>(messageBody);
492         TestController::singleton().setMockGeolocationPositionUnavailableError(errorMessage);
493         return;
494     }
495
496     if (WKStringIsEqualToUTF8CString(messageName, "SetUserMediaPermission")) {
497         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
498         WKBooleanRef enabledWK = static_cast<WKBooleanRef>(messageBody);
499         TestController::singleton().setUserMediaPermission(WKBooleanGetValue(enabledWK));
500         return;
501     }
502
503     if (WKStringIsEqualToUTF8CString(messageName, "ResetUserMediaPermission")) {
504         TestController::singleton().resetUserMediaPermission();
505         return;
506     }
507
508     if (WKStringIsEqualToUTF8CString(messageName, "SetUserMediaPersistentPermissionForOrigin")) {
509         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
510         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
511
512         WKRetainPtr<WKStringRef> permissionKeyWK(AdoptWK, WKStringCreateWithUTF8CString("permission"));
513         WKBooleanRef permissionWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, permissionKeyWK.get()));
514         bool permission = WKBooleanGetValue(permissionWK);
515
516         WKRetainPtr<WKStringRef> originKey(AdoptWK, WKStringCreateWithUTF8CString("origin"));
517         WKStringRef originWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, originKey.get()));
518
519         WKRetainPtr<WKStringRef> parentOriginKey(AdoptWK, WKStringCreateWithUTF8CString("parentOrigin"));
520         WKStringRef parentOriginWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, parentOriginKey.get()));
521
522         TestController::singleton().setUserMediaPersistentPermissionForOrigin(permission, originWK, parentOriginWK);
523         return;
524     }
525
526     if (WKStringIsEqualToUTF8CString(messageName, "ResetUserMediaPermissionRequestCountForOrigin")) {
527         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
528         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
529
530         WKRetainPtr<WKStringRef> originKey(AdoptWK, WKStringCreateWithUTF8CString("origin"));
531         WKStringRef originWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, originKey.get()));
532
533         WKRetainPtr<WKStringRef> parentOriginKey(AdoptWK, WKStringCreateWithUTF8CString("parentOrigin"));
534         WKStringRef parentOriginWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, parentOriginKey.get()));
535         
536         TestController::singleton().resetUserMediaPermissionRequestCountForOrigin(originWK, parentOriginWK);
537         return;
538     }
539
540     if (WKStringIsEqualToUTF8CString(messageName, "SetCacheModel")) {
541         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
542         uint64_t model = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
543         WKContextSetCacheModel(TestController::singleton().context(), model);
544         return;
545     }
546
547     if (WKStringIsEqualToUTF8CString(messageName, "SetCustomPolicyDelegate")) {
548         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
549         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
550
551         WKRetainPtr<WKStringRef> enabledKeyWK(AdoptWK, WKStringCreateWithUTF8CString("enabled"));
552         WKBooleanRef enabledWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, enabledKeyWK.get()));
553         bool enabled = WKBooleanGetValue(enabledWK);
554
555         WKRetainPtr<WKStringRef> permissiveKeyWK(AdoptWK, WKStringCreateWithUTF8CString("permissive"));
556         WKBooleanRef permissiveWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, permissiveKeyWK.get()));
557         bool permissive = WKBooleanGetValue(permissiveWK);
558
559         TestController::singleton().setCustomPolicyDelegate(enabled, permissive);
560         return;
561     }
562
563     if (WKStringIsEqualToUTF8CString(messageName, "SetHidden")) {
564         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
565         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
566
567         WKRetainPtr<WKStringRef> isInitialKeyWK(AdoptWK, WKStringCreateWithUTF8CString("hidden"));
568         WKBooleanRef hiddenWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, isInitialKeyWK.get()));
569         bool hidden = WKBooleanGetValue(hiddenWK);
570
571         TestController::singleton().setHidden(hidden);
572         return;
573     }
574
575     if (WKStringIsEqualToUTF8CString(messageName, "ProcessWorkQueue")) {
576         if (TestController::singleton().workQueueManager().processWorkQueue()) {
577             WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("WorkQueueProcessedCallback"));
578             WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
579         }
580         return;
581     }
582
583     if (WKStringIsEqualToUTF8CString(messageName, "QueueBackNavigation")) {
584         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
585         uint64_t stepCount = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
586         TestController::singleton().workQueueManager().queueBackNavigation(stepCount);
587         return;
588     }
589
590     if (WKStringIsEqualToUTF8CString(messageName, "QueueForwardNavigation")) {
591         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
592         uint64_t stepCount = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
593         TestController::singleton().workQueueManager().queueForwardNavigation(stepCount);
594         return;
595     }
596
597     if (WKStringIsEqualToUTF8CString(messageName, "QueueLoad")) {
598         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
599         WKDictionaryRef loadDataDictionary = static_cast<WKDictionaryRef>(messageBody);
600
601         WKRetainPtr<WKStringRef> urlKey(AdoptWK, WKStringCreateWithUTF8CString("url"));
602         WKStringRef urlWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, urlKey.get()));
603
604         WKRetainPtr<WKStringRef> targetKey(AdoptWK, WKStringCreateWithUTF8CString("target"));
605         WKStringRef targetWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, targetKey.get()));
606
607         WKRetainPtr<WKStringRef> shouldOpenExternalURLsKey(AdoptWK, WKStringCreateWithUTF8CString("shouldOpenExternalURLs"));
608         WKBooleanRef shouldOpenExternalURLsValueWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(loadDataDictionary, shouldOpenExternalURLsKey.get()));
609
610         TestController::singleton().workQueueManager().queueLoad(toWTFString(urlWK), toWTFString(targetWK), WKBooleanGetValue(shouldOpenExternalURLsValueWK));
611         return;
612     }
613
614     if (WKStringIsEqualToUTF8CString(messageName, "QueueLoadHTMLString")) {
615         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
616         WKDictionaryRef loadDataDictionary = static_cast<WKDictionaryRef>(messageBody);
617
618         WKRetainPtr<WKStringRef> contentKey(AdoptWK, WKStringCreateWithUTF8CString("content"));
619         WKStringRef contentWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, contentKey.get()));
620
621         WKRetainPtr<WKStringRef> baseURLKey(AdoptWK, WKStringCreateWithUTF8CString("baseURL"));
622         WKStringRef baseURLWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, baseURLKey.get()));
623
624         WKRetainPtr<WKStringRef> unreachableURLKey(AdoptWK, WKStringCreateWithUTF8CString("unreachableURL"));
625         WKStringRef unreachableURLWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, unreachableURLKey.get()));
626
627         TestController::singleton().workQueueManager().queueLoadHTMLString(toWTFString(contentWK), baseURLWK ? toWTFString(baseURLWK) : String(), unreachableURLWK ? toWTFString(unreachableURLWK) : String());
628         return;
629     }
630
631     if (WKStringIsEqualToUTF8CString(messageName, "QueueReload")) {
632         TestController::singleton().workQueueManager().queueReload();
633         return;
634     }
635
636     if (WKStringIsEqualToUTF8CString(messageName, "QueueLoadingScript")) {
637         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
638         WKStringRef script = static_cast<WKStringRef>(messageBody);
639         TestController::singleton().workQueueManager().queueLoadingScript(toWTFString(script));
640         return;
641     }
642
643     if (WKStringIsEqualToUTF8CString(messageName, "QueueNonLoadingScript")) {
644         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
645         WKStringRef script = static_cast<WKStringRef>(messageBody);
646         TestController::singleton().workQueueManager().queueNonLoadingScript(toWTFString(script));
647         return;
648     }
649
650     if (WKStringIsEqualToUTF8CString(messageName, "SetRejectsProtectionSpaceAndContinueForAuthenticationChallenges")) {
651         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
652         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
653         TestController::singleton().setRejectsProtectionSpaceAndContinueForAuthenticationChallenges(WKBooleanGetValue(value));
654         return;
655     }
656
657     if (WKStringIsEqualToUTF8CString(messageName, "SetHandlesAuthenticationChallenges")) {
658         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
659         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
660         TestController::singleton().setHandlesAuthenticationChallenges(WKBooleanGetValue(value));
661         return;
662     }
663
664     if (WKStringIsEqualToUTF8CString(messageName, "SetShouldLogCanAuthenticateAgainstProtectionSpace")) {
665         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
666         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
667         TestController::singleton().setShouldLogCanAuthenticateAgainstProtectionSpace(WKBooleanGetValue(value));
668         return;
669     }
670
671     if (WKStringIsEqualToUTF8CString(messageName, "SetShouldLogDownloadCallbacks")) {
672         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
673         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
674         TestController::singleton().setShouldLogDownloadCallbacks(WKBooleanGetValue(value));
675         return;
676     }
677
678     if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationUsername")) {
679         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
680         WKStringRef username = static_cast<WKStringRef>(messageBody);
681         TestController::singleton().setAuthenticationUsername(toWTFString(username));
682         return;
683     }
684
685     if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationPassword")) {
686         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
687         WKStringRef password = static_cast<WKStringRef>(messageBody);
688         TestController::singleton().setAuthenticationPassword(toWTFString(password));
689         return;
690     }
691
692     if (WKStringIsEqualToUTF8CString(messageName, "SetBlockAllPlugins")) {
693         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
694         WKBooleanRef shouldBlock = static_cast<WKBooleanRef>(messageBody);
695         TestController::singleton().setBlockAllPlugins(WKBooleanGetValue(shouldBlock));
696         return;
697     }
698
699     if (WKStringIsEqualToUTF8CString(messageName, "SetPluginSupportedMode")) {
700         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
701         WKStringRef mode = static_cast<WKStringRef>(messageBody);
702         TestController::singleton().setPluginSupportedMode(toWTFString(mode));
703         return;
704     }
705
706     if (WKStringIsEqualToUTF8CString(messageName, "SetShouldDecideNavigationPolicyAfterDelay")) {
707         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
708         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
709         TestController::singleton().setShouldDecideNavigationPolicyAfterDelay(WKBooleanGetValue(value));
710         return;
711     }
712
713     if (WKStringIsEqualToUTF8CString(messageName, "SetShouldDecideResponsePolicyAfterDelay")) {
714         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
715         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
716         TestController::singleton().setShouldDecideResponsePolicyAfterDelay(WKBooleanGetValue(value));
717         return;
718     }
719
720     if (WKStringIsEqualToUTF8CString(messageName, "SetNavigationGesturesEnabled")) {
721         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
722         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
723         TestController::singleton().setNavigationGesturesEnabled(WKBooleanGetValue(value));
724         return;
725     }
726     
727     if (WKStringIsEqualToUTF8CString(messageName, "SetIgnoresViewportScaleLimits")) {
728         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
729         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
730         TestController::singleton().setIgnoresViewportScaleLimits(WKBooleanGetValue(value));
731         return;
732     }
733
734     if (WKStringIsEqualToUTF8CString(messageName, "SetShouldDownloadUndisplayableMIMETypes")) {
735         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
736         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
737         TestController::singleton().setShouldDownloadUndisplayableMIMETypes(WKBooleanGetValue(value));
738         return;
739     }
740
741     if (WKStringIsEqualToUTF8CString(messageName, "RunUIProcessScript")) {
742         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
743         WKRetainPtr<WKStringRef> scriptKey(AdoptWK, WKStringCreateWithUTF8CString("Script"));
744         WKRetainPtr<WKStringRef> callbackIDKey(AdoptWK, WKStringCreateWithUTF8CString("CallbackID"));
745
746         UIScriptInvocationData* invocationData = new UIScriptInvocationData();
747         invocationData->testInvocation = this;
748         invocationData->callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));
749         invocationData->scriptString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, scriptKey.get()));
750         m_pendingUIScriptInvocationData = invocationData;
751         WKPageCallAfterNextPresentationUpdate(TestController::singleton().mainWebView()->page(), invocationData, runUISideScriptAfterUpdateCallback);
752         return;
753     }
754
755     if (WKStringIsEqualToUTF8CString(messageName, "SetOpenPanelFileURLs")) {
756         TestController::singleton().setOpenPanelFileURLs(static_cast<WKArrayRef>(messageBody));
757         return;
758     }
759
760     ASSERT_NOT_REACHED();
761 }
762
763 WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
764 {
765     if (WKStringIsEqualToUTF8CString(messageName, "Initialization")) {
766         auto settings = createTestSettingsDictionary();
767         WKRetainPtr<WKStringRef> resumeTestingKey = adoptWK(WKStringCreateWithUTF8CString("ResumeTesting"));
768         WKRetainPtr<WKBooleanRef> resumeTestingValue = adoptWK(WKBooleanCreate(m_startedTesting));
769         WKDictionarySetItem(settings.get(), resumeTestingKey.get(), resumeTestingValue.get());
770         return settings;
771     }
772
773     if (WKStringIsEqualToUTF8CString(messageName, "SetDumpPixels")) {
774         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
775         m_dumpPixels = WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody));
776         return nullptr;
777     }
778     if (WKStringIsEqualToUTF8CString(messageName, "GetDumpPixels"))
779         return WKRetainPtr<WKTypeRef>(AdoptWK, WKBooleanCreate(m_dumpPixels));
780
781     if (WKStringIsEqualToUTF8CString(messageName, "SetWhatToDump")) {
782         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
783         m_whatToDump = static_cast<WhatToDump>(WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)));
784         return nullptr;
785     }
786     if (WKStringIsEqualToUTF8CString(messageName, "GetWhatToDump"))
787         return WKRetainPtr<WKTypeRef>(AdoptWK, WKUInt64Create(static_cast<uint64_t>(m_whatToDump)));
788
789     if (WKStringIsEqualToUTF8CString(messageName, "SetWaitUntilDone")) {
790         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
791         m_waitUntilDone = static_cast<unsigned char>(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)));
792         return nullptr;
793     }
794     if (WKStringIsEqualToUTF8CString(messageName, "GetWaitUntilDone"))
795         return WKRetainPtr<WKTypeRef>(AdoptWK, WKBooleanCreate(m_waitUntilDone));
796
797     if (WKStringIsEqualToUTF8CString(messageName, "SetDumpFrameLoadCallbacks")) {
798         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
799         m_dumpFrameLoadCallbacks = static_cast<unsigned char>(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)));
800         return nullptr;
801     }
802     if (WKStringIsEqualToUTF8CString(messageName, "GetDumpFrameLoadCallbacks"))
803         return WKRetainPtr<WKTypeRef>(AdoptWK, WKBooleanCreate(m_dumpFrameLoadCallbacks));
804
805     if (WKStringIsEqualToUTF8CString(messageName, "SetCanOpenWindows")) {
806         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
807         m_canOpenWindows = static_cast<unsigned char>(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)));
808         return nullptr;
809     }
810
811     if (WKStringIsEqualToUTF8CString(messageName, "SetWindowIsKey")) {
812         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
813         WKBooleanRef isKeyValue = static_cast<WKBooleanRef>(messageBody);
814         TestController::singleton().mainWebView()->setWindowIsKey(WKBooleanGetValue(isKeyValue));
815         return nullptr;
816     }
817
818     if (WKStringIsEqualToUTF8CString(messageName, "SetViewSize")) {
819         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
820
821         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
822         WKRetainPtr<WKStringRef> widthKey(AdoptWK, WKStringCreateWithUTF8CString("width"));
823         WKRetainPtr<WKStringRef> heightKey(AdoptWK, WKStringCreateWithUTF8CString("height"));
824
825         WKDoubleRef widthWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, widthKey.get()));
826         WKDoubleRef heightWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, heightKey.get()));
827
828         TestController::singleton().mainWebView()->resizeTo(WKDoubleGetValue(widthWK), WKDoubleGetValue(heightWK));
829         return nullptr;
830     }
831
832     if (WKStringIsEqualToUTF8CString(messageName, "IsGeolocationClientActive")) {
833         bool isActive = TestController::singleton().isGeolocationProviderActive();
834         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(isActive));
835         return result;
836     }
837
838     if (WKStringIsEqualToUTF8CString(messageName, "IsWorkQueueEmpty")) {
839         bool isEmpty = TestController::singleton().workQueueManager().isWorkQueueEmpty();
840         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(isEmpty));
841         return result;
842     }
843
844     if (WKStringIsEqualToUTF8CString(messageName, "DidReceiveServerRedirectForProvisionalNavigation")) {
845         WKRetainPtr<WKBooleanRef> result(AdoptWK, WKBooleanCreate(TestController::singleton().didReceiveServerRedirectForProvisionalNavigation()));
846         return result;
847     }
848
849     if (WKStringIsEqualToUTF8CString(messageName, "ClearDidReceiveServerRedirectForProvisionalNavigation")) {
850         TestController::singleton().clearDidReceiveServerRedirectForProvisionalNavigation();
851         return nullptr;
852     }
853
854     if (WKStringIsEqualToUTF8CString(messageName, "SecureEventInputIsEnabled")) {
855 #if PLATFORM(MAC) && !PLATFORM(IOS_FAMILY)
856         WKRetainPtr<WKBooleanRef> result(AdoptWK, WKBooleanCreate(IsSecureEventInputEnabled()));
857 #else
858         WKRetainPtr<WKBooleanRef> result(AdoptWK, WKBooleanCreate(false));
859 #endif
860         return result;
861     }
862
863     if (WKStringIsEqualToUTF8CString(messageName, "SetAlwaysAcceptCookies")) {
864         WKBooleanRef accept = static_cast<WKBooleanRef>(messageBody);
865         WKHTTPCookieAcceptPolicy policy = WKBooleanGetValue(accept) ? kWKHTTPCookieAcceptPolicyAlways : kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
866         // FIXME: This updates the policy in WebProcess and in NetworkProcess asynchronously, which might break some tests' expectations.
867         WKCookieManagerSetHTTPCookieAcceptPolicy(WKContextGetCookieManager(TestController::singleton().context()), policy);
868         return nullptr;
869     }
870
871     if (WKStringIsEqualToUTF8CString(messageName, "SetCustomUserAgent")) {
872         WKStringRef userAgent = static_cast<WKStringRef>(messageBody);
873         WKPageSetCustomUserAgent(TestController::singleton().mainWebView()->page(), userAgent);
874         return nullptr;
875     }
876
877     if (WKStringIsEqualToUTF8CString(messageName, "SetStorageAccessAPIEnabled")) {
878         WKBooleanRef accept = static_cast<WKBooleanRef>(messageBody);
879         WKCookieManagerSetStorageAccessAPIEnabled(WKContextGetCookieManager(TestController::singleton().context()), WKBooleanGetValue(accept));
880         return nullptr;
881     }
882
883     if (WKStringIsEqualToUTF8CString(messageName, "GetAllStorageAccessEntries")) {
884         TestController::singleton().getAllStorageAccessEntries();
885         return nullptr;
886     }
887
888     if (WKStringIsEqualToUTF8CString(messageName, "SetAllowsAnySSLCertificate")) {
889         TestController::singleton().setAllowsAnySSLCertificate(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)));
890         return nullptr;
891     }
892
893     if (WKStringIsEqualToUTF8CString(messageName, "ImageCountInGeneralPasteboard")) {
894         unsigned count = TestController::singleton().imageCountInGeneralPasteboard();
895         WKRetainPtr<WKUInt64Ref> result(AdoptWK, WKUInt64Create(count));
896         return result;
897     }
898     
899     if (WKStringIsEqualToUTF8CString(messageName, "DeleteAllIndexedDatabases")) {
900         WKWebsiteDataStoreRemoveAllIndexedDatabases(WKContextGetWebsiteDataStore(TestController::singleton().context()));
901         return nullptr;
902     }
903
904     if (WKStringIsEqualToUTF8CString(messageName, "AddMockMediaDevice")) {
905         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
906
907         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
908         WKRetainPtr<WKStringRef> persistentIDKey(AdoptWK, WKStringCreateWithUTF8CString("PersistentID"));
909         WKRetainPtr<WKStringRef> labelKey(AdoptWK, WKStringCreateWithUTF8CString("Label"));
910         WKRetainPtr<WKStringRef> typeKey(AdoptWK, WKStringCreateWithUTF8CString("Type"));
911
912         auto persistentID = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, persistentIDKey.get()));
913         auto label = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, labelKey.get()));
914         auto type = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, typeKey.get()));
915
916         TestController::singleton().addMockMediaDevice(persistentID, label, type);
917         return nullptr;
918     }
919
920     if (WKStringIsEqualToUTF8CString(messageName, "ClearMockMediaDevices")) {
921         TestController::singleton().clearMockMediaDevices();
922         return nullptr;
923     }
924
925     if (WKStringIsEqualToUTF8CString(messageName, "RemoveMockMediaDevice")) {
926         WKStringRef persistentId = static_cast<WKStringRef>(messageBody);
927
928         TestController::singleton().removeMockMediaDevice(persistentId);
929         return nullptr;
930     }
931
932     if (WKStringIsEqualToUTF8CString(messageName, "ResetMockMediaDevices")) {
933         TestController::singleton().resetMockMediaDevices();
934         return nullptr;
935     }
936
937 #if PLATFORM(MAC)
938     if (WKStringIsEqualToUTF8CString(messageName, "ConnectMockGamepad")) {
939         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
940
941         uint64_t index = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
942         WebCoreTestSupport::connectMockGamepad(index);
943         
944         return nullptr;
945     }
946
947     if (WKStringIsEqualToUTF8CString(messageName, "DisconnectMockGamepad")) {
948         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
949
950         uint64_t index = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
951         WebCoreTestSupport::disconnectMockGamepad(index);
952
953         return nullptr;
954     }
955
956     if (WKStringIsEqualToUTF8CString(messageName, "SetMockGamepadDetails")) {
957         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
958
959         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
960         WKRetainPtr<WKStringRef> gamepadIndexKey(AdoptWK, WKStringCreateWithUTF8CString("GamepadIndex"));
961         WKRetainPtr<WKStringRef> gamepadIDKey(AdoptWK, WKStringCreateWithUTF8CString("GamepadID"));
962         WKRetainPtr<WKStringRef> axisCountKey(AdoptWK, WKStringCreateWithUTF8CString("AxisCount"));
963         WKRetainPtr<WKStringRef> buttonCountKey(AdoptWK, WKStringCreateWithUTF8CString("ButtonCount"));
964
965         WKUInt64Ref gamepadIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIndexKey.get()));
966         WKStringRef gamepadID = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIDKey.get()));
967         WKUInt64Ref axisCount = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, axisCountKey.get()));
968         WKUInt64Ref buttonCount = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, buttonCountKey.get()));
969
970         WebCoreTestSupport::setMockGamepadDetails(WKUInt64GetValue(gamepadIndex), toWTFString(gamepadID), WKUInt64GetValue(axisCount), WKUInt64GetValue(buttonCount));
971         return nullptr;
972     }
973
974     if (WKStringIsEqualToUTF8CString(messageName, "SetMockGamepadAxisValue")) {
975         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
976
977         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
978         WKRetainPtr<WKStringRef> gamepadIndexKey(AdoptWK, WKStringCreateWithUTF8CString("GamepadIndex"));
979         WKRetainPtr<WKStringRef> axisIndexKey(AdoptWK, WKStringCreateWithUTF8CString("AxisIndex"));
980         WKRetainPtr<WKStringRef> valueKey(AdoptWK, WKStringCreateWithUTF8CString("Value"));
981
982         WKUInt64Ref gamepadIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIndexKey.get()));
983         WKUInt64Ref axisIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, axisIndexKey.get()));
984         WKDoubleRef value = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get()));
985
986         WebCoreTestSupport::setMockGamepadAxisValue(WKUInt64GetValue(gamepadIndex), WKUInt64GetValue(axisIndex), WKDoubleGetValue(value));
987
988         return nullptr;
989     }
990
991     if (WKStringIsEqualToUTF8CString(messageName, "SetMockGamepadButtonValue")) {
992         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
993
994         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
995         WKRetainPtr<WKStringRef> gamepadIndexKey(AdoptWK, WKStringCreateWithUTF8CString("GamepadIndex"));
996         WKRetainPtr<WKStringRef> buttonIndexKey(AdoptWK, WKStringCreateWithUTF8CString("ButtonIndex"));
997         WKRetainPtr<WKStringRef> valueKey(AdoptWK, WKStringCreateWithUTF8CString("Value"));
998
999         WKUInt64Ref gamepadIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIndexKey.get()));
1000         WKUInt64Ref buttonIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, buttonIndexKey.get()));
1001         WKDoubleRef value = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get()));
1002
1003         WebCoreTestSupport::setMockGamepadButtonValue(WKUInt64GetValue(gamepadIndex), WKUInt64GetValue(buttonIndex), WKDoubleGetValue(value));
1004
1005         return nullptr;
1006     }
1007 #endif // PLATFORM(MAC)
1008
1009     if (WKStringIsEqualToUTF8CString(messageName, "UserMediaPermissionRequestCountForOrigin")) {
1010         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1011         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1012
1013         WKRetainPtr<WKStringRef> originKey(AdoptWK, WKStringCreateWithUTF8CString("origin"));
1014         WKStringRef originWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, originKey.get()));
1015
1016         WKRetainPtr<WKStringRef> parentOriginKey(AdoptWK, WKStringCreateWithUTF8CString("parentOrigin"));
1017         WKStringRef parentOriginWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, parentOriginKey.get()));
1018         
1019         unsigned count = TestController::singleton().userMediaPermissionRequestCountForOrigin(originWK, parentOriginWK);
1020         WKRetainPtr<WKUInt64Ref> result(AdoptWK, WKUInt64Create(count));
1021         return result;
1022     }
1023
1024     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsDebugMode")) {
1025         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
1026         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
1027         TestController::singleton().setStatisticsDebugMode(WKBooleanGetValue(value));
1028         return nullptr;
1029     }
1030     
1031     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsPrevalentResourceForDebugMode")) {
1032         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1033         WKStringRef hostName = static_cast<WKStringRef>(messageBody);
1034         TestController::singleton().setStatisticsPrevalentResourceForDebugMode(hostName);
1035         return nullptr;
1036     }
1037     
1038     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsLastSeen")) {
1039         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1040         
1041         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1042         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1043         WKRetainPtr<WKStringRef> valueKey(AdoptWK, WKStringCreateWithUTF8CString("Value"));
1044         
1045         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1046         WKDoubleRef value = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get()));
1047         
1048         TestController::singleton().setStatisticsLastSeen(hostName, WKDoubleGetValue(value));
1049         
1050         return nullptr;
1051     }
1052     
1053     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsPrevalentResource")) {
1054         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1055
1056         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1057         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1058         WKRetainPtr<WKStringRef> valueKey(AdoptWK, WKStringCreateWithUTF8CString("Value"));
1059
1060         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1061         WKBooleanRef value = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get()));
1062
1063         TestController::singleton().setStatisticsPrevalentResource(hostName, WKBooleanGetValue(value));
1064         return nullptr;
1065     }
1066
1067     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsVeryPrevalentResource")) {
1068         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1069         
1070         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1071         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1072         WKRetainPtr<WKStringRef> valueKey(AdoptWK, WKStringCreateWithUTF8CString("Value"));
1073         
1074         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1075         WKBooleanRef value = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get()));
1076         
1077         TestController::singleton().setStatisticsVeryPrevalentResource(hostName, WKBooleanGetValue(value));
1078         return nullptr;
1079     }
1080     
1081     if (WKStringIsEqualToUTF8CString(messageName, "dumpResourceLoadStatistics")) {
1082         dumpResourceLoadStatistics();
1083         return nullptr;
1084     }
1085
1086     if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsPrevalentResource")) {
1087         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1088
1089         WKStringRef hostName = static_cast<WKStringRef>(messageBody);
1090         bool isPrevalent = TestController::singleton().isStatisticsPrevalentResource(hostName);
1091         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(isPrevalent));
1092         return result;
1093     }
1094
1095     if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsVeryPrevalentResource")) {
1096         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1097         
1098         WKStringRef hostName = static_cast<WKStringRef>(messageBody);
1099         bool isPrevalent = TestController::singleton().isStatisticsVeryPrevalentResource(hostName);
1100         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(isPrevalent));
1101         return result;
1102     }
1103     
1104     if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsRegisteredAsSubresourceUnder")) {
1105         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1106         
1107         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1108         WKRetainPtr<WKStringRef> subresourceHostKey(AdoptWK, WKStringCreateWithUTF8CString("SubresourceHost"));
1109         WKRetainPtr<WKStringRef> topFrameHostKey(AdoptWK, WKStringCreateWithUTF8CString("TopFrameHost"));
1110         
1111         WKStringRef subresourceHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, subresourceHostKey.get()));
1112         WKStringRef topFrameHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameHostKey.get()));
1113         
1114         bool isRegisteredAsSubresourceUnder = TestController::singleton().isStatisticsRegisteredAsSubresourceUnder(subresourceHost, topFrameHost);
1115         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(isRegisteredAsSubresourceUnder));
1116         return result;
1117     }
1118     
1119     if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsRegisteredAsSubFrameUnder")) {
1120         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1121         
1122         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1123         WKRetainPtr<WKStringRef> subFrameHostKey(AdoptWK, WKStringCreateWithUTF8CString("SubFrameHost"));
1124         WKRetainPtr<WKStringRef> topFrameHostKey(AdoptWK, WKStringCreateWithUTF8CString("TopFrameHost"));
1125         
1126         WKStringRef subFrameHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, subFrameHostKey.get()));
1127         WKStringRef topFrameHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameHostKey.get()));
1128
1129         bool isRegisteredAsSubFrameUnder = TestController::singleton().isStatisticsRegisteredAsSubFrameUnder(subFrameHost, topFrameHost);
1130         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(isRegisteredAsSubFrameUnder));
1131         return result;
1132     }
1133     
1134     if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsRegisteredAsRedirectingTo")) {
1135         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1136         
1137         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1138         WKRetainPtr<WKStringRef> hostRedirectedFromKey(AdoptWK, WKStringCreateWithUTF8CString("HostRedirectedFrom"));
1139         WKRetainPtr<WKStringRef> hostRedirectedToKey(AdoptWK, WKStringCreateWithUTF8CString("HostRedirectedTo"));
1140         
1141         WKStringRef hostRedirectedFrom = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostRedirectedFromKey.get()));
1142         WKStringRef hostRedirectedTo = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostRedirectedToKey.get()));
1143         
1144         bool isRegisteredAsRedirectingTo = TestController::singleton().isStatisticsRegisteredAsRedirectingTo(hostRedirectedFrom, hostRedirectedTo);
1145         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(isRegisteredAsRedirectingTo));
1146         return result;
1147     }
1148     
1149     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsHasHadUserInteraction")) {
1150         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1151         
1152         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1153         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1154         WKRetainPtr<WKStringRef> valueKey(AdoptWK, WKStringCreateWithUTF8CString("Value"));
1155         
1156         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1157         WKBooleanRef value = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get()));
1158         
1159         TestController::singleton().setStatisticsHasHadUserInteraction(hostName, WKBooleanGetValue(value));
1160         return nullptr;
1161     }
1162
1163     if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsHasHadUserInteraction")) {
1164         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1165         
1166         WKStringRef hostName = static_cast<WKStringRef>(messageBody);
1167         bool hasHadUserInteraction = TestController::singleton().isStatisticsHasHadUserInteraction(hostName);
1168         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(hasHadUserInteraction));
1169         return result;
1170     }
1171     
1172     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsGrandfathered")) {
1173         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1174         
1175         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1176         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1177         WKRetainPtr<WKStringRef> valueKey(AdoptWK, WKStringCreateWithUTF8CString("Value"));
1178         
1179         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1180         WKBooleanRef value = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get()));
1181         
1182         TestController::singleton().setStatisticsGrandfathered(hostName, WKBooleanGetValue(value));
1183         return nullptr;
1184     }
1185     
1186     if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsGrandfathered")) {
1187         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1188         
1189         WKStringRef hostName = static_cast<WKStringRef>(messageBody);
1190         bool isGrandfathered = TestController::singleton().isStatisticsGrandfathered(hostName);
1191         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(isGrandfathered));
1192         return result;
1193     }
1194     
1195     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsSubframeUnderTopFrameOrigin")) {
1196         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1197         
1198         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1199         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1200         WKRetainPtr<WKStringRef> topFrameHostNameKey(AdoptWK, WKStringCreateWithUTF8CString("TopFrameHostName"));
1201         
1202         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1203         WKStringRef topFrameHostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameHostNameKey.get()));
1204
1205         TestController::singleton().setStatisticsSubframeUnderTopFrameOrigin(hostName, topFrameHostName);
1206         return nullptr;
1207     }
1208     
1209     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsSubresourceUnderTopFrameOrigin")) {
1210         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1211         
1212         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1213         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1214         WKRetainPtr<WKStringRef> topFrameHostNameKey(AdoptWK, WKStringCreateWithUTF8CString("TopFrameHostName"));
1215         
1216         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1217         WKStringRef topFrameHostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameHostNameKey.get()));
1218         
1219         TestController::singleton().setStatisticsSubresourceUnderTopFrameOrigin(hostName, topFrameHostName);
1220         return nullptr;
1221     }
1222     
1223     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsSubresourceUniqueRedirectTo")) {
1224         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1225         
1226         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1227         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1228         WKRetainPtr<WKStringRef> hostNameRedirectedToKey(AdoptWK, WKStringCreateWithUTF8CString("HostNameRedirectedTo"));
1229         
1230         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1231         WKStringRef hostNameRedirectedTo = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameRedirectedToKey.get()));
1232         
1233         TestController::singleton().setStatisticsSubresourceUniqueRedirectTo(hostName, hostNameRedirectedTo);
1234         return nullptr;
1235     }
1236
1237     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsSubresourceUniqueRedirectFrom")) {
1238         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1239         
1240         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1241         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1242         WKRetainPtr<WKStringRef> hostNameRedirectedFromKey(AdoptWK, WKStringCreateWithUTF8CString("HostNameRedirectedFrom"));
1243         
1244         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1245         WKStringRef hostNameRedirectedFrom = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameRedirectedFromKey.get()));
1246         
1247         TestController::singleton().setStatisticsSubresourceUniqueRedirectFrom(hostName, hostNameRedirectedFrom);
1248         return nullptr;
1249     }
1250     
1251     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsTopFrameUniqueRedirectTo")) {
1252         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1253         
1254         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1255         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1256         WKRetainPtr<WKStringRef> hostNameRedirectedToKey(AdoptWK, WKStringCreateWithUTF8CString("HostNameRedirectedTo"));
1257         
1258         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1259         WKStringRef hostNameRedirectedTo = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameRedirectedToKey.get()));
1260         
1261         TestController::singleton().setStatisticsTopFrameUniqueRedirectTo(hostName, hostNameRedirectedTo);
1262         return nullptr;
1263     }
1264     
1265     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsTopFrameUniqueRedirectFrom")) {
1266         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1267         
1268         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
1269         WKRetainPtr<WKStringRef> hostNameKey(AdoptWK, WKStringCreateWithUTF8CString("HostName"));
1270         WKRetainPtr<WKStringRef> hostNameRedirectedFromKey(AdoptWK, WKStringCreateWithUTF8CString("HostNameRedirectedFrom"));
1271         
1272         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
1273         WKStringRef hostNameRedirectedFrom = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameRedirectedFromKey.get()));
1274         
1275         TestController::singleton().setStatisticsTopFrameUniqueRedirectFrom(hostName, hostNameRedirectedFrom);
1276         return nullptr;
1277     }
1278     
1279     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsTimeToLiveUserInteraction")) {
1280         ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID());
1281         WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody);
1282         TestController::singleton().setStatisticsTimeToLiveUserInteraction(WKDoubleGetValue(seconds));
1283         return nullptr;
1284     }
1285     
1286     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsProcessStatisticsAndDataRecords")) {
1287         TestController::singleton().statisticsProcessStatisticsAndDataRecords();
1288         return nullptr;
1289     }
1290     
1291     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsUpdateCookieBlocking")) {
1292         TestController::singleton().statisticsUpdateCookieBlocking();
1293         return nullptr;
1294     }
1295
1296     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsSubmitTelemetry")) {
1297         TestController::singleton().statisticsSubmitTelemetry();
1298         return nullptr;
1299     }
1300     
1301     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsNotifyPagesWhenDataRecordsWereScanned")) {
1302         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
1303         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
1304         TestController::singleton().setStatisticsNotifyPagesWhenDataRecordsWereScanned(WKBooleanGetValue(value));
1305         return nullptr;
1306     }
1307
1308     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsNotifyPagesWhenTelemetryWasCaptured")) {
1309         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
1310         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
1311         TestController::singleton().setStatisticsNotifyPagesWhenTelemetryWasCaptured(WKBooleanGetValue(value));
1312         return nullptr;
1313     }
1314     
1315     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsShouldClassifyResourcesBeforeDataRecordsRemoval")) {
1316         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
1317         WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
1318         TestController::singleton().setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(WKBooleanGetValue(value));
1319         return nullptr;
1320     }
1321
1322     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsMinimumTimeBetweenDataRecordsRemoval")) {
1323         ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID());
1324         WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody);
1325         TestController::singleton().setStatisticsMinimumTimeBetweenDataRecordsRemoval(WKDoubleGetValue(seconds));
1326         return nullptr;
1327     }
1328     
1329     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsGrandfatheringTime")) {
1330         ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID());
1331         WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody);
1332         TestController::singleton().setStatisticsGrandfatheringTime(WKDoubleGetValue(seconds));
1333         return nullptr;
1334     }
1335     
1336     if (WKStringIsEqualToUTF8CString(messageName, "SetMaxStatisticsEntries")) {
1337         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
1338         WKUInt64Ref entries = static_cast<WKUInt64Ref>(messageBody);
1339         TestController::singleton().setStatisticsMaxStatisticsEntries(WKUInt64GetValue(entries));
1340         return nullptr;
1341     }
1342     
1343     if (WKStringIsEqualToUTF8CString(messageName, "SetPruneEntriesDownTo")) {
1344         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
1345         WKUInt64Ref entries = static_cast<WKUInt64Ref>(messageBody);
1346         TestController::singleton().setStatisticsPruneEntriesDownTo(WKUInt64GetValue(entries));
1347         return nullptr;
1348     }
1349     
1350     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsClearInMemoryAndPersistentStore")) {
1351         TestController::singleton().statisticsClearInMemoryAndPersistentStore();
1352         return nullptr;
1353     }
1354     
1355     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsClearInMemoryAndPersistentStoreModifiedSinceHours")) {
1356         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
1357         WKUInt64Ref hours = static_cast<WKUInt64Ref>(messageBody);
1358         TestController::singleton().statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(WKUInt64GetValue(hours));
1359         return nullptr;
1360     }
1361     
1362     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsClearThroughWebsiteDataRemoval")) {
1363         TestController::singleton().statisticsClearThroughWebsiteDataRemoval();
1364         return nullptr;
1365     }
1366     
1367     if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsCacheMaxAgeCap")) {
1368         ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID());
1369         WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody);
1370         TestController::singleton().setStatisticsCacheMaxAgeCap(WKDoubleGetValue(seconds));
1371         return nullptr;
1372     }
1373
1374     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsResetToConsistentState")) {
1375         if (m_shouldDumpResourceLoadStatistics)
1376             m_savedResourceLoadStatistics = TestController::singleton().dumpResourceLoadStatistics();
1377         TestController::singleton().statisticsResetToConsistentState();
1378         return nullptr;
1379     }
1380
1381     if (WKStringIsEqualToUTF8CString(messageName, "RemoveAllSessionCredentials")) {
1382         TestController::singleton().removeAllSessionCredentials();
1383         return nullptr;
1384     }
1385
1386     if (WKStringIsEqualToUTF8CString(messageName, "ClearDOMCache")) {
1387         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1388         WKStringRef origin = static_cast<WKStringRef>(messageBody);
1389
1390         TestController::singleton().clearDOMCache(origin);
1391         return nullptr;
1392     }
1393
1394     if (WKStringIsEqualToUTF8CString(messageName, "ClearDOMCaches")) {
1395         TestController::singleton().clearDOMCaches();
1396         return nullptr;
1397     }
1398
1399     if (WKStringIsEqualToUTF8CString(messageName, "HasDOMCache")) {
1400         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1401         WKStringRef origin = static_cast<WKStringRef>(messageBody);
1402
1403         bool hasDOMCache = TestController::singleton().hasDOMCache(origin);
1404         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(hasDOMCache));
1405         return result;
1406     }
1407
1408     if (WKStringIsEqualToUTF8CString(messageName, "DOMCacheSize")) {
1409         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1410         WKStringRef origin = static_cast<WKStringRef>(messageBody);
1411
1412         auto domCacheSize = TestController::singleton().domCacheSize(origin);
1413         WKRetainPtr<WKTypeRef> result(AdoptWK, WKUInt64Create(domCacheSize));
1414         return result;
1415     }
1416
1417     if (WKStringIsEqualToUTF8CString(messageName, "SetIDBPerOriginQuota")) {
1418         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
1419         WKUInt64Ref quota = static_cast<WKUInt64Ref>(messageBody);
1420         TestController::singleton().setIDBPerOriginQuota(WKUInt64GetValue(quota));
1421         return nullptr;
1422     }
1423
1424     if (WKStringIsEqualToUTF8CString(messageName, "InjectUserScript")) {
1425         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1426         WKStringRef script = static_cast<WKStringRef>(messageBody);
1427
1428         TestController::singleton().injectUserScript(script);
1429         return nullptr;
1430     }
1431
1432     if (WKStringIsEqualToUTF8CString(messageName, "GetApplicationManifest")) {
1433 #ifdef __BLOCKS__
1434         WKPageGetApplicationManifest_b(TestController::singleton().mainWebView()->page(), ^{
1435             WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("DidGetApplicationManifest"));
1436             WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1437         });
1438 #else
1439         // FIXME: Add API for loading the manifest on non-__BLOCKS__ ports.
1440         ASSERT_NOT_REACHED();
1441 #endif
1442         return nullptr;
1443     }
1444
1445     if (WKStringIsEqualToUTF8CString(messageName, "SendDisplayConfigurationChangedMessageForTesting")) {
1446         TestController::singleton().sendDisplayConfigurationChangedMessageForTesting();
1447         return nullptr;
1448     }
1449
1450     if (WKStringIsEqualToUTF8CString(messageName, "TerminateNetworkProcess")) {
1451         ASSERT(!messageBody);
1452         TestController::singleton().terminateNetworkProcess();
1453         return nullptr;
1454     }
1455
1456     if (WKStringIsEqualToUTF8CString(messageName, "TerminateServiceWorkerProcess")) {
1457         ASSERT(!messageBody);
1458         TestController::singleton().terminateServiceWorkerProcess();
1459         return nullptr;
1460     }
1461
1462     if (WKStringIsEqualToUTF8CString(messageName, "SetWebAuthenticationMockConfiguration")) {
1463         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1464         TestController::singleton().setWebAuthenticationMockConfiguration(static_cast<WKDictionaryRef>(messageBody));
1465         return nullptr;
1466     }
1467
1468     if (WKStringIsEqualToUTF8CString(messageName, "AddTestKeyToKeychain")) {
1469         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1470         WKDictionaryRef testKeyDictionary = static_cast<WKDictionaryRef>(messageBody);
1471
1472         WKRetainPtr<WKStringRef> privateKeyKey(AdoptWK, WKStringCreateWithUTF8CString("PrivateKey"));
1473         WKStringRef privateKeyWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testKeyDictionary, privateKeyKey.get()));
1474
1475         WKRetainPtr<WKStringRef> attrLabelKey(AdoptWK, WKStringCreateWithUTF8CString("AttrLabel"));
1476         WKStringRef attrLabelWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testKeyDictionary, attrLabelKey.get()));
1477
1478         WKRetainPtr<WKStringRef> applicationTagKey(AdoptWK, WKStringCreateWithUTF8CString("ApplicationTag"));
1479         WKStringRef applicationTagWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testKeyDictionary, applicationTagKey.get()));
1480
1481         TestController::singleton().addTestKeyToKeychain(toWTFString(privateKeyWK), toWTFString(attrLabelWK), toWTFString(applicationTagWK));
1482         return nullptr;
1483     }
1484
1485     if (WKStringIsEqualToUTF8CString(messageName, "CleanUpKeychain")) {
1486         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
1487         TestController::singleton().cleanUpKeychain(toWTFString(static_cast<WKStringRef>(messageBody)));
1488         return nullptr;
1489     }
1490
1491     if (WKStringIsEqualToUTF8CString(messageName, "KeyExistsInKeychain")) {
1492         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
1493         WKDictionaryRef testDictionary = static_cast<WKDictionaryRef>(messageBody);
1494
1495         WKRetainPtr<WKStringRef> attrLabelKey(AdoptWK, WKStringCreateWithUTF8CString("AttrLabel"));
1496         WKStringRef attrLabelWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testDictionary, attrLabelKey.get()));
1497
1498         WKRetainPtr<WKStringRef> applicationTagKey(AdoptWK, WKStringCreateWithUTF8CString("ApplicationTag"));
1499         WKStringRef applicationTagWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testDictionary, applicationTagKey.get()));
1500
1501         bool keyExistsInKeychain = TestController::singleton().keyExistsInKeychain(toWTFString(attrLabelWK), toWTFString(applicationTagWK));
1502         WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(keyExistsInKeychain));
1503         return result;
1504     }
1505
1506 #if PLATFORM(MAC)
1507     if (WKStringIsEqualToUTF8CString(messageName, "ToggleCapsLock")) {
1508         TestController::singleton().toggleCapsLock();
1509         return nullptr;
1510     }
1511 #endif
1512
1513     ASSERT_NOT_REACHED();
1514     return nullptr;
1515 }
1516
1517 void TestInvocation::runUISideScriptAfterUpdateCallback(WKErrorRef, void* context)
1518 {
1519     UIScriptInvocationData* data = static_cast<UIScriptInvocationData*>(context);
1520     if (TestInvocation* invocation = data->testInvocation) {
1521         RELEASE_ASSERT(TestController::singleton().isCurrentInvocation(invocation));
1522         invocation->runUISideScript(data->scriptString.get(), data->callbackID);
1523     }
1524     delete data;
1525 }
1526
1527 void TestInvocation::runUISideScript(WKStringRef script, unsigned scriptCallbackID)
1528 {
1529     m_pendingUIScriptInvocationData = nullptr;
1530
1531     if (!m_UIScriptContext)
1532         m_UIScriptContext = std::make_unique<UIScriptContext>(*this);
1533     
1534     m_UIScriptContext->runUIScript(toWTFString(script), scriptCallbackID);
1535 }
1536
1537 void TestInvocation::uiScriptDidComplete(const String& result, unsigned scriptCallbackID)
1538 {
1539     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallUISideScriptCallback"));
1540
1541     WKRetainPtr<WKMutableDictionaryRef> messageBody(AdoptWK, WKMutableDictionaryCreate());
1542     WKRetainPtr<WKStringRef> resultKey(AdoptWK, WKStringCreateWithUTF8CString("Result"));
1543     WKRetainPtr<WKStringRef> callbackIDKey(AdoptWK, WKStringCreateWithUTF8CString("CallbackID"));
1544     WKRetainPtr<WKUInt64Ref> callbackIDValue = adoptWK(WKUInt64Create(scriptCallbackID));
1545
1546     WKDictionarySetItem(messageBody.get(), resultKey.get(), toWK(result).get());
1547     WKDictionarySetItem(messageBody.get(), callbackIDKey.get(), callbackIDValue.get());
1548
1549     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), messageBody.get());
1550 }
1551
1552 void TestInvocation::outputText(const WTF::String& text)
1553 {
1554     m_textOutput.append(text);
1555 }
1556
1557 void TestInvocation::didBeginSwipe()
1558 {
1559     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidBeginSwipeCallback"));
1560     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1561 }
1562
1563 void TestInvocation::willEndSwipe()
1564 {
1565     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallWillEndSwipeCallback"));
1566     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1567 }
1568
1569 void TestInvocation::didEndSwipe()
1570 {
1571     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidEndSwipeCallback"));
1572     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1573 }
1574
1575 void TestInvocation::didRemoveSwipeSnapshot()
1576 {
1577     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidRemoveSwipeSnapshotCallback"));
1578     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1579 }
1580
1581 void TestInvocation::notifyDownloadDone()
1582 {
1583     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("NotifyDownloadDone"));
1584     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1585 }
1586
1587 void TestInvocation::didClearStatisticsThroughWebsiteDataRemoval()
1588 {
1589     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidClearStatisticsThroughWebsiteDataRemoval"));
1590     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1591 }
1592
1593 void TestInvocation::didResetStatisticsToConsistentState()
1594 {
1595     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidResetStatisticsToConsistentState"));
1596     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1597 }
1598
1599 void TestInvocation::didSetBlockCookiesForHost()
1600 {
1601     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetBlockCookiesForHost"));
1602     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1603 }
1604
1605 void TestInvocation::didSetStatisticsDebugMode()
1606 {
1607     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetStatisticsDebugMode"));
1608     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1609 }
1610
1611 void TestInvocation::didSetPrevalentResourceForDebugMode()
1612 {
1613     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetPrevalentResourceForDebugMode"));
1614     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1615 }
1616
1617 void TestInvocation::didSetLastSeen()
1618 {
1619     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetLastSeen"));
1620     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1621 }
1622
1623 void TestInvocation::didSetPrevalentResource()
1624 {
1625     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetPrevalentResource"));
1626     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1627 }
1628
1629 void TestInvocation::didSetVeryPrevalentResource()
1630 {
1631     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetVeryPrevalentResource"));
1632     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1633 }
1634
1635 void TestInvocation::didSetHasHadUserInteraction()
1636 {
1637     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetHasHadUserInteraction"));
1638     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1639 }
1640
1641 void TestInvocation::didReceiveAllStorageAccessEntries(Vector<String>& domains)
1642 {
1643     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidReceiveAllStorageAccessEntries"));
1644     
1645     WKRetainPtr<WKMutableArrayRef> messageBody(AdoptWK, WKMutableArrayCreate());
1646     for (auto& domain : domains)
1647         WKArrayAppendItem(messageBody.get(), adoptWK(WKStringCreateWithUTF8CString(domain.utf8().data())).get());
1648     
1649     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), messageBody.get());
1650 }
1651
1652 void TestInvocation::didRemoveAllSessionCredentials()
1653 {
1654     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidRemoveAllSessionCredentialsCallback"));
1655     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
1656 }
1657
1658 void TestInvocation::dumpResourceLoadStatistics()
1659 {
1660     m_shouldDumpResourceLoadStatistics = true;
1661 }
1662
1663 } // namespace WTR