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