void TestInvocation::invoke() { sizeWebViewForCurrentTest(m_pathOrURL.c_str()); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("BeginTest")); WKRetainPtr<WKBooleanRef> dumpPixels = adoptWK(WKBooleanCreate(m_dumpPixels)); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), dumpPixels.get()); TestController::shared().runUntil(m_gotInitialResponse, TestController::ShortTimeout); if (!m_gotInitialResponse) { dump("Timed out waiting for initial response from web process\n"); return; } if (m_error) { dump("FAIL\n"); return; } if (shouldOpenWebInspector(m_pathOrURL.c_str())) WKInspectorShow(WKPageGetInspector(TestController::shared().mainWebView()->page())); WKPageLoadURL(TestController::shared().mainWebView()->page(), m_url.get()); TestController::shared().runUntil(m_gotFinalMessage, TestController::LongTimeout); if (!m_gotFinalMessage) dump("Timed out waiting for final message from web process\n"); else if (m_error) dump("FAIL\n"); WKInspectorClose(WKPageGetInspector(TestController::shared().mainWebView()->page())); }
// Used to test sending a WKType round trip to the WebProcess and back. // Result is stored into the recievedBody member variable. void roundTrip(WKTypeRef object) { WKTypeID storedTypeID = WKGetTypeID(object); recievedBody.clear(); didReceiveMessage = false; WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("RoundTrip").get(), object); Util::run(&didReceiveMessage); EXPECT_NOT_NULL(recievedBody); EXPECT_EQ(storedTypeID, WKGetTypeID(recievedBody.get())); }
bool TestController::resetStateToConsistentValues() { m_state = Resetting; WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("Reset")); WKRetainPtr<WKMutableDictionaryRef> resetMessageBody = adoptWK(WKMutableDictionaryCreate()); WKRetainPtr<WKStringRef> shouldGCKey = adoptWK(WKStringCreateWithUTF8CString("ShouldGC")); WKRetainPtr<WKBooleanRef> shouldGCValue = adoptWK(WKBooleanCreate(m_gcBetweenTests)); WKDictionaryAddItem(resetMessageBody.get(), shouldGCKey.get(), shouldGCValue.get()); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), resetMessageBody.get()); // FIXME: This function should also ensure that there is only one page open. // Reset preferences WKPreferencesRef preferences = WKPageGroupGetPreferences(m_pageGroup.get()); WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true); WKPreferencesSetFontSmoothingLevel(preferences, kWKFontSmoothingLevelNoSubpixelAntiAliasing); WKPreferencesSetXSSAuditorEnabled(preferences, false); WKPreferencesSetDeveloperExtrasEnabled(preferences, true); WKPreferencesSetJavaScriptCanOpenWindowsAutomatically(preferences, true); WKPreferencesSetJavaScriptCanAccessClipboard(preferences, true); WKPreferencesSetDOMPasteAllowed(preferences, true); WKPreferencesSetUniversalAccessFromFileURLsAllowed(preferences, true); WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true); #if ENABLE(FULLSCREEN_API) WKPreferencesSetFullScreenEnabled(preferences, true); #endif static WKStringRef standardFontFamily = WKStringCreateWithUTF8CString("Times"); static WKStringRef cursiveFontFamily = WKStringCreateWithUTF8CString("Apple Chancery"); static WKStringRef fantasyFontFamily = WKStringCreateWithUTF8CString("Papyrus"); static WKStringRef fixedFontFamily = WKStringCreateWithUTF8CString("Courier"); static WKStringRef sansSerifFontFamily = WKStringCreateWithUTF8CString("Helvetica"); static WKStringRef serifFontFamily = WKStringCreateWithUTF8CString("Times"); WKPreferencesSetStandardFontFamily(preferences, standardFontFamily); WKPreferencesSetCursiveFontFamily(preferences, cursiveFontFamily); WKPreferencesSetFantasyFontFamily(preferences, fantasyFontFamily); WKPreferencesSetFixedFontFamily(preferences, fixedFontFamily); WKPreferencesSetSansSerifFontFamily(preferences, sansSerifFontFamily); WKPreferencesSetSerifFontFamily(preferences, serifFontFamily); m_mainWebView->focus(); // Reset main page back to about:blank m_doneResetting = false; WKPageLoadURL(m_mainWebView->page(), blankURL()); runUntil(m_doneResetting, ShortTimeout); return m_doneResetting; }
TEST(WebKit2, CanHandleRequest) { WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("CanHandleRequestTest")); setInjectedBundleClient(context.get()); _WKContextRegisterURLSchemeAsEmptyDocument(context.get(), Util::toWK("emptyscheme").get()); PlatformWebView webView(context.get()); WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("CheckCanHandleRequest").get(), 0); Util::run(&didReceiveMessage); EXPECT_TRUE(canHandleRequest); }
void TestInvocation::invoke() { sizeWebViewForCurrentTest(m_pathOrURL.c_str()); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("BeginTest")); WKRetainPtr<WKMutableDictionaryRef> beginTestMessageBody = adoptWK(WKMutableDictionaryCreate()); WKRetainPtr<WKStringRef> dumpFrameLoadDelegatesKey = adoptWK(WKStringCreateWithUTF8CString("DumpFrameLoadDelegates")); WKRetainPtr<WKBooleanRef> dumpFrameLoadDelegatesValue = adoptWK(WKBooleanCreate(shouldLogFrameLoadDelegates(m_pathOrURL.c_str()))); WKDictionaryAddItem(beginTestMessageBody.get(), dumpFrameLoadDelegatesKey.get(), dumpFrameLoadDelegatesValue.get()); WKRetainPtr<WKStringRef> dumpPixelsKey = adoptWK(WKStringCreateWithUTF8CString("DumpPixels")); WKRetainPtr<WKBooleanRef> dumpPixelsValue = adoptWK(WKBooleanCreate(m_dumpPixels)); WKDictionaryAddItem(beginTestMessageBody.get(), dumpPixelsKey.get(), dumpPixelsValue.get()); WKRetainPtr<WKStringRef> useWaitToDumpWatchdogTimerKey = adoptWK(WKStringCreateWithUTF8CString("UseWaitToDumpWatchdogTimer")); WKRetainPtr<WKBooleanRef> useWaitToDumpWatchdogTimerValue = adoptWK(WKBooleanCreate(TestController::shared().useWaitToDumpWatchdogTimer())); WKDictionaryAddItem(beginTestMessageBody.get(), useWaitToDumpWatchdogTimerKey.get(), useWaitToDumpWatchdogTimerValue.get()); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), beginTestMessageBody.get()); TestController::shared().runUntil(m_gotInitialResponse, TestController::ShortTimeout); if (!m_gotInitialResponse) { dump("Timed out waiting for initial response from web process\n"); return; } if (m_error) { dump("FAIL\n"); return; } #if ENABLE(INSPECTOR) if (shouldOpenWebInspector(m_pathOrURL.c_str())) WKInspectorShow(WKPageGetInspector(TestController::shared().mainWebView()->page())); #endif // ENABLE(INSPECTOR) WKPageLoadURL(TestController::shared().mainWebView()->page(), m_url.get()); TestController::shared().runUntil(m_gotFinalMessage, TestController::shared().useWaitToDumpWatchdogTimer() ? TestController::LongTimeout : TestController::NoTimeout); if (!m_gotFinalMessage) dump("Timed out waiting for final message from web process\n"); else if (m_error) dump("FAIL\n"); #if ENABLE(INSPECTOR) WKInspectorClose(WKPageGetInspector(TestController::shared().mainWebView()->page())); #endif // ENABLE(INSPECTOR) }
TEST(WebKit2, MouseMoveAfterCrash) #endif { WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("MouseMoveAfterCrashTest")); PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("mouse-move-listener", "html")); WKPageLoadURL(webView.page(), url.get()); Util::run(&didFinishLoad); didFinishLoad = false; WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("Pause").get(), 0); webView.simulateSpacebarKeyPress(); // Move the mouse once we are hung. webView.simulateMouseMove(10, 10); webView.simulateMouseMove(20, 20); // After moving the mouse (while the web process was hung on the Pause message), kill the web process. It is restarted by reloading the page. WKPageTerminate(webView.page()); WKPageReload(webView.page()); // Wait until we load the page a second time. Util::run(&didFinishLoad); EXPECT_JS_FALSE(webView.page(), "didMoveMouse()"); // Once the page has reloaded, try moving the mouse to verify that we get mouse move events. webView.simulateMouseMove(10, 10); webView.simulateMouseMove(20, 20); EXPECT_JS_TRUE(webView.page(), "didMoveMouse()"); }
void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody) { if (WKStringIsEqualToUTF8CString(messageName, "Error")) { // Set all states to true to stop spinning the runloop. m_gotInitialResponse = true; m_gotFinalMessage = true; m_error = true; TestController::shared().notifyDone(); return; } if (WKStringIsEqualToUTF8CString(messageName, "Ack")) { ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); WKStringRef messageBodyString = static_cast<WKStringRef>(messageBody); if (WKStringIsEqualToUTF8CString(messageBodyString, "BeginTest")) { m_gotInitialResponse = true; TestController::shared().notifyDone(); return; } ASSERT_NOT_REACHED(); } if (WKStringIsEqualToUTF8CString(messageName, "Done")) { ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); WKRetainPtr<WKStringRef> textOutputKey(AdoptWK, WKStringCreateWithUTF8CString("TextOutput")); WKStringRef textOutput = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, textOutputKey.get())); WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult")); WKImageRef pixelResult = static_cast<WKImageRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultKey.get())); ASSERT(!pixelResult || m_dumpPixels); WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects")); WKArrayRef repaintRects = static_cast<WKArrayRef>(WKDictionaryGetItemForKey(messageBodyDictionary, repaintRectsKey.get())); // Dump text. dump(toSTD(textOutput).c_str(), true); // Dump pixels (if necessary). if (m_dumpPixels && pixelResult) dumpPixelsAndCompareWithExpected(pixelResult, repaintRects); fputs("#EOF\n", stdout); fflush(stdout); fflush(stderr); m_gotFinalMessage = true; TestController::shared().notifyDone(); return; } if (WKStringIsEqualToUTF8CString(messageName, "BeforeUnloadReturnValue")) { ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); WKBooleanRef beforeUnloadReturnValue = static_cast<WKBooleanRef>(messageBody); TestController::shared().setBeforeUnloadReturnValue(WKBooleanGetValue(beforeUnloadReturnValue)); return; } if (WKStringIsEqualToUTF8CString(messageName, "AddChromeInputField")) { TestController::shared().mainWebView()->addChromeInputField(); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallAddChromeInputFieldCallback")); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0); return; } if (WKStringIsEqualToUTF8CString(messageName, "RemoveChromeInputField")) { TestController::shared().mainWebView()->removeChromeInputField(); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallRemoveChromeInputFieldCallback")); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0); return; } if (WKStringIsEqualToUTF8CString(messageName, "FocusWebView")) { TestController::shared().mainWebView()->makeWebViewFirstResponder(); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallFocusWebViewCallback")); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0); return; } if (WKStringIsEqualToUTF8CString(messageName, "SetBackingScaleFactor")) { ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID()); double backingScaleFactor = WKDoubleGetValue(static_cast<WKDoubleRef>(messageBody)); WKPageSetCustomBackingScaleFactor(TestController::shared().mainWebView()->page(), backingScaleFactor); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallSetBackingScaleFactorCallback")); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0); return; } ASSERT_NOT_REACHED(); }
bool TestController::resetStateToConsistentValues() { m_state = Resetting; m_beforeUnloadReturnValue = true; WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("Reset")); WKRetainPtr<WKMutableDictionaryRef> resetMessageBody = adoptWK(WKMutableDictionaryCreate()); WKRetainPtr<WKStringRef> shouldGCKey = adoptWK(WKStringCreateWithUTF8CString("ShouldGC")); WKRetainPtr<WKBooleanRef> shouldGCValue = adoptWK(WKBooleanCreate(m_gcBetweenTests)); WKDictionaryAddItem(resetMessageBody.get(), shouldGCKey.get(), shouldGCValue.get()); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), resetMessageBody.get()); WKContextSetShouldUseFontSmoothing(TestController::shared().context(), false); WKContextSetCacheModel(TestController::shared().context(), kWKCacheModelDocumentBrowser); // FIXME: This function should also ensure that there is only one page open. // Reset the EventSender for each test. #if PLATFORM(MAC) || PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL) m_eventSenderProxy = adoptPtr(new EventSenderProxy(this)); #endif // Reset preferences WKPreferencesRef preferences = WKPageGroupGetPreferences(m_pageGroup.get()); WKPreferencesResetTestRunnerOverrides(preferences); WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true); WKPreferencesSetFontSmoothingLevel(preferences, kWKFontSmoothingLevelNoSubpixelAntiAliasing); WKPreferencesSetXSSAuditorEnabled(preferences, false); WKPreferencesSetWebAudioEnabled(preferences, true); WKPreferencesSetDeveloperExtrasEnabled(preferences, true); WKPreferencesSetJavaScriptExperimentsEnabled(preferences, true); WKPreferencesSetJavaScriptCanOpenWindowsAutomatically(preferences, true); WKPreferencesSetJavaScriptCanAccessClipboard(preferences, true); WKPreferencesSetDOMPasteAllowed(preferences, true); WKPreferencesSetUniversalAccessFromFileURLsAllowed(preferences, true); WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true); #if ENABLE(FULLSCREEN_API) WKPreferencesSetFullScreenEnabled(preferences, true); #endif WKPreferencesSetPageCacheEnabled(preferences, false); WKPreferencesSetAsynchronousPluginInitializationEnabled(preferences, false); WKPreferencesSetAsynchronousPluginInitializationEnabledForAllPlugins(preferences, false); WKPreferencesSetArtificialPluginInitializationDelayEnabled(preferences, false); WKPreferencesSetTabToLinksEnabled(preferences, false); WKPreferencesSetInteractiveFormValidationEnabled(preferences, true); WKPreferencesSetMockScrollbarsEnabled(preferences, true); #if !PLATFORM(QT) static WKStringRef standardFontFamily = WKStringCreateWithUTF8CString("Times"); static WKStringRef cursiveFontFamily = WKStringCreateWithUTF8CString("Apple Chancery"); static WKStringRef fantasyFontFamily = WKStringCreateWithUTF8CString("Papyrus"); static WKStringRef fixedFontFamily = WKStringCreateWithUTF8CString("Courier"); static WKStringRef pictographFontFamily = WKStringCreateWithUTF8CString("Apple Color Emoji"); static WKStringRef sansSerifFontFamily = WKStringCreateWithUTF8CString("Helvetica"); static WKStringRef serifFontFamily = WKStringCreateWithUTF8CString("Times"); WKPreferencesSetStandardFontFamily(preferences, standardFontFamily); WKPreferencesSetCursiveFontFamily(preferences, cursiveFontFamily); WKPreferencesSetFantasyFontFamily(preferences, fantasyFontFamily); WKPreferencesSetFixedFontFamily(preferences, fixedFontFamily); WKPreferencesSetPictographFontFamily(preferences, pictographFontFamily); WKPreferencesSetSansSerifFontFamily(preferences, sansSerifFontFamily); WKPreferencesSetSerifFontFamily(preferences, serifFontFamily); #endif WKPreferencesSetScreenFontSubstitutionEnabled(preferences, true); WKPreferencesSetInspectorUsesWebKitUserInterface(preferences, true); WKPreferencesSetAsynchronousSpellCheckingEnabled(preferences, false); #if !PLATFORM(MAC) WKTextCheckerContinuousSpellCheckingEnabledStateChanged(true); #endif // in the case that a test using the chrome input field failed, be sure to clean up for the next test m_mainWebView->removeChromeInputField(); m_mainWebView->focus(); // Re-set to the default backing scale factor by setting the custom scale factor to 0. WKPageSetCustomBackingScaleFactor(m_mainWebView->page(), 0); #if PLATFORM(EFL) // EFL use a real window while other ports such as Qt don't. // In EFL, we need to resize the window to the original size after calls to window.resizeTo. WKRect rect = m_mainWebView->windowFrame(); m_mainWebView->setWindowFrame(WKRectMake(rect.origin.x, rect.origin.y, TestController::viewWidth, TestController::viewHeight)); #endif // Reset notification permissions m_webNotificationProvider.reset(); // Reset Geolocation permissions. m_geolocationPermissionRequests.clear(); m_isGeolocationPermissionSet = false; m_isGeolocationPermissionAllowed = false; // Reset Custom Policy Delegate. setCustomPolicyDelegate(false, false); m_workQueueManager.clearWorkQueue(); m_handlesAuthenticationChallenges = false; m_authenticationUsername = String(); m_authenticationPassword = String(); // Reset main page back to about:blank m_doneResetting = false; WKPageLoadURL(m_mainWebView->page(), blankURL()); runUntil(m_doneResetting, ShortTimeout); return m_doneResetting; }
void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody) { if (WKStringIsEqualToUTF8CString(messageName, "Error")) { // Set all states to true to stop spinning the runloop. m_gotInitialResponse = true; m_gotFinalMessage = true; m_error = true; m_errorMessage = "FAIL\n"; TestController::shared().notifyDone(); return; } if (WKStringIsEqualToUTF8CString(messageName, "Ack")) { ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); WKStringRef messageBodyString = static_cast<WKStringRef>(messageBody); if (WKStringIsEqualToUTF8CString(messageBodyString, "BeginTest")) { m_gotInitialResponse = true; TestController::shared().notifyDone(); return; } ASSERT_NOT_REACHED(); } if (WKStringIsEqualToUTF8CString(messageName, "Done")) { ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); WKRetainPtr<WKStringRef> textOutputKey(AdoptWK, WKStringCreateWithUTF8CString("TextOutput")); m_textOutput = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, textOutputKey.get())); WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult")); m_pixelResult = static_cast<WKImageRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultKey.get())); ASSERT(!m_pixelResult || m_dumpPixels); WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects")); m_repaintRects = static_cast<WKArrayRef>(WKDictionaryGetItemForKey(messageBodyDictionary, repaintRectsKey.get())); m_gotFinalMessage = true; TestController::shared().notifyDone(); return; } if (WKStringIsEqualToUTF8CString(messageName, "BeforeUnloadReturnValue")) { ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); WKBooleanRef beforeUnloadReturnValue = static_cast<WKBooleanRef>(messageBody); TestController::shared().setBeforeUnloadReturnValue(WKBooleanGetValue(beforeUnloadReturnValue)); return; } if (WKStringIsEqualToUTF8CString(messageName, "AddChromeInputField")) { TestController::shared().mainWebView()->addChromeInputField(); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallAddChromeInputFieldCallback")); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0); return; } if (WKStringIsEqualToUTF8CString(messageName, "RemoveChromeInputField")) { TestController::shared().mainWebView()->removeChromeInputField(); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallRemoveChromeInputFieldCallback")); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0); return; } if (WKStringIsEqualToUTF8CString(messageName, "FocusWebView")) { TestController::shared().mainWebView()->makeWebViewFirstResponder(); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallFocusWebViewCallback")); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0); return; } if (WKStringIsEqualToUTF8CString(messageName, "SetBackingScaleFactor")) { ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID()); double backingScaleFactor = WKDoubleGetValue(static_cast<WKDoubleRef>(messageBody)); WKPageSetCustomBackingScaleFactor(TestController::shared().mainWebView()->page(), backingScaleFactor); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallSetBackingScaleFactorCallback")); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0); return; } if (WKStringIsEqualToUTF8CString(messageName, "SimulateWebNotificationClick")) { ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); uint64_t notificationID = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)); TestController::shared().simulateWebNotificationClick(notificationID); return; } if (WKStringIsEqualToUTF8CString(messageName, "SetGeolocationPermission")) { ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); WKBooleanRef enabledWK = static_cast<WKBooleanRef>(messageBody); TestController::shared().setGeolocationPermission(WKBooleanGetValue(enabledWK)); return; } if (WKStringIsEqualToUTF8CString(messageName, "SetMockGeolocationPosition")) { ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); WKRetainPtr<WKStringRef> latitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("latitude")); WKDoubleRef latitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, latitudeKeyWK.get())); double latitude = WKDoubleGetValue(latitudeWK); WKRetainPtr<WKStringRef> longitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("longitude")); WKDoubleRef longitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, longitudeKeyWK.get())); double longitude = WKDoubleGetValue(longitudeWK); WKRetainPtr<WKStringRef> accuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("accuracy")); WKDoubleRef accuracyWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, accuracyKeyWK.get())); double accuracy = WKDoubleGetValue(accuracyWK); WKRetainPtr<WKStringRef> providesAltitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitude")); WKBooleanRef providesAltitudeWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesAltitudeKeyWK.get())); bool providesAltitude = WKBooleanGetValue(providesAltitudeWK); WKRetainPtr<WKStringRef> altitudeKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitude")); WKDoubleRef altitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, altitudeKeyWK.get())); double altitude = WKDoubleGetValue(altitudeWK); WKRetainPtr<WKStringRef> providesAltitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesAltitudeAccuracy")); WKBooleanRef providesAltitudeAccuracyWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesAltitudeAccuracyKeyWK.get())); bool providesAltitudeAccuracy = WKBooleanGetValue(providesAltitudeAccuracyWK); WKRetainPtr<WKStringRef> altitudeAccuracyKeyWK(AdoptWK, WKStringCreateWithUTF8CString("altitudeAccuracy")); WKDoubleRef altitudeAccuracyWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, altitudeAccuracyKeyWK.get())); double altitudeAccuracy = WKDoubleGetValue(altitudeAccuracyWK); WKRetainPtr<WKStringRef> providesHeadingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesHeading")); WKBooleanRef providesHeadingWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesHeadingKeyWK.get())); bool providesHeading = WKBooleanGetValue(providesHeadingWK); WKRetainPtr<WKStringRef> headingKeyWK(AdoptWK, WKStringCreateWithUTF8CString("heading")); WKDoubleRef headingWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, headingKeyWK.get())); double heading = WKDoubleGetValue(headingWK); WKRetainPtr<WKStringRef> providesSpeedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("providesSpeed")); WKBooleanRef providesSpeedWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesSpeedKeyWK.get())); bool providesSpeed = WKBooleanGetValue(providesSpeedWK); WKRetainPtr<WKStringRef> speedKeyWK(AdoptWK, WKStringCreateWithUTF8CString("speed")); WKDoubleRef speedWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, speedKeyWK.get())); double speed = WKDoubleGetValue(speedWK); TestController::shared().setMockGeolocationPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed); return; } if (WKStringIsEqualToUTF8CString(messageName, "SetMockGeolocationPositionUnavailableError")) { ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); WKStringRef errorMessage = static_cast<WKStringRef>(messageBody); TestController::shared().setMockGeolocationPositionUnavailableError(errorMessage); return; } if (WKStringIsEqualToUTF8CString(messageName, "SetCustomPolicyDelegate")) { ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); WKRetainPtr<WKStringRef> enabledKeyWK(AdoptWK, WKStringCreateWithUTF8CString("enabled")); WKBooleanRef enabledWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, enabledKeyWK.get())); bool enabled = WKBooleanGetValue(enabledWK); WKRetainPtr<WKStringRef> permissiveKeyWK(AdoptWK, WKStringCreateWithUTF8CString("permissive")); WKBooleanRef permissiveWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, permissiveKeyWK.get())); bool permissive = WKBooleanGetValue(permissiveWK); TestController::shared().setCustomPolicyDelegate(enabled, permissive); return; } if (WKStringIsEqualToUTF8CString(messageName, "ProcessWorkQueue")) { if (TestController::shared().workQueueManager().processWorkQueue()) { WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("WorkQueueProcessedCallback")); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0); } return; } if (WKStringIsEqualToUTF8CString(messageName, "QueueBackNavigation")) { ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); uint64_t stepCount = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)); TestController::shared().workQueueManager().queueBackNavigation(stepCount); return; } if (WKStringIsEqualToUTF8CString(messageName, "QueueForwardNavigation")) { ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); uint64_t stepCount = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)); TestController::shared().workQueueManager().queueForwardNavigation(stepCount); return; } if (WKStringIsEqualToUTF8CString(messageName, "QueueLoad")) { ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef loadDataDictionary = static_cast<WKDictionaryRef>(messageBody); WKRetainPtr<WKStringRef> urlKey(AdoptWK, WKStringCreateWithUTF8CString("url")); WKStringRef urlWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, urlKey.get())); WKRetainPtr<WKStringRef> targetKey(AdoptWK, WKStringCreateWithUTF8CString("target")); WKStringRef targetWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, targetKey.get())); TestController::shared().workQueueManager().queueLoad(toWTFString(urlWK), toWTFString(targetWK)); return; } if (WKStringIsEqualToUTF8CString(messageName, "QueueLoadHTMLString")) { ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef loadDataDictionary = static_cast<WKDictionaryRef>(messageBody); WKRetainPtr<WKStringRef> contentKey(AdoptWK, WKStringCreateWithUTF8CString("content")); WKStringRef contentWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, contentKey.get())); WKRetainPtr<WKStringRef> baseURLKey(AdoptWK, WKStringCreateWithUTF8CString("baseURL")); WKStringRef baseURLWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, baseURLKey.get())); WKRetainPtr<WKStringRef> unreachableURLKey(AdoptWK, WKStringCreateWithUTF8CString("unreachableURL")); WKStringRef unreachableURLWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, unreachableURLKey.get())); TestController::shared().workQueueManager().queueLoadHTMLString(toWTFString(contentWK), baseURLWK ? toWTFString(baseURLWK) : String(), unreachableURLWK ? toWTFString(unreachableURLWK) : String()); return; } if (WKStringIsEqualToUTF8CString(messageName, "QueueReload")) { TestController::shared().workQueueManager().queueReload(); return; } if (WKStringIsEqualToUTF8CString(messageName, "QueueLoadingScript")) { ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); WKStringRef script = static_cast<WKStringRef>(messageBody); TestController::shared().workQueueManager().queueLoadingScript(toWTFString(script)); return; } if (WKStringIsEqualToUTF8CString(messageName, "QueueNonLoadingScript")) { ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); WKStringRef script = static_cast<WKStringRef>(messageBody); TestController::shared().workQueueManager().queueNonLoadingScript(toWTFString(script)); return; } ASSERT_NOT_REACHED(); }
void TestInvocation::invoke() { sizeWebViewForCurrentTest(m_pathOrURL.c_str()); updateLayoutType(m_pathOrURL.c_str()); updateTiledDrawingForCurrentTest(m_pathOrURL.c_str()); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("BeginTest")); WKRetainPtr<WKMutableDictionaryRef> beginTestMessageBody = adoptWK(WKMutableDictionaryCreate()); WKRetainPtr<WKStringRef> dumpFrameLoadDelegatesKey = adoptWK(WKStringCreateWithUTF8CString("DumpFrameLoadDelegates")); WKRetainPtr<WKBooleanRef> dumpFrameLoadDelegatesValue = adoptWK(WKBooleanCreate(shouldLogFrameLoadDelegates(m_pathOrURL.c_str()))); WKDictionaryAddItem(beginTestMessageBody.get(), dumpFrameLoadDelegatesKey.get(), dumpFrameLoadDelegatesValue.get()); WKRetainPtr<WKStringRef> dumpPixelsKey = adoptWK(WKStringCreateWithUTF8CString("DumpPixels")); WKRetainPtr<WKBooleanRef> dumpPixelsValue = adoptWK(WKBooleanCreate(m_dumpPixels)); WKDictionaryAddItem(beginTestMessageBody.get(), dumpPixelsKey.get(), dumpPixelsValue.get()); WKRetainPtr<WKStringRef> useWaitToDumpWatchdogTimerKey = adoptWK(WKStringCreateWithUTF8CString("UseWaitToDumpWatchdogTimer")); WKRetainPtr<WKBooleanRef> useWaitToDumpWatchdogTimerValue = adoptWK(WKBooleanCreate(TestController::shared().useWaitToDumpWatchdogTimer())); WKDictionaryAddItem(beginTestMessageBody.get(), useWaitToDumpWatchdogTimerKey.get(), useWaitToDumpWatchdogTimerValue.get()); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), beginTestMessageBody.get()); TestController::shared().runUntil(m_gotInitialResponse, TestController::ShortTimeout); if (!m_gotInitialResponse) { m_errorMessage = "Timed out waiting for initial response from web process\n"; m_webProcessIsUnresponsive = true; goto end; } if (m_error) goto end; #if ENABLE(INSPECTOR) if (shouldOpenWebInspector(m_pathOrURL.c_str())) WKInspectorShow(WKPageGetInspector(TestController::shared().mainWebView()->page())); #endif // ENABLE(INSPECTOR) WKPageLoadURL(TestController::shared().mainWebView()->page(), m_url.get()); TestController::shared().runUntil(m_gotFinalMessage, TestController::shared().useWaitToDumpWatchdogTimer() ? TestController::LongTimeout : TestController::NoTimeout); if (!m_gotFinalMessage) { m_errorMessage = "Timed out waiting for final message from web process\n"; m_webProcessIsUnresponsive = true; goto end; } if (m_error) goto end; dumpResults(); end: #if ENABLE(INSPECTOR) if (m_gotInitialResponse) WKInspectorClose(WKPageGetInspector(TestController::shared().mainWebView()->page())); #endif // ENABLE(INSPECTOR) if (m_webProcessIsUnresponsive) dumpWebProcessUnresponsiveness(); else if (!TestController::shared().resetStateToConsistentValues()) { m_errorMessage = "Timed out loading about:blank before the next test"; dumpWebProcessUnresponsiveness(); } }
bool TestController::resetStateToConsistentValues() { m_state = Resetting; m_beforeUnloadReturnValue = true; WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("Reset")); WKRetainPtr<WKMutableDictionaryRef> resetMessageBody = adoptWK(WKMutableDictionaryCreate()); WKRetainPtr<WKStringRef> shouldGCKey = adoptWK(WKStringCreateWithUTF8CString("ShouldGC")); WKRetainPtr<WKBooleanRef> shouldGCValue = adoptWK(WKBooleanCreate(m_gcBetweenTests)); WKDictionaryAddItem(resetMessageBody.get(), shouldGCKey.get(), shouldGCValue.get()); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), resetMessageBody.get()); WKContextSetShouldUseFontSmoothing(TestController::shared().context(), false); // FIXME: This function should also ensure that there is only one page open. // Reset preferences WKPreferencesRef preferences = WKPageGroupGetPreferences(m_pageGroup.get()); WKPreferencesResetTestRunnerOverrides(preferences); WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true); WKPreferencesSetFontSmoothingLevel(preferences, kWKFontSmoothingLevelNoSubpixelAntiAliasing); WKPreferencesSetXSSAuditorEnabled(preferences, false); WKPreferencesSetDeveloperExtrasEnabled(preferences, true); WKPreferencesSetJavaScriptCanOpenWindowsAutomatically(preferences, true); WKPreferencesSetJavaScriptCanAccessClipboard(preferences, true); WKPreferencesSetDOMPasteAllowed(preferences, true); WKPreferencesSetUniversalAccessFromFileURLsAllowed(preferences, true); WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true); #if ENABLE(FULLSCREEN_API) WKPreferencesSetFullScreenEnabled(preferences, true); #endif WKPreferencesSetPageCacheEnabled(preferences, false); // [Qt][WK2]REGRESSION(r104881):It broke hundreds of tests // FIXME: https://bugs.webkit.org/show_bug.cgi?id=76247 #if !PLATFORM(QT) WKPreferencesSetMockScrollbarsEnabled(preferences, true); #endif #if !PLATFORM(QT) static WKStringRef standardFontFamily = WKStringCreateWithUTF8CString("Times"); static WKStringRef cursiveFontFamily = WKStringCreateWithUTF8CString("Apple Chancery"); static WKStringRef fantasyFontFamily = WKStringCreateWithUTF8CString("Papyrus"); static WKStringRef fixedFontFamily = WKStringCreateWithUTF8CString("Courier"); static WKStringRef pictographFontFamily = WKStringCreateWithUTF8CString("Apple Color Emoji"); static WKStringRef sansSerifFontFamily = WKStringCreateWithUTF8CString("Helvetica"); static WKStringRef serifFontFamily = WKStringCreateWithUTF8CString("Times"); WKPreferencesSetStandardFontFamily(preferences, standardFontFamily); WKPreferencesSetCursiveFontFamily(preferences, cursiveFontFamily); WKPreferencesSetFantasyFontFamily(preferences, fantasyFontFamily); WKPreferencesSetFixedFontFamily(preferences, fixedFontFamily); WKPreferencesSetPictographFontFamily(preferences, pictographFontFamily); WKPreferencesSetSansSerifFontFamily(preferences, sansSerifFontFamily); WKPreferencesSetSerifFontFamily(preferences, serifFontFamily); #endif // in the case that a test using the chrome input field failed, be sure to clean up for the next test m_mainWebView->removeChromeInputField(); m_mainWebView->focus(); // Re-set to the default backing scale factor by setting the custom scale factor to 0. WKPageSetCustomBackingScaleFactor(m_mainWebView->page(), 0); // Reset main page back to about:blank m_doneResetting = false; WKPageLoadURL(m_mainWebView->page(), blankURL()); runUntil(m_doneResetting, ShortTimeout); return m_doneResetting; }
void TestInvocation::invoke() { sizeWebViewForCurrentTest(m_pathOrURL.c_str()); WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("BeginTest")); WKRetainPtr<WKMutableDictionaryRef> beginTestMessageBody = adoptWK(WKMutableDictionaryCreate()); WKRetainPtr<WKStringRef> dumpFrameLoadDelegatesKey = adoptWK(WKStringCreateWithUTF8CString("DumpFrameLoadDelegates")); WKRetainPtr<WKBooleanRef> dumpFrameLoadDelegatesValue = adoptWK(WKBooleanCreate(shouldLogFrameLoadDelegates(m_pathOrURL.c_str()))); WKDictionaryAddItem(beginTestMessageBody.get(), dumpFrameLoadDelegatesKey.get(), dumpFrameLoadDelegatesValue.get()); WKRetainPtr<WKStringRef> dumpPixelsKey = adoptWK(WKStringCreateWithUTF8CString("DumpPixels")); WKRetainPtr<WKBooleanRef> dumpPixelsValue = adoptWK(WKBooleanCreate(m_dumpPixels)); WKDictionaryAddItem(beginTestMessageBody.get(), dumpPixelsKey.get(), dumpPixelsValue.get()); WKRetainPtr<WKStringRef> useWaitToDumpWatchdogTimerKey = adoptWK(WKStringCreateWithUTF8CString("UseWaitToDumpWatchdogTimer")); WKRetainPtr<WKBooleanRef> useWaitToDumpWatchdogTimerValue = adoptWK(WKBooleanCreate(TestController::shared().useWaitToDumpWatchdogTimer())); WKDictionaryAddItem(beginTestMessageBody.get(), useWaitToDumpWatchdogTimerKey.get(), useWaitToDumpWatchdogTimerValue.get()); WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), beginTestMessageBody.get()); const char* errorMessage = 0; TestController::shared().runUntil(m_gotInitialResponse, TestController::ShortTimeout); if (!m_gotInitialResponse) { errorMessage = "Timed out waiting for initial response from web process\n"; goto end; } if (m_error) { errorMessage = "FAIL\n"; goto end; } #if ENABLE(INSPECTOR) if (shouldOpenWebInspector(m_pathOrURL.c_str())) WKInspectorShow(WKPageGetInspector(TestController::shared().mainWebView()->page())); #endif // ENABLE(INSPECTOR) WKPageLoadURL(TestController::shared().mainWebView()->page(), m_url.get()); TestController::shared().runUntil(m_gotFinalMessage, TestController::shared().useWaitToDumpWatchdogTimer() ? TestController::LongTimeout : TestController::NoTimeout); if (!m_gotFinalMessage) { errorMessage = "Timed out waiting for final message from web process\n"; goto end; } if (m_error) { errorMessage = "FAIL\n"; goto end; } end: #if ENABLE(INSPECTOR) if (m_gotInitialResponse) WKInspectorClose(WKPageGetInspector(TestController::shared().mainWebView()->page())); #endif // ENABLE(INSPECTOR) bool resetDone = TestController::shared().resetStateToConsistentValues(); // We expect resetting to not fail if there was no error or timeout. ASSERT(resetDone || errorMessage); const char* errorMessageToStderr = 0; #if PLATFORM(MAC) char buffer[64]; if (!resetDone) { pid_t pid = WKPageGetProcessIdentifier(TestController::shared().mainWebView()->page()); sprintf(buffer, "#PROCESS UNRESPONSIVE - WebProcess (pid %ld)\n", static_cast<long>(pid)); errorMessageToStderr = buffer; } #else if (!resetDone) errorMessageToStderr = "#PROCESS UNRESPONSIVE - WebProcess"; #endif if (errorMessage) dump(errorMessage, errorMessageToStderr, true); }