2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "TestController.h"
29 #include "PlatformWebView.h"
30 #include "StringFunctions.h"
31 #include "TestInvocation.h"
32 #include <WebKit2/WKContextPrivate.h>
33 #include <WebKit2/WKNumber.h>
34 #include <WebKit2/WKPageGroup.h>
35 #include <WebKit2/WKPagePrivate.h>
36 #include <WebKit2/WKPreferencesPrivate.h>
37 #include <WebKit2/WKRetainPtr.h>
39 #include <wtf/PassOwnPtr.h>
42 #include <WebKit2/WKPagePrivateMac.h>
45 #if PLATFORM(MAC) || PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
46 #include "EventSenderProxy.h"
51 static const double defaultLongTimeout = 30;
52 static const double defaultShortTimeout = 15;
53 static const double defaultNoTimeout = -1;
55 static WKURLRef blankURL()
57 static WKURLRef staticBlankURL = WKURLCreateWithUTF8CString("about:blank");
58 return staticBlankURL;
61 static TestController* controller;
63 TestController& TestController::shared()
69 TestController::TestController(int argc, const char* argv[])
72 , m_printSeparators(false)
73 , m_usingServerMode(false)
74 , m_gcBetweenTests(false)
76 , m_doneResetting(false)
77 , m_longTimeout(defaultLongTimeout)
78 , m_shortTimeout(defaultShortTimeout)
79 , m_noTimeout(defaultNoTimeout)
80 , m_useWaitToDumpWatchdogTimer(true)
81 , m_didPrintWebProcessCrashedMessage(false)
82 , m_shouldExitWhenWebProcessCrashes(true)
83 , m_beforeUnloadReturnValue(true)
84 #if PLATFORM(MAC) || PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
85 , m_eventSenderProxy(new EventSenderProxy(this))
88 initialize(argc, argv);
94 TestController::~TestController()
98 static WKRect getWindowFrameMainPage(WKPageRef page, const void* clientInfo)
100 PlatformWebView* view = static_cast<TestController*>(const_cast<void*>(clientInfo))->mainWebView();
101 return view->windowFrame();
104 static void setWindowFrameMainPage(WKPageRef page, WKRect frame, const void* clientInfo)
106 PlatformWebView* view = static_cast<TestController*>(const_cast<void*>(clientInfo))->mainWebView();
107 view->setWindowFrame(frame);
110 static WKRect getWindowFrameOtherPage(WKPageRef page, const void* clientInfo)
112 PlatformWebView* view = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo));
113 return view->windowFrame();
116 static void setWindowFrameOtherPage(WKPageRef page, WKRect frame, const void* clientInfo)
118 PlatformWebView* view = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo));
119 view->setWindowFrame(frame);
122 static bool runBeforeUnloadConfirmPanel(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo)
124 TestController* testController = static_cast<TestController*>(const_cast<void*>(clientInfo));
125 printf("CONFIRM NAVIGATION: %s\n", toSTD(message).c_str());
126 return testController->beforeUnloadReturnValue();
129 static unsigned long long exceededDatabaseQuota(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKStringRef, WKStringRef, unsigned long long, unsigned long long, unsigned long long, unsigned long long, const void*)
131 static const unsigned long long defaultQuota = 5 * 1024 * 1024;
136 void TestController::runModal(WKPageRef page, const void* clientInfo)
138 PlatformWebView* view = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo));
139 view->setWindowIsKey(false);
141 view->setWindowIsKey(true);
144 static void closeOtherPage(WKPageRef page, const void* clientInfo)
147 PlatformWebView* view = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo));
151 static void focus(WKPageRef page, const void* clientInfo)
153 PlatformWebView* view = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo));
154 view->setWindowIsKey(true);
157 static void unfocus(WKPageRef page, const void* clientInfo)
159 PlatformWebView* view = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo));
160 view->setWindowIsKey(false);
163 WKPageRef TestController::createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*)
165 PlatformWebView* view = new PlatformWebView(WKPageGetContext(oldPage), WKPageGetPageGroup(oldPage));
166 WKPageRef newPage = view->page();
168 view->resizeTo(800, 600);
170 WKPageUIClient otherPageUIClient = {
171 kWKPageUIClientCurrentVersion,
173 0, // createNewPage_deprecatedForUseWithV0
179 0, // runJavaScriptAlert
180 0, // runJavaScriptConfirm
181 0, // runJavaScriptPrompt
183 0, // mouseDidMoveOverElement_deprecatedForUseWithV0
184 0, // missingPluginButtonClicked
185 0, // didNotHandleKeyEvent
186 0, // didNotHandleWheelEvent
187 0, // toolbarsAreVisible
188 0, // setToolbarsAreVisible
189 0, // menuBarIsVisible
190 0, // setMenuBarIsVisible
191 0, // statusBarIsVisible
192 0, // setStatusBarIsVisible
195 getWindowFrameOtherPage,
196 setWindowFrameOtherPage,
197 runBeforeUnloadConfirmPanel,
200 exceededDatabaseQuota,
202 0, // decidePolicyForGeolocationPermissionRequest
209 0, // didCompleteRubberBandForMainFrame
210 0, // saveDataToFileInDownloadsFolder
211 0, // shouldInterruptJavaScript
213 0, // mouseDidMoveOverElement
214 0, // decidePolicyForNotificationPermissionRequest
215 0, // unavailablePluginButtonClicked
217 WKPageSetPageUIClient(newPage, &otherPageUIClient);
223 const char* TestController::libraryPathForTesting()
225 // FIXME: This may not be sufficient to prevent interactions/crashes
226 // when running more than one copy of DumpRenderTree.
227 // See https://bugs.webkit.org/show_bug.cgi?id=10906
228 char* dumpRenderTreeTemp = getenv("DUMPRENDERTREE_TEMP");
229 if (dumpRenderTreeTemp)
230 return dumpRenderTreeTemp;
231 return platformLibraryPathForTesting();
235 void TestController::initialize(int argc, const char* argv[])
237 platformInitialize();
240 fputs("Usage: WebKitTestRunner [options] filename [filename2..n]\n", stderr);
241 // FIXME: Refactor option parsing to allow us to print
242 // an auto-generated list of options.
246 bool printSupportedFeatures = false;
248 for (int i = 1; i < argc; ++i) {
249 std::string argument(argv[i]);
251 if (argument == "--timeout" && i + 1 < argc) {
252 m_longTimeout = atoi(argv[++i]);
253 // Scale up the short timeout to match.
254 m_shortTimeout = defaultShortTimeout * m_longTimeout / defaultLongTimeout;
258 if (argument == "--no-timeout") {
259 m_useWaitToDumpWatchdogTimer = false;
263 if (argument == "--pixel-tests") {
267 if (argument == "--verbose") {
271 if (argument == "--gc-between-tests") {
272 m_gcBetweenTests = true;
275 if (argument == "--print-supported-features") {
276 printSupportedFeatures = true;
280 // Skip any other arguments that begin with '--'.
281 if (argument.length() >= 2 && argument[0] == '-' && argument[1] == '-')
284 m_paths.push_back(argument);
287 if (printSupportedFeatures) {
288 // FIXME: On Windows, DumpRenderTree uses this to expose whether it supports 3d
289 // transforms and accelerated compositing. When we support those features, we
290 // should match DRT's behavior.
294 m_usingServerMode = (m_paths.size() == 1 && m_paths[0] == "-");
295 if (m_usingServerMode)
296 m_printSeparators = true;
298 m_printSeparators = m_paths.size() > 1;
300 initializeInjectedBundlePath();
301 initializeTestPluginDirectory();
303 WKRetainPtr<WKStringRef> pageGroupIdentifier(AdoptWK, WKStringCreateWithUTF8CString("WebKitTestRunnerPageGroup"));
304 m_pageGroup.adopt(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get()));
306 m_context.adopt(WKContextCreateWithInjectedBundlePath(injectedBundlePath()));
308 const char* path = libraryPathForTesting();
310 Vector<char> databaseDirectory(strlen(path) + strlen("/Databases") + 1);
311 sprintf(databaseDirectory.data(), "%s%s", path, "/Databases");
312 WKRetainPtr<WKStringRef> databaseDirectoryWK(AdoptWK, WKStringCreateWithUTF8CString(databaseDirectory.data()));
313 WKContextSetDatabaseDirectory(m_context.get(), databaseDirectoryWK.get());
316 platformInitializeContext();
318 WKContextInjectedBundleClient injectedBundleClient = {
319 kWKContextInjectedBundleClientCurrentVersion,
321 didReceiveMessageFromInjectedBundle,
322 didReceiveSynchronousMessageFromInjectedBundle
324 WKContextSetInjectedBundleClient(m_context.get(), &injectedBundleClient);
326 WKContextSetAdditionalPluginsDirectory(m_context.get(), testPluginDirectory());
328 m_mainWebView = adoptPtr(new PlatformWebView(m_context.get(), m_pageGroup.get()));
330 WKPageUIClient pageUIClient = {
331 kWKPageUIClientCurrentVersion,
333 0, // createNewPage_deprecatedForUseWithV0
339 0, // runJavaScriptAlert
340 0, // runJavaScriptConfirm
341 0, // runJavaScriptPrompt
343 0, // mouseDidMoveOverElement_deprecatedForUseWithV0
344 0, // missingPluginButtonClicked
345 0, // didNotHandleKeyEvent
346 0, // didNotHandleWheelEvent
347 0, // toolbarsAreVisible
348 0, // setToolbarsAreVisible
349 0, // menuBarIsVisible
350 0, // setMenuBarIsVisible
351 0, // statusBarIsVisible
352 0, // setStatusBarIsVisible
355 getWindowFrameMainPage,
356 setWindowFrameMainPage,
357 runBeforeUnloadConfirmPanel,
360 exceededDatabaseQuota,
362 0, // decidePolicyForGeolocationPermissionRequest
369 0, // didCompleteRubberBandForMainFrame
370 0, // saveDataToFileInDownloadsFolder
371 0, // shouldInterruptJavaScript
373 0, // mouseDidMoveOverElement
374 0, // decidePolicyForNotificationPermissionRequest
375 0, // unavailablePluginButtonClicked
377 WKPageSetPageUIClient(m_mainWebView->page(), &pageUIClient);
379 WKPageLoaderClient pageLoaderClient = {
380 kWKPageLoaderClientCurrentVersion,
382 0, // didStartProvisionalLoadForFrame
383 0, // didReceiveServerRedirectForProvisionalLoadForFrame
384 0, // didFailProvisionalLoadWithErrorForFrame
385 didCommitLoadForFrame,
386 0, // didFinishDocumentLoadForFrame
387 didFinishLoadForFrame,
388 0, // didFailLoadWithErrorForFrame
389 0, // didSameDocumentNavigationForFrame
390 0, // didReceiveTitleForFrame
391 0, // didFirstLayoutForFrame
392 0, // didFirstVisuallyNonEmptyLayoutForFrame
393 0, // didRemoveFrameFromHierarchy
394 0, // didFailToInitializePlugin
395 0, // didDisplayInsecureContentForFrame
396 0, // canAuthenticateAgainstProtectionSpaceInFrame
397 0, // didReceiveAuthenticationChallengeInFrame
398 0, // didStartProgress
399 0, // didChangeProgress
400 0, // didFinishProgress
401 0, // didBecomeUnresponsive
402 0, // didBecomeResponsive
404 0, // didChangeBackForwardList
405 0, // shouldGoToBackForwardListItem
406 0, // didRunInsecureContentForFrame
407 0, // didDetectXSSForFrame
408 0, // didNewFirstVisuallyNonEmptyLayout
409 0, // willGoToBackForwardListItem
410 0, // interactionOccurredWhileProcessUnresponsive
413 WKPageSetPageLoaderClient(m_mainWebView->page(), &pageLoaderClient);
416 bool TestController::resetStateToConsistentValues()
420 m_beforeUnloadReturnValue = true;
422 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("Reset"));
423 WKRetainPtr<WKMutableDictionaryRef> resetMessageBody = adoptWK(WKMutableDictionaryCreate());
425 WKRetainPtr<WKStringRef> shouldGCKey = adoptWK(WKStringCreateWithUTF8CString("ShouldGC"));
426 WKRetainPtr<WKBooleanRef> shouldGCValue = adoptWK(WKBooleanCreate(m_gcBetweenTests));
427 WKDictionaryAddItem(resetMessageBody.get(), shouldGCKey.get(), shouldGCValue.get());
429 WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), resetMessageBody.get());
431 WKContextSetShouldUseFontSmoothing(TestController::shared().context(), false);
433 WKContextSetCacheModel(TestController::shared().context(), kWKCacheModelDocumentBrowser);
435 // FIXME: This function should also ensure that there is only one page open.
438 WKPreferencesRef preferences = WKPageGroupGetPreferences(m_pageGroup.get());
439 WKPreferencesResetTestRunnerOverrides(preferences);
440 WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true);
441 WKPreferencesSetFontSmoothingLevel(preferences, kWKFontSmoothingLevelNoSubpixelAntiAliasing);
442 WKPreferencesSetXSSAuditorEnabled(preferences, false);
443 WKPreferencesSetWebAudioEnabled(preferences, true);
444 WKPreferencesSetDeveloperExtrasEnabled(preferences, true);
445 WKPreferencesSetJavaScriptExperimentsEnabled(preferences, true);
446 WKPreferencesSetJavaScriptCanOpenWindowsAutomatically(preferences, true);
447 WKPreferencesSetJavaScriptCanAccessClipboard(preferences, true);
448 WKPreferencesSetDOMPasteAllowed(preferences, true);
449 WKPreferencesSetUniversalAccessFromFileURLsAllowed(preferences, true);
450 WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true);
451 #if ENABLE(FULLSCREEN_API)
452 WKPreferencesSetFullScreenEnabled(preferences, true);
454 WKPreferencesSetPageCacheEnabled(preferences, false);
456 // [Qt][WK2]REGRESSION(r104881):It broke hundreds of tests
457 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=76247
459 WKPreferencesSetMockScrollbarsEnabled(preferences, true);
463 static WKStringRef standardFontFamily = WKStringCreateWithUTF8CString("Times");
464 static WKStringRef cursiveFontFamily = WKStringCreateWithUTF8CString("Apple Chancery");
465 static WKStringRef fantasyFontFamily = WKStringCreateWithUTF8CString("Papyrus");
466 static WKStringRef fixedFontFamily = WKStringCreateWithUTF8CString("Courier");
467 static WKStringRef pictographFontFamily = WKStringCreateWithUTF8CString("Apple Color Emoji");
468 static WKStringRef sansSerifFontFamily = WKStringCreateWithUTF8CString("Helvetica");
469 static WKStringRef serifFontFamily = WKStringCreateWithUTF8CString("Times");
471 WKPreferencesSetStandardFontFamily(preferences, standardFontFamily);
472 WKPreferencesSetCursiveFontFamily(preferences, cursiveFontFamily);
473 WKPreferencesSetFantasyFontFamily(preferences, fantasyFontFamily);
474 WKPreferencesSetFixedFontFamily(preferences, fixedFontFamily);
475 WKPreferencesSetPictographFontFamily(preferences, pictographFontFamily);
476 WKPreferencesSetSansSerifFontFamily(preferences, sansSerifFontFamily);
477 WKPreferencesSetSerifFontFamily(preferences, serifFontFamily);
479 WKPreferencesSetInspectorUsesWebKitUserInterface(preferences, true);
481 // in the case that a test using the chrome input field failed, be sure to clean up for the next test
482 m_mainWebView->removeChromeInputField();
483 m_mainWebView->focus();
485 // Re-set to the default backing scale factor by setting the custom scale factor to 0.
486 WKPageSetCustomBackingScaleFactor(m_mainWebView->page(), 0);
488 // Reset main page back to about:blank
489 m_doneResetting = false;
491 WKPageLoadURL(m_mainWebView->page(), blankURL());
492 runUntil(m_doneResetting, ShortTimeout);
493 return m_doneResetting;
496 bool TestController::runTest(const char* test)
498 if (!resetStateToConsistentValues()) {
500 pid_t pid = WKPageGetProcessIdentifier(m_mainWebView->page());
501 fprintf(stderr, "#CRASHED - WebProcess (pid %ld)\n", static_cast<long>(pid));
503 fputs("#CRASHED - WebProcess\n", stderr);
509 std::string pathOrURL(test);
510 std::string expectedPixelHash;
511 size_t separatorPos = pathOrURL.find("'");
512 if (separatorPos != std::string::npos) {
513 pathOrURL = std::string(std::string(test), 0, separatorPos);
514 expectedPixelHash = std::string(std::string(test), separatorPos + 1);
517 m_state = RunningTest;
519 m_currentInvocation = adoptPtr(new TestInvocation(pathOrURL));
521 m_currentInvocation->setIsPixelTest(expectedPixelHash);
523 m_currentInvocation->invoke();
524 m_currentInvocation.clear();
529 void TestController::runTestingServerLoop()
531 char filenameBuffer[2048];
532 while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) {
533 char* newLineCharacter = strchr(filenameBuffer, '\n');
534 if (newLineCharacter)
535 *newLineCharacter = '\0';
537 if (strlen(filenameBuffer) == 0)
540 if (!runTest(filenameBuffer))
545 void TestController::run()
547 if (m_usingServerMode)
548 runTestingServerLoop();
550 for (size_t i = 0; i < m_paths.size(); ++i) {
551 if (!runTest(m_paths[i].c_str()))
557 void TestController::runUntil(bool& done, TimeoutDuration timeoutDuration)
560 switch (timeoutDuration) {
562 timeout = m_shortTimeout;
565 timeout = m_longTimeout;
569 timeout = m_noTimeout;
573 platformRunUntil(done, timeout);
576 // WKContextInjectedBundleClient
578 void TestController::didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
580 static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveMessageFromInjectedBundle(messageName, messageBody);
583 void TestController::didReceiveSynchronousMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void* clientInfo)
585 *returnData = static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody).leakRef();
588 void TestController::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
590 if (!m_currentInvocation)
592 m_currentInvocation->didReceiveMessageFromInjectedBundle(messageName, messageBody);
595 WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
597 #if PLATFORM(MAC) || PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
598 if (WKStringIsEqualToUTF8CString(messageName, "EventSender")) {
599 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
600 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
602 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
603 WKStringRef subMessageName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, subMessageKey.get()));
605 if (WKStringIsEqualToUTF8CString(subMessageName, "KeyDown")) {
606 WKRetainPtr<WKStringRef> keyKey = adoptWK(WKStringCreateWithUTF8CString("Key"));
607 WKStringRef key = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, keyKey.get()));
609 WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers"));
610 WKEventModifiers modifiers = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get()))));
612 WKRetainPtr<WKStringRef> locationKey = adoptWK(WKStringCreateWithUTF8CString("Location"));
613 unsigned location = static_cast<unsigned>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, locationKey.get()))));
615 // Forward to WebProcess
616 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
617 m_eventSenderProxy->keyDown(key, modifiers, location);
618 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
622 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown") || WKStringIsEqualToUTF8CString(subMessageName, "MouseUp")) {
623 WKRetainPtr<WKStringRef> buttonKey = adoptWK(WKStringCreateWithUTF8CString("Button"));
624 unsigned button = static_cast<unsigned>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, buttonKey.get()))));
626 WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers"));
627 WKEventModifiers modifiers = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get()))));
629 // Forward to WebProcess
630 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
631 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown"))
632 m_eventSenderProxy->mouseDown(button, modifiers);
634 m_eventSenderProxy->mouseUp(button, modifiers);
635 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
639 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseMoveTo")) {
640 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
641 double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get())));
643 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
644 double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get())));
646 // Forward to WebProcess
647 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
648 m_eventSenderProxy->mouseMoveTo(x, y);
649 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
653 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollBy")) {
654 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
655 double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get())));
657 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
658 double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get())));
660 // Forward to WebProcess
661 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
662 m_eventSenderProxy->mouseScrollBy(x, y);
663 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
667 if (WKStringIsEqualToUTF8CString(subMessageName, "LeapForward")) {
668 WKRetainPtr<WKStringRef> timeKey = adoptWK(WKStringCreateWithUTF8CString("TimeInMilliseconds"));
669 unsigned time = static_cast<unsigned>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, timeKey.get()))));
671 m_eventSenderProxy->leapForward(time);
675 #if ENABLE(TOUCH_EVENTS)
676 if (WKStringIsEqualToUTF8CString(subMessageName, "AddTouchPoint")) {
677 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
678 int x = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))));
680 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
681 int y = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))));
683 m_eventSenderProxy->addTouchPoint(x, y);
687 if (WKStringIsEqualToUTF8CString(subMessageName, "UpdateTouchPoint")) {
688 WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index"));
689 int index = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get()))));
691 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));
692 int x = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))));
694 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));
695 int y = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))));
697 m_eventSenderProxy->updateTouchPoint(index, x, y);
701 if (WKStringIsEqualToUTF8CString(subMessageName, "SetTouchModifier")) {
702 WKRetainPtr<WKStringRef> modifierKey = adoptWK(WKStringCreateWithUTF8CString("Modifier"));
703 WKEventModifiers modifier = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifierKey.get()))));
705 WKRetainPtr<WKStringRef> enableKey = adoptWK(WKStringCreateWithUTF8CString("Enable"));
706 bool enable = static_cast<bool>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, enableKey.get()))));
708 m_eventSenderProxy->setTouchModifier(modifier, enable);
712 if (WKStringIsEqualToUTF8CString(subMessageName, "SetTouchPointRadius")) {
713 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("RadiusX"));
714 int x = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))));
716 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("RadiusY"));
717 int y = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))));
719 m_eventSenderProxy->setTouchPointRadius(x, y);
723 if (WKStringIsEqualToUTF8CString(subMessageName, "TouchStart")) {
724 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
725 m_eventSenderProxy->touchStart();
726 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
730 if (WKStringIsEqualToUTF8CString(subMessageName, "TouchMove")) {
731 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
732 m_eventSenderProxy->touchMove();
733 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
737 if (WKStringIsEqualToUTF8CString(subMessageName, "TouchEnd")) {
738 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
739 m_eventSenderProxy->touchEnd();
740 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
744 if (WKStringIsEqualToUTF8CString(subMessageName, "TouchCancel")) {
745 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true);
746 m_eventSenderProxy->touchCancel();
747 WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false);
751 if (WKStringIsEqualToUTF8CString(subMessageName, "ClearTouchPoints")) {
752 m_eventSenderProxy->clearTouchPoints();
756 if (WKStringIsEqualToUTF8CString(subMessageName, "ReleaseTouchPoint")) {
757 WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index"));
758 int index = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get()))));
759 m_eventSenderProxy->releaseTouchPoint(index);
763 if (WKStringIsEqualToUTF8CString(subMessageName, "CancelTouchPoint")) {
764 WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index"));
765 int index = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get()))));
766 m_eventSenderProxy->cancelTouchPoint(index);
770 ASSERT_NOT_REACHED();
773 return m_currentInvocation->didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody);
776 // WKPageLoaderClient
778 void TestController::didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef, const void* clientInfo)
780 static_cast<TestController*>(const_cast<void*>(clientInfo))->didCommitLoadForFrame(page, frame);
783 void TestController::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef, const void* clientInfo)
785 static_cast<TestController*>(const_cast<void*>(clientInfo))->didFinishLoadForFrame(page, frame);
788 void TestController::processDidCrash(WKPageRef page, const void* clientInfo)
790 static_cast<TestController*>(const_cast<void*>(clientInfo))->processDidCrash();
793 void TestController::didCommitLoadForFrame(WKPageRef page, WKFrameRef frame)
795 if (!WKFrameIsMainFrame(frame))
798 mainWebView()->focus();
801 void TestController::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame)
803 if (m_state != Resetting)
806 if (!WKFrameIsMainFrame(frame))
809 WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKFrameCopyURL(frame));
810 if (!WKURLIsEqual(wkURL.get(), blankURL()))
813 m_doneResetting = true;
814 shared().notifyDone();
817 void TestController::processDidCrash()
819 // This function can be called multiple times when crash logs are being saved on Windows, so
820 // ensure we only print the crashed message once.
821 if (!m_didPrintWebProcessCrashedMessage) {
823 pid_t pid = WKPageGetProcessIdentifier(m_mainWebView->page());
824 fprintf(stderr, "#CRASHED - WebProcess (pid %ld)\n", static_cast<long>(pid));
826 fputs("#CRASHED - WebProcess\n", stderr);
829 m_didPrintWebProcessCrashedMessage = true;
832 if (m_shouldExitWhenWebProcessCrashes)