From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- .../TestWebKitAPI/Tests/WebKit2/18-characters.html | 0 .../TestWebKitAPI/Tests/WebKit2/AboutBlankLoad.cpp | 5 + Tools/TestWebKitAPI/Tests/WebKit2/Ahem.ttf | Bin 0 -> 12480 bytes .../Tests/WebKit2/CanHandleRequest.cpp | 7 +- .../Tests/WebKit2/CanHandleRequest_Bundle.cpp | 7 +- .../Tests/WebKit2/CloseFromWithinCreatePage.cpp | 94 ++++++++ .../Tests/WebKit2/CloseThenTerminate.cpp | 5 + .../TestWebKitAPI/Tests/WebKit2/CookieManager.cpp | 9 +- .../WKViewIsActiveSetIsActive.cpp | 131 +++++++++++ .../WKViewIsActiveSetIsActive_Bundle.cpp | 52 +++++ .../WKViewRestoreZoomAndScrollBackForward.cpp | 129 +++++++++++ .../WKViewUserViewportToContents.cpp | 148 ++++++++++++ .../WebKit2/CoordinatedGraphics/backforward1.html | 5 + .../WebKit2/CoordinatedGraphics/backforward2.html | 1 + .../Tests/WebKit2/DOMWindowExtensionBasic.cpp | 7 +- .../WebKit2/DOMWindowExtensionBasic_Bundle.cpp | 19 +- .../Tests/WebKit2/DOMWindowExtensionNoCache.cpp | 5 + .../WebKit2/DOMWindowExtensionNoCache_Bundle.cpp | 19 +- .../Tests/WebKit2/DidAssociateFormControls.cpp | 5 + .../WebKit2/DidAssociateFormControls_Bundle.cpp | 13 +- .../Tests/WebKit2/DidNotHandleKeyDown.cpp | 7 +- .../DidRemoveFrameFromHiearchyInPageCache.cpp | 109 +++++++++ ...idRemoveFrameFromHiearchyInPageCache_Bundle.cpp | 75 ++++++ .../WebKit2/DocumentStartUserScriptAlertCrash.cpp | 7 +- .../DocumentStartUserScriptAlertCrash_Bundle.cpp | 13 +- .../WebKit2/DownloadDecideDestinationCrash.cpp | 9 +- .../Tests/WebKit2/EnumerateMediaDevices.cpp | 84 +++++++ .../EphemeralSessionPushStateNoHistoryCallback.cpp | 87 +++++++ .../Tests/WebKit2/EvaluateJavaScript.cpp | 9 +- .../TestWebKitAPI/Tests/WebKit2/EventModifiers.cpp | 82 +++++++ Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp | 7 +- Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp | 7 +- Tools/TestWebKitAPI/Tests/WebKit2/ForceRepaint.cpp | 7 +- Tools/TestWebKitAPI/Tests/WebKit2/FrameHandle.cpp | 70 ++++++ .../Tests/WebKit2/FrameMIMETypeHTML.cpp | 7 +- .../Tests/WebKit2/FrameMIMETypePNG.cpp | 7 +- Tools/TestWebKitAPI/Tests/WebKit2/Geolocation.cpp | 55 +++-- ...njectedBundleInitializationUserDataCallback.cpp | 7 +- ...BundleInitializationUserDataCallback_Bundle.cpp | 7 +- .../Tests/WebKit2/HitTestResultNodeHandle.cpp | 7 +- .../WebKit2/HitTestResultNodeHandle_Bundle.cpp | 13 +- .../Tests/WebKit2/InjectedBundleBasic.cpp | 7 +- .../Tests/WebKit2/InjectedBundleBasic_Bundle.cpp | 7 +- .../Tests/WebKit2/InjectedBundleFrameHitTest.cpp | 7 +- .../WebKit2/InjectedBundleFrameHitTest_Bundle.cpp | 17 +- ...tedBundleInitializationUserDataCallbackWins.cpp | 7 +- ...leInitializationUserDataCallbackWins_Bundle.cpp | 7 +- .../InjectedBundleMakeAllShadowRootsOpen.cpp | 109 +++++++++ ...InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp | 98 ++++++++ .../LayoutMilestonesWithAllContentInFrame.cpp | 9 +- .../TestWebKitAPI/Tests/WebKit2/LimitTitleSize.cpp | 79 +++++++ .../LoadAlternateHTMLStringWithNonDirectoryURL.cpp | 37 ++- .../LoadCanceledNoServerRedirectCallback.cpp | 11 +- ...LoadCanceledNoServerRedirectCallback_Bundle.cpp | 11 +- .../Tests/WebKit2/LoadPageOnCrash.cpp | 7 +- .../Tests/WebKit2/MenuTypesForMouseEvents.cpp | 149 ++++++++++++ .../TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp | 123 ++++++++++ .../Tests/WebKit2/MouseMoveAfterCrash.cpp | 9 +- .../Tests/WebKit2/MouseMoveAfterCrash_Bundle.cpp | 5 + .../WebKit2/NewFirstVisuallyNonEmptyLayout.cpp | 7 +- .../NewFirstVisuallyNonEmptyLayoutFails.cpp | 9 +- .../NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp | 9 +- .../NewFirstVisuallyNonEmptyLayoutForImages.cpp | 7 +- ...FirstVisuallyNonEmptyLayoutForImages_Bundle.cpp | 9 +- .../NewFirstVisuallyNonEmptyLayoutFrames.cpp | 11 +- ...NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp | 9 +- .../NewFirstVisuallyNonEmptyLayout_Bundle.cpp | 9 +- Tools/TestWebKitAPI/Tests/WebKit2/PageGroup.cpp | 80 +++++++ .../TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp | 27 ++- ...PageLoadDidChangeLocationWithinPageForFrame.cpp | 7 +- Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp | 7 +- .../Tests/WebKit2/ParentFrame_Bundle.cpp | 11 +- .../WebKit2/PasteboardNotifications_Bundle.cpp | 89 +++++++ .../Tests/WebKit2/PendingAPIRequestURL.cpp | 167 +++++++++++++ .../Tests/WebKit2/PreventEmptyUserAgent.cpp | 9 +- .../PrivateBrowsingPushStateNoHistoryCallback.cpp | 32 ++- .../ProvisionalURLAfterWillSendRequestCallback.cpp | 89 +++++++ ...ionalURLAfterWillSendRequestCallback_Bundle.cpp | 85 +++++++ .../Tests/WebKit2/ReloadPageAfterCrash.cpp | 7 +- .../WebKit2/ResizeReversePaginatedWebView.cpp | 11 +- .../Tests/WebKit2/ResizeWindowAfterCrash.cpp | 7 +- .../WebKit2/ResponsivenessTimerDoesntFireEarly.cpp | 5 + .../ResponsivenessTimerDoesntFireEarly_Bundle.cpp | 5 + .../RestoreSessionStateContainingFormData.cpp | 17 +- .../RestoreSessionStateWithoutNavigation.cpp | 105 +++++++++ .../Tests/WebKit2/ScrollPinningBehaviors.cpp | 13 +- .../WebKit2/ShouldGoToBackForwardListItem.cpp | 7 +- .../ShouldGoToBackForwardListItem_Bundle.cpp | 9 +- .../ShouldKeepCurrentBackForwardListItemInList.cpp | 163 +++++++++++++ .../Tests/WebKit2/SpacebarScrolling.cpp | 27 +-- .../StopLoadingDuringDidFailProvisionalLoad.cpp | 83 +++++++ ...pLoadingDuringDidFailProvisionalLoad_bundle.cpp | 81 +++++++ .../TestWebKitAPI/Tests/WebKit2/TerminateTwice.cpp | 4 + .../WebKit2/TextFieldDidBeginAndEndEditing.cpp | 137 +++++++++++ .../TextFieldDidBeginAndEndEditing_Bundle.cpp | 76 ++++++ Tools/TestWebKitAPI/Tests/WebKit2/UserMedia.cpp | 85 +++++++ Tools/TestWebKitAPI/Tests/WebKit2/UserMessage.cpp | 13 +- .../Tests/WebKit2/UserMessage_Bundle.cpp | 5 + .../Tests/WebKit2/WKBundleFileHandle.cpp | 86 +++++++ .../Tests/WebKit2/WKBundleFileHandle_Bundle.cpp | 99 ++++++++ .../Tests/WebKit2/WKImageCreateCGImageCrash.cpp | 41 ++++ .../Tests/WebKit2/WKPageConfiguration.cpp | 132 +++++++++++ .../WKPageCopySessionStateWithFiltering.cpp | 136 +++++++++++ .../Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp | 15 +- .../Tests/WebKit2/WKPageIsPlayingAudio.cpp | 152 ++++++++++++ .../TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp | 39 ++-- Tools/TestWebKitAPI/Tests/WebKit2/WKRetainPtr.cpp | 58 +++++ Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp | 4 + .../Tests/WebKit2/WKStringJSString.cpp | 7 +- Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp | 135 +++++++++++ .../Tests/WebKit2/WebArchive_Bundle.cpp | 69 ++++++ .../WebKit2/WebCoreStatisticsWithNoWebProcess.cpp | 55 +++++ Tools/TestWebKitAPI/Tests/WebKit2/WillLoad.cpp | 11 +- .../Tests/WebKit2/WillLoad_Bundle.cpp | 15 +- .../Tests/WebKit2/WillSendSubmitEvent.cpp | 5 + .../Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp | 9 +- .../Tests/WebKit2/all-content-in-one-iframe.html | 1 + .../Tests/WebKit2/associate-form-controls.html | 31 +++ .../Tests/WebKit2/auto-submitting-form.html | 20 ++ .../Tests/WebKit2/autoplay-check-frame.html | 16 ++ .../Tests/WebKit2/autoplay-check-in-iframe.html | 16 ++ .../Tests/WebKit2/autoplay-check.html | 20 ++ .../Tests/WebKit2/autoplay-no-audio-check.html | 20 ++ .../Tests/WebKit2/autoplay-with-controls.html | 19 ++ Tools/TestWebKitAPI/Tests/WebKit2/bundle-file.html | 16 ++ .../WebKit2/chinese-character-with-image.html | 15 ++ .../WebKit2/close-from-within-create-page.html | 16 ++ .../Tests/WebKit2/closed-shadow-tree-test.html | 28 +++ .../Tests/WebKit2/contentBlockerCheck.html | 13 ++ .../Tests/WebKit2/custom-protocol-sync-xhr.html | 6 + .../Tests/WebKit2/enumerateMediaDevices.html | 24 ++ Tools/TestWebKitAPI/Tests/WebKit2/execCopy.html | 15 ++ .../Tests/WebKit2/file-with-anchor.html | 19 ++ .../TestWebKitAPI/Tests/WebKit2/file-with-mse.html | 41 ++++ .../Tests/WebKit2/file-with-video.html | 18 ++ Tools/TestWebKitAPI/Tests/WebKit2/find.html | 5 + Tools/TestWebKitAPI/Tests/WebKit2/findRanges.html | 11 + .../WebKit2/geolocationGetCurrentPosition.html | 3 + ...locationGetCurrentPositionWithHighAccuracy.html | 3 + .../Tests/WebKit2/geolocationWatchPosition.html | 3 + .../geolocationWatchPositionWithHighAccuracy.html | 3 + .../TestWebKitAPI/Tests/WebKit2/getUserMedia.html | 14 ++ .../Tests/WebKit2/gtk/InputMethodFilter.cpp | 258 +++++++++++++++++++++ Tools/TestWebKitAPI/Tests/WebKit2/icon.png | Bin 0 -> 36541 bytes .../Tests/WebKit2/input-focus-blur.html | 28 +++ .../Tests/WebKit2/js-play-with-controls.html | 20 ++ .../WebKit2/link-with-download-attribute.html | 10 + .../Tests/WebKit2/link-with-title.html | 5 + .../Tests/WebKit2/lots-of-iframes.html | 35 +++ .../Tests/WebKit2/lots-of-images.html | 17 ++ .../Tests/WebKit2/lots-of-text-vertical-lr.html | 3 + .../TestWebKitAPI/Tests/WebKit2/lots-of-text.html | 3 + .../TestWebKitAPI/Tests/WebKit2/many-iframes.html | 15 ++ .../modal-alerts-in-new-about-blank-window.html | 13 ++ .../Tests/WebKit2/mouse-button-listener.html | 30 +++ .../Tests/WebKit2/mouse-move-listener.html | 16 ++ .../Tests/WebKit2/no-autoplay-with-controls.html | 25 ++ .../Tests/WebKit2/open-and-close-window.html | 11 + Tools/TestWebKitAPI/Tests/WebKit2/push-state.html | 3 + .../Tests/WebKit2/set-long-title.html | 10 + .../WebKit2/should-open-external-schemes.html | 21 ++ .../WebKit2/simple-accelerated-compositing.html | 5 + Tools/TestWebKitAPI/Tests/WebKit2/simple-form.html | 11 + .../TestWebKitAPI/Tests/WebKit2/simple-iframe.html | 6 + Tools/TestWebKitAPI/Tests/WebKit2/simple-tall.html | 7 + Tools/TestWebKitAPI/Tests/WebKit2/simple.html | 5 + Tools/TestWebKitAPI/Tests/WebKit2/simple2.html | 5 + Tools/TestWebKitAPI/Tests/WebKit2/simple3.html | 5 + .../Tests/WebKit2/spacebar-scrolling.html | 26 +++ Tools/TestWebKitAPI/Tests/WebKit2/test-mse.mp4 | Bin 0 -> 80933 bytes .../Tests/WebKit2/test-without-audio-track.mp4 | Bin 0 -> 189906 bytes Tools/TestWebKitAPI/Tests/WebKit2/test.mp4 | Bin 0 -> 192844 bytes Tools/TestWebKitAPI/Tests/WebKit2/webfont.html | 15 ++ 173 files changed, 5444 insertions(+), 197 deletions(-) create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/18-characters.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/Ahem.ttf create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/CloseFromWithinCreatePage.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewIsActiveSetIsActive.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewIsActiveSetIsActive_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewRestoreZoomAndScrollBackForward.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewUserViewportToContents.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/backforward1.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/backforward2.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/EnumerateMediaDevices.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/EphemeralSessionPushStateNoHistoryCallback.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/EventModifiers.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/FrameHandle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/LimitTitleSize.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/MenuTypesForMouseEvents.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/PageGroup.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/PasteboardNotifications_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/PendingAPIRequestURL.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateWithoutNavigation.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/ShouldKeepCurrentBackForwardListItemInList.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/StopLoadingDuringDidFailProvisionalLoad.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/StopLoadingDuringDidFailProvisionalLoad_bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/UserMedia.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKBundleFileHandle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKBundleFileHandle_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKImageCreateCGImageCrash.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKPageConfiguration.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKPageCopySessionStateWithFiltering.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKPageIsPlayingAudio.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKRetainPtr.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WebCoreStatisticsWithNoWebProcess.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/all-content-in-one-iframe.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/associate-form-controls.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/auto-submitting-form.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-frame.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-in-iframe.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/autoplay-no-audio-check.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/autoplay-with-controls.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/bundle-file.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/chinese-character-with-image.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/close-from-within-create-page.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/closed-shadow-tree-test.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/contentBlockerCheck.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/enumerateMediaDevices.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/execCopy.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/file-with-anchor.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/file-with-mse.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/file-with-video.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/find.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/findRanges.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/geolocationGetCurrentPosition.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/geolocationGetCurrentPositionWithHighAccuracy.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/geolocationWatchPosition.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/geolocationWatchPositionWithHighAccuracy.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/getUserMedia.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/gtk/InputMethodFilter.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/icon.png create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/input-focus-blur.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/link-with-download-attribute.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/link-with-title.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/lots-of-iframes.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/lots-of-images.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/lots-of-text-vertical-lr.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/lots-of-text.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/many-iframes.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/modal-alerts-in-new-about-blank-window.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/mouse-button-listener.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/mouse-move-listener.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/no-autoplay-with-controls.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/open-and-close-window.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/push-state.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/set-long-title.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/should-open-external-schemes.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/simple-accelerated-compositing.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/simple-form.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/simple-iframe.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/simple-tall.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/simple.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/simple2.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/simple3.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/spacebar-scrolling.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/test-mse.mp4 create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/test-without-audio-track.mp4 create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/test.mp4 create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/webfont.html (limited to 'Tools/TestWebKitAPI/Tests/WebKit2') diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/18-characters.html b/Tools/TestWebKitAPI/Tests/WebKit2/18-characters.html new file mode 100644 index 000000000..e69de29bb diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/AboutBlankLoad.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/AboutBlankLoad.cpp index 0a2f00ca5..5503edd9e 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/AboutBlankLoad.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/AboutBlankLoad.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" @@ -57,3 +60,5 @@ TEST(WebKit2, AboutBlankLoad) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/Ahem.ttf b/Tools/TestWebKitAPI/Tests/WebKit2/Ahem.ttf new file mode 100644 index 000000000..ac81cb031 Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/WebKit2/Ahem.ttf differ diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest.cpp index 4c0c77963..a1d09f2cd 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -71,3 +74,5 @@ TEST(WebKit2, CanHandleRequest) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest_Bundle.cpp index 5f66b537a..590615e8c 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest_Bundle.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include +#include namespace TestWebKitAPI { @@ -65,3 +68,5 @@ void CanHandleRequestTest::didReceiveMessage(WKBundleRef bundle, WKStringRef mes } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CloseFromWithinCreatePage.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CloseFromWithinCreatePage.cpp new file mode 100644 index 000000000..fabfd2d80 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CloseFromWithinCreatePage.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2014-2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include + +namespace TestWebKitAPI { + +static bool testDone; +static std::unique_ptr openedWebView; + +static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, WKSecurityOriginRef, const void* clientInfo) +{ + // FIXME: Check that the alert text matches the storage. + testDone = true; +} + +static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef urlRequest, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo) +{ + EXPECT_TRUE(openedWebView == nullptr); + + openedWebView = std::make_unique(page); + + WKPageUIClientV5 uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + uiClient.base.version = 5; + uiClient.runJavaScriptAlert = runJavaScriptAlert; + WKPageSetPageUIClient(openedWebView->page(), &uiClient.base); + + WKPageClose(page); + + WKRetain(openedWebView->page()); + return openedWebView->page(); +} + +TEST(WebKit2, CloseFromWithinCreatePage) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + + PlatformWebView webView(context.get()); + + WKPageUIClientV5 uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + uiClient.base.version = 5; + uiClient.createNewPage = createNewPage; + uiClient.runJavaScriptAlert = runJavaScriptAlert; + WKPageSetPageUIClient(webView.page(), &uiClient.base); + + // Allow file URLs to load non-file resources + WKRetainPtr preferences(AdoptWK, WKPreferencesCreate()); + WKPageGroupRef pageGroup = WKPageGetPageGroup(webView.page()); + WKPreferencesSetUniversalAccessFromFileURLsAllowed(preferences.get(), true); + WKPageGroupSetPreferences(pageGroup, preferences.get()); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("close-from-within-create-page", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&testDone); + + openedWebView = nullptr; +} + +} + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CloseThenTerminate.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CloseThenTerminate.cpp index ff70511f4..71239e4f0 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/CloseThenTerminate.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CloseThenTerminate.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" @@ -62,3 +65,5 @@ TEST(WebKit2, CloseThenTerminate) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CookieManager.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CookieManager.cpp index 2f17b8162..d231e0e75 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/CookieManager.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CookieManager.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -86,3 +89,5 @@ TEST(WebKit2, CookieManager) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewIsActiveSetIsActive.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewIsActiveSetIsActive.cpp new file mode 100644 index 000000000..ef9625b99 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewIsActiveSetIsActive.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "PlatformUtilities.h" +#include "Test.h" + +#include +#include +#include +#include + +namespace TestWebKitAPI { + +static bool didWebProcessCrash = false; +static bool didWebProcessRelaunch = false; +static bool didFinishLoad = false; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +static void webProcessCrashed(WKViewRef view, WKURLRef, const void*) +{ + // WebProcess crashed, so at this point the view should not be active. + ASSERT_FALSE(WKViewIsActive(view)); + didWebProcessCrash = true; +} + +static void webProcessRelaunched(WKViewRef view, const void*) +{ + // WebProcess just relaunched, so at this point the view should not be active. + ASSERT_FALSE(WKViewIsActive(view)); + + didWebProcessRelaunch = true; +} + +TEST(WebKit2, WKViewIsActiveSetIsActive) +{ + WKRetainPtr context = adoptWK(WKContextCreate()); + WKRetainPtr view = adoptWK(WKViewCreate(context.get(), 0)); + + WKViewInitialize(view.get()); + + // At this point we should have an active view. + ASSERT_TRUE(WKViewIsActive(view.get())); + + // Now we are going to play with its active state a few times. + WKViewSetIsActive(view.get(), true); + ASSERT_TRUE(WKViewIsActive(view.get())); + + WKViewSetIsActive(view.get(), false); + ASSERT_FALSE(WKViewIsActive(view.get())); + + WKViewSetIsActive(view.get(), false); + ASSERT_FALSE(WKViewIsActive(view.get())); + + WKViewSetIsActive(view.get(), true); + ASSERT_TRUE(WKViewIsActive(view.get())); +} + +TEST(WebKit2, WKViewIsActive) +{ + WKRetainPtr context = adoptWK(Util::createContextForInjectedBundleTest("WKViewIsActiveSetIsActiveTest")); + WKRetainPtr view = adoptWK(WKViewCreate(context.get(), 0)); + + WKViewClientV0 viewClient; + memset(&viewClient, 0, sizeof(WKViewClientV0)); + viewClient.base.version = 0; + viewClient.webProcessCrashed = webProcessCrashed; + viewClient.webProcessDidRelaunch = webProcessRelaunched; + WKViewSetViewClient(view.get(), &viewClient.base); + + WKViewInitialize(view.get()); + + // At this point we should have an active view. + ASSERT_TRUE(WKViewIsActive(view.get())); + + WKPageLoaderClientV3 pageLoaderClient; + memset(&pageLoaderClient, 0, sizeof(WKPageLoaderClient)); + pageLoaderClient.base.version = 3; + pageLoaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(WKViewGetPage(view.get()), &pageLoaderClient.base); + + const WKSize size = WKSizeMake(100, 100); + WKViewSetSize(view.get(), size); + + didFinishLoad = false; + didWebProcessCrash = false; + didWebProcessRelaunch = false; + + WKRetainPtr simpleUrl = adoptWK(Util::createURLForResource("../WebKit/simple", "html")); + WKPageLoadURL(WKViewGetPage(view.get()), simpleUrl.get()); + Util::run(&didFinishLoad); + didFinishLoad = false; + + WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("Crash").get(), 0); + Util::run(&didWebProcessCrash); + ASSERT_TRUE(didWebProcessCrash); + + WKPageLoadURL(WKViewGetPage(view.get()), simpleUrl.get()); + Util::run(&didFinishLoad); + + ASSERT_TRUE(didWebProcessRelaunch); + ASSERT_TRUE(didFinishLoad); +} + +} // TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewIsActiveSetIsActive_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewIsActiveSetIsActive_Bundle.cpp new file mode 100644 index 000000000..a3cb1b6de --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewIsActiveSetIsActive_Bundle.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundleTest.h" +#include + +#include + +namespace TestWebKitAPI { + +class WKViewIsActiveSetIsActiveTest : public InjectedBundleTest { +public: + WKViewIsActiveSetIsActiveTest(const std::string& identifier) + : InjectedBundleTest(identifier) + { + } + + virtual void didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody) + { + if (!WKStringIsEqualToUTF8CString(messageName, "Crash")) + return; + abort(); + } +}; + +static InjectedBundleTest::Register registrar("WKViewIsActiveSetIsActiveTest"); + +} // namespace TestWebKitAPI + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewRestoreZoomAndScrollBackForward.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewRestoreZoomAndScrollBackForward.cpp new file mode 100644 index 000000000..5c556ecee --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewRestoreZoomAndScrollBackForward.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2012-2013 Nokia Corporation and/or its subsidiary(-ies). + * Copyright (C) 2011 Samsung Electronics. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "ewk_view_private.h" +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include +#include "Test.h" + +namespace TestWebKitAPI { + +static bool finishedLoad = false; +static bool scroll = false; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) +{ + finishedLoad = true; +} + +static void didChangeContentsPosition(WKViewRef, WKPoint p, const void*) +{ + scroll = true; +} + +TEST(WebKit2, WKViewRestoreZoomAndScrollBackForward) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + WKRetainPtr view = EWKViewGetWKView(webView.platformView()); + + WKPageSetUseFixedLayout(webView.page(), true); + + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); + + WKViewClientV0 viewClient; + memset(&viewClient, 0, sizeof(viewClient)); + viewClient.base.version = 0; + viewClient.didChangeContentsPosition = didChangeContentsPosition; + WKViewSetViewClient(view.get(), &viewClient.base); + + // Load first page. + WKRetainPtr url(AdoptWK, Util::createURLForResource("CoordinatedGraphics/backforward1", "html")); + WKPageLoadURL(webView.page(), url.get()); + Util::run(&finishedLoad); + + // Change scale and position on first page. + float firstPageScale = 2.0; + WKPoint firstPageScrollPosition = WKPointMake(10, 350); // Scroll position of first page. + WKViewSetContentPosition(view.get(), firstPageScrollPosition); + WKViewSetContentScaleFactor(view.get(), firstPageScale); + float currentPageScale = WKViewGetContentScaleFactor(view.get()); + WKPoint currentPagePosition = WKViewGetContentPosition(view.get()); + Util::run(&scroll); + EXPECT_EQ(firstPageScale, currentPageScale); + EXPECT_EQ(firstPageScrollPosition.x, currentPagePosition.x); + EXPECT_EQ(firstPageScrollPosition.y, currentPagePosition.y); + + // Load second page. + finishedLoad = false; + url = adoptWK(Util::createURLForResource("CoordinatedGraphics/backforward2", "html")); + WKPageLoadURL(webView.page(), url.get()); + Util::run(&finishedLoad); + + // Check if second page scale and position is correct. + currentPageScale = WKViewGetContentScaleFactor(view.get()); + currentPagePosition = WKViewGetContentPosition(view.get()); + EXPECT_EQ(1, currentPageScale); + EXPECT_EQ(0, currentPagePosition.x); + EXPECT_EQ(0, currentPagePosition.y); + + // Go back first page. + scroll = false; + finishedLoad = false; + WKPageGoBack(webView.page()); + Util::run(&finishedLoad); + Util::run(&scroll); + + // Check if scroll position and scale of first page are restored correctly. + currentPageScale = WKViewGetContentScaleFactor(view.get()); + currentPagePosition = WKViewGetContentPosition(view.get()); + EXPECT_EQ(firstPageScale, currentPageScale); + EXPECT_EQ(firstPageScrollPosition.x, currentPagePosition.x); + EXPECT_EQ(firstPageScrollPosition.y, currentPagePosition.y); + + // Go to second page again. + WKPageGoForward(webView.page()); + scroll = false; + finishedLoad = false; + Util::run(&finishedLoad); + + // Check if the scroll position and scale of second page are restored correctly. + currentPageScale = WKViewGetContentScaleFactor(view.get()); + currentPagePosition = WKViewGetContentPosition(view.get()); + EXPECT_EQ(1, currentPageScale); + EXPECT_EQ(0, currentPagePosition.x); + EXPECT_EQ(0, currentPagePosition.y); +} + +} // TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewUserViewportToContents.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewUserViewportToContents.cpp new file mode 100644 index 000000000..e6465480c --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewUserViewportToContents.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "WebKit/WKView.h" +#include "WebKit/WKRetainPtr.h" + +namespace TestWebKitAPI { + +TEST(WebKit2, DISABLED_WKViewUserViewportToContents) +{ + // This test creates a WKView and uses the WKViewUserViewportToContents + // function to convert viewport coordinates to contents (page) coordinates. + // It scrolls and scales around the contents and check if the coordinates + // conversion math is right. + + WKRetainPtr context(AdoptWK, WKContextCreate()); + WKRetainPtr configuration(AdoptWK, WKPageConfigurationCreate()); + WKPageConfigurationSetContext(configuration.get(), context.get()); + + WKRetainPtr webView(AdoptWK, WKViewCreate(configuration.get())); + + WKViewSetIsActive(webView.get(), true); + WKPageSetUseFixedLayout(WKViewGetPage(webView.get()), false); + + WKPoint out; + + // At scale 1.0 the viewport and contents coordinates should match. + + WKViewSetContentScaleFactor(webView.get(), 1.0); + WKViewSetContentPosition(webView.get(), WKPointMake(0, 0)); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0)); + EXPECT_EQ(out.x, 0); + EXPECT_EQ(out.y, 0); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10)); + EXPECT_EQ(out.x, 10); + EXPECT_EQ(out.y, 10); + + WKViewSetContentPosition(webView.get(), WKPointMake(20, 20)); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0)); + EXPECT_EQ(out.x, 20); + EXPECT_EQ(out.y, 20); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10)); + EXPECT_EQ(out.x, 30); + EXPECT_EQ(out.y, 30); + + // At scale 2.0 the viewport distance values will be half + // the ones seem in the contents. + + WKViewSetContentScaleFactor(webView.get(), 2.0); + WKViewSetContentPosition(webView.get(), WKPointMake(0, 0)); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0)); + EXPECT_EQ(out.x, 0); + EXPECT_EQ(out.y, 0); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10)); + EXPECT_EQ(out.x, 5); + EXPECT_EQ(out.y, 5); + + WKViewSetContentPosition(webView.get(), WKPointMake(20, 20)); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0)); + EXPECT_EQ(out.x, 20); + EXPECT_EQ(out.y, 20); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10)); + EXPECT_EQ(out.x, 25); + EXPECT_EQ(out.y, 25); + + // At scale 0.5 the viewport distance values will be twice + // the ones seem in the contents. + + WKViewSetContentScaleFactor(webView.get(), 0.5); + WKViewSetContentPosition(webView.get(), WKPointMake(0, 0)); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0)); + EXPECT_EQ(out.x, 0); + EXPECT_EQ(out.y, 0); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10)); + EXPECT_EQ(out.x, 20); + EXPECT_EQ(out.y, 20); + + WKViewSetContentPosition(webView.get(), WKPointMake(20, 20)); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0)); + EXPECT_EQ(out.x, 20); + EXPECT_EQ(out.y, 20); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10)); + EXPECT_EQ(out.x, 40); + EXPECT_EQ(out.y, 40); + + // Let's add translation to the viewport. + + const int delta = 10; + WKViewSetUserViewportTranslation(webView.get(), delta, delta); + + WKViewSetContentPosition(webView.get(), WKPointMake(0, 0)); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0)); + EXPECT_EQ(out.x, 0 - delta / 0.5); + EXPECT_EQ(out.y, 0 - delta / 0.5); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10)); + EXPECT_EQ(out.x, 20 - delta / 0.5); + EXPECT_EQ(out.y, 20 - delta / 0.5); + + WKViewSetContentPosition(webView.get(), WKPointMake(20, 20)); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0)); + EXPECT_EQ(out.x, 20 - delta / 0.5); + EXPECT_EQ(out.y, 20 - delta / 0.5); + + out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10)); + EXPECT_EQ(out.x, 40 - delta / 0.5); + EXPECT_EQ(out.y, 40 - delta / 0.5); +} + +} diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/backforward1.html b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/backforward1.html new file mode 100644 index 000000000..98c1c107c --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/backforward1.html @@ -0,0 +1,5 @@ + + +
+ + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/backforward2.html b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/backforward2.html new file mode 100644 index 000000000..3806b9d32 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/backforward2.html @@ -0,0 +1 @@ + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic.cpp index 06abe884b..c336652ac 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include #include namespace TestWebKitAPI { @@ -133,3 +136,5 @@ TEST(WebKit2, DISABLED_DOMWindowExtensionBasic) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic_Bundle.cpp index 5c946625a..9bdc683ba 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic_Bundle.cpp @@ -24,14 +24,17 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -257,3 +260,5 @@ static void willDestroyGlobalObjectForDOMWindowExtensionCallback(WKBundlePageRef } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionNoCache.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionNoCache.cpp index c5f6104f6..56a069fb9 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionNoCache.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionNoCache.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" @@ -132,3 +135,5 @@ TEST(WebKit2, DISABLED_DOMWindowExtensionNoCache) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionNoCache_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionNoCache_Bundle.cpp index 680c17288..e48dadd1e 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionNoCache_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionNoCache_Bundle.cpp @@ -24,14 +24,17 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -276,3 +279,5 @@ static void willDestroyGlobalObjectForDOMWindowExtensionCallback(WKBundlePageRef } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DidAssociateFormControls.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DidAssociateFormControls.cpp index a78b8867f..a930f5346 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DidAssociateFormControls.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DidAssociateFormControls.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" @@ -83,3 +86,5 @@ TEST(WebKit2, DidAssociateFormControls) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DidAssociateFormControls_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DidAssociateFormControls_Bundle.cpp index fd373d282..4e30eee5f 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DidAssociateFormControls_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DidAssociateFormControls_Bundle.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -36,7 +39,7 @@ class DidAssociateFormControlsTest : public InjectedBundleTest { public: DidAssociateFormControlsTest(const std::string& identifier); - virtual void didCreatePage(WKBundleRef, WKBundlePageRef) override; + void didCreatePage(WKBundleRef, WKBundlePageRef) override; }; static InjectedBundleTest::Register registrar("DidAssociateFormControlsTest"); @@ -54,7 +57,7 @@ static void didAssociateFormControls(WKBundlePageRef page, WKArrayRef elementHan WKRetainPtr numberOfElements = adoptWK(WKUInt64Create(WKArrayGetSize(elementHandles))); WKDictionarySetItem(messageBody.get(), Util::toWK("NumberOfControls").get(), numberOfElements.get()); - WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("DidReceiveDidAssociateFormControls").get(), messageBody.get()); + WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("DidReceiveDidAssociateFormControls").get(), messageBody.get()); } DidAssociateFormControlsTest::DidAssociateFormControlsTest(const std::string& identifier) @@ -76,3 +79,5 @@ void DidAssociateFormControlsTest::didCreatePage(WKBundleRef bundle, WKBundlePag } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DidNotHandleKeyDown.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DidNotHandleKeyDown.cpp index e0c5cb0d8..b5f4fb863 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DidNotHandleKeyDown.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DidNotHandleKeyDown.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "JavaScriptTest.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -76,3 +79,5 @@ TEST(WebKit2, DidNotHandleKeyDown) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache.cpp new file mode 100644 index 000000000..2a6f5da0a --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" + +#include + +namespace TestWebKitAPI { + +static bool finished = false; +static int didRemoveFrameFromHierarchyCount; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef, const void*) +{ + // Only mark finished when the main frame loads + if (!WKFrameIsMainFrame(frame)) + return; + + finished = true; +} + +static void setPageLoaderClient(WKPageRef page) +{ + WKPageLoaderClientV1 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 1; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + + WKPageSetPageLoaderClient(page, &loaderClient.base); +} + +static void didReceivePageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef, const void*) +{ + if (WKStringIsEqualToUTF8CString(messageName, "DidRemoveFrameFromHierarchy")) + ++didRemoveFrameFromHierarchyCount; +} + +static void setInjectedBundleClient(WKPageRef page) +{ + WKPageInjectedBundleClientV0 injectedBundleClient = { + { 0, nullptr }, + didReceivePageMessageFromInjectedBundle, + nullptr, + }; + WKPageSetPageInjectedBundleClient(page, &injectedBundleClient.base); +} + +TEST(WebKit2, DidRemoveFrameFromHiearchyInPageCache) +{ + WKRetainPtr context = adoptWK(Util::createContextForInjectedBundleTest("DidRemoveFrameFromHiearchyInPageCache")); + // Enable the page cache so we can test the WKBundlePageDidRemoveFrameFromHierarchyCallback API + WKContextSetCacheModel(context.get(), kWKCacheModelPrimaryWebBrowser); + + PlatformWebView webView(context.get()); + setPageLoaderClient(webView.page()); + setInjectedBundleClient(webView.page()); + + finished = false; + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("many-iframes", "html")).get()); + Util::run(&finished); + + // Perform a couple of loads so "many-iframes" gets kicked out of the PageCache. + finished = false; + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); + Util::run(&finished); + + finished = false; + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple2", "html")).get()); + Util::run(&finished); + + finished = false; + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple3", "html")).get()); + Util::run(&finished); + + EXPECT_EQ(didRemoveFrameFromHierarchyCount, 10); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache_Bundle.cpp new file mode 100644 index 000000000..712b3fb06 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache_Bundle.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "InjectedBundleTest.h" + +#include "PlatformUtilities.h" +#include + +namespace TestWebKitAPI { + +class DidRemoveFrameFromHiearchyInPageCacheTest : public InjectedBundleTest { +public: + DidRemoveFrameFromHiearchyInPageCacheTest(const std::string& identifier); + + virtual void didCreatePage(WKBundleRef, WKBundlePageRef); +}; + +static InjectedBundleTest::Register registrar("DidRemoveFrameFromHiearchyInPageCache"); + +static unsigned didRemoveFrameFromHierarchyCount; + +void didRemoveFrameFromHierarchyCallback(WKBundlePageRef page, WKBundleFrameRef, WKTypeRef*, const void*) +{ + didRemoveFrameFromHierarchyCount++; + + WKRetainPtr message(AdoptWK, WKStringCreateWithUTF8CString("DidRemoveFrameFromHierarchy")); + WKBundlePagePostMessage(page, message.get(), message.get()); +} + +DidRemoveFrameFromHiearchyInPageCacheTest::DidRemoveFrameFromHiearchyInPageCacheTest(const std::string& identifier) + : InjectedBundleTest(identifier) +{ +} + +void DidRemoveFrameFromHiearchyInPageCacheTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page) +{ + WKBundlePageLoaderClientV8 pageLoaderClient; + memset(&pageLoaderClient, 0, sizeof(pageLoaderClient)); + + pageLoaderClient.base.version = 8; + pageLoaderClient.base.clientInfo = this; + pageLoaderClient.didRemoveFrameFromHierarchy = didRemoveFrameFromHierarchyCallback; + + WKBundlePageSetPageLoaderClient(page, &pageLoaderClient.base); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp index efdcd56a7..21bca74dd 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { @@ -65,3 +68,5 @@ TEST(WebKit2, DocumentStartUserScriptAlertCrashTest) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp index 30805f759..18b9f1b48 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" -#include -#include -#include -#include +#include +#include +#include +#include #include namespace TestWebKitAPI { @@ -53,3 +56,5 @@ public: static InjectedBundleTest::Register registrar("DocumentStartUserScriptAlertCrashTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DownloadDecideDestinationCrash.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DownloadDecideDestinationCrash.cpp index aaead72dd..eac36d87a 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/DownloadDecideDestinationCrash.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DownloadDecideDestinationCrash.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -41,7 +44,7 @@ static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownlo { didDecideDestination = true; WKDownloadCancel(download); - return Util::toWK("does not matter").leakRef(); + return Util::toWK("/tmp/WebKitAPITest/DownloadDecideDestinationCrash").leakRef(); } static void setContextDownloadClient(WKContextRef context) @@ -83,3 +86,5 @@ TEST(WebKit2, DownloadDecideDestinationCrash) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/EnumerateMediaDevices.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/EnumerateMediaDevices.cpp new file mode 100644 index 000000000..0ac7d0fe1 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/EnumerateMediaDevices.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#if ENABLE(MEDIA_STREAM) +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include +#include +#include +#include +#include +#include + +namespace TestWebKitAPI { + +static bool loadedFirstTime; +static bool loadedSecondTime; + +void checkUserMediaPermissionCallback(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKSecurityOriginRef, WKUserMediaPermissionCheckRef permissionRequest, const void*) +{ + WKUserMediaPermissionCheckSetUserMediaAccessInfo(permissionRequest, WKStringCreateWithUTF8CString("0x123456789"), true); + if (!loadedFirstTime) { + loadedFirstTime = true; + return; + } + + loadedSecondTime = true; +} + +TEST(WebKit2, EnumerateDevices) +{ + auto context = adoptWK(WKContextCreate()); + + WKRetainPtr pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(Util::toWK("EnumerateDevices").get())); + WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup.get()); + WKPreferencesSetMediaStreamEnabled(preferences, true); + WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true); + WKPreferencesSetMediaCaptureRequiresSecureConnection(preferences, false); + + WKPageUIClientV6 uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + uiClient.base.version = 6; + uiClient.checkUserMediaPermissionForOrigin = checkUserMediaPermissionCallback; + + PlatformWebView webView(context.get(), pageGroup.get()); + WKPageSetPageUIClient(webView.page(), &uiClient.base); + + auto url = adoptWK(Util::createURLForResource("enumerateMediaDevices", "html")); + + // Load and kill the page. + WKPageLoadURL(webView.page(), url.get()); + Util::run(&loadedFirstTime); + WKPageTerminate(webView.page()); + + // Load it again to make sure the user media process manager doesn't assert. + WKPageLoadURL(webView.page(), url.get()); + Util::run(&loadedSecondTime); +} + +} // namespace TestWebKitAPI + +#endif // ENABLE(MEDIA_STREAM) + +#endif // WK_HAVE_C_SPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/EphemeralSessionPushStateNoHistoryCallback.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/EphemeralSessionPushStateNoHistoryCallback.cpp new file mode 100644 index 000000000..64b666ab4 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/EphemeralSessionPushStateNoHistoryCallback.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include +#include + +namespace TestWebKitAPI { + +static bool testDone; + +static void didNavigateWithNavigationData(WKContextRef context, WKPageRef page, WKNavigationDataRef navigationData, WKFrameRef frame, const void* clientInfo) +{ + // This should never be called when navigating in Private Browsing. + FAIL(); +} + +static void didSameDocumentNavigationForFrame(WKPageRef page, WKFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef userData, const void *clientInfo) +{ + testDone = true; +} + +TEST(WebKit2, EphemeralSessionPushStateNoHistoryCallback) +{ + auto configuration = adoptWK(WKPageConfigurationCreate()); + + auto context = adoptWK(WKContextCreate()); + WKPageConfigurationSetContext(configuration.get(), context.get()); + + auto websiteDataStore = adoptWK(WKWebsiteDataStoreCreateNonPersistentDataStore()); + WKPageConfigurationSetWebsiteDataStore(configuration.get(), websiteDataStore.get()); + + WKContextHistoryClientV0 historyClient; + memset(&historyClient, 0, sizeof(historyClient)); + + historyClient.base.version = 0; + historyClient.didNavigateWithNavigationData = didNavigateWithNavigationData; + + WKContextSetHistoryClient(context.get(), &historyClient.base); + + PlatformWebView webView(configuration.get()); + + WKPageLoaderClientV0 pageLoaderClient; + memset(&pageLoaderClient, 0, sizeof(pageLoaderClient)); + + pageLoaderClient.base.version = 0; + pageLoaderClient.didSameDocumentNavigationForFrame = didSameDocumentNavigationForFrame; + + WKPageSetPageLoaderClient(webView.page(), &pageLoaderClient.base); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("push-state", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&testDone); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp index 90ad04fd1..a6b5a4dd5 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -58,3 +61,5 @@ TEST(WebKit2, EvaluateJavaScriptThatThrowsAnException) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/EventModifiers.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/EventModifiers.cpp new file mode 100644 index 000000000..d2cc644e1 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/EventModifiers.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2017 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "JavaScriptTest.h" +#include "PlatformUtilities.h" +#include "PlatformWebView.h" + +namespace TestWebKitAPI { + +static bool didFinishLoad { false }; +static bool mouseMoveCallbackFinished { false }; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +static void mouseDidMoveOverElement(WKPageRef, WKHitTestResultRef, WKEventModifiers modifiers, WKTypeRef, const void*) +{ + EXPECT_EQ(modifiers, kWKEventModifiersControlKey); + mouseMoveCallbackFinished = true; +} + +static void setClients(WKPageRef page) +{ + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(page, &loaderClient.base); + + WKPageUIClientV1 uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + uiClient.base.version = 1; + uiClient.mouseDidMoveOverElement = mouseDidMoveOverElement; + WKPageSetPageUIClient(page, &uiClient.base); +} + +TEST(WebKit2, EventModifiers) +{ + WKRetainPtr context = adoptWK(WKContextCreate()); + + PlatformWebView webView(context.get()); + setClients(webView.page()); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + Util::run(&didFinishLoad); + + webView.simulateMouseMove(10, 10, kWKEventModifiersControlKey); + Util::run(&mouseMoveCallbackFinished); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp index ac8d6a39d..c12b5366b 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { @@ -65,3 +68,5 @@ TEST(WebKit2, FailedLoad) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp index 41b52eacd..2e2189906 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -79,3 +82,5 @@ TEST(WebKit2, Find) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ForceRepaint.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ForceRepaint.cpp index 86c6754a2..6cd63fab4 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ForceRepaint.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ForceRepaint.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { @@ -67,3 +70,5 @@ TEST(WebKit2, ForceRepaint) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/FrameHandle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/FrameHandle.cpp new file mode 100644 index 000000000..1e3281d89 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/FrameHandle.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include +#include +#include + +namespace TestWebKitAPI { + +static bool done; + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + done = true; +} + +TEST(WebKit2, FrameHandle) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); + + WKPageLoadURL(webView.page(), adoptWK(WKURLCreateWithUTF8CString("about:blank")).get()); + Util::run(&done); + + auto frame = WKPageGetMainFrame(webView.page()); + auto frameInfo = adoptWK(WKFrameCreateFrameInfo(frame)); + auto handleFromInfo = WKFrameInfoGetFrameHandleRef(frameInfo.get()); + auto handleFromFrame = adoptWK(WKFrameCreateFrameHandle(frame)); + + EXPECT_EQ(WKFrameHandleGetFrameID(handleFromInfo), WKFrameHandleGetFrameID(handleFromFrame.get())); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypeHTML.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypeHTML.cpp index 093a5747b..2c9c11332 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypeHTML.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypeHTML.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { @@ -75,3 +78,5 @@ TEST(WebKit2, FrameMIMETypeHTML) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypePNG.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypePNG.cpp index edaa7cada..eb3bf38a3 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypePNG.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypePNG.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -74,3 +77,5 @@ TEST(WebKit2, FrameMIMETypePNG) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/Geolocation.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/Geolocation.cpp index bf7a93726..90fd37937 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/Geolocation.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/Geolocation.cpp @@ -24,10 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include +#include #include #include @@ -103,7 +107,7 @@ void decidePolicyForGeolocationPermissionRequestCallBack(WKPageRef page, WKFrame void setupGeolocationProvider(WKContextRef context, void *clientInfo) { WKGeolocationProviderV1 providerCallback; - memset(&providerCallback, 0, sizeof(WKGeolocationProvider)); + memset(&providerCallback, 0, sizeof(WKGeolocationProviderV1)); providerCallback.base.version = 1; providerCallback.base.clientInfo = clientInfo; @@ -209,14 +213,9 @@ TEST(WebKit2, GeolocationBasicWithHighAccuracy) // Geolocation start without High Accuracy, then requires High Accuracy. struct GeolocationTransitionToHighAccuracyStateTracker : GeolocationStateTracker { - bool finishedFirstStep; - bool finished; - - GeolocationTransitionToHighAccuracyStateTracker() - : finishedFirstStep(false) - , finished(false) - { - } + bool finishedFirstStep { false }; + bool enabledHighAccuracy { false }; + bool finished { false }; virtual void eventsChanged() { @@ -230,11 +229,19 @@ struct GeolocationTransitionToHighAccuracyStateTracker : GeolocationStateTracker break; case 3: EXPECT_EQ(GeolocationEvent::EnableHighAccuracy, events[2]); + enabledHighAccuracy = true; + break; + case 4: + EXPECT_EQ(GeolocationEvent::DisableHighAccuracy, events[3]); + break; + case 5: + EXPECT_EQ(GeolocationEvent::StopUpdating, events[4]); finished = true; break; default: EXPECT_TRUE(false); finishedFirstStep = true; + enabledHighAccuracy = true; finished = true; } } @@ -243,6 +250,7 @@ struct GeolocationTransitionToHighAccuracyStateTracker : GeolocationStateTracker TEST(WebKit2, GeolocationTransitionToHighAccuracy) { WKRetainPtr context(AdoptWK, WKContextCreate()); + WKContextSetMaximumNumberOfProcesses(context.get(), 1); GeolocationTransitionToHighAccuracyStateTracker stateTracker; setupGeolocationProvider(context.get(), &stateTracker); @@ -257,19 +265,20 @@ TEST(WebKit2, GeolocationTransitionToHighAccuracy) setupView(highAccuracyWebView); WKRetainPtr highAccuracyURL(AdoptWK, Util::createURLForResource("geolocationWatchPositionWithHighAccuracy", "html")); WKPageLoadURL(highAccuracyWebView.page(), highAccuracyURL.get()); + Util::run(&stateTracker.enabledHighAccuracy); + + WKRetainPtr resetUrl = adoptWK(WKURLCreateWithUTF8CString("about:blank")); + WKPageLoadURL(highAccuracyWebView.page(), resetUrl.get()); + Util::run(&stateTracker.enabledHighAccuracy); + WKPageLoadURL(lowAccuracyWebView.page(), resetUrl.get()); Util::run(&stateTracker.finished); } // Geolocation start with High Accuracy, then should fall back to low accuracy. struct GeolocationTransitionToLowAccuracyStateTracker : GeolocationStateTracker { - bool finishedFirstStep; - bool finished; - - GeolocationTransitionToLowAccuracyStateTracker() - : finishedFirstStep(false) - , finished(false) - { - } + bool finishedFirstStep { false }; + bool disabledHighAccuracy { false }; + bool finished { false }; virtual void eventsChanged() { @@ -283,11 +292,16 @@ struct GeolocationTransitionToLowAccuracyStateTracker : GeolocationStateTracker break; case 3: EXPECT_EQ(GeolocationEvent::DisableHighAccuracy, events[2]); + disabledHighAccuracy = true; + break; + case 4: + EXPECT_EQ(GeolocationEvent::StopUpdating, events[3]); finished = true; break; default: EXPECT_TRUE(false); finishedFirstStep = true; + disabledHighAccuracy = true; finished = true; } } @@ -301,6 +315,7 @@ static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef us TEST(WebKit2, GeolocationTransitionToLowAccuracy) { WKRetainPtr context(AdoptWK, WKContextCreate()); + WKContextSetMaximumNumberOfProcesses(context.get(), 1); GeolocationTransitionToLowAccuracyStateTracker stateTracker; setupGeolocationProvider(context.get(), &stateTracker); @@ -331,7 +346,11 @@ TEST(WebKit2, GeolocationTransitionToLowAccuracy) WKRetainPtr resetUrl = adoptWK(WKURLCreateWithUTF8CString("about:blank")); WKPageLoadURL(highAccuracyWebView.page(), resetUrl.get()); + Util::run(&stateTracker.disabledHighAccuracy); + WKPageLoadURL(lowAccuracyWebView.page(), resetUrl.get()); Util::run(&stateTracker.finished); } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/GetInjectedBundleInitializationUserDataCallback.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/GetInjectedBundleInitializationUserDataCallback.cpp index fe898ffa8..e3280a3b7 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/GetInjectedBundleInitializationUserDataCallback.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/GetInjectedBundleInitializationUserDataCallback.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -65,3 +68,5 @@ TEST(WebKit2, GetInjectedBundleInitializationUserDataCallback) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/GetInjectedBundleInitializationUserDataCallback_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/GetInjectedBundleInitializationUserDataCallback_Bundle.cpp index 97500b59b..bf8da42e3 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/GetInjectedBundleInitializationUserDataCallback_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/GetInjectedBundleInitializationUserDataCallback_Bundle.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include +#include namespace TestWebKitAPI { @@ -46,3 +49,5 @@ public: static InjectedBundleTest::Register registrar("GetInjectedBundleInitializationUserDataCallbackTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle.cpp index 2f7c7deed..1f4a3726c 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -86,3 +89,5 @@ TEST(WebKit2, HitTestResultNodeHandle) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle_Bundle.cpp index c6aaa1fec..d68ff2193 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/HitTestResultNodeHandle_Bundle.cpp @@ -24,12 +24,15 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "InjectedBundleController.h" #include "PlatformUtilities.h" -#include -#include -#include +#include +#include +#include namespace TestWebKitAPI { @@ -46,7 +49,7 @@ public: if (!nodeHandle) return; - WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("HitTestResultNodeHandleTestDoneMessageName").get(), Util::toWK("HitTestResultNodeHandleTestDoneMessageBody").get()); + WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("HitTestResultNodeHandleTestDoneMessageName").get(), Util::toWK("HitTestResultNodeHandleTestDoneMessageBody").get()); } virtual void didCreatePage(WKBundleRef bundle, WKBundlePageRef page) @@ -64,3 +67,5 @@ public: static InjectedBundleTest::Register registrar("HitTestResultNodeHandleTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp index 1b3b3b7b6..a1d4046ed 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -77,3 +80,5 @@ TEST(WebKit2, InjectedBundleBasic) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic_Bundle.cpp index 6a597be41..4d8689b93 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic_Bundle.cpp @@ -24,8 +24,11 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" -#include +#include namespace TestWebKitAPI { @@ -47,3 +50,5 @@ public: static InjectedBundleTest::Register registrar("InjectedBundleBasicTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleFrameHitTest.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleFrameHitTest.cpp index acc76c01e..e178dc3cb 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleFrameHitTest.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleFrameHitTest.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -66,3 +69,5 @@ TEST(WebKit2, InjectedBundleFrameHitTest) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleFrameHitTest_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleFrameHitTest_Bundle.cpp index 6ae018765..747858501 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleFrameHitTest_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleFrameHitTest_Bundle.cpp @@ -24,13 +24,16 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace TestWebKitAPI { @@ -41,7 +44,7 @@ public: { } - virtual void didCreatePage(WKBundleRef, WKBundlePageRef) override; + void didCreatePage(WKBundleRef, WKBundlePageRef) override; void frameLoadFinished(WKBundleFrameRef); WKBundleRef m_bundle; @@ -76,3 +79,5 @@ void InjectedBundleFrameHitTestTest::frameLoadFinished(WKBundleFrameRef frame) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleInitializationUserDataCallbackWins.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleInitializationUserDataCallbackWins.cpp index 407ecceb5..678aaa85b 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleInitializationUserDataCallbackWins.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleInitializationUserDataCallbackWins.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -67,3 +70,5 @@ TEST(WebKit2, InjectedBundleInitializationUserDataCallbackWins) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp index 36708a4d7..cac7738dd 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include +#include namespace TestWebKitAPI { @@ -46,3 +49,5 @@ public: static InjectedBundleTest::Register registrar("InjectedBundleInitializationUserDataCallbackWinsTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp new file mode 100644 index 000000000..91fc88929 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2010, 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include + +namespace TestWebKitAPI { + +static unsigned testNumber = 0; +static bool done; + +static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo) +{ + ASSERT_NOT_NULL(frame); + + EXPECT_EQ(page, WKFrameGetPage(frame)); + switch (++testNumber) { + case 1: + EXPECT_WK_STREQ("PASS: shadowRoot created in injected bundle", alertText); + break; + case 2: + EXPECT_WK_STREQ("PASS: shadowRoot created by normal world", alertText); + break; + case 3: + EXPECT_WK_STREQ("PASS: collectMatchingElementsInFlatTree exists", alertText); + break; + case 4: + EXPECT_WK_STREQ("PASS: collectMatchingElementsInFlatTree was not present in the normal world", alertText); + break; + case 5: + EXPECT_WK_STREQ("Found:1,2,3,4,5,6", alertText); + break; + case 6: + EXPECT_WK_STREQ("Found:2,3,4", alertText); + break; + case 7: + EXPECT_WK_STREQ("PASS: matchingElementInFlatTree exists", alertText); + break; + case 8: + EXPECT_WK_STREQ("PASS: matchingElementInFlatTree was not present in the normal world", alertText); + break; + case 9: + EXPECT_WK_STREQ("Found:1", alertText); + break; + case 10: + EXPECT_WK_STREQ("Found:2", alertText); + break; + case 11: + EXPECT_WK_STREQ("Found:0 divs", alertText); + break; + case 12: + EXPECT_WK_STREQ("Found:false", alertText); + done = true; + break; + } +} + +TEST(WebKit2, InjectedBundleMakeAllShadowRootOpenTest) +{ + WKRetainPtr pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("InjectedBundleMakeAllShadowRootOpenTestPageGroup"))); + + WKRetainPtr context(AdoptWK, Util::createContextForInjectedBundleTest("InjectedBundleMakeAllShadowRootOpenTest", pageGroup.get())); + PlatformWebView webView(context.get(), pageGroup.get()); + + WKPageUIClientV0 uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + uiClient.base.version = 0; + uiClient.runJavaScriptAlert = runJavaScriptAlert; + + WKPageSetPageUIClient(webView.page(), &uiClient.base); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("closed-shadow-tree-test", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&done); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp new file mode 100644 index 000000000..ee5761993 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2010, 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "InjectedBundleTest.h" +#include +#include +#include +#include +#include + +namespace TestWebKitAPI { + +class InjectedBundleMakeAllShadowRootOpenTest : public InjectedBundleTest { +public: + InjectedBundleMakeAllShadowRootOpenTest(const std::string& identifier) + : InjectedBundleTest(identifier) + { } + + virtual void initialize(WKBundleRef bundle, WKTypeRef userData) + { + assert(WKGetTypeID(userData) == WKBundlePageGroupGetTypeID()); + WKBundlePageGroupRef pageGroup = static_cast(userData); + + auto world = WKBundleScriptWorldCreateWorld(); + WKBundleScriptWorldMakeAllShadowRootsOpen(world); + + WKRetainPtr source(AdoptWK, WKStringCreateWithUTF8CString( + "window.onload = function () {\n" + " const element = document.createElement('div');\n" + " const queryMethodName = 'collectMatchingElementsInFlatTree';\n" + " element.attachShadow({mode: 'closed'});\n" + // Test 1 + " alert(element.shadowRoot ? 'PASS: shadowRoot created in injected bundle' : 'FAIL');\n" + // Test 2 + " alert(document.querySelector('shadow-host').shadowRoot ? 'PASS: shadowRoot created by normal world' : 'FAIL');\n" + // Test 3 + " alert(window[queryMethodName] ? `PASS: ${queryMethodName} exists` : `FAIL: ${queryMethodName} does not exist`);\n" + // Test 4 + " document.dispatchEvent(new CustomEvent('testnormalworld', {detail: queryMethodName}));\n" + // Test 5 + " const queryMethod = window[queryMethodName];\n" + " let queryResult = Array.from(queryMethod(document, 'span'));\n" + " alert('Found:' + queryResult.map((span) => span.textContent).join(','));\n" + // Test 6 + " const innerHost = queryMethod(document, 'inner-host')[0];\n" + " queryResult = Array.from(queryMethod(innerHost, 'span'));\n" + " alert('Found:' + queryResult.map((span) => span.textContent).join(','));\n" + // Test 7 + " alert(window.matchingElementInFlatTree ? `PASS: matchingElementInFlatTree exists` : `FAIL: matchingElementInFlatTree does not exist`);\n" + // Test 8 + " document.dispatchEvent(new CustomEvent('testnormalworld', {detail: 'matchingElementInFlatTree'}));\n" + // Test 9 + " queryResult = window.matchingElementInFlatTree(document, 'span');\n" + " alert('Found:' + (queryResult ? queryResult.textContent : 'null'));\n" + // Test 10 + " queryResult = window.matchingElementInFlatTree(innerHost, 'span');\n" + " alert('Found:' + (queryResult ? queryResult.textContent : 'null'));\n" + // Test 11 + " alert(`Found:${queryMethod(document, 'div').length} divs`);\n" + // Test 12 + " queryResult = window.matchingElementInFlatTree(document, 'div');\n" + " alert(`Found:${!!queryResult}`);\n" + "}\n")); + WKBundleAddUserScript(bundle, pageGroup, world, source.get(), 0, 0, 0, kWKInjectAtDocumentStart, kWKInjectInAllFrames); + } +}; + +static InjectedBundleTest::Register registrar("InjectedBundleMakeAllShadowRootOpenTest"); + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/LayoutMilestonesWithAllContentInFrame.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/LayoutMilestonesWithAllContentInFrame.cpp index ef53f5e91..aa294643c 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/LayoutMilestonesWithAllContentInFrame.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/LayoutMilestonesWithAllContentInFrame.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -64,3 +67,5 @@ TEST(WebKit2, LayoutMilestonesWithAllContentInFrame) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/LimitTitleSize.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/LimitTitleSize.cpp new file mode 100644 index 000000000..fde62c624 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/LimitTitleSize.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2017 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include + +namespace TestWebKitAPI { + +static bool waitUntilLongTitleReceived = false; +static bool didFinishLoad = false; +static size_t maxTitleLength = 4096; + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + didFinishLoad = true; +} + +static void didReceiveTitleForFrame(WKPageRef page, WKStringRef title, WKFrameRef, WKTypeRef, const void*) +{ + WKStringRef titleString = (WKStringRef)title; + + if (WKStringIsEqualToUTF8CString(titleString, "Original Short Title")) + return; + + EXPECT_LE(WKStringGetLength(titleString), maxTitleLength); + waitUntilLongTitleReceived = true; +} + +TEST(WebKit2, LimitTitleSize) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 0; + loaderClient.didReceiveTitleForFrame = didReceiveTitleForFrame; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + + WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("set-long-title", "html")); + + WKPageLoadURL(webView.page(), url.get()); + Util::run(&waitUntilLongTitleReceived); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/LoadAlternateHTMLStringWithNonDirectoryURL.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/LoadAlternateHTMLStringWithNonDirectoryURL.cpp index def60bcb9..acc23348b 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/LoadAlternateHTMLStringWithNonDirectoryURL.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/LoadAlternateHTMLStringWithNonDirectoryURL.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 Apple Inc. All rights reserved. + * Copyright (C) 2015 Igalia S.L. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,13 +25,16 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "JavaScriptTest.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include -#include -#include +#include +#include +#include namespace TestWebKitAPI { @@ -41,7 +45,7 @@ static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef us didFinishLoad = true; } -TEST(WebKit2, LoadAlternateHTMLStringWithNonDirectoryURL) +static void loadAlternateHTMLString(WKURLRef baseURL, WKURLRef unreachableURL) { WKRetainPtr context(AdoptWK, WKContextCreate()); PlatformWebView webView(context.get()); @@ -53,14 +57,29 @@ TEST(WebKit2, LoadAlternateHTMLStringWithNonDirectoryURL) loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); - WKRetainPtr fileURL(AdoptWK, Util::createURLForResource("simple", "html")); WKRetainPtr alternateHTMLString(AdoptWK, WKStringCreateWithUTF8CString("")); - - // Call WKPageLoadAlternateHTMLString() with fileURL which does not point to a directory - WKPageLoadAlternateHTMLString(webView.page(), alternateHTMLString.get(), fileURL.get(), fileURL.get()); - + WKPageLoadAlternateHTMLString(webView.page(), alternateHTMLString.get(), baseURL, unreachableURL); + // If we can finish loading the html without resulting in an invalid message being sent from the WebProcess, this test passes. Util::run(&didFinishLoad); } +TEST(WebKit2, LoadAlternateHTMLStringWithNonDirectoryURL) +{ + // Call WKPageLoadAlternateHTMLString() with fileURL which does not point to a directory. + WKRetainPtr fileURL(AdoptWK, Util::createURLForResource("simple", "html")); + loadAlternateHTMLString(fileURL.get(), fileURL.get()); +} + +TEST(WebKit2, LoadAlternateHTMLStringWithEmptyBaseURL) +{ + // Call WKPageLoadAlternateHTMLString() with empty baseURL to make sure this test works + // when baseURL does not grant read access to the unreachableURL. We use a separate test + // to ensure the previous test does not pollute the result. + WKRetainPtr unreachableURL(AdoptWK, Util::URLForNonExistentResource()); + loadAlternateHTMLString(nullptr, unreachableURL.get()); +} + } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback.cpp index abf447155..ac45fba26 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback.cpp @@ -24,13 +24,16 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "JavaScriptTest.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include -#include -#include +#include +#include +#include namespace TestWebKitAPI { @@ -93,3 +96,5 @@ TEST(WebKit2, LoadCanceledNoServerRedirectCallback) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback_Bundle.cpp index 13aa1106e..6ea0dc77d 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback_Bundle.cpp @@ -24,13 +24,16 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" #include "Test.h" -#include -#include -#include +#include +#include +#include #include @@ -70,3 +73,5 @@ public: static InjectedBundleTest::Register registrar("LoadCanceledNoServerRedirectCallbackTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/LoadPageOnCrash.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/LoadPageOnCrash.cpp index 3228d084a..63ad664e2 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/LoadPageOnCrash.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/LoadPageOnCrash.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { @@ -103,3 +106,5 @@ TEST(WebKit2, LoadPageAfterCrash) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/MenuTypesForMouseEvents.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/MenuTypesForMouseEvents.cpp new file mode 100644 index 000000000..f77a11ad8 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/MenuTypesForMouseEvents.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "JavaScriptTest.h" +#include "PlatformUtilities.h" +#include "PlatformWebView.h" + +namespace TestWebKitAPI { + +static bool didFinishLoad; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +static void setPageLoaderClient(WKPageRef page) +{ + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + + WKPageSetPageLoaderClient(page, &loaderClient.base); +} + +static void buildAndPerformTest(WKEventMouseButton button, WKEventModifiers modifiers, const char* expectedButton, const char* expectedMenuType) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + setPageLoaderClient(webView.page()); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("mouse-button-listener", "html")); + WKPageLoadURL(webView.page(), url.get()); + Util::run(&didFinishLoad); + + didFinishLoad = false; + + webView.simulateButtonClick(button, 10, 10, modifiers); + + EXPECT_JS_EQ(webView.page(), "pressedMouseButton()", expectedButton); + EXPECT_JS_EQ(webView.page(), "displayedMenu()", expectedMenuType); +} + +TEST(WebKit2, MenuAndButtonForNormalLeftClick) +{ + buildAndPerformTest(kWKEventMouseButtonLeftButton, 0, "0", "none"); +} + +TEST(WebKit2, MenuAndButtonForNormalRightClick) +{ + buildAndPerformTest(kWKEventMouseButtonRightButton, 0, "2", "context"); +} + +TEST(WebKit2, MenuAndButtonForNormalMiddleClick) +{ + buildAndPerformTest(kWKEventMouseButtonMiddleButton, 0, "1", "none"); +} + +TEST(WebKit2, MenuAndButtonForControlLeftClick) +{ + buildAndPerformTest(kWKEventMouseButtonLeftButton, kWKEventModifiersControlKey, "0", "context"); +} + +TEST(WebKit2, MenuAndButtonForControlRightClick) +{ + buildAndPerformTest(kWKEventMouseButtonRightButton, kWKEventModifiersControlKey, "2", "context"); +} + +TEST(WebKit2, MenuAndButtonForControlMiddleClick) +{ + buildAndPerformTest(kWKEventMouseButtonMiddleButton, kWKEventModifiersControlKey, "1", "none"); +} + +TEST(WebKit2, MenuAndButtonForShiftLeftClick) +{ + buildAndPerformTest(kWKEventMouseButtonLeftButton, kWKEventModifiersShiftKey, "0", "none"); +} + +TEST(WebKit2, MenuAndButtonForShiftRightClick) +{ + buildAndPerformTest(kWKEventMouseButtonRightButton, kWKEventModifiersShiftKey, "2", "context"); +} + +TEST(WebKit2, MenuAndButtonForShiftMiddleClick) +{ + buildAndPerformTest(kWKEventMouseButtonMiddleButton, kWKEventModifiersShiftKey, "1", "none"); +} + +TEST(WebKit2, MenuAndButtonForCommandLeftClick) +{ + buildAndPerformTest(kWKEventMouseButtonLeftButton, kWKEventModifiersMetaKey, "0", "none"); +} + +TEST(WebKit2, MenuAndButtonForCommandRightClick) +{ + buildAndPerformTest(kWKEventMouseButtonRightButton, kWKEventModifiersMetaKey, "2", "context"); +} + +TEST(WebKit2, MenuAndButtonForCommandMiddleClick) +{ + buildAndPerformTest(kWKEventMouseButtonMiddleButton, kWKEventModifiersMetaKey, "1", "none"); +} + +TEST(WebKit2, MenuAndButtonForAltLeftClick) +{ + buildAndPerformTest(kWKEventMouseButtonLeftButton, kWKEventModifiersAltKey, "0", "none"); +} + +TEST(WebKit2, MenuAndButtonForAltRightClick) +{ + buildAndPerformTest(kWKEventMouseButtonRightButton, kWKEventModifiersAltKey, "2", "context"); +} + +TEST(WebKit2, MenuAndButtonForAltMiddleClick) +{ + buildAndPerformTest(kWKEventMouseButtonMiddleButton, kWKEventModifiersAltKey, "1", "none"); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp new file mode 100644 index 000000000..0278f005b --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include +#include +#include + +namespace TestWebKitAPI { + +static bool done; +static unsigned dialogsSeen; +static const unsigned dialogsExpected = 3; + +static void analyzeDialogArguments(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef securityOrigin) +{ + EXPECT_EQ(page, WKFrameGetPage(frame)); + + WKRetainPtr url = adoptWK(WKFrameCopyURL(frame)); + WKRetainPtr urlString = adoptWK(WKURLCopyString(url.get())); + EXPECT_WK_STREQ("about:blank", urlString.get()); + + WKRetainPtr protocol = adoptWK(WKSecurityOriginCopyProtocol(securityOrigin)); + EXPECT_WK_STREQ("file", protocol.get()); + + WKRetainPtr host = adoptWK(WKSecurityOriginCopyHost(securityOrigin)); + EXPECT_WK_STREQ("", host.get()); + + EXPECT_EQ(WKSecurityOriginGetPort(securityOrigin), 0); + + if (++dialogsSeen == dialogsExpected) + done = true; +} + +static void runJavaScriptAlert(WKPageRef page, WKStringRef, WKFrameRef frame, WKSecurityOriginRef securityOrigin, const void*) +{ + analyzeDialogArguments(page, frame, securityOrigin); +} + +static bool runJavaScriptConfirm(WKPageRef page, WKStringRef, WKFrameRef frame, WKSecurityOriginRef securityOrigin, const void*) +{ + analyzeDialogArguments(page, frame, securityOrigin); + return false; +} + +static WKStringRef runJavaScriptPrompt(WKPageRef page, WKStringRef, WKStringRef, WKFrameRef frame, WKSecurityOriginRef securityOrigin, const void*) +{ + analyzeDialogArguments(page, frame, securityOrigin); + return nullptr; +} + +static std::unique_ptr openedWebView; + +static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef urlRequest, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo) +{ + EXPECT_TRUE(openedWebView == nullptr); + + openedWebView = std::make_unique(page); + + WKPageUIClientV5 uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + uiClient.base.version = 5; + uiClient.runJavaScriptAlert = runJavaScriptAlert; + uiClient.runJavaScriptConfirm = runJavaScriptConfirm; + uiClient.runJavaScriptPrompt = runJavaScriptPrompt; + + WKPageSetPageUIClient(openedWebView->page(), &uiClient.base); + + WKRetain(openedWebView->page()); + return openedWebView->page(); +} + +TEST(WebKit2, ModalAlertsSPI) +{ + WKRetainPtr context = adoptWK(WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageUIClientV5 uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + uiClient.base.version = 5; + uiClient.createNewPage = createNewPage; + + WKPageSetPageUIClient(webView.page(), &uiClient.base); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("modal-alerts-in-new-about-blank-window", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&done); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash.cpp index b75be6a1a..9d7f3997d 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "JavaScriptTest.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" @@ -48,11 +51,7 @@ static void setPageLoaderClient(WKPageRef page) WKPageSetPageLoaderClient(page, &loaderClient.base); } -#if PLATFORM(WIN) -TEST(WebKit2, DISABLED_MouseMoveAfterCrash) -#else TEST(WebKit2, MouseMoveAfterCrash) -#endif { WKRetainPtr context = adoptWK(Util::createContextForInjectedBundleTest("MouseMoveAfterCrashTest")); @@ -90,3 +89,5 @@ TEST(WebKit2, MouseMoveAfterCrash) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash_Bundle.cpp index a07562093..8d92f4209 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash_Bundle.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" @@ -54,3 +57,5 @@ void MouseMoveAfterCrashTest::didReceiveMessage(WKBundleRef bundle, WKStringRef } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout.cpp index 640a825f8..778d285ba 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -86,3 +89,5 @@ TEST(WebKit2, DISABLED_NewFirstVisuallyNonEmptyLayout) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFails.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFails.cpp index 1568b7663..5cff318fa 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFails.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFails.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -86,3 +89,5 @@ TEST(WebKit2, NewFirstVisuallyNonEmptyLayoutFails) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp index b909ec941..2700d66c8 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -49,3 +52,5 @@ public: static InjectedBundleTest::Register registrar("NewFirstVisuallyNonEmptyLayoutFailsTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutForImages.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutForImages.cpp index 11fc17ebd..7bd1fd7b3 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutForImages.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutForImages.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -86,3 +89,5 @@ TEST(WebKit2, DISABLED_NewFirstVisuallyNonEmptyLayoutForImages) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp index bdaade77b..d8644bb69 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -49,3 +52,5 @@ public: static InjectedBundleTest::Register registrar("NewFirstVisuallyNonEmptyLayoutForImagesTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames.cpp index 04d6ee448..c7b24680e 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -64,7 +67,7 @@ static void setPageLoaderClient(WKPageRef page) WKPageLoaderClientV3 loaderClient; memset(&loaderClient, 0, sizeof(loaderClient)); - loaderClient.base.version = kWKPageLoaderClientCurrentVersion; + loaderClient.base.version = 3; loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; loaderClient.didLayout = didLayout; @@ -90,3 +93,5 @@ TEST(WebKit2, NewFirstVisuallyNonEmptyLayoutFrames) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp index 33e16bd3e..f66fc957d 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -49,3 +52,5 @@ public: static InjectedBundleTest::Register registrar("NewFirstVisuallyNonEmptyLayoutFramesTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout_Bundle.cpp index c408c3b2c..8f1901d10 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout_Bundle.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -49,3 +52,5 @@ public: static InjectedBundleTest::Register registrar("NewFirstVisuallyNonEmptyLayoutTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PageGroup.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PageGroup.cpp new file mode 100644 index 000000000..c1a5071ab --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PageGroup.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "config.h" +#import + +#if WK_HAVE_C_SPI + +#import "PlatformUtilities.h" +#import "PlatformWebView.h" +#import "Test.h" +#import +#import +#import + +namespace TestWebKitAPI { + +TEST(PageGroup, DefaultUserContentController) +{ + auto pageConfiguration = adoptWK(WKPageConfigurationCreate()); + auto context = adoptWK(WKContextCreate()); + WKPageConfigurationSetContext(pageConfiguration.get(), context.get()); + auto pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(Util::toWK("TestPageGroup").get())); + WKPageConfigurationSetPageGroup(pageConfiguration.get(), pageGroup.get()); + + auto pageGroupUserContentController = retainWK(WKPageGroupGetUserContentController(pageGroup.get())); + + EXPECT_NULL(WKPageConfigurationGetUserContentController(pageConfiguration.get())); + + PlatformWebView webView(pageConfiguration.get()); + auto copiedPageConfiguration = adoptWK(WKPageCopyPageConfiguration(webView.page())); + + ASSERT_EQ(pageGroupUserContentController.get(), WKPageConfigurationGetUserContentController(copiedPageConfiguration.get())); +} + +TEST(PageGroup, CustomUserContentController) +{ + auto pageConfiguration = adoptWK(WKPageConfigurationCreate()); + auto context = adoptWK(WKContextCreate()); + WKPageConfigurationSetContext(pageConfiguration.get(), context.get()); + auto pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(Util::toWK("TestPageGroup").get())); + WKPageConfigurationSetPageGroup(pageConfiguration.get(), pageGroup.get()); + auto userContentController = adoptWK(WKUserContentControllerCreate()); + WKPageConfigurationSetUserContentController(pageConfiguration.get(), userContentController.get()); + + auto pageGroupUserContentController = retainWK(WKPageGroupGetUserContentController(pageGroup.get())); + + EXPECT_EQ(userContentController.get(), WKPageConfigurationGetUserContentController(pageConfiguration.get())); + + PlatformWebView webView(pageConfiguration.get()); + auto copiedPageConfiguration = adoptWK(WKPageCopyPageConfiguration(webView.page())); + + EXPECT_EQ(userContentController.get(), WKPageConfigurationGetUserContentController(copiedPageConfiguration.get())); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp index 26a6fddfd..7ac216b2a 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { @@ -151,4 +154,26 @@ TEST(WebKit2, PageLoadBasic) Util::run(&test1Done); } +TEST(WebKit2, PageReload) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + // Reload test before url loading. + WKPageReload(webView.page()); + WKPageReload(webView.page()); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + + // Reload test after url loading. + WKPageReload(webView.page()); + + WKRetainPtr activeUrl = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeUrl.get()); + EXPECT_TRUE(WKURLIsEqual(activeUrl.get(), url.get())); +} + } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadDidChangeLocationWithinPageForFrame.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadDidChangeLocationWithinPageForFrame.cpp index 8ef9bb66d..46838db93 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadDidChangeLocationWithinPageForFrame.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadDidChangeLocationWithinPageForFrame.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -84,3 +87,5 @@ TEST(WebKit2, PageLoadDidChangeLocationWithinPageForFrame) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp index ec97ac0b0..7953608c8 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include +#include namespace TestWebKitAPI { @@ -68,3 +71,5 @@ TEST(WebKit2, ParentFrame) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp index b23336293..e1da9ee02 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp @@ -24,12 +24,15 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include -#include -#include +#include +#include +#include namespace TestWebKitAPI { @@ -77,3 +80,5 @@ void ParentFrameTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PasteboardNotifications_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PasteboardNotifications_Bundle.cpp new file mode 100644 index 000000000..8c1404e7a --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PasteboardNotifications_Bundle.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2012 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "InjectedBundleTest.h" + +#include "PlatformUtilities.h" +#include +#include +#include +#include + +namespace TestWebKitAPI { + +class PasteboardNotificationsTest : public InjectedBundleTest { +public: + PasteboardNotificationsTest(const std::string& identifier); + + virtual void didCreatePage(WKBundleRef, WKBundlePageRef); +}; + +static InjectedBundleTest::Register registrar("PasteboardNotificationsTest"); + +static void willWriteToPasteboard(WKBundlePageRef page, WKBundleRangeHandleRef range, const void*) +{ + if (!range) + WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("PasteboardNotificationTestDoneMessageName").get(), Util::toWK("willWritetoPasteboardFail").get()); +} + +static void getPasteboardDataForRange(WKBundlePageRef, WKBundleRangeHandleRef range, WKArrayRef* pasteboardTypes, WKArrayRef* pasteboardData, const void*) +{ + WKTypeRef typeName = WKStringCreateWithUTF8CString("AnotherArchivePasteboardType"); + *pasteboardTypes = WKArrayCreateAdoptingValues(&typeName, 1); + WKTypeRef typeData = WKWebArchiveCopyData(WKWebArchiveCreateFromRange(range)); + *pasteboardData = WKArrayCreateAdoptingValues(&typeData, 1); +} + +static void didWriteToPasteboard(WKBundlePageRef, const void*) +{ + WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("PasteboardNotificationTestDoneMessageName").get(), Util::toWK("didWriteToPasteboard").get()); +} + +PasteboardNotificationsTest::PasteboardNotificationsTest(const std::string& identifier) + : InjectedBundleTest(identifier) +{ +} + +void PasteboardNotificationsTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page) +{ + WKBundlePageEditorClientV1 pageEditorClient; + memset(&pageEditorClient, 0, sizeof(pageEditorClient)); + + pageEditorClient.base.version = 1; + pageEditorClient.base.clientInfo = this; + pageEditorClient.willWriteToPasteboard = willWriteToPasteboard; + pageEditorClient.getPasteboardDataForRange = getPasteboardDataForRange; + pageEditorClient.didWriteToPasteboard = didWriteToPasteboard; + + WKBundlePageSetEditorClient(page, &pageEditorClient.base); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PendingAPIRequestURL.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PendingAPIRequestURL.cpp new file mode 100644 index 000000000..22a8f04fa --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PendingAPIRequestURL.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2014 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include + +namespace TestWebKitAPI { + +static bool done; + +TEST(WebKit2, PendingAPIRequestURL) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = [](WKPageRef, WKFrameRef, WKTypeRef, const void*) { done = true; }; + WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); + + WKRetainPtr activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + EXPECT_NULL(activeURL.get()); + + WKRetainPtr url = adoptWK(Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); + Util::run(&done); + done = false; + + WKPageReload(webView.page()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); + Util::run(&done); + done = false; + + WKRetainPtr htmlString = Util::toWK("Hello, World"); + WKRetainPtr blankURL = adoptWK(WKURLCreateWithUTF8CString("about:blank")); + WKPageLoadHTMLString(webView.page(), htmlString.get(), nullptr); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); + Util::run(&done); + done = false; + + WKPageReload(webView.page()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); + Util::run(&done); + done = false; + + url = adoptWK(Util::createURLForResource("simple2", "html")); + WKPageLoadHTMLString(webView.page(), htmlString.get(), url.get()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); + Util::run(&done); + done = false; + + WKPageReload(webView.page()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); + Util::run(&done); + done = false; + + WKRetainPtr data = adoptWK(WKDataCreate(nullptr, 0)); + WKPageLoadData(webView.page(), data.get(), nullptr, nullptr, nullptr); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); + Util::run(&done); + done = false; + + WKPageReload(webView.page()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); + Util::run(&done); + done = false; + + WKPageLoadData(webView.page(), data.get(), nullptr, nullptr, url.get()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); + Util::run(&done); + done = false; + + WKPageReload(webView.page()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); + Util::run(&done); + done = false; + + WKPageLoadAlternateHTMLString(webView.page(), htmlString.get(), nullptr, url.get()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); + Util::run(&done); + done = false; + + WKPageReload(webView.page()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); + Util::run(&done); + done = false; + + WKRetainPtr plainTextString = Util::toWK("Hello, World"); + WKPageLoadPlainTextString(webView.page(), plainTextString.get()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); + Util::run(&done); + done = false; + + WKPageReload(webView.page()); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); + Util::run(&done); + done = false; + + url = adoptWK(WKURLCreateWithUTF8CString("file:///tmp/index.html")); + WKPageLoadFile(webView.page(), url.get(), nullptr); + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); + WKPageStopLoading(webView.page()); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp index c5acb6172..7712b142c 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp @@ -24,12 +24,15 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" #include -#include -#include +#include +#include namespace TestWebKitAPI { @@ -68,3 +71,5 @@ TEST(WebKit2, PreventEmptyUserAgent) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PrivateBrowsingPushStateNoHistoryCallback.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PrivateBrowsingPushStateNoHistoryCallback.cpp index 3d0db3d2f..532c92373 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/PrivateBrowsingPushStateNoHistoryCallback.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PrivateBrowsingPushStateNoHistoryCallback.cpp @@ -24,24 +24,33 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { -static bool testDone; +static bool didNavigate; +static bool didSameDocumentNavigation; -static void didNavigateWithNavigationData(WKContextRef context, WKPageRef page, WKNavigationDataRef navigationData, WKFrameRef frame, const void* clientInfo) +static void didNavigateWithoutNavigationData(WKContextRef context, WKPageRef page, WKNavigationDataRef navigationData, WKFrameRef frame, const void* clientInfo) { // This should never be called when navigating in Private Browsing. FAIL(); } +static void didNavigateWithNavigationData(WKContextRef context, WKPageRef page, WKNavigationDataRef navigationData, WKFrameRef frame, const void* clientInfo) +{ + didNavigate = true; +} + static void didSameDocumentNavigationForFrame(WKPageRef page, WKFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef userData, const void *clientInfo) { - testDone = true; + didSameDocumentNavigation = true; } TEST(WebKit2, PrivateBrowsingPushStateNoHistoryCallback) @@ -52,7 +61,7 @@ TEST(WebKit2, PrivateBrowsingPushStateNoHistoryCallback) memset(&historyClient, 0, sizeof(historyClient)); historyClient.base.version = 0; - historyClient.didNavigateWithNavigationData = didNavigateWithNavigationData; + historyClient.didNavigateWithNavigationData = didNavigateWithoutNavigationData; WKContextSetHistoryClient(context.get(), &historyClient.base); @@ -75,7 +84,18 @@ TEST(WebKit2, PrivateBrowsingPushStateNoHistoryCallback) WKRetainPtr url(AdoptWK, Util::createURLForResource("push-state", "html")); WKPageLoadURL(webView.page(), url.get()); - Util::run(&testDone); + Util::run(&didSameDocumentNavigation); + + WKPreferencesSetPrivateBrowsingEnabled(preferences.get(), false); + + historyClient.didNavigateWithNavigationData = didNavigateWithNavigationData; + WKContextSetHistoryClient(context.get(), &historyClient.base); + + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&didNavigate); } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp new file mode 100644 index 000000000..2979f792c --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2016 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include +#include +#include + +namespace TestWebKitAPI { + +static bool committedLoad; + +static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void*) +{ + if (!WKFrameIsMainFrame(frame)) + return; + + // The provisional URL should be null. + EXPECT_NULL(WKFrameCopyProvisionalURL(frame)); + + // The committed URL is the last known provisional URL. + WKRetainPtr committedURL = adoptWK(WKFrameCopyURL(frame)); + ASSERT_NOT_NULL(committedURL.get()); + WKRetainPtr activeURL = adoptWK(WKPageCopyActiveURL(page)); + ASSERT_NOT_NULL(activeURL.get()); + EXPECT_TRUE(WKURLIsEqual(committedURL.get(), activeURL.get())); + assert(WKGetTypeID(userData) == WKURLGetTypeID()); + EXPECT_TRUE(WKURLIsEqual(committedURL.get(), static_cast(userData))); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("simple2", "html")); + EXPECT_TRUE(WKURLIsEqual(committedURL.get(), url.get())); + + committedLoad = true; +} + +TEST(WebKit2, ProvisionalURLAfterWillSendRequestCallback) +{ + WKRetainPtr context(AdoptWK, Util::createContextForInjectedBundleTest("ProvisionalURLAfterWillSendRequestCallbackTest")); + + WKContextInjectedBundleClientV0 injectedBundleClient; + memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); + injectedBundleClient.base.version = 0; + WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base); + + PlatformWebView webView(context.get()); + + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 0; + loaderClient.didCommitLoadForFrame = didCommitLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + Util::run(&committedLoad); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp new file mode 100644 index 000000000..6c3d74a95 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2016 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "InjectedBundleTest.h" +#include "PlatformUtilities.h" +#include "Test.h" +#include +#include +#include + +namespace TestWebKitAPI { + +class ProvisionalURLAfterWillSendRequestCallbackTest : public InjectedBundleTest { +public: + ProvisionalURLAfterWillSendRequestCallbackTest(const std::string& identifier) + : InjectedBundleTest(identifier) + { + } + + static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef, WKBundleFrameRef frame, uint64_t resourceIdentifier, WKURLRequestRef request, WKURLResponseRef redirectResponse, const void*) + { + if (!WKBundleFrameIsMainFrame(frame)) { + WKRetainPtr newRequest = request; + return newRequest.leakRef(); + } + + // Change the main frame URL. + WKRetainPtr url(AdoptWK, Util::createURLForResource("simple2", "html")); + return WKURLRequestCreateWithWKURL(url.get()); + } + + static void didCommitLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef* userData, const void*) + { + if (!WKBundleFrameIsMainFrame(frame)) + return; + *userData = WKBundleFrameCopyURL(frame); + } + + void didCreatePage(WKBundleRef bundle, WKBundlePageRef page) override + { + WKBundlePageResourceLoadClientV0 resourceLoadClient; + memset(&resourceLoadClient, 0, sizeof(resourceLoadClient)); + resourceLoadClient.base.version = 0; + resourceLoadClient.willSendRequestForFrame = willSendRequestForFrame; + WKBundlePageSetResourceLoadClient(page, &resourceLoadClient.base); + + WKBundlePageLoaderClientV0 pageLoaderClient; + memset(&pageLoaderClient, 0, sizeof(pageLoaderClient)); + pageLoaderClient.base.version = 0; + pageLoaderClient.didCommitLoadForFrame = didCommitLoadForFrame; + WKBundlePageSetPageLoaderClient(page, &pageLoaderClient.base); + } +}; + +static InjectedBundleTest::Register registrar("ProvisionalURLAfterWillSendRequestCallbackTest"); + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ReloadPageAfterCrash.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ReloadPageAfterCrash.cpp index fb265abc1..190c85341 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ReloadPageAfterCrash.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ReloadPageAfterCrash.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { @@ -86,3 +89,5 @@ TEST(WebKit2, ReloadPageAfterCrash) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ResizeReversePaginatedWebView.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ResizeReversePaginatedWebView.cpp index af1f1e705..f2e1ae17f 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ResizeReversePaginatedWebView.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ResizeReversePaginatedWebView.cpp @@ -24,14 +24,17 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "JavaScriptTest.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" #include -#include -#include -#include +#include +#include +#include namespace TestWebKitAPI { @@ -88,3 +91,5 @@ TEST(WebKit2, ResizeReversePaginatedWebView) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ResizeWindowAfterCrash.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ResizeWindowAfterCrash.cpp index 4cd9eddb4..2dfc8b4c2 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ResizeWindowAfterCrash.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ResizeWindowAfterCrash.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { @@ -97,3 +100,5 @@ TEST(WebKit2, ResizeWindowAfterCrash) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly.cpp index 9de11a286..a034637e3 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" @@ -96,3 +99,5 @@ TEST(WebKit2, ResponsivenessTimerDoesntFireEarly) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp index 50d664f38..ddd2ca158 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" @@ -57,3 +60,5 @@ void ResponsivenessTimerDoesntFireEarlyTest::didReceiveMessage(WKBundleRef bundl } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp index 079c51856..b16537e70 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp @@ -24,10 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "JavaScriptTest.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" +#include namespace TestWebKitAPI { @@ -49,7 +53,7 @@ static void setPageLoaderClient(WKPageRef page) WKPageSetPageLoaderClient(page, &loaderClient.base); } -static WKRetainPtr createSessionStateContainingFormData(WKContextRef context) +static WKRetainPtr createSessionStateDataContainingFormData(WKContextRef context) { PlatformWebView webView(context); setPageLoaderClient(webView.page()); @@ -62,7 +66,8 @@ static WKRetainPtr createSessionStateContainingFormData(WKContextRef Util::run(&didFinishLoad); didFinishLoad = false; - return adoptWK(WKPageCopySessionState(webView.page(), 0, 0)); + auto sessionState = adoptWK(static_cast(WKPageCopySessionState(webView.page(), reinterpret_cast(1), nullptr))); + return adoptWK(WKSessionStateCopyData(sessionState.get())); } TEST(WebKit2, RestoreSessionStateContainingFormData) @@ -75,13 +80,17 @@ TEST(WebKit2, RestoreSessionStateContainingFormData) PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); - WKRetainPtr data = createSessionStateContainingFormData(context.get()); + WKRetainPtr data = createSessionStateDataContainingFormData(context.get()); EXPECT_NOT_NULL(data); - WKPageRestoreFromSessionState(webView.page(), data.get()); + auto sessionState = adoptWK(WKSessionStateCreateFromData(data.get())); + WKPageRestoreFromSessionState(webView.page(), sessionState.get()); + Util::run(&didFinishLoad); EXPECT_TRUE(WKPageCanGoBack(webView.page())); } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateWithoutNavigation.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateWithoutNavigation.cpp new file mode 100644 index 000000000..d597ba5fd --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateWithoutNavigation.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "JavaScriptTest.h" +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include +#include + +namespace TestWebKitAPI { + +static bool didFinishLoad; +static bool didChangeBackForwardList; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +static void didChangeBackForwardListForPage(WKPageRef, WKBackForwardListItemRef addedItem, WKArrayRef, const void*) +{ + didChangeBackForwardList = true; +} + +static void setPageLoaderClient(WKPageRef page) +{ + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + loaderClient.didChangeBackForwardList = didChangeBackForwardListForPage; + + WKPageSetPageLoaderClient(page, &loaderClient.base); +} + +static WKRetainPtr createSessionStateData(WKContextRef context) +{ + PlatformWebView webView(context); + setPageLoaderClient(webView.page()); + + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); + Util::run(&didFinishLoad); + didFinishLoad = false; + + auto sessionState = adoptWK(static_cast(WKPageCopySessionState(webView.page(), reinterpret_cast(1), nullptr))); + return adoptWK(WKSessionStateCopyData(sessionState.get())); +} + +TEST(WebKit2, RestoreSessionStateWithoutNavigation) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + + PlatformWebView webView(context.get()); + setPageLoaderClient(webView.page()); + + WKRetainPtr data = createSessionStateData(context.get()); + EXPECT_NOT_NULL(data); + + auto sessionState = adoptWK(WKSessionStateCreateFromData(data.get())); + WKPageRestoreFromSessionStateWithoutNavigation(webView.page(), sessionState.get()); + + Util::run(&didChangeBackForwardList); + + WKRetainPtr committedURL = adoptWK(WKPageCopyCommittedURL(webView.page())); + EXPECT_NULL(committedURL.get()); + + auto backForwardList = WKPageGetBackForwardList(webView.page()); + auto currentItem = WKBackForwardListGetCurrentItem(backForwardList); + auto currentItemURL = adoptWK(WKBackForwardListItemCopyURL(currentItem)); + auto expectedURL = adoptWK(Util::createURLForResource("simple", "html")); + EXPECT_NOT_NULL(expectedURL); + EXPECT_TRUE(WKURLIsEqual(currentItemURL.get(), expectedURL.get())); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ScrollPinningBehaviors.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ScrollPinningBehaviors.cpp index 5b628a932..015571f5f 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ScrollPinningBehaviors.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ScrollPinningBehaviors.cpp @@ -24,15 +24,18 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "JavaScriptTest.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" #include -#include -#include -#include -#include +#include +#include +#include +#include namespace TestWebKitAPI { @@ -95,3 +98,5 @@ TEST(WebKit2, ScrollPinningBehaviors) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp index 5754155ed..f41e44a5e 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include +#include namespace TestWebKitAPI { @@ -90,3 +93,5 @@ TEST(WebKit2, ShouldGoToBackForwardListItem) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp index dd81bf3bf..5eba75a9e 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -68,3 +71,5 @@ void ShouldGoToBackForwardListItemTest::didCreatePage(WKBundleRef bundle, WKBund } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ShouldKeepCurrentBackForwardListItemInList.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldKeepCurrentBackForwardListItemInList.cpp new file mode 100644 index 000000000..f8098e6f1 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldKeepCurrentBackForwardListItemInList.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" + +// This test navigates from simple.html, to simple2.html, to simple3.html +// When navigating from simple2 to simple3, it disallows the simple2 back/forward list item from staying in the list +// It then navigates back from simple3, expecting to land at simple. + +namespace TestWebKitAPI { + +static bool finished = false; +static bool successfulSoFar = true; +static int navigationNumber = 0; + +static bool itemURLLastComponentIsString(WKBackForwardListItemRef item, const char* string) +{ + WKRetainPtr url = adoptWK(WKBackForwardListItemCopyURL(item)); + WKRetainPtr path = adoptWK(WKURLCopyLastPathComponent(url.get())); + + return WKStringIsEqualToUTF8CString(path.get(), string); +} + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef, const void*) +{ + // Only mark finished when the main frame loads + if (!WKFrameIsMainFrame(frame)) + return; + + finished = true; + navigationNumber++; + + WKBackForwardListRef list = WKPageGetBackForwardList(page); + WKBackForwardListItemRef currentItem = WKBackForwardListGetCurrentItem(list); + WKBackForwardListItemRef backItem = WKBackForwardListGetBackItem(list); + WKBackForwardListItemRef forwardItem = WKBackForwardListGetForwardItem(list); + unsigned forwardCount = WKBackForwardListGetForwardListCount(list); + + // This test should never have a forward list. + if (forwardCount) + successfulSoFar = false; + + if (navigationNumber == 1) { + // We've only performed 1 navigation, we should only have a current item. + if (!currentItem || !itemURLLastComponentIsString(currentItem, "simple.html")) + successfulSoFar = false; + if (backItem || forwardItem) + successfulSoFar = false; + } else if (navigationNumber == 2) { + // On the second navigation, simple2 should be current and simple should be the back item. + if (!currentItem || !itemURLLastComponentIsString(currentItem, "simple2.html")) + successfulSoFar = false; + if (!backItem || !itemURLLastComponentIsString(backItem, "simple.html")) + successfulSoFar = false; + if (forwardItem) + successfulSoFar = false; + } else if (navigationNumber == 3) { + // On the third navigation the item for simple2 should have been removed. + // So simple3 should be current and simple should still be the back item. + if (!currentItem || !itemURLLastComponentIsString(currentItem, "simple3.html")) + successfulSoFar = false; + if (!backItem || !itemURLLastComponentIsString(backItem, "simple.html")) + successfulSoFar = false; + if (forwardItem) + successfulSoFar = false; + } else if (navigationNumber == 4) { + // After the fourth navigation (which was a "back" navigation), the item for simple3 should have been removed. + // So simple should be current and there should be no other items. + if (!currentItem || !itemURLLastComponentIsString(currentItem, "simple.html")) + successfulSoFar = false; + if (backItem || forwardItem) + successfulSoFar = false; + } +} + +static void willGoToBackForwardListItem(WKPageRef, WKBackForwardListItemRef item, WKTypeRef userData, const void*) +{ + if (!itemURLLastComponentIsString(item, "simple.html")) + successfulSoFar = false; +} + +static bool shouldKeepCurrentBackForwardListItemInList(WKPageRef page, WKBackForwardListItemRef item, const void*) +{ + // We make sure the item for "simple2.html" is removed when we navigate to "simple3.html" + // We also want to make sure the item for "simple3.html" is removed when we go back to "simple.html" + // So we only want to keep "simple.html" + return itemURLLastComponentIsString(item, "simple.html"); +} + +static void setPageLoaderClient(WKPageRef page) +{ + WKPageLoaderClientV5 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 5; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + loaderClient.shouldKeepCurrentBackForwardListItemInList = shouldKeepCurrentBackForwardListItemInList; + loaderClient.willGoToBackForwardListItem = willGoToBackForwardListItem; + + WKPageSetPageLoaderClient(page, &loaderClient.base); +} + +TEST(WebKit2, ShouldKeepCurrentBackForwardListItemInList) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + + PlatformWebView webView(context.get()); + setPageLoaderClient(webView.page()); + + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); + Util::run(&finished); + EXPECT_EQ(successfulSoFar, true); + + finished = false; + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple2", "html")).get()); + Util::run(&finished); + EXPECT_EQ(successfulSoFar, true); + + finished = false; + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple3", "html")).get()); + Util::run(&finished); + EXPECT_EQ(successfulSoFar, true); + + finished = false; + WKPageGoBack(webView.page()); + Util::run(&finished); + + EXPECT_EQ(successfulSoFar, true); + EXPECT_EQ(navigationNumber, 4); +} + +} // namespace TestWebKitAPI + + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp index 577e0d77c..226f52cc2 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "JavaScriptTest.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -86,13 +89,11 @@ TEST(WebKit2, SpacebarScrolling) EXPECT_JS_FALSE(webView.page(), "isDocumentScrolled()"); EXPECT_JS_TRUE(webView.page(), "textFieldContainsSpace()"); - // On Mac, a key down event represents both a raw key down and a key press. On Windows, a key - // down event only represents a raw key down. We expect the key press to be handled (because it - // inserts text into the text field). But the raw key down should not be handled. -#if PLATFORM(MAC) + // On Mac, a key down event represents both a raw key down and a key press. + // We expect the key press to be handled (because it inserts text into the text field), + // but the raw key down should not be handled. +#if PLATFORM(COCOA) EXPECT_FALSE(didNotHandleKeyDownEvent); -#elif PLATFORM(WIN) - EXPECT_TRUE(didNotHandleKeyDownEvent); #endif EXPECT_JS_EQ(webView.page(), "blurTextField()", "undefined"); @@ -100,18 +101,14 @@ TEST(WebKit2, SpacebarScrolling) didNotHandleKeyDownEvent = false; webView.simulateSpacebarKeyPress(); - // This EXPECT_JS_TRUE test fails on Windows port - // https://bugs.webkit.org/show_bug.cgi?id=84961 -#if !PLATFORM(WIN) EXPECT_JS_TRUE(webView.page(), "isDocumentScrolled()"); -#endif EXPECT_JS_TRUE(webView.page(), "textFieldContainsSpace()"); -#if PLATFORM(MAC) +#if PLATFORM(COCOA) EXPECT_FALSE(didNotHandleKeyDownEvent); -#elif PLATFORM(WIN) - EXPECT_TRUE(didNotHandleKeyDownEvent); #endif } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/StopLoadingDuringDidFailProvisionalLoad.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/StopLoadingDuringDidFailProvisionalLoad.cpp new file mode 100644 index 000000000..386dfd303 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/StopLoadingDuringDidFailProvisionalLoad.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include + +namespace TestWebKitAPI { + +static bool done; +static bool receivedMessageFromBundle; + +static void didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo) +{ + if (WKStringIsEqualToUTF8CString(messageName, "StopLoadingDuringDidFailProvisionalLoadTestDone")) + receivedMessageFromBundle = true; +} + +static void setInjectedBundleClient(WKContextRef context) +{ + WKContextInjectedBundleClientV0 injectedBundleClient; + memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); + + injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; + + WKContextSetInjectedBundleClient(context, &injectedBundleClient.base); +} + +static void didFailProvisionalLoadWithErrorForFrame(WKPageRef, WKFrameRef, WKErrorRef, WKTypeRef, const void*) +{ + // The injected bundle is notified of the failed load first. If we also receive this callback, the test didn't crash. + EXPECT_TRUE(receivedMessageFromBundle); + done = true; +} + +TEST(WebKit2, StopLoadingDuringDidFailProvisionalLoadTest) +{ + WKRetainPtr context(AdoptWK, Util::createContextForInjectedBundleTest("StopLoadingDuringDidFailProvisionalLoadTest")); + setInjectedBundleClient(context.get()); + + PlatformWebView webView(context.get()); + + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + loaderClient.didFailProvisionalLoadWithErrorForFrame = didFailProvisionalLoadWithErrorForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); + + WKRetainPtr url(AdoptWK, Util::URLForNonExistentResource()); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&done); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/StopLoadingDuringDidFailProvisionalLoad_bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/StopLoadingDuringDidFailProvisionalLoad_bundle.cpp new file mode 100644 index 000000000..ad302ff51 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/StopLoadingDuringDidFailProvisionalLoad_bundle.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "InjectedBundleTest.h" +#include "PlatformUtilities.h" +#include +#include +#include +#include + +namespace TestWebKitAPI { + +class StopLoadingDuringDidFailProvisionalLoadTest : public InjectedBundleTest { +public: + StopLoadingDuringDidFailProvisionalLoadTest(const std::string& identifier) + : InjectedBundleTest(identifier) + { + } + + void didCreatePage(WKBundleRef, WKBundlePageRef) override; + void didFailProvisionalLoad(WKBundlePageRef, WKBundleFrameRef); + + WKBundleRef m_bundle; +}; + +static InjectedBundleTest::Register registrar("StopLoadingDuringDidFailProvisionalLoadTest"); + +static void didFailProvisionalLoadWithErrorForFrameCallback(WKBundlePageRef page, WKBundleFrameRef frame, WKErrorRef, WKTypeRef*, const void *clientInfo) +{ + ((StopLoadingDuringDidFailProvisionalLoadTest*)clientInfo)->didFailProvisionalLoad(page, frame); +} + +void StopLoadingDuringDidFailProvisionalLoadTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page) +{ + m_bundle = bundle; + + WKBundlePageLoaderClientV2 pageLoaderClient; + memset(&pageLoaderClient, 0, sizeof(pageLoaderClient)); + + pageLoaderClient.base.version = 2; + pageLoaderClient.base.clientInfo = this; + pageLoaderClient.didFailProvisionalLoadWithErrorForFrame = didFailProvisionalLoadWithErrorForFrameCallback; + + WKBundlePageSetPageLoaderClient(page, &pageLoaderClient.base); +} + +void StopLoadingDuringDidFailProvisionalLoadTest::didFailProvisionalLoad(WKBundlePageRef page, WKBundleFrameRef) +{ + WKBundlePageStopLoading(page); + WKBundlePostMessage(m_bundle, Util::toWK("StopLoadingDuringDidFailProvisionalLoadTestDone").get(), nullptr); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/TerminateTwice.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/TerminateTwice.cpp index 879312520..5d5c2f79d 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/TerminateTwice.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/TerminateTwice.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" @@ -64,3 +67,4 @@ TEST(WebKit2, TerminateTwice) } // namespace TestWebKitAPI +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp new file mode 100644 index 000000000..731e8e51e --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include + +namespace TestWebKitAPI { + +struct WebKit2TextFieldBeginAndEditEditingTest : public ::testing::Test { + std::unique_ptr webView; + + WKRetainPtr messageName; + + bool didFinishLoad { false }; + bool didReceiveMessage { false }; + + static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef, const void* clientInfo) + { + WebKit2TextFieldBeginAndEditEditingTest& client = *static_cast(const_cast(clientInfo)); + client.messageName = messageName; + client.didReceiveMessage = true; + } + + static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo) + { + WebKit2TextFieldBeginAndEditEditingTest& client = *static_cast(const_cast(clientInfo)); + client.didFinishLoad = true; + } + + static void setInjectedBundleClient(WKContextRef context, const void* clientInfo) + { + WKContextInjectedBundleClientV1 injectedBundleClient; + memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); + + injectedBundleClient.base.version = 1; + injectedBundleClient.base.clientInfo = clientInfo; + injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; + + WKContextSetInjectedBundleClient(context, &injectedBundleClient.base); + } + + static void setPageLoaderClient(WKPageRef page, const void* clientInfo) + { + WKPageLoaderClientV6 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 6; + loaderClient.base.clientInfo = clientInfo; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + + WKPageSetPageLoaderClient(page, &loaderClient.base); + } + + static void nullJavaScriptCallback(WKSerializedScriptValueRef, WKErrorRef, void*) + { + } + + void executeJavaScriptAndCheckDidReceiveMessage(const char* javaScriptCode, const char* expectedMessageName) + { + didReceiveMessage = false; + WKPageRunJavaScriptInMainFrame(webView->page(), Util::toWK(javaScriptCode).get(), 0, nullJavaScriptCallback); + Util::run(&didReceiveMessage); + EXPECT_WK_STREQ(expectedMessageName, messageName); + } + + // From ::testing::Test + void SetUp() override + { + WKRetainPtr context = adoptWK(Util::createContextForInjectedBundleTest("TextFieldDidBeginAndEndEditingEventsTest")); + setInjectedBundleClient(context.get(), this); + + webView = std::make_unique(context.get()); + setPageLoaderClient(webView->page(), this); + + didFinishLoad = false; + didReceiveMessage = false; + + WKPageLoadURL(webView->page(), adoptWK(Util::createURLForResource("input-focus-blur", "html")).get()); + Util::run(&didFinishLoad); + } +}; + +TEST_F(WebKit2TextFieldBeginAndEditEditingTest, TextFieldDidBeginAndEndEditingEvents) +{ + executeJavaScriptAndCheckDidReceiveMessage("focusTextField('input')", "DidReceiveTextFieldDidBeginEditing"); + executeJavaScriptAndCheckDidReceiveMessage("blurTextField('input')", "DidReceiveTextFieldDidEndEditing"); +} + +TEST_F(WebKit2TextFieldBeginAndEditEditingTest, TextFieldDidBeginAndEndEditingEventsInReadOnlyField) +{ + executeJavaScriptAndCheckDidReceiveMessage("focusTextField('readonly')", "DidReceiveTextFieldDidBeginEditing"); + executeJavaScriptAndCheckDidReceiveMessage("blurTextField('readonly')", "DidReceiveTextFieldDidEndEditing"); +} + +TEST_F(WebKit2TextFieldBeginAndEditEditingTest, TextFieldDidBeginShouldNotBeDispatchedForAlreadyFocusedField) +{ + executeJavaScriptAndCheckDidReceiveMessage("focusTextField('input'); focusTextField('input')", "DidReceiveTextFieldDidBeginEditing"); + executeJavaScriptAndCheckDidReceiveMessage("blurTextField('input')", "DidReceiveTextFieldDidEndEditing"); +} + +TEST_F(WebKit2TextFieldBeginAndEditEditingTest, TextFieldDidEndShouldBeDispatchedForRemovedFocusField) +{ + executeJavaScriptAndCheckDidReceiveMessage("focusTextField('input')", "DidReceiveTextFieldDidBeginEditing"); + executeJavaScriptAndCheckDidReceiveMessage("removeTextField('input')", "DidReceiveTextFieldDidEndEditing"); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing_Bundle.cpp new file mode 100644 index 000000000..347ce826c --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing_Bundle.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "InjectedBundleTest.h" + +#include "PlatformUtilities.h" +#include + +namespace TestWebKitAPI { + +class TextFieldDidBeginAndEndEditingEventsTest : public InjectedBundleTest { +public: + TextFieldDidBeginAndEndEditingEventsTest(const std::string& identifier); + + virtual void didCreatePage(WKBundleRef, WKBundlePageRef); +}; + +static InjectedBundleTest::Register registrar("TextFieldDidBeginAndEndEditingEventsTest"); + +static void textFieldDidBeginEditing(WKBundlePageRef, WKBundleNodeHandleRef inputElement, WKBundleFrameRef, const void*) +{ + WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("DidReceiveTextFieldDidBeginEditing").get(), nullptr); +} + +static void textFieldDidEndEditing(WKBundlePageRef, WKBundleNodeHandleRef inputElement, WKBundleFrameRef, const void*) +{ + WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("DidReceiveTextFieldDidEndEditing").get(), nullptr); +} + +TextFieldDidBeginAndEndEditingEventsTest::TextFieldDidBeginAndEndEditingEventsTest(const std::string& identifier) + : InjectedBundleTest(identifier) +{ +} + +void TextFieldDidBeginAndEndEditingEventsTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page) +{ + WKBundlePageFormClientV2 formClient; + memset(&formClient, 0, sizeof(formClient)); + + formClient.base.version = 2; + formClient.base.clientInfo = this; + formClient.textFieldDidBeginEditing = textFieldDidBeginEditing; + formClient.textFieldDidEndEditing = textFieldDidEndEditing; + + WKBundlePageSetFormClient(page, &formClient.base); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/UserMedia.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/UserMedia.cpp new file mode 100644 index 000000000..fc7ade42f --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/UserMedia.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2014 Igalia S.L + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#if ENABLE(MEDIA_STREAM) +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include +#include +#include + +namespace TestWebKitAPI { + +static bool done; + +void decidePolicyForUserMediaPermissionRequestCallBack(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKSecurityOriginRef, WKUserMediaPermissionRequestRef permissionRequest, const void* /* clientInfo */) +{ + WKRetainPtr audioDeviceUIDs = WKUserMediaPermissionRequestAudioDeviceUIDs(permissionRequest); + WKRetainPtr videoDeviceUIDs = WKUserMediaPermissionRequestVideoDeviceUIDs(permissionRequest); + + if (WKArrayGetSize(videoDeviceUIDs.get()) || WKArrayGetSize(audioDeviceUIDs.get())) { + WKRetainPtr videoDeviceUID; + if (WKArrayGetSize(videoDeviceUIDs.get())) + videoDeviceUID = reinterpret_cast(WKArrayGetItemAtIndex(videoDeviceUIDs.get(), 0)); + else + videoDeviceUID = WKStringCreateWithUTF8CString(""); + + WKRetainPtr audioDeviceUID; + if (WKArrayGetSize(audioDeviceUIDs.get())) + audioDeviceUID = reinterpret_cast(WKArrayGetItemAtIndex(audioDeviceUIDs.get(), 0)); + else + audioDeviceUID = WKStringCreateWithUTF8CString(""); + + WKUserMediaPermissionRequestAllow(permissionRequest, audioDeviceUID.get(), videoDeviceUID.get()); + } + + done = true; +} + +TEST(WebKit2, DISABLED_UserMediaBasic) +{ + auto context = adoptWK(WKContextCreate()); + PlatformWebView webView(context.get()); + WKPageUIClientV5 uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + + uiClient.base.version = 5; + uiClient.decidePolicyForUserMediaPermissionRequest = decidePolicyForUserMediaPermissionRequestCallBack; + + WKPageSetPageUIClient(webView.page(), &uiClient.base); + + done = false; + auto url = adoptWK(Util::createURLForResource("getUserMedia", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&done); +} + +} // namespace TestWebKitAPI + +#endif // ENABLE(MEDIA_STREAM) + +#endif // WK_HAVE_C_SPI + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/UserMessage.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/UserMessage.cpp index 2585a06ff..064cbb838 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/UserMessage.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/UserMessage.cpp @@ -24,12 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "Test.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include -#include namespace TestWebKitAPI { @@ -42,7 +43,7 @@ public: } WKRetainPtr context; - OwnPtr webView; + std::unique_ptr webView; WKRetainPtr recievedBody; @@ -80,7 +81,7 @@ public: WKPageLoaderClientV3 loaderClient; memset(&loaderClient, 0, sizeof(loaderClient)); - loaderClient.base.version = kWKPageLoaderClientCurrentVersion; + loaderClient.base.version = 3; loaderClient.base.clientInfo = clientInfo; loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; @@ -92,7 +93,7 @@ public: context = adoptWK(Util::createContextForInjectedBundleTest("UserMessageTest")); setInjectedBundleClient(context.get(), this); - webView = adoptPtr(new PlatformWebView(context.get())); + webView = std::make_unique(context.get()); setPageLoaderClient(webView->page(), this); didFinishLoad = false; @@ -157,3 +158,5 @@ TEST_F(WebKit2UserMessageRoundTripTest, WKString) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/UserMessage_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/UserMessage_Bundle.cpp index 29ede3d83..cec713655 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/UserMessage_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/UserMessage_Bundle.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" @@ -50,3 +53,5 @@ private: static InjectedBundleTest::Register registrar("UserMessageTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKBundleFileHandle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKBundleFileHandle.cpp new file mode 100644 index 000000000..b9a84ff80 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKBundleFileHandle.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" + +namespace TestWebKitAPI { + +static bool done; +static bool loadDone; + +static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*) +{ + if (!WKStringIsEqualToUTF8CString(messageName, "SUCCESS")) + FAIL(); + else + SUCCEED(); + + done = true; +} + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void*) +{ + loadDone = true; +} + +TEST(WebKit2, WKBundleFileHandle) +{ + WKRetainPtr context = adoptWK(Util::createContextForInjectedBundleTest("WKBundleFileHandleTest")); + + WKContextInjectedBundleClientV0 injectedBundleClient; + memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); + injectedBundleClient.base.version = 0; + injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; + WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base); + + PlatformWebView webView(context.get()); + + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); + + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("bundle-file", "html")).get()); + Util::run(&loadDone); + + // Get path to a file. + auto urlToFile = adoptWK(Util::createURLForResource("simple", "html")); + auto pathToFile = adoptWK(WKURLCopyPath(urlToFile.get())); + + WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("TestFile").get(), pathToFile.get()); + + Util::run(&done); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKBundleFileHandle_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKBundleFileHandle_Bundle.cpp new file mode 100644 index 000000000..fcb0ab7a0 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKBundleFileHandle_Bundle.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "InjectedBundleTest.h" + +#include "PlatformUtilities.h" +#include +#include +#include +#include + +namespace TestWebKitAPI { + +static WKBundlePageRef loadedPage; + +class WKBundleFileHandleTest : public InjectedBundleTest { +public: + WKBundleFileHandleTest(const std::string& identifier) + : InjectedBundleTest(identifier) + { + } + +private: + void didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody) override + { + if (!WKStringIsEqualToUTF8CString(messageName, "TestFile")) { + WKBundlePostMessage(bundle, Util::toWK("FAIL").get(), Util::toWK("Recieved invalid message").get()); + return; + } + + if (!loadedPage) { + WKBundlePostMessage(bundle, Util::toWK("FAIL").get(), Util::toWK("No loaded page").get()); + return; + } + + if (WKGetTypeID(messageBody) != WKStringGetTypeID()) { + WKBundlePostMessage(bundle, Util::toWK("FAIL").get(), Util::toWK("Message body has invalid type").get()); + return; + } + + WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(loadedPage); + WKBundleScriptWorldRef world = WKBundleScriptWorldNormalWorld(); + + JSGlobalContextRef globalContext = WKBundleFrameGetJavaScriptContextForWorld(mainFrame, world); + + auto fileHandle = adoptWK(WKBundleFileHandleCreateWithPath((WKStringRef)messageBody)); + JSValueRef jsFileHandle = WKBundleFrameGetJavaScriptWrapperForFileForWorld(mainFrame, fileHandle.get(), world); + + JSObjectRef globalObject = JSContextGetGlobalObject(globalContext); + + JSStringRef jsString = JSStringCreateWithUTF8CString("testFile"); + JSValueRef function = JSObjectGetProperty(globalContext, globalObject, jsString, nullptr); + JSStringRelease(jsString); + + JSValueRef result = JSObjectCallAsFunction(globalContext, (JSObjectRef)function, globalObject, 1, &jsFileHandle, nullptr); + + if (JSValueToBoolean(globalContext, result)) + WKBundlePostMessage(bundle, Util::toWK("SUCCESS").get(), nullptr); + else + WKBundlePostMessage(bundle, Util::toWK("FAIL").get(), Util::toWK("Script failed").get()); + } + + void didCreatePage(WKBundleRef bundle, WKBundlePageRef page) override + { + loadedPage = page; + } +}; + +static InjectedBundleTest::Register registrar("WKBundleFileHandleTest"); + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKImageCreateCGImageCrash.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKImageCreateCGImageCrash.cpp new file mode 100644 index 000000000..f0d19025f --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKImageCreateCGImageCrash.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include + +namespace TestWebKitAPI { + +TEST(WebKit2, WKImageCreateCGImageCrash) +{ + EXPECT_FALSE(WKImageCreateCGImage(nullptr)); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKPageConfiguration.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageConfiguration.cpp new file mode 100644 index 000000000..d041eeaed --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageConfiguration.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" + +#include + +namespace TestWebKitAPI { + +TEST(WebKit2, WKPageConfigurationEmpty) +{ + WKRetainPtr configuration = adoptWK(WKPageConfigurationCreate()); + + ASSERT_NULL(WKPageConfigurationGetContext(configuration.get())); + ASSERT_NULL(WKPageConfigurationGetUserContentController(configuration.get())); + ASSERT_NULL(WKPageConfigurationGetPageGroup(configuration.get())); + ASSERT_NULL(WKPageConfigurationGetPreferences(configuration.get())); + ASSERT_NULL(WKPageConfigurationGetRelatedPage(configuration.get())); +} + +static bool didFinishLoad; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +static void setPageLoaderClient(WKPageRef page) +{ + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + + WKPageSetPageLoaderClient(page, &loaderClient.base); +} + +TEST(WebKit2, WKPageConfigurationBasic) +{ + WKRetainPtr configuration = adoptWK(WKPageConfigurationCreate()); + WKRetainPtr context = adoptWK(WKContextCreate()); + WKPageConfigurationSetContext(configuration.get(), context.get()); + + PlatformWebView webView(configuration.get()); + setPageLoaderClient(webView.page()); + + WKRetainPtr copiedConfiguration = adoptWK(WKPageCopyPageConfiguration(webView.page())); + ASSERT_EQ(context.get(), WKPageConfigurationGetContext(copiedConfiguration.get())); + + WKRetainPtr url = adoptWK(Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + + didFinishLoad = false; + Util::run(&didFinishLoad); +} + +TEST(WebKit2, WKPageConfigurationBasicWithDataStore) +{ + WKRetainPtr configuration = adoptWK(WKPageConfigurationCreate()); + WKRetainPtr context = adoptWK(WKContextCreate()); + WKPageConfigurationSetContext(configuration.get(), context.get()); + WKRetainPtr websiteDataStore = WKWebsiteDataStoreGetDefaultDataStore(); + WKPageConfigurationSetWebsiteDataStore(configuration.get(), websiteDataStore.get()); + + PlatformWebView webView(configuration.get()); + setPageLoaderClient(webView.page()); + + WKRetainPtr copiedConfiguration = adoptWK(WKPageCopyPageConfiguration(webView.page())); + ASSERT_EQ(context.get(), WKPageConfigurationGetContext(copiedConfiguration.get())); + ASSERT_EQ(WKWebsiteDataStoreGetDefaultDataStore(), WKPageConfigurationGetWebsiteDataStore(copiedConfiguration.get())); + + WKRetainPtr url = adoptWK(Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + + didFinishLoad = false; + Util::run(&didFinishLoad); +} + +TEST(WebKit2, WKPageConfigurationBasicWithNonPersistentDataStore) +{ + WKRetainPtr configuration = adoptWK(WKPageConfigurationCreate()); + WKRetainPtr context = adoptWK(WKContextCreate()); + WKPageConfigurationSetContext(configuration.get(), context.get()); + WKRetainPtr websiteDataStore = adoptWK(WKWebsiteDataStoreCreateNonPersistentDataStore()); + WKPageConfigurationSetWebsiteDataStore(configuration.get(), websiteDataStore.get()); + + PlatformWebView webView(configuration.get()); + setPageLoaderClient(webView.page()); + + WKRetainPtr copiedConfiguration = adoptWK(WKPageCopyPageConfiguration(webView.page())); + ASSERT_EQ(context.get(), WKPageConfigurationGetContext(copiedConfiguration.get())); + ASSERT_EQ(websiteDataStore.get(), WKPageConfigurationGetWebsiteDataStore(copiedConfiguration.get())); + + WKRetainPtr url = adoptWK(Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + + didFinishLoad = false; + Util::run(&didFinishLoad); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKPageCopySessionStateWithFiltering.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageCopySessionStateWithFiltering.cpp new file mode 100644 index 000000000..6ce49a13b --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageCopySessionStateWithFiltering.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" + +namespace TestWebKitAPI { + +static bool didFinishLoad; +static WKRetainPtr sessionStateWithFirstItemRemoved; +static WKRetainPtr sessionStateWithAllItemsRemoved; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +static void setPageLoaderClient(WKPageRef page) +{ + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + + WKPageSetPageLoaderClient(page, &loaderClient.base); +} + +static bool filterFirstItemCallback(WKPageRef page, WKStringRef valueType, WKTypeRef value, void* context) +{ + if (!WKStringIsEqual(valueType, WKPageGetSessionBackForwardListItemValueType())) + return true; + + ASSERT(WKGetTypeID(value) == WKBackForwardListItemGetTypeID()); + WKBackForwardListItemRef backForwardListItem = static_cast(value); + + WKRetainPtr url = adoptWK(WKBackForwardListItemCopyURL(backForwardListItem)); + WKRetainPtr path = adoptWK(WKURLCopyLastPathComponent(url.get())); + + return !WKStringIsEqualToUTF8CString(path.get(), "simple.html"); +} + +static bool filterAllItemsCallback(WKPageRef page, WKStringRef valueType, WKTypeRef value, void* context) +{ + return false; +} + +static void createSessionStates(WKContextRef context) +{ + PlatformWebView webView(context); + setPageLoaderClient(webView.page()); + + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); + Util::run(&didFinishLoad); + didFinishLoad = false; + + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple2", "html")).get()); + Util::run(&didFinishLoad); + didFinishLoad = false; + + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple3", "html")).get()); + Util::run(&didFinishLoad); + didFinishLoad = false; + + WKPageGoBack(webView.page()); + Util::run(&didFinishLoad); + didFinishLoad = false; + + WKPageGoBack(webView.page()); + Util::run(&didFinishLoad); + didFinishLoad = false; + + // Should be back on simple.html at this point. + + sessionStateWithFirstItemRemoved = adoptWK(static_cast(WKPageCopySessionState(webView.page(), reinterpret_cast(1), filterFirstItemCallback))); + sessionStateWithAllItemsRemoved = adoptWK(static_cast(WKPageCopySessionState(webView.page(), reinterpret_cast(1), filterAllItemsCallback))); +} + +TEST(WebKit2, WKPageCopySessionStateWithFiltering) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + + createSessionStates(context.get()); + + EXPECT_NOT_NULL(sessionStateWithFirstItemRemoved); + PlatformWebView webView1(context.get()); + setPageLoaderClient(webView1.page()); + WKPageRestoreFromSessionState(webView1.page(), sessionStateWithFirstItemRemoved.get()); + Util::run(&didFinishLoad); + didFinishLoad = false; + + WKBackForwardListRef backForwardList1 = WKPageGetBackForwardList(webView1.page()); + EXPECT_EQ(0u, WKBackForwardListGetBackListCount(backForwardList1)); + EXPECT_EQ(1u, WKBackForwardListGetForwardListCount(backForwardList1)); + + EXPECT_NOT_NULL(sessionStateWithAllItemsRemoved); + PlatformWebView webView2(context.get()); + setPageLoaderClient(webView2.page()); + WKPageRestoreFromSessionState(webView2.page(), sessionStateWithAllItemsRemoved.get()); + // Because the session state ends up being empty, nothing is actually loaded. + + WKBackForwardListRef backForwardList2 = WKPageGetBackForwardList(webView2.page()); + EXPECT_EQ(0u, WKBackForwardListGetBackListCount(backForwardList2)); + EXPECT_EQ(0u, WKBackForwardListGetForwardListCount(backForwardList2)); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp index 8ecf1659f..929baaa71 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" @@ -48,7 +51,7 @@ static void setPageLoaderClient(WKPageRef page) WKPageSetPageLoaderClient(page, &loaderClient.base); } -static WKRetainPtr createSessionState(WKContextRef context) +static WKRetainPtr createSessionState(WKContextRef context) { PlatformWebView webView(context); setPageLoaderClient(webView.page()); @@ -57,7 +60,7 @@ static WKRetainPtr createSessionState(WKContextRef context) Util::run(&didFinishLoad); didFinishLoad = false; - return adoptWK(WKPageCopySessionState(webView.page(), 0, 0)); + return adoptWK(static_cast(WKPageCopySessionState(webView.page(), reinterpret_cast(1), nullptr))); } TEST(WebKit2, WKPageGetScaleFactorNotZero) @@ -67,13 +70,15 @@ TEST(WebKit2, WKPageGetScaleFactorNotZero) PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); - WKRetainPtr data = createSessionState(context.get()); - EXPECT_NOT_NULL(data); + auto sessionState = createSessionState(context.get()); + EXPECT_NOT_NULL(sessionState); - WKPageRestoreFromSessionState(webView.page(), data.get()); + WKPageRestoreFromSessionState(webView.page(), sessionState.get()); Util::run(&didFinishLoad); EXPECT_TRUE(WKPageGetScaleFactor(webView.page()) == 1.0); } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKPageIsPlayingAudio.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageIsPlayingAudio.cpp new file mode 100644 index 000000000..1e848133f --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageIsPlayingAudio.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2014 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include +#include +#include +#include +#include +#include + +// This test loads file-with-video.html. It first checks to make sure WKPageIsPlayingAudio() returns +// false for the page. Then it calls a JavaScript method to play the video, waits for +// WKPageUIClient::isPlayingAudioDidChange() to get called, and checks that WKPageIsPlayingAudio() now +// returns true for the page. + +namespace TestWebKitAPI { + +static bool isMSEEnabledChanged; +static bool isMSEEnabled; +static bool didFinishLoad; +static bool isPlayingAudioChanged; + +static void nullJavaScriptCallback(WKSerializedScriptValueRef, WKErrorRef error, void*) +{ +} + +static void isMSEEnabledCallback(WKSerializedScriptValueRef serializedResultValue, WKErrorRef error, void*) +{ + JSGlobalContextRef scriptContext = JSGlobalContextCreate(0); + + JSValueRef resultValue = WKSerializedScriptValueDeserialize(serializedResultValue, scriptContext, 0); + EXPECT_TRUE(JSValueIsBoolean(scriptContext, resultValue)); + + isMSEEnabledChanged = true; + isMSEEnabled = JSValueToBoolean(scriptContext, resultValue); + + JSGlobalContextRelease(scriptContext); +} + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +static void isPlayingAudioDidChangeCallback(WKPageRef page, const void*) +{ + isPlayingAudioChanged = true; +} + +static void setUpClients(WKPageRef page) +{ + WKPageLoaderClientV0 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + + WKPageSetPageLoaderClient(page, &loaderClient.base); + + WKPageUIClientV5 uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + uiClient.base.version = 5; + uiClient.isPlayingAudioDidChange = isPlayingAudioDidChangeCallback; + + WKPageSetPageUIClient(page, &uiClient.base); +} + +TEST(WebKit2, WKPageIsPlayingAudio) +{ + WKRetainPtr context = adoptWK(WKContextCreate()); + + PlatformWebView webView(context.get()); + setUpClients(webView.page()); + + WKRetainPtr url = adoptWK(Util::createURLForResource("file-with-video", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&didFinishLoad); + + EXPECT_FALSE(WKPageIsPlayingAudio(webView.page())); + WKPageRunJavaScriptInMainFrame(webView.page(), Util::toWK("playVideo()").get(), 0, nullJavaScriptCallback); + + Util::run(&isPlayingAudioChanged); + EXPECT_TRUE(WKPageIsPlayingAudio(webView.page())); +} + +TEST(WebKit2, MSEIsPlayingAudio) +{ + WKRetainPtr context = adoptWK(WKContextCreate()); + + WKRetainPtr pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(Util::toWK("MSEIsPlayingAudioPageGroup").get())); + WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup.get()); + WKPreferencesSetMediaSourceEnabled(preferences, true); + WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true); + + PlatformWebView webView(context.get(), pageGroup.get()); + setUpClients(webView.page()); + + WKRetainPtr url = adoptWK(Util::createURLForResource("file-with-mse", "html")); + didFinishLoad = false; + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&didFinishLoad); + + // Bail out of the test early if the platform does not support MSE. + isMSEEnabledChanged = false; + WKPageRunJavaScriptInMainFrame(webView.page(), Util::toWK("window.MediaSource !== undefined").get(), 0, isMSEEnabledCallback); + Util::run(&isMSEEnabledChanged); + if (!isMSEEnabled) + return; + + EXPECT_FALSE(WKPageIsPlayingAudio(webView.page())); + isPlayingAudioChanged = false; + WKPageRunJavaScriptInMainFrame(webView.page(), Util::toWK("playVideo()").get(), 0, nullJavaScriptCallback); + + Util::run(&isPlayingAudioChanged); + EXPECT_TRUE(WKPageIsPlayingAudio(webView.page())); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp index 976e7041b..7f8616f5d 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp @@ -24,9 +24,12 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -41,15 +44,15 @@ TEST(WebKit2, WKPreferencesBasic) TEST(WebKit2, WKPreferencesDefaults) { -#if PLATFORM(WIN) - static const char* expectedStandardFontFamily = "Times New Roman"; +#if PLATFORM(GTK) || PLATFORM(EFL) + static const char* expectedStandardFontFamily = "Times"; static const char* expectedFixedFontFamily = "Courier New"; - static const char* expectedSerifFontFamily = "Times New Roman"; - static const char* expectedSansSerifFontFamily = "Arial"; + static const char* expectedSerifFontFamily = "Times"; + static const char* expectedSansSerifFontFamily = "Helvetica"; static const char* expectedCursiveFontFamily = "Comic Sans MS"; - static const char* expectedFantasyFontFamily = "Comic Sans MS"; - static const char* expectedPictographFontFamily = "Times New Roman"; -#elif PLATFORM(MAC) + static const char* expectedFantasyFontFamily = "Impact"; + static const char* expectedPictographFontFamily = "Times"; +#elif WK_HAVE_C_SPI static const char* expectedStandardFontFamily = "Times"; static const char* expectedFixedFontFamily = "Courier"; static const char* expectedSerifFontFamily = "Times"; @@ -57,21 +60,21 @@ TEST(WebKit2, WKPreferencesDefaults) static const char* expectedCursiveFontFamily = "Apple Chancery"; static const char* expectedFantasyFontFamily = "Papyrus"; static const char* expectedPictographFontFamily = "Apple Color Emoji"; -#elif PLATFORM(GTK) || PLATFORM(EFL) +#elif PLATFORM(IOS) static const char* expectedStandardFontFamily = "Times"; - static const char* expectedFixedFontFamily = "Courier New"; + static const char* expectedFixedFontFamily = "Courier"; static const char* expectedSerifFontFamily = "Times"; static const char* expectedSansSerifFontFamily = "Helvetica"; - static const char* expectedCursiveFontFamily = "Comic Sans MS"; - static const char* expectedFantasyFontFamily = "Impact"; - static const char* expectedPictographFontFamily = "Times"; + static const char* expectedCursiveFontFamily = "Snell Roundhand"; + static const char* expectedFantasyFontFamily = "Papyrus"; + static const char* expectedPictographFontFamily = "AppleColorEmoji"; #endif WKPreferencesRef preference = WKPreferencesCreate(); EXPECT_TRUE(WKPreferencesGetJavaScriptEnabled(preference)); EXPECT_TRUE(WKPreferencesGetLoadsImagesAutomatically(preference)); - EXPECT_FALSE(WKPreferencesGetOfflineWebApplicationCacheEnabled(preference)); + EXPECT_TRUE(WKPreferencesGetOfflineWebApplicationCacheEnabled(preference)); EXPECT_TRUE(WKPreferencesGetLocalStorageEnabled(preference)); EXPECT_TRUE(WKPreferencesGetXSSAuditorEnabled(preference)); EXPECT_FALSE(WKPreferencesGetFrameFlatteningEnabled(preference)); @@ -91,11 +94,7 @@ TEST(WebKit2, WKPreferencesDefaults) EXPECT_FALSE(WKPreferencesGetDeveloperExtrasEnabled(preference)); EXPECT_TRUE(WKPreferencesGetTextAreasAreResizable(preference)); -#if PLATFORM(WIN) - EXPECT_EQ(kWKFontSmoothingLevelWindows, WKPreferencesGetFontSmoothingLevel(preference)); -#else EXPECT_EQ(kWKFontSmoothingLevelMedium, WKPreferencesGetFontSmoothingLevel(preference)); -#endif EXPECT_TRUE(WKPreferencesGetAcceleratedCompositingEnabled(preference)); EXPECT_FALSE(WKPreferencesGetCompositingBordersVisible(preference)); @@ -122,3 +121,5 @@ TEST(WebKit2, WKPreferencesCopying) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKRetainPtr.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKRetainPtr.cpp new file mode 100644 index 000000000..860d7d48d --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKRetainPtr.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include + +namespace TestWebKitAPI { + +TEST(WebKit2, WKRetainPtr) +{ + WKRetainPtr string1 = adoptWK(WKStringCreateWithUTF8CString("a")); + WKRetainPtr string2 = adoptWK(WKStringCreateWithUTF8CString("a")); + WKRetainPtr string3 = adoptWK(WKStringCreateWithUTF8CString("a")); + WKRetainPtr string4 = adoptWK(WKStringCreateWithUTF8CString("a")); + + HashMap, int> map; + + map.set(string2, 2); + map.set(string1, 1); + + EXPECT_TRUE(map.contains(string1)); + EXPECT_TRUE(map.contains(string2)); + EXPECT_FALSE(map.contains(string3)); + EXPECT_FALSE(map.contains(string4)); + + EXPECT_EQ(1, map.get(string1)); + EXPECT_EQ(2, map.get(string2)); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp index b67235932..b4167be81 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp @@ -25,6 +25,8 @@ #include "config.h" +#if WK_HAVE_C_SPI + namespace TestWebKitAPI { TEST(WebKit2, WKString) @@ -69,3 +71,5 @@ TEST(WebKit2, WKString) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKStringJSString.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKStringJSString.cpp index cdba57de4..8b6e08b9d 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/WKStringJSString.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKStringJSString.cpp @@ -24,7 +24,10 @@ */ #include "config.h" -#include + +#if WK_HAVE_C_SPI + +#include #include namespace TestWebKitAPI { @@ -48,3 +51,5 @@ TEST(WebKit2, WKStringJSString) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp new file mode 100644 index 000000000..06d673e21 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include +#include +#include + +namespace TestWebKitAPI { + +static bool didFinishLoad; +static bool didReceiveMessage; + +static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*) +{ + didReceiveMessage = true; + + EXPECT_WK_STREQ("DidGetWebArchive", messageName); + EXPECT_TRUE(body); + EXPECT_EQ(WKDataGetTypeID(), WKGetTypeID(body)); + WKDataRef receivedData = static_cast(body); + + // Do basic sanity checks on the returned webarchive. We have more thorough checks in LayoutTests. + size_t size = WKDataGetSize(receivedData); + const unsigned char* bytes = WKDataGetBytes(receivedData); + RetainPtr data = adoptCF(CFDataCreate(0, bytes, size)); + RetainPtr propertyList = adoptCF(CFPropertyListCreateWithData(0, data.get(), kCFPropertyListImmutable, 0, 0)); + EXPECT_TRUE(propertyList); + + // It should be a dictionary. + EXPECT_EQ(CFDictionaryGetTypeID(), CFGetTypeID(propertyList.get())); + CFDictionaryRef dictionary = (CFDictionaryRef)propertyList.get(); + + // It should have a main resource. + CFTypeRef mainResource = CFDictionaryGetValue(dictionary, CFSTR("WebMainResource")); + EXPECT_TRUE(mainResource); + EXPECT_EQ(CFDictionaryGetTypeID(), CFGetTypeID(mainResource)); + CFDictionaryRef mainResourceDictionary = (CFDictionaryRef)mainResource; + + // Main resource should have a non-empty url and mime type. + CFTypeRef url = CFDictionaryGetValue(mainResourceDictionary, CFSTR("WebResourceURL")); + EXPECT_TRUE(url); + EXPECT_EQ(CFStringGetTypeID(), CFGetTypeID(url)); + EXPECT_NE(CFStringGetLength((CFStringRef)url), 0); + + CFTypeRef mimeType = CFDictionaryGetValue(mainResourceDictionary, CFSTR("WebResourceMIMEType")); + EXPECT_TRUE(mimeType); + EXPECT_EQ(CFStringGetTypeID(), CFGetTypeID(mimeType)); + EXPECT_NE(CFStringGetLength((CFStringRef)mimeType), 0); + + // Main resource dictionary should have a "WebResourceData" key. + CFTypeRef resourceData = CFDictionaryGetValue(mainResourceDictionary, CFSTR("WebResourceData")); + EXPECT_TRUE(resourceData); + EXPECT_EQ(CFDataGetTypeID(), CFGetTypeID(resourceData)); + + RetainPtr stringData = adoptCF(CFStringCreateFromExternalRepresentation(0, (CFDataRef)resourceData, kCFStringEncodingUTF8)); + EXPECT_TRUE(stringData); + + // It should contain the string "Simple HTML file." in it. + bool foundString = CFStringFind(stringData.get(), CFSTR("Simple HTML file."), 0).location != kCFNotFound; + EXPECT_TRUE(foundString); +} + +static void setInjectedBundleClient(WKContextRef context) +{ + WKContextInjectedBundleClientV0 injectedBundleClient; + memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); + + injectedBundleClient.base.version = 0; + injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; + + WKContextSetInjectedBundleClient(context, &injectedBundleClient.base); +} + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +TEST(WebKit2, WebArchive) +{ + WKRetainPtr context = adoptWK(Util::createContextForInjectedBundleTest("WebArchiveTest")); + setInjectedBundleClient(context.get()); + + PlatformWebView webView(context.get()); + + WKPageLoaderClientV3 loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.base.version = 3; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + + WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); + + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); + + // Wait till the load finishes before getting the web archive. + Util::run(&didFinishLoad); + WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("GetWebArchive").get(), webView.page()); + + // Wait till we have received the web archive from the injected bundle. + Util::run(&didReceiveMessage); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp new file mode 100644 index 000000000..11109fee0 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "InjectedBundleTest.h" + +#include "PlatformUtilities.h" +#include +#include + +namespace TestWebKitAPI { + +class WebArchiveTest : public InjectedBundleTest { +public: + WebArchiveTest(const std::string& identifier); + +private: + virtual void didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody); +}; + +static InjectedBundleTest::Register registrar("WebArchiveTest"); + +WebArchiveTest::WebArchiveTest(const std::string& identifier) + : InjectedBundleTest(identifier) +{ +} + +void WebArchiveTest::didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef body) +{ + if (!WKStringIsEqualToUTF8CString(messageName, "GetWebArchive")) + return; + + if (WKGetTypeID(body) != WKBundlePageGetTypeID()) + return; + + WKBundleFrameRef frame = WKBundlePageGetMainFrame(static_cast(body)); + if (!frame) + return; + WKBundlePostMessage(bundle, Util::toWK("DidGetWebArchive").get(), adoptWK(WKBundleFrameCopyWebArchive(frame)).get()); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WebCoreStatisticsWithNoWebProcess.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WebCoreStatisticsWithNoWebProcess.cpp new file mode 100644 index 000000000..ff5eef04d --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WebCoreStatisticsWithNoWebProcess.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2012 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if WK_HAVE_C_SPI + +#include "PlatformUtilities.h" +#include "Test.h" + +namespace TestWebKitAPI { + +static bool done; + +// Callback for WKContextGetStatistics. +static void wkContextGetStatisticsCallback(WKDictionaryRef statistics, WKErrorRef error, void* functionContext) +{ + EXPECT_NOT_NULL(error); + done = true; +} + +TEST(WebKit2, WebCoreStatisticsWithNoWebProcess) +{ + WKRetainPtr context = adoptWK(WKContextCreate()); + + WKContextGetStatistics(context.get(), 0, wkContextGetStatisticsCallback); + + Util::run(&done); +} + +} // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WillLoad.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WillLoad.cpp index 0f0bf4caf..83d63ab18 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/WillLoad.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WillLoad.cpp @@ -24,12 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "Test.h" #include "PlatformUtilities.h" #include "PlatformWebView.h" -#include -#include namespace TestWebKitAPI { @@ -41,7 +42,7 @@ public: } WKRetainPtr context; - OwnPtr webView; + std::unique_ptr webView; WKRetainPtr messageName; WKRetainPtr messageBody; @@ -71,7 +72,7 @@ public: context = adoptWK(Util::createContextForInjectedBundleTest("WillLoadTest")); setInjectedBundleClient(context.get(), this); - webView = adoptPtr(new PlatformWebView(context.get())); + webView = std::make_unique(context.get()); didReceiveMessage = false; } @@ -239,3 +240,5 @@ TEST_F(WebKit2WillLoadTest, WKPageLoadPlainTextString) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WillLoad_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WillLoad_Bundle.cpp index 783aebe7a..906ff05b7 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/WillLoad_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WillLoad_Bundle.cpp @@ -24,11 +24,14 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include -#include +#include +#include namespace TestWebKitAPI { @@ -47,7 +50,7 @@ private: WKDictionarySetItem(messageBody.get(), Util::toWK("URLRequestReturn").get(), request); WKDictionarySetItem(messageBody.get(), Util::toWK("UserDataReturn").get(), userData); - WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WillLoadURLRequestReturn").get(), messageBody.get()); + WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("WillLoadURLRequestReturn").get(), messageBody.get()); } static void willLoadDataRequest(WKBundlePageRef page, WKURLRequestRef request, WKDataRef data, WKStringRef MIMEType, WKStringRef encodingName, WKURLRef unreachableURL, WKTypeRef userData, const void *clientInfo) @@ -61,11 +64,11 @@ private: WKDictionarySetItem(messageBody.get(), Util::toWK("UnreachableURLReturn").get(), unreachableURL); WKDictionarySetItem(messageBody.get(), Util::toWK("UserDataReturn").get(), userData); - WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WillLoadDataRequestReturn").get(), messageBody.get()); + WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("WillLoadDataRequestReturn").get(), messageBody.get()); } - virtual void didCreatePage(WKBundleRef, WKBundlePageRef bundlePage) override + void didCreatePage(WKBundleRef, WKBundlePageRef bundlePage) override { WKBundlePageLoaderClientV6 pageLoaderClient; memset(&pageLoaderClient, 0, sizeof(pageLoaderClient)); @@ -82,3 +85,5 @@ private: static InjectedBundleTest::Register registrar("WillLoadTest"); } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent.cpp index ee5934688..951aaf005 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent.cpp @@ -24,6 +24,9 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" @@ -77,3 +80,5 @@ TEST(WebKit2, WillSendSubmitEvent) } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp index e85ca256f..fa7d2a9a7 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp @@ -24,10 +24,13 @@ */ #include "config.h" + +#if WK_HAVE_C_SPI + #include "InjectedBundleTest.h" #include "PlatformUtilities.h" -#include +#include namespace TestWebKitAPI { @@ -42,7 +45,7 @@ static InjectedBundleTest::Register registrar("WillSend static void willSendSubmitEvent(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef, WKBundleFrameRef, WKDictionaryRef values, const void*) { - WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("DidReceiveWillSendSubmitEvent").get(), values); + WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("DidReceiveWillSendSubmitEvent").get(), values); } WillSendSubmitEventTest::WillSendSubmitEventTest(const std::string& identifier) @@ -63,3 +66,5 @@ void WillSendSubmitEventTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef } } // namespace TestWebKitAPI + +#endif diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/all-content-in-one-iframe.html b/Tools/TestWebKitAPI/Tests/WebKit2/all-content-in-one-iframe.html new file mode 100644 index 000000000..6f45cbd6b --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/all-content-in-one-iframe.html @@ -0,0 +1 @@ + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/associate-form-controls.html b/Tools/TestWebKitAPI/Tests/WebKit2/associate-form-controls.html new file mode 100644 index 000000000..906246a54 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/associate-form-controls.html @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/auto-submitting-form.html b/Tools/TestWebKitAPI/Tests/WebKit2/auto-submitting-form.html new file mode 100644 index 000000000..9ed815e03 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/auto-submitting-form.html @@ -0,0 +1,20 @@ + + + + + +
+ + + + +
+ + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-frame.html b/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-frame.html new file mode 100644 index 000000000..2c43fda1a --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-frame.html @@ -0,0 +1,16 @@ + + + + + +