880d621272f2af1fc9de0af39c3d404219c078f4
[WebKit-https.git] / Tools / WebKitTestRunner / InjectedBundle / TestRunner.cpp
1 /*
2  * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "TestRunner.h"
28
29 #include "InjectedBundle.h"
30 #include "InjectedBundlePage.h"
31 #include "JSTestRunner.h"
32 #include "PlatformWebView.h"
33 #include "StringFunctions.h"
34 #include "TestController.h"
35 #include <JavaScriptCore/JSCTestRunnerUtils.h>
36 #include <WebKit/WKBundle.h>
37 #include <WebKit/WKBundleBackForwardList.h>
38 #include <WebKit/WKBundleFrame.h>
39 #include <WebKit/WKBundleFramePrivate.h>
40 #include <WebKit/WKBundleInspector.h>
41 #include <WebKit/WKBundleNodeHandlePrivate.h>
42 #include <WebKit/WKBundlePage.h>
43 #include <WebKit/WKBundlePagePrivate.h>
44 #include <WebKit/WKBundlePrivate.h>
45 #include <WebKit/WKBundleScriptWorld.h>
46 #include <WebKit/WKData.h>
47 #include <WebKit/WKRetainPtr.h>
48 #include <WebKit/WKSerializedScriptValue.h>
49 #include <WebKit/WebKit2_C.h>
50 #include <wtf/CurrentTime.h>
51 #include <wtf/HashMap.h>
52 #include <wtf/StdLibExtras.h>
53 #include <wtf/text/CString.h>
54 #include <wtf/text/StringBuilder.h>
55
56 namespace WTR {
57
58 PassRefPtr<TestRunner> TestRunner::create()
59 {
60     return adoptRef(new TestRunner);
61 }
62
63 TestRunner::TestRunner()
64     : m_whatToDump(RenderTree)
65     , m_shouldDumpAllFrameScrollPositions(false)
66     , m_shouldDumpBackForwardListsForAllWindows(false)
67     , m_shouldAllowEditing(true)
68     , m_shouldCloseExtraWindows(false)
69     , m_dumpEditingCallbacks(false)
70     , m_dumpStatusCallbacks(false)
71     , m_dumpTitleChanges(false)
72     , m_dumpPixels(true)
73     , m_dumpSelectionRect(false)
74     , m_dumpFullScreenCallbacks(false)
75     , m_dumpFrameLoadCallbacks(false)
76     , m_dumpProgressFinishedCallback(false)
77     , m_dumpResourceLoadCallbacks(false)
78     , m_dumpResourceResponseMIMETypes(false)
79     , m_dumpWillCacheResponse(false)
80     , m_dumpApplicationCacheDelegateCallbacks(false)
81     , m_dumpDatabaseCallbacks(false)
82     , m_disallowIncreaseForApplicationCacheQuota(false)
83     , m_waitToDump(false)
84     , m_testRepaint(false)
85     , m_testRepaintSweepHorizontally(false)
86     , m_isPrinting(false)
87     , m_willSendRequestReturnsNull(false)
88     , m_willSendRequestReturnsNullOnRedirect(false)
89     , m_shouldStopProvisionalFrameLoads(false)
90     , m_policyDelegateEnabled(false)
91     , m_policyDelegatePermissive(false)
92     , m_globalFlag(false)
93     , m_customFullScreenBehavior(false)
94     , m_timeout(30000)
95     , m_databaseDefaultQuota(-1)
96     , m_databaseMaxQuota(-1)
97     , m_userStyleSheetEnabled(false)
98     , m_userStyleSheetLocation(adoptWK(WKStringCreateWithUTF8CString("")))
99 #if PLATFORM(GTK)
100     , m_waitToDumpWatchdogTimer(RunLoop::main(), this, &TestRunner::waitToDumpWatchdogTimerFired)
101 #endif
102 {
103     platformInitialize();
104 }
105
106 TestRunner::~TestRunner()
107 {
108 }
109
110 JSClassRef TestRunner::wrapperClass()
111 {
112     return JSTestRunner::testRunnerClass();
113 }
114
115 void TestRunner::display()
116 {
117     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
118     WKBundlePageForceRepaint(page);
119     WKBundlePageSetTracksRepaints(page, true);
120     WKBundlePageResetTrackedRepaints(page);
121 }
122
123 void TestRunner::dumpAsText(bool dumpPixels)
124 {
125     if (m_whatToDump < MainFrameText)
126         m_whatToDump = MainFrameText;
127     m_dumpPixels = dumpPixels;
128 }
129
130 void TestRunner::setCustomPolicyDelegate(bool enabled, bool permissive)
131 {
132     m_policyDelegateEnabled = enabled;
133     m_policyDelegatePermissive = permissive;
134
135     InjectedBundle::singleton().setCustomPolicyDelegate(enabled, permissive);
136 }
137
138 void TestRunner::waitForPolicyDelegate()
139 {
140     setCustomPolicyDelegate(true);
141     waitUntilDone();
142 }
143
144 void TestRunner::waitUntilDownloadFinished()
145 {
146     m_shouldFinishAfterDownload = true;
147     waitUntilDone();
148 }
149
150 void TestRunner::waitUntilDone()
151 {
152     m_waitToDump = true;
153     if (InjectedBundle::singleton().useWaitToDumpWatchdogTimer())
154         initializeWaitToDumpWatchdogTimerIfNeeded();
155 }
156
157 void TestRunner::waitToDumpWatchdogTimerFired()
158 {
159     invalidateWaitToDumpWatchdogTimer();
160     auto& injectedBundle = InjectedBundle::singleton();
161     injectedBundle.outputText("FAIL: Timed out waiting for notifyDone to be called\n\n");
162     injectedBundle.done();
163 }
164
165 void TestRunner::notifyDone()
166 {
167     auto& injectedBundle = InjectedBundle::singleton();
168     if (!injectedBundle.isTestRunning())
169         return;
170
171     if (m_waitToDump && !injectedBundle.topLoadingFrame())
172         injectedBundle.page()->dump();
173
174     // We don't call invalidateWaitToDumpWatchdogTimer() here, even if we continue to wait for a load to finish.
175     // The test is still subject to timeout checking - it is better to detect an async timeout inside WebKitTestRunner
176     // than to let webkitpy do that, because WebKitTestRunner will dump partial results.
177
178     m_waitToDump = false;
179 }
180
181 unsigned TestRunner::imageCountInGeneralPasteboard() const
182 {
183     return InjectedBundle::singleton().imageCountInGeneralPasteboard();
184 }
185
186 void TestRunner::addUserScript(JSStringRef source, bool runAtStart, bool allFrames)
187 {
188     WKRetainPtr<WKStringRef> sourceWK = toWK(source);
189
190     WKBundlePageAddUserScript(InjectedBundle::singleton().page()->page(), sourceWK.get(),
191         (runAtStart ? kWKInjectAtDocumentStart : kWKInjectAtDocumentEnd),
192         (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly));
193 }
194
195 void TestRunner::addUserStyleSheet(JSStringRef source, bool allFrames)
196 {
197     WKRetainPtr<WKStringRef> sourceWK = toWK(source);
198
199     WKBundlePageAddUserStyleSheet(InjectedBundle::singleton().page()->page(), sourceWK.get(),
200         (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly));
201 }
202
203 void TestRunner::keepWebHistory()
204 {
205     InjectedBundle::singleton().postSetAddsVisitedLinks(true);
206 }
207
208 void TestRunner::execCommand(JSStringRef name, JSStringRef argument)
209 {
210     WKBundlePageExecuteEditingCommand(InjectedBundle::singleton().page()->page(), toWK(name).get(), toWK(argument).get());
211 }
212
213 bool TestRunner::findString(JSStringRef target, JSValueRef optionsArrayAsValue)
214 {
215     WKFindOptions options = 0;
216
217     auto& injectedBundle = InjectedBundle::singleton();
218     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page());
219     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
220     JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length"));
221     JSObjectRef optionsArray = JSValueToObject(context, optionsArrayAsValue, 0);
222     JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0);
223     if (!JSValueIsNumber(context, lengthValue))
224         return false;
225
226     size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0));
227     for (size_t i = 0; i < length; ++i) {
228         JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
229         if (!JSValueIsString(context, value))
230             continue;
231
232         JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0));
233
234         if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive"))
235             options |= kWKFindOptionsCaseInsensitive;
236         else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts"))
237             options |= kWKFindOptionsAtWordStarts;
238         else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart"))
239             options |= kWKFindOptionsTreatMedialCapitalAsWordStart;
240         else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards"))
241             options |= kWKFindOptionsBackwards;
242         else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround"))
243             options |= kWKFindOptionsWrapAround;
244         else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection")) {
245             // FIXME: No kWKFindOptionsStartInSelection.
246         }
247     }
248
249     return WKBundlePageFindString(injectedBundle.page()->page(), toWK(target).get(), options);
250 }
251
252 void TestRunner::clearAllDatabases()
253 {
254     WKBundleClearAllDatabases(InjectedBundle::singleton().bundle());
255
256     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("DeleteAllIndexedDatabases"));
257     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(true));
258
259     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
260 }
261
262 void TestRunner::setDatabaseQuota(uint64_t quota)
263 {
264     return WKBundleSetDatabaseQuota(InjectedBundle::singleton().bundle(), quota);
265 }
266
267 void TestRunner::clearAllApplicationCaches()
268 {
269     WKBundlePageClearApplicationCache(InjectedBundle::singleton().page()->page());
270 }
271
272 void TestRunner::clearApplicationCacheForOrigin(JSStringRef origin)
273 {
274     WKBundlePageClearApplicationCacheForOrigin(InjectedBundle::singleton().page()->page(), toWK(origin).get());
275 }
276
277 void TestRunner::setAppCacheMaximumSize(uint64_t size)
278 {
279     WKBundlePageSetAppCacheMaximumSize(InjectedBundle::singleton().page()->page(), size);
280 }
281
282 long long TestRunner::applicationCacheDiskUsageForOrigin(JSStringRef origin)
283 {
284     return WKBundlePageGetAppCacheUsageForOrigin(InjectedBundle::singleton().page()->page(), toWK(origin).get());
285 }
286
287 void TestRunner::disallowIncreaseForApplicationCacheQuota()
288 {
289     m_disallowIncreaseForApplicationCacheQuota = true;
290 }
291
292 static inline JSValueRef stringArrayToJS(JSContextRef context, WKArrayRef strings)
293 {
294     const size_t count = WKArrayGetSize(strings);
295
296     JSValueRef arrayResult = JSObjectMakeArray(context, 0, 0, 0);
297     JSObjectRef arrayObj = JSValueToObject(context, arrayResult, 0);
298     for (size_t i = 0; i < count; ++i) {
299         WKStringRef stringRef = static_cast<WKStringRef>(WKArrayGetItemAtIndex(strings, i));
300         JSRetainPtr<JSStringRef> stringJS = toJS(stringRef);
301         JSObjectSetPropertyAtIndex(context, arrayObj, i, JSValueMakeString(context, stringJS.get()), 0);
302     }
303
304     return arrayResult;
305 }
306
307 JSValueRef TestRunner::originsWithApplicationCache()
308 {
309     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
310
311     WKRetainPtr<WKArrayRef> origins(AdoptWK, WKBundlePageCopyOriginsWithApplicationCache(page));
312
313     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(page);
314     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
315
316     return stringArrayToJS(context, origins.get());
317 }
318
319 bool TestRunner::isCommandEnabled(JSStringRef name)
320 {
321     return WKBundlePageIsEditingCommandEnabled(InjectedBundle::singleton().page()->page(), toWK(name).get());
322 }
323
324 void TestRunner::setCanOpenWindows(bool)
325 {
326     // It's not clear if or why any tests require opening windows be forbidden.
327     // For now, just ignore this setting, and if we find later it's needed we can add it.
328 }
329
330 void TestRunner::setXSSAuditorEnabled(bool enabled)
331 {
332     WKRetainPtr<WKStringRef> key(AdoptWK, WKStringCreateWithUTF8CString("WebKitXSSAuditorEnabled"));
333     auto& injectedBundle = InjectedBundle::singleton();
334     WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled);
335 }
336
337 void TestRunner::setShadowDOMEnabled(bool enabled)
338 {
339     WKRetainPtr<WKStringRef> key(AdoptWK, WKStringCreateWithUTF8CString("WebKitShadowDOMEnabled"));
340     auto& injectedBundle = InjectedBundle::singleton();
341     WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled);
342 }
343
344 void TestRunner::setCustomElementsEnabled(bool enabled)
345 {
346     WKRetainPtr<WKStringRef> key(AdoptWK, WKStringCreateWithUTF8CString("WebKitCustomElementsEnabled"));
347     auto& injectedBundle = InjectedBundle::singleton();
348     WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled);
349 }
350
351 void TestRunner::setWebGL2Enabled(bool enabled)
352 {
353     WKRetainPtr<WKStringRef> key(AdoptWK, WKStringCreateWithUTF8CString("WebKitWebGL2Enabled"));
354     auto& injectedBundle = InjectedBundle::singleton();
355     WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled);
356 }
357
358 void TestRunner::setFetchAPIEnabled(bool enabled)
359 {
360     WKRetainPtr<WKStringRef> key(AdoptWK, WKStringCreateWithUTF8CString("WebKitFetchAPIEnabled"));
361     auto& injectedBundle = InjectedBundle::singleton();
362     WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled);
363 }
364
365 void TestRunner::setDownloadAttributeEnabled(bool enabled)
366 {
367     WKRetainPtr<WKStringRef> key(AdoptWK, WKStringCreateWithUTF8CString("WebKitDownloadAttributeEnabled"));
368     auto& injectedBundle = InjectedBundle::singleton();
369     WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled);
370 }
371
372 void TestRunner::setAllowsAnySSLCertificate(bool enabled)
373 {
374     InjectedBundle::singleton().setAllowsAnySSLCertificate(enabled);
375 }
376
377 void TestRunner::setAllowUniversalAccessFromFileURLs(bool enabled)
378 {
379     auto& injectedBundle = InjectedBundle::singleton();
380     WKBundleSetAllowUniversalAccessFromFileURLs(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
381 }
382
383 void TestRunner::setAllowFileAccessFromFileURLs(bool enabled)
384 {
385     auto& injectedBundle = InjectedBundle::singleton();
386     WKBundleSetAllowFileAccessFromFileURLs(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
387 }
388
389 void TestRunner::setPluginsEnabled(bool enabled)
390 {
391     auto& injectedBundle = InjectedBundle::singleton();
392     WKBundleSetPluginsEnabled(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
393 }
394
395 void TestRunner::setJavaScriptCanAccessClipboard(bool enabled)
396 {
397     auto& injectedBundle = InjectedBundle::singleton();
398      WKBundleSetJavaScriptCanAccessClipboard(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
399 }
400
401 void TestRunner::setPrivateBrowsingEnabled(bool enabled)
402 {
403     auto& injectedBundle = InjectedBundle::singleton();
404      WKBundleSetPrivateBrowsingEnabled(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
405 }
406
407 void TestRunner::setPopupBlockingEnabled(bool enabled)
408 {
409     auto& injectedBundle = InjectedBundle::singleton();
410      WKBundleSetPopupBlockingEnabled(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
411 }
412
413 void TestRunner::setAuthorAndUserStylesEnabled(bool enabled)
414 {
415     auto& injectedBundle = InjectedBundle::singleton();
416      WKBundleSetAuthorAndUserStylesEnabled(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
417 }
418
419 void TestRunner::addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains)
420 {
421     WKBundleAddOriginAccessWhitelistEntry(InjectedBundle::singleton().bundle(), toWK(sourceOrigin).get(), toWK(destinationProtocol).get(), toWK(destinationHost).get(), allowDestinationSubdomains);
422 }
423
424 void TestRunner::removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains)
425 {
426     WKBundleRemoveOriginAccessWhitelistEntry(InjectedBundle::singleton().bundle(), toWK(sourceOrigin).get(), toWK(destinationProtocol).get(), toWK(destinationHost).get(), allowDestinationSubdomains);
427 }
428
429 bool TestRunner::isPageBoxVisible(int pageIndex)
430 {
431     auto& injectedBundle = InjectedBundle::singleton();
432     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page());
433     return WKBundleIsPageBoxVisible(injectedBundle.bundle(), mainFrame, pageIndex);
434 }
435
436 void TestRunner::setValueForUser(JSContextRef context, JSValueRef element, JSStringRef value)
437 {
438     if (!element || !JSValueIsObject(context, element))
439         return;
440
441     WKRetainPtr<WKBundleNodeHandleRef> nodeHandle(AdoptWK, WKBundleNodeHandleCreate(context, const_cast<JSObjectRef>(element)));
442     WKBundleNodeHandleSetHTMLInputElementValueForUser(nodeHandle.get(), toWK(value).get());
443 }
444
445 void TestRunner::setAudioResult(JSContextRef context, JSValueRef data)
446 {
447     auto& injectedBundle = InjectedBundle::singleton();
448     // FIXME (123058): Use a JSC API to get buffer contents once such is exposed.
449     WKRetainPtr<WKDataRef> audioData(AdoptWK, WKBundleCreateWKDataFromUInt8Array(injectedBundle.bundle(), context, data));
450     injectedBundle.setAudioResult(audioData.get());
451     m_whatToDump = Audio;
452     m_dumpPixels = false;
453 }
454
455 unsigned TestRunner::windowCount()
456 {
457     return InjectedBundle::singleton().pageCount();
458 }
459
460 void TestRunner::clearBackForwardList()
461 {
462     WKBundleBackForwardListClear(WKBundlePageGetBackForwardList(InjectedBundle::singleton().page()->page()));
463 }
464
465 // Object Creation
466
467 void TestRunner::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
468 {
469     setProperty(context, windowObject, "testRunner", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
470 }
471
472 void TestRunner::showWebInspector()
473 {
474     WKBundleInspectorShow(WKBundlePageGetInspector(InjectedBundle::singleton().page()->page()));
475 }
476
477 void TestRunner::closeWebInspector()
478 {
479     WKBundleInspectorClose(WKBundlePageGetInspector(InjectedBundle::singleton().page()->page()));
480 }
481
482 void TestRunner::evaluateInWebInspector(JSStringRef script)
483 {
484     WKRetainPtr<WKStringRef> scriptWK = toWK(script);
485     WKBundleInspectorEvaluateScriptForTest(WKBundlePageGetInspector(InjectedBundle::singleton().page()->page()), scriptWK.get());
486 }
487
488 typedef WTF::HashMap<unsigned, WKRetainPtr<WKBundleScriptWorldRef> > WorldMap;
489 static WorldMap& worldMap()
490 {
491     static WorldMap& map = *new WorldMap;
492     return map;
493 }
494
495 unsigned TestRunner::worldIDForWorld(WKBundleScriptWorldRef world)
496 {
497     WorldMap::const_iterator end = worldMap().end();
498     for (WorldMap::const_iterator it = worldMap().begin(); it != end; ++it) {
499         if (it->value == world)
500             return it->key;
501     }
502
503     return 0;
504 }
505
506 void TestRunner::evaluateScriptInIsolatedWorld(JSContextRef context, unsigned worldID, JSStringRef script)
507 {
508     // A worldID of 0 always corresponds to a new world. Any other worldID corresponds to a world
509     // that is created once and cached forever.
510     WKRetainPtr<WKBundleScriptWorldRef> world;
511     if (!worldID)
512         world.adopt(WKBundleScriptWorldCreateWorld());
513     else {
514         WKRetainPtr<WKBundleScriptWorldRef>& worldSlot = worldMap().add(worldID, nullptr).iterator->value;
515         if (!worldSlot)
516             worldSlot.adopt(WKBundleScriptWorldCreateWorld());
517         world = worldSlot;
518     }
519
520     WKBundleFrameRef frame = WKBundleFrameForJavaScriptContext(context);
521     if (!frame)
522         frame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
523
524     JSGlobalContextRef jsContext = WKBundleFrameGetJavaScriptContextForWorld(frame, world.get());
525     JSEvaluateScript(jsContext, script, 0, 0, 0, 0); 
526 }
527
528 void TestRunner::setPOSIXLocale(JSStringRef locale)
529 {
530     char localeBuf[32];
531     JSStringGetUTF8CString(locale, localeBuf, sizeof(localeBuf));
532     setlocale(LC_ALL, localeBuf);
533 }
534
535 void TestRunner::setTextDirection(JSStringRef direction)
536 {
537     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
538     return WKBundleFrameSetTextDirection(mainFrame, toWK(direction).get());
539 }
540     
541 void TestRunner::setShouldStayOnPageAfterHandlingBeforeUnload(bool shouldStayOnPage)
542 {
543     InjectedBundle::singleton().postNewBeforeUnloadReturnValue(!shouldStayOnPage);
544 }
545
546 void TestRunner::setDefersLoading(bool shouldDeferLoading)
547 {
548     WKBundlePageSetDefersLoading(InjectedBundle::singleton().page()->page(), shouldDeferLoading);
549 }
550
551 void TestRunner::setPageVisibility(JSStringRef state)
552 {
553     InjectedBundle::singleton().setHidden(JSStringIsEqualToUTF8CString(state, "hidden") || JSStringIsEqualToUTF8CString(state, "prerender"));
554 }
555
556 void TestRunner::resetPageVisibility()
557 {
558     InjectedBundle::singleton().setHidden(false);
559 }
560
561 typedef WTF::HashMap<unsigned, JSValueRef> CallbackMap;
562 static CallbackMap& callbackMap()
563 {
564     static CallbackMap& map = *new CallbackMap;
565     return map;
566 }
567
568 enum {
569     AddChromeInputFieldCallbackID = 1,
570     RemoveChromeInputFieldCallbackID,
571     FocusWebViewCallbackID,
572     SetBackingScaleFactorCallbackID,
573     DidBeginSwipeCallbackID,
574     WillEndSwipeCallbackID,
575     DidEndSwipeCallbackID,
576     DidRemoveSwipeSnapshotCallbackID,
577     FirstUIScriptCallbackID = 100
578 };
579
580 static void cacheTestRunnerCallback(unsigned index, JSValueRef callback)
581 {
582     if (!callback)
583         return;
584
585     if (callbackMap().contains(index)) {
586         InjectedBundle::singleton().outputText(String::format("FAIL: Tried to install a second TestRunner callback for the same event (id %d)\n\n", index));
587         return;
588     }
589
590     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
591     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
592     JSValueProtect(context, callback);
593     callbackMap().add(index, callback);
594 }
595
596 static void callTestRunnerCallback(unsigned index, size_t argumentCount = 0, const JSValueRef arguments[] = nullptr)
597 {
598     if (!callbackMap().contains(index))
599         return;
600     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
601     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
602     JSObjectRef callback = JSValueToObject(context, callbackMap().take(index), 0);
603     JSObjectCallAsFunction(context, callback, JSContextGetGlobalObject(context), argumentCount, arguments, 0);
604     JSValueUnprotect(context, callback);
605 }
606
607 void TestRunner::clearTestRunnerCallbacks()
608 {
609     for (auto& iter : callbackMap()) {
610         WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
611         JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
612         JSObjectRef callback = JSValueToObject(context, iter.value, 0);
613         JSValueUnprotect(context, callback);
614     }
615
616     callbackMap().clear();
617 }
618
619 void TestRunner::accummulateLogsForChannel(JSStringRef)
620 {
621     // FIXME: Implement getting the call to all processes.
622 }
623
624 void TestRunner::addChromeInputField(JSValueRef callback)
625 {
626     cacheTestRunnerCallback(AddChromeInputFieldCallbackID, callback);
627     InjectedBundle::singleton().postAddChromeInputField();
628 }
629
630 void TestRunner::removeChromeInputField(JSValueRef callback)
631 {
632     cacheTestRunnerCallback(RemoveChromeInputFieldCallbackID, callback);
633     InjectedBundle::singleton().postRemoveChromeInputField();
634 }
635
636 void TestRunner::focusWebView(JSValueRef callback)
637 {
638     cacheTestRunnerCallback(FocusWebViewCallbackID, callback);
639     InjectedBundle::singleton().postFocusWebView();
640 }
641
642 void TestRunner::setBackingScaleFactor(double backingScaleFactor, JSValueRef callback)
643 {
644     cacheTestRunnerCallback(SetBackingScaleFactorCallbackID, callback);
645     InjectedBundle::singleton().postSetBackingScaleFactor(backingScaleFactor);
646 }
647
648 void TestRunner::setWindowIsKey(bool isKey)
649 {
650     InjectedBundle::singleton().postSetWindowIsKey(isKey);
651 }
652
653 void TestRunner::setViewSize(double width, double height)
654 {
655     InjectedBundle::singleton().postSetViewSize(width, height);
656 }
657
658 void TestRunner::callAddChromeInputFieldCallback()
659 {
660     callTestRunnerCallback(AddChromeInputFieldCallbackID);
661 }
662
663 void TestRunner::callRemoveChromeInputFieldCallback()
664 {
665     callTestRunnerCallback(RemoveChromeInputFieldCallbackID);
666 }
667
668 void TestRunner::callFocusWebViewCallback()
669 {
670     callTestRunnerCallback(FocusWebViewCallbackID);
671 }
672
673 void TestRunner::callSetBackingScaleFactorCallback()
674 {
675     callTestRunnerCallback(SetBackingScaleFactorCallbackID);
676 }
677
678 static inline bool toBool(JSStringRef value)
679 {
680     return JSStringIsEqualToUTF8CString(value, "true") || JSStringIsEqualToUTF8CString(value, "1");
681 }
682
683 void TestRunner::overridePreference(JSStringRef preference, JSStringRef value)
684 {
685     auto& injectedBundle = InjectedBundle::singleton();
686     // FIXME: handle non-boolean preferences.
687     WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), toWK(preference).get(), toBool(value));
688 }
689
690 void TestRunner::setAlwaysAcceptCookies(bool accept)
691 {
692     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetAlwaysAcceptCookies"));
693
694     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(accept));
695
696     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
697 }
698
699 double TestRunner::preciseTime()
700 {
701     return currentTime();
702 }
703
704 void TestRunner::setUserStyleSheetEnabled(bool enabled)
705 {
706     m_userStyleSheetEnabled = enabled;
707
708     WKRetainPtr<WKStringRef> emptyUrl = adoptWK(WKStringCreateWithUTF8CString(""));
709     WKStringRef location = enabled ? m_userStyleSheetLocation.get() : emptyUrl.get();
710     auto& injectedBundle = InjectedBundle::singleton();
711     WKBundleSetUserStyleSheetLocation(injectedBundle.bundle(), injectedBundle.pageGroup(), location);
712 }
713
714 void TestRunner::setUserStyleSheetLocation(JSStringRef location)
715 {
716     m_userStyleSheetLocation = adoptWK(WKStringCreateWithJSString(location));
717
718     if (m_userStyleSheetEnabled)
719         setUserStyleSheetEnabled(true);
720 }
721
722 void TestRunner::setSpatialNavigationEnabled(bool enabled)
723 {
724     auto& injectedBundle = InjectedBundle::singleton();
725     WKBundleSetSpatialNavigationEnabled(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
726 }
727
728 void TestRunner::setTabKeyCyclesThroughElements(bool enabled)
729 {
730     auto& injectedBundle = InjectedBundle::singleton();
731     WKBundleSetTabKeyCyclesThroughElements(injectedBundle.bundle(), injectedBundle.page()->page(), enabled);
732 }
733
734 void TestRunner::setSerializeHTTPLoads()
735 {
736     // WK2 doesn't reorder loads.
737 }
738
739 void TestRunner::dispatchPendingLoadRequests()
740 {
741     // WK2 doesn't keep pending requests.
742 }
743
744 void TestRunner::setCacheModel(int model)
745 {
746     InjectedBundle::singleton().setCacheModel(model);
747 }
748
749 void TestRunner::setAsynchronousSpellCheckingEnabled(bool enabled)
750 {
751     auto& injectedBundle = InjectedBundle::singleton();
752     WKBundleSetAsynchronousSpellCheckingEnabled(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
753 }
754
755 void TestRunner::grantWebNotificationPermission(JSStringRef origin)
756 {
757     WKRetainPtr<WKStringRef> originWK = toWK(origin);
758     auto& injectedBundle = InjectedBundle::singleton();
759     WKBundleSetWebNotificationPermission(injectedBundle.bundle(), injectedBundle.page()->page(), originWK.get(), true);
760 }
761
762 void TestRunner::denyWebNotificationPermission(JSStringRef origin)
763 {
764     WKRetainPtr<WKStringRef> originWK = toWK(origin);
765     auto& injectedBundle = InjectedBundle::singleton();
766     WKBundleSetWebNotificationPermission(injectedBundle.bundle(), injectedBundle.page()->page(), originWK.get(), false);
767 }
768
769 void TestRunner::removeAllWebNotificationPermissions()
770 {
771     auto& injectedBundle = InjectedBundle::singleton();
772     WKBundleRemoveAllWebNotificationPermissions(injectedBundle.bundle(), injectedBundle.page()->page());
773 }
774
775 void TestRunner::simulateWebNotificationClick(JSValueRef notification)
776 {
777     auto& injectedBundle = InjectedBundle::singleton();
778     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page());
779     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
780     uint64_t notificationID = WKBundleGetWebNotificationID(injectedBundle.bundle(), context, notification);
781     injectedBundle.postSimulateWebNotificationClick(notificationID);
782 }
783
784 void TestRunner::setGeolocationPermission(bool enabled)
785 {
786     // FIXME: this should be done by frame.
787     InjectedBundle::singleton().setGeolocationPermission(enabled);
788 }
789
790 bool TestRunner::isGeolocationProviderActive()
791 {
792     return InjectedBundle::singleton().isGeolocationProviderActive();
793 }
794
795 void TestRunner::setMockGeolocationPosition(double latitude, double longitude, double accuracy, JSValueRef jsAltitude, JSValueRef jsAltitudeAccuracy, JSValueRef jsHeading, JSValueRef jsSpeed)
796 {
797     auto& injectedBundle = InjectedBundle::singleton();
798     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page());
799     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
800
801     bool providesAltitude = false;
802     double altitude = 0.;
803     if (!JSValueIsUndefined(context, jsAltitude)) {
804         providesAltitude = true;
805         altitude = JSValueToNumber(context, jsAltitude, 0);
806     }
807
808     bool providesAltitudeAccuracy = false;
809     double altitudeAccuracy = 0.;
810     if (!JSValueIsUndefined(context, jsAltitudeAccuracy)) {
811         providesAltitudeAccuracy = true;
812         altitudeAccuracy = JSValueToNumber(context, jsAltitudeAccuracy, 0);
813     }
814
815     bool providesHeading = false;
816     double heading = 0.;
817     if (!JSValueIsUndefined(context, jsHeading)) {
818         providesHeading = true;
819         heading = JSValueToNumber(context, jsHeading, 0);
820     }
821
822     bool providesSpeed = false;
823     double speed = 0.;
824     if (!JSValueIsUndefined(context, jsSpeed)) {
825         providesSpeed = true;
826         speed = JSValueToNumber(context, jsSpeed, 0);
827     }
828
829     injectedBundle.setMockGeolocationPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed);
830 }
831
832 void TestRunner::setMockGeolocationPositionUnavailableError(JSStringRef message)
833 {
834     WKRetainPtr<WKStringRef> messageWK = toWK(message);
835     InjectedBundle::singleton().setMockGeolocationPositionUnavailableError(messageWK.get());
836 }
837
838 void TestRunner::setUserMediaPermission(bool enabled)
839 {
840     // FIXME: this should be done by frame.
841     InjectedBundle::singleton().setUserMediaPermission(enabled);
842 }
843
844 void TestRunner::setUserMediaPermissionForOrigin(bool permission, JSStringRef origin, JSStringRef parentOrigin)
845 {
846     WKRetainPtr<WKStringRef> originWK = toWK(origin);
847     WKRetainPtr<WKStringRef> parentOriginWK = toWK(parentOrigin);
848     InjectedBundle::singleton().setUserMediaPermissionForOrigin(permission, originWK.get(), parentOriginWK.get());
849 }
850
851 bool TestRunner::callShouldCloseOnWebView()
852 {
853     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
854     return WKBundleFrameCallShouldCloseOnWebView(mainFrame);
855 }
856
857 void TestRunner::queueBackNavigation(unsigned howFarBackward)
858 {
859     InjectedBundle::singleton().queueBackNavigation(howFarBackward);
860 }
861
862 void TestRunner::queueForwardNavigation(unsigned howFarForward)
863 {
864     InjectedBundle::singleton().queueForwardNavigation(howFarForward);
865 }
866
867 void TestRunner::queueLoad(JSStringRef url, JSStringRef target, bool shouldOpenExternalURLs)
868 {
869     auto& injectedBundle = InjectedBundle::singleton();
870     WKRetainPtr<WKURLRef> baseURLWK(AdoptWK, WKBundleFrameCopyURL(WKBundlePageGetMainFrame(injectedBundle.page()->page())));
871     WKRetainPtr<WKURLRef> urlWK(AdoptWK, WKURLCreateWithBaseURL(baseURLWK.get(), toWTFString(toWK(url)).utf8().data()));
872     WKRetainPtr<WKStringRef> urlStringWK(AdoptWK, WKURLCopyString(urlWK.get()));
873
874     injectedBundle.queueLoad(urlStringWK.get(), toWK(target).get(), shouldOpenExternalURLs);
875 }
876
877 void TestRunner::queueLoadHTMLString(JSStringRef content, JSStringRef baseURL, JSStringRef unreachableURL)
878 {
879     WKRetainPtr<WKStringRef> contentWK = toWK(content);
880     WKRetainPtr<WKStringRef> baseURLWK = baseURL ? toWK(baseURL) : WKRetainPtr<WKStringRef>();
881     WKRetainPtr<WKStringRef> unreachableURLWK = unreachableURL ? toWK(unreachableURL) : WKRetainPtr<WKStringRef>();
882
883     InjectedBundle::singleton().queueLoadHTMLString(contentWK.get(), baseURLWK.get(), unreachableURLWK.get());
884 }
885
886 void TestRunner::queueReload()
887 {
888     InjectedBundle::singleton().queueReload();
889 }
890
891 void TestRunner::queueLoadingScript(JSStringRef script)
892 {
893     WKRetainPtr<WKStringRef> scriptWK = toWK(script);
894     InjectedBundle::singleton().queueLoadingScript(scriptWK.get());
895 }
896
897 void TestRunner::queueNonLoadingScript(JSStringRef script)
898 {
899     WKRetainPtr<WKStringRef> scriptWK = toWK(script);
900     InjectedBundle::singleton().queueNonLoadingScript(scriptWK.get());
901 }
902
903 void TestRunner::setHandlesAuthenticationChallenges(bool handlesAuthenticationChallenges)
904 {
905     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetHandlesAuthenticationChallenge"));
906     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(handlesAuthenticationChallenges));
907     WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get());
908 }
909
910 void TestRunner::setShouldLogCanAuthenticateAgainstProtectionSpace(bool value)
911 {
912     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetShouldLogCanAuthenticateAgainstProtectionSpace"));
913     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
914     WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get());
915 }
916
917 void TestRunner::setAuthenticationUsername(JSStringRef username)
918 {
919     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetAuthenticationUsername"));
920     WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithJSString(username));
921     WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get());
922 }
923
924 void TestRunner::setAuthenticationPassword(JSStringRef password)
925 {
926     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetAuthenticationPassword"));
927     WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithJSString(password));
928     WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get());
929 }
930
931 bool TestRunner::secureEventInputIsEnabled() const
932 {
933     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SecureEventInputIsEnabled"));
934     WKTypeRef returnData = 0;
935
936     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), 0, &returnData);
937     return WKBooleanGetValue(static_cast<WKBooleanRef>(returnData));
938 }
939
940 void TestRunner::setBlockAllPlugins(bool shouldBlock)
941 {
942     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetBlockAllPlugins"));
943     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(shouldBlock));
944     WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get());
945 }
946
947 JSValueRef TestRunner::failNextNewCodeBlock()
948 {
949     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
950     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
951     return JSC::failNextNewCodeBlock(context);
952 }
953
954 JSValueRef TestRunner::numberOfDFGCompiles(JSValueRef theFunction)
955 {
956     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
957     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
958     return JSC::numberOfDFGCompiles(context, theFunction);
959 }
960
961 JSValueRef TestRunner::neverInlineFunction(JSValueRef theFunction)
962 {
963     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
964     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
965     return JSC::setNeverInline(context, theFunction);
966 }
967
968 void TestRunner::setShouldDecideNavigationPolicyAfterDelay(bool value)
969 {
970     m_shouldDecideNavigationPolicyAfterDelay = value;
971     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetShouldDecideNavigationPolicyAfterDelay"));
972     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
973     WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get());
974 }
975
976 void TestRunner::setNavigationGesturesEnabled(bool value)
977 {
978     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetNavigationGesturesEnabled"));
979     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
980     WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get());
981 }
982
983 static unsigned nextUIScriptCallbackID()
984 {
985     static unsigned callbackID = FirstUIScriptCallbackID;
986     return callbackID++;
987 }
988
989 void TestRunner::runUIScript(JSStringRef script, JSValueRef callback)
990 {
991     unsigned callbackID = nextUIScriptCallbackID();
992     cacheTestRunnerCallback(callbackID, callback);
993
994     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("RunUIProcessScript"));
995
996     WKRetainPtr<WKMutableDictionaryRef> testDictionary(AdoptWK, WKMutableDictionaryCreate());
997
998     WKRetainPtr<WKStringRef> scriptKey(AdoptWK, WKStringCreateWithUTF8CString("Script"));
999     WKRetainPtr<WKStringRef> scriptValue(AdoptWK, WKStringCreateWithJSString(script));
1000
1001     WKRetainPtr<WKStringRef> callbackIDKey(AdoptWK, WKStringCreateWithUTF8CString("CallbackID"));
1002     WKRetainPtr<WKUInt64Ref> callbackIDValue = adoptWK(WKUInt64Create(callbackID));
1003
1004     WKDictionarySetItem(testDictionary.get(), scriptKey.get(), scriptValue.get());
1005     WKDictionarySetItem(testDictionary.get(), callbackIDKey.get(), callbackIDValue.get());
1006
1007     WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), testDictionary.get());
1008 }
1009
1010 void TestRunner::runUIScriptCallback(unsigned callbackID, JSStringRef result)
1011 {
1012     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
1013     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
1014
1015     JSValueRef resultValue = JSValueMakeString(context, result);
1016     callTestRunnerCallback(callbackID, 1, &resultValue);
1017 }
1018
1019 void TestRunner::installDidBeginSwipeCallback(JSValueRef callback)
1020 {
1021     cacheTestRunnerCallback(DidBeginSwipeCallbackID, callback);
1022 }
1023
1024 void TestRunner::installWillEndSwipeCallback(JSValueRef callback)
1025 {
1026     cacheTestRunnerCallback(WillEndSwipeCallbackID, callback);
1027 }
1028
1029 void TestRunner::installDidEndSwipeCallback(JSValueRef callback)
1030 {
1031     cacheTestRunnerCallback(DidEndSwipeCallbackID, callback);
1032 }
1033
1034 void TestRunner::installDidRemoveSwipeSnapshotCallback(JSValueRef callback)
1035 {
1036     cacheTestRunnerCallback(DidRemoveSwipeSnapshotCallbackID, callback);
1037 }
1038
1039 void TestRunner::callDidBeginSwipeCallback()
1040 {
1041     callTestRunnerCallback(DidBeginSwipeCallbackID);
1042 }
1043
1044 void TestRunner::callWillEndSwipeCallback()
1045 {
1046     callTestRunnerCallback(WillEndSwipeCallbackID);
1047 }
1048
1049 void TestRunner::callDidEndSwipeCallback()
1050 {
1051     callTestRunnerCallback(DidEndSwipeCallbackID);
1052 }
1053
1054 void TestRunner::callDidRemoveSwipeSnapshotCallback()
1055 {
1056     callTestRunnerCallback(DidRemoveSwipeSnapshotCallbackID);
1057 }
1058
1059 } // namespace WTR