From f05b935882198ccf7d81675736e3aeb089c5113a Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Thu, 5 May 2011 14:36:32 +0100 Subject: Merge WebKit at r74534: Initial merge by git. Change-Id: I6ccd1154fa1b19c2ec2a66878eb675738735f1eb --- Tools/TestWebKitAPI/Tests/WTF/VectorBasic.cpp | 40 ++++++ .../WebKit2/DocumentStartUserScriptAlertCrash.cpp | 66 ++++++++++ .../DocumentStartUserScriptAlertCrash_Bundle.cpp | 58 +++++++++ .../Tests/WebKit2/EvaluateJavaScript.cpp | 60 +++++++++ Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp | 68 ++++++++++ Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp | 81 ++++++++++++ .../Tests/WebKit2/FrameMIMETypeHTML.cpp | 78 +++++++++++ .../Tests/WebKit2/FrameMIMETypePNG.cpp | 78 +++++++++++ .../Tests/WebKit2/InjectedBundleBasic.cpp | 79 +++++++++++ .../Tests/WebKit2/InjectedBundleBasic_Bundle.cpp | 49 +++++++ .../TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp | 144 +++++++++++++++++++++ ...PageLoadDidChangeLocationWithinPageForFrame.cpp | 85 ++++++++++++ .../Tests/WebKit2/PreventEmptyUserAgent.cpp | 60 +++++++++ .../Tests/WebKit2/SpacebarScrolling.cpp | 132 +++++++++++++++++++ .../TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp | 100 ++++++++++++++ Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp | 52 ++++++++ .../Tests/WebKit2/WKStringJSString.cpp | 52 ++++++++ .../Tests/WebKit2/file-with-anchor.html | 19 +++ Tools/TestWebKitAPI/Tests/WebKit2/find.html | 5 + Tools/TestWebKitAPI/Tests/WebKit2/icon.png | Bin 0 -> 36541 bytes Tools/TestWebKitAPI/Tests/WebKit2/simple.html | 5 + .../Tests/WebKit2/spacebar-scrolling.html | 26 ++++ .../WebKit2/win/AltKeyGeneratesWMSysCommand.cpp | 86 ++++++++++++ .../WebKit2/win/WMCloseCallsUIClientClose.cpp | 57 ++++++++ 24 files changed, 1480 insertions(+) create mode 100644 Tools/TestWebKitAPI/Tests/WTF/VectorBasic.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypeHTML.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypePNG.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic_Bundle.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/PageLoadDidChangeLocationWithinPageForFrame.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/WKStringJSString.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/file-with-anchor.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/find.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/icon.png create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/simple.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/spacebar-scrolling.html create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/win/AltKeyGeneratesWMSysCommand.cpp create mode 100644 Tools/TestWebKitAPI/Tests/WebKit2/win/WMCloseCallsUIClientClose.cpp (limited to 'Tools/TestWebKitAPI/Tests') diff --git a/Tools/TestWebKitAPI/Tests/WTF/VectorBasic.cpp b/Tools/TestWebKitAPI/Tests/WTF/VectorBasic.cpp new file mode 100644 index 0000000..012fa27 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WTF/VectorBasic.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include + +namespace TestWebKitAPI { + +TEST(WTF, VectorBasic) +{ + Vector intVector; + TEST_ASSERT(intVector.isEmpty()); + TEST_ASSERT(intVector.size() == 0); + TEST_ASSERT(intVector.capacity() == 0); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp new file mode 100644 index 0000000..fdda8c7 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +static bool done; + +static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo) +{ + TEST_ASSERT(frame); + TEST_ASSERT(WKFrameGetPage(frame) == page); + TEST_ASSERT(WKStringIsEqualToUTF8CString(alertText, "an alert")); + + done = true; +} + +TEST(WebKit2, DocumentStartUserScriptAlertCrashTest) +{ + WKRetainPtr pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DocumentStartUserScriptAlertCrashTestPageGroup"))); + + WKRetainPtr context(AdoptWK, Util::createContextForInjectedBundleTest("DocumentStartUserScriptAlertCrashTest", pageGroup.get())); + PlatformWebView webView(context.get(), pageGroup.get()); + + WKPageUIClient uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + uiClient.version = 0; + uiClient.clientInfo = 0; + uiClient.runJavaScriptAlert = runJavaScriptAlert; + WKPageSetPageUIClient(webView.page(), &uiClient); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&done); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp new file mode 100644 index 0000000..dbd5d21 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2010 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 "InjectedBundleTest.h" +#include +#include +#include +#include +#include +#include + +namespace TestWebKitAPI { + +class DocumentStartUserScriptAlertCrashTest : public InjectedBundleTest { +public: + DocumentStartUserScriptAlertCrashTest(const std::string& identifier) + : InjectedBundleTest(identifier) + { + } + + virtual void initialize(WKBundleRef bundle, WKTypeRef userData) + { + assert(WKGetTypeID(userData) == WKBundlePageGroupGetTypeID()); + WKBundlePageGroupRef pageGroup = static_cast(userData); + + WKRetainPtr source(AdoptWK, WKStringCreateWithUTF8CString("alert('an alert');")); + WKBundleAddUserScript(bundle, pageGroup, WKBundleScriptWorldNormalWorld(), source.get(), 0, 0, 0, kWKInjectAtDocumentStart, kWKInjectInAllFrames); + } + +private: + WKBundlePageGroupRef m_pageGroup; +}; + +static InjectedBundleTest::Register registrar("DocumentStartUserScriptAlertCrashTest"); + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp new file mode 100644 index 0000000..32bd563 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +static bool testDone; + +static void didRunJavaScript(WKStringRef resultString, WKErrorRef error, void* context) +{ + TEST_ASSERT(context == reinterpret_cast(0x1234578)); + TEST_ASSERT(WKStringIsEmpty(resultString)); + + // FIXME: We should also check the error, but right now it's always null. + // Assert that it's null so we can revisit when this changes. + TEST_ASSERT(!error); + + testDone = true; +} + +TEST(WebKit2, EvaluateJavaScriptThatThrowsAnException) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKRetainPtr javaScriptString(AdoptWK, WKStringCreateWithUTF8CString("throw 'Hello'")); + WKPageRunJavaScriptInMainFrame(webView.page(), javaScriptString.get(), reinterpret_cast(0x1234578), didRunJavaScript); + + Util::run(&testDone); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp new file mode 100644 index 0000000..fdb3693 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/FailedLoad.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +// FIXME: This should also test the that the load state after didFailLoadWithErrorForFrame is kWKFrameLoadStateFinished + +static bool testDone; + +static void didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo) +{ + TEST_ASSERT(WKFrameGetFrameLoadState(frame) == kWKFrameLoadStateFinished); + + WKURLRef url = WKFrameCopyProvisionalURL(frame); + TEST_ASSERT(!url); + + testDone = true; +} + +TEST(WebKit2, FailedLoad) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClient loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.version = 0; + loaderClient.clientInfo = 0; + loaderClient.didFailProvisionalLoadWithErrorForFrame = didFailProvisionalLoadWithErrorForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient); + + WKRetainPtr url(AdoptWK, Util::URLForNonExistentResource()); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&testDone); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp new file mode 100644 index 0000000..f22c44d --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/Find.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +static bool didFinishLoad = false; +static bool didCallCountStringMatches = false; + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + didFinishLoad = true; +} + +static void didCountStringMatches(WKPageRef page, WKStringRef string, unsigned numMatches, const void* clientInfo) +{ + TEST_ASSERT(WKStringIsEqualToUTF8CString(string, "Hello")); + TEST_ASSERT(numMatches == 3); + + didCallCountStringMatches = true; +} + +TEST(WebKit2, Find) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClient loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient); + + WKPageFindClient findClient; + memset(&findClient, 0, sizeof(findClient)); + + findClient.version = 0; + findClient.didCountStringMatches = didCountStringMatches; + WKPageSetPageFindClient(webView.page(), &findClient); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("find", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&didFinishLoad); + + WKRetainPtr findString(AdoptWK, WKStringCreateWithUTF8CString("Hello")); + WKPageCountStringMatches(webView.page(), findString.get(), true, 100); + + Util::run(&didCallCountStringMatches); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypeHTML.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypeHTML.cpp new file mode 100644 index 0000000..1188bb2 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypeHTML.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +static bool testDone; + +static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + WKRetainPtr wkMIME(AdoptWK, WKFrameCopyMIMEType(frame)); + TEST_ASSERT(WKStringIsEmpty(wkMIME.get())); +} + +static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + WKRetainPtr wkMIME(AdoptWK, WKFrameCopyMIMEType(frame)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(wkMIME.get(), "text/html")); +} + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + WKRetainPtr wkMIME(AdoptWK, WKFrameCopyMIMEType(frame)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(wkMIME.get(), "text/html")); + + testDone = true; +} + +TEST(WebKit2, FrameMIMETypeHTML) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClient loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.version = 0; + loaderClient.clientInfo = 0; + loaderClient.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFrame; + loaderClient.didCommitLoadForFrame = didCommitLoadForFrame; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&testDone); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypePNG.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypePNG.cpp new file mode 100644 index 0000000..1b56bae --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/FrameMIMETypePNG.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +static bool testDone; + +static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + WKRetainPtr wkMIME(AdoptWK, WKFrameCopyMIMEType(frame)); + TEST_ASSERT(WKStringIsEmpty(wkMIME.get())); +} + +static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + WKRetainPtr wkMIME(AdoptWK, WKFrameCopyMIMEType(frame)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(wkMIME.get(), "image/png")); +} + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + WKRetainPtr wkMIME(AdoptWK, WKFrameCopyMIMEType(frame)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(wkMIME.get(), "image/png")); + + testDone = true; +} + +TEST(WebKit2, FrameMIMETypePNG) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClient loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.version = 0; + loaderClient.clientInfo = 0; + loaderClient.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFrame; + loaderClient.didCommitLoadForFrame = didCommitLoadForFrame; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("icon", "png")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&testDone); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp new file mode 100644 index 0000000..f28971d --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +static bool done; +static bool loadDone; +static bool messageReceived; + +void didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo) +{ + messageReceived = true; + if (loadDone) + done = true; +} + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + loadDone = true; + if (messageReceived) + done = true; +} + +TEST(WebKit2, InjectedBundleBasic) +{ + WKRetainPtr context(AdoptWK, Util::createContextForInjectedBundleTest("InjectedBundleBasicTest")); + + WKContextInjectedBundleClient injectedBundleClient; + memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); + injectedBundleClient.version = 0; + injectedBundleClient.clientInfo = 0; + injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; + WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient); + + PlatformWebView webView(context.get()); + + WKPageLoaderClient loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + loaderClient.version = 0; + loaderClient.clientInfo = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&done); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic_Bundle.cpp new file mode 100644 index 0000000..67c062b --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic_Bundle.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2010 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 "InjectedBundleTest.h" +#include +#include + +namespace TestWebKitAPI { + +class InjectedBundleBasicTest : public InjectedBundleTest { +public: + InjectedBundleBasicTest(const std::string& identifier) + : InjectedBundleTest(identifier) + { + } + + virtual void didCreatePage(WKBundleRef bundle, WKBundlePageRef page) + { + WKRetainPtr doneMessageName(AdoptWK, WKStringCreateWithUTF8CString("DoneMessageName")); + WKRetainPtr doneMessageBody(AdoptWK, WKStringCreateWithUTF8CString("DoneMessageBody")); + WKBundlePostMessage(bundle, doneMessageName.get(), doneMessageBody.get()); + } +}; + +static InjectedBundleTest::Register registrar("InjectedBundleBasicTest"); + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp new file mode 100644 index 0000000..98a636c --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +static bool test1Done; + +struct State { + State() + : didDecidePolicyForNavigationAction(false) + , didStartProvisionalLoadForFrame(false) + , didCommitLoadForFrame(false) + { + } + + bool didDecidePolicyForNavigationAction; + bool didStartProvisionalLoadForFrame; + bool didCommitLoadForFrame; +}; + +static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + State* state = reinterpret_cast(const_cast(clientInfo)); + TEST_ASSERT(state->didDecidePolicyForNavigationAction); + TEST_ASSERT(!state->didCommitLoadForFrame); + + // The commited URL should be null. + TEST_ASSERT(!WKFrameCopyURL(frame)); + + TEST_ASSERT(!state->didStartProvisionalLoadForFrame); + + + state->didStartProvisionalLoadForFrame = true; +} + +static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + State* state = reinterpret_cast(const_cast(clientInfo)); + TEST_ASSERT(state->didDecidePolicyForNavigationAction); + TEST_ASSERT(state->didStartProvisionalLoadForFrame); + + // The provisional URL should be null. + TEST_ASSERT(!WKFrameCopyProvisionalURL(frame)); + + state->didCommitLoadForFrame = true; +} + +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + State* state = reinterpret_cast(const_cast(clientInfo)); + TEST_ASSERT(state->didDecidePolicyForNavigationAction); + TEST_ASSERT(state->didStartProvisionalLoadForFrame); + TEST_ASSERT(state->didCommitLoadForFrame); + + // The provisional URL should be null. + TEST_ASSERT(!WKFrameCopyProvisionalURL(frame)); + + test1Done = true; +} + +static void decidePolicyForNavigationAction(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void* clientInfo) +{ + State* state = reinterpret_cast(const_cast(clientInfo)); + TEST_ASSERT(!state->didStartProvisionalLoadForFrame); + TEST_ASSERT(!state->didCommitLoadForFrame); + + state->didDecidePolicyForNavigationAction = true; + + WKFramePolicyListenerUse(listener); +} + +static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void* clientInfo) +{ + WKFramePolicyListenerUse(listener); +} + +static void decidePolicyForMIMEType(WKPageRef page, WKStringRef MIMEType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void* clientInfo) +{ + WKFramePolicyListenerUse(listener); +} + +TEST(WebKit2, PageLoadBasic) +{ + State state; + + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClient loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.version = 0; + loaderClient.clientInfo = &state; + loaderClient.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFrame; + loaderClient.didCommitLoadForFrame = didCommitLoadForFrame; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient); + + WKPagePolicyClient policyClient; + memset(&policyClient, 0, sizeof(policyClient)); + + policyClient.version = 0; + policyClient.clientInfo = &state; + policyClient.decidePolicyForNavigationAction = decidePolicyForNavigationAction; + policyClient.decidePolicyForNewWindowAction = decidePolicyForNewWindowAction; + policyClient.decidePolicyForMIMEType = decidePolicyForMIMEType; + WKPageSetPagePolicyClient(webView.page(), &policyClient); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url.get()); + + Util::run(&test1Done); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadDidChangeLocationWithinPageForFrame.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadDidChangeLocationWithinPageForFrame.cpp new file mode 100644 index 0000000..3cbe113 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadDidChangeLocationWithinPageForFrame.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +static void nullJavaScriptCallback(WKStringRef, WKErrorRef error, void*) +{ +} + +static bool didFinishLoad; +static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +static bool didPopStateWithinPage; +static bool didChangeLocationWithinPage; +static void didSameDocumentNavigationForFrame(WKPageRef, WKFrameRef, WKSameDocumentNavigationType type, WKTypeRef, const void*) +{ + if (!didPopStateWithinPage) { + TEST_ASSERT(type == kWKSameDocumentNavigationSessionStatePop); + TEST_ASSERT(!didChangeLocationWithinPage); + didPopStateWithinPage = true; + return; + } + + TEST_ASSERT(type == kWKSameDocumentNavigationAnchorNavigation); + didChangeLocationWithinPage = true; +} + +TEST(WebKit2, PageLoadDidChangeLocationWithinPageForFrame) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClient loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + loaderClient.didSameDocumentNavigationForFrame = didSameDocumentNavigationForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("file-with-anchor", "html")); + WKPageLoadURL(webView.page(), url.get()); + Util::run(&didFinishLoad); + + WKRetainPtr initialURL = Util::adoptWK(WKFrameCopyURL(WKPageGetMainFrame(webView.page()))); + + WKPageRunJavaScriptInMainFrame(webView.page(), Util::toWK("clickLink()").get(), 0, nullJavaScriptCallback); + Util::run(&didChangeLocationWithinPage); + + WKRetainPtr urlAfterAnchorClick = Util::adoptWK(WKFrameCopyURL(WKPageGetMainFrame(webView.page()))); + + TEST_ASSERT(!WKURLIsEqual(initialURL.get(), urlAfterAnchorClick.get())); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp new file mode 100644 index 0000000..306174a --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include +#include + +namespace TestWebKitAPI { + +static bool testDone; + +static void didRunJavaScript(WKStringRef resultString, WKErrorRef error, void* context) +{ + TEST_ASSERT(context == reinterpret_cast(0x1234578)); + + // Make sure that the result of navigator.userAgent isn't empty, even if we set the custom + // user agent to the empty string. + TEST_ASSERT(!WKStringIsEmpty(resultString)); + + testDone = true; +} + +TEST(WebKit2, PreventEmptyUserAgent) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageSetCustomUserAgent(webView.page(), WKStringCreateWithUTF8CString("")); + WKRetainPtr javaScriptString(AdoptWK, WKStringCreateWithUTF8CString("navigator.userAgent")); + WKPageRunJavaScriptInMainFrame(webView.page(), javaScriptString.get(), reinterpret_cast(0x1234578), didRunJavaScript); + + Util::run(&testDone); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp new file mode 100644 index 0000000..6d4783c --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include + +namespace TestWebKitAPI { + +struct JavaScriptCallbackContext { + JavaScriptCallbackContext(const char* expectedString) : didFinish(false), expectedString(expectedString), didMatchExpectedString(false) { } + + bool didFinish; + const char* expectedString; + bool didMatchExpectedString; +}; + +static bool didFinishLoad; +static bool didNotHandleKeyDownEvent; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) +{ + didFinishLoad = true; +} + +static void didNotHandleKeyEventCallback(WKPageRef, WKNativeEventPtr event, const void*) +{ + if (Util::isKeyDown(event)) + didNotHandleKeyDownEvent = true; +} + +static void javaScriptCallback(WKStringRef string, WKErrorRef error, void* ctx) +{ + JavaScriptCallbackContext* context = static_cast(ctx); + + context->didFinish = true; + context->didMatchExpectedString = WKStringIsEqualToUTF8CString(string, context->expectedString); + + TEST_ASSERT(!error); +} + +static WKRetainPtr wk(const char* utf8String) +{ + return WKRetainPtr(AdoptWK, WKStringCreateWithUTF8CString(utf8String)); +} + +static bool runJSTest(WKPageRef page, const char* script, const char* expectedResult) +{ + JavaScriptCallbackContext context(expectedResult); + WKPageRunJavaScriptInMainFrame(page, wk(script).get(), &context, javaScriptCallback); + Util::run(&context.didFinish); + return context.didMatchExpectedString; +} + +TEST(WebKit2, SpacebarScrolling) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageLoaderClient loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + + loaderClient.version = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + WKPageSetPageLoaderClient(webView.page(), &loaderClient); + + WKPageUIClient uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + uiClient.didNotHandleKeyEvent = didNotHandleKeyEventCallback; + WKPageSetPageUIClient(webView.page(), &uiClient); + + WKRetainPtr url(AdoptWK, Util::createURLForResource("spacebar-scrolling", "html")); + WKPageLoadURL(webView.page(), url.get()); + Util::run(&didFinishLoad); + + TEST_ASSERT(runJSTest(webView.page(), "isDocumentScrolled()", "false")); + TEST_ASSERT(runJSTest(webView.page(), "textFieldContainsSpace()", "false")); + + webView.simulateSpacebarKeyPress(); + + TEST_ASSERT(runJSTest(webView.page(), "isDocumentScrolled()", "false")); + TEST_ASSERT(runJSTest(webView.page(), "textFieldContainsSpace()", "true")); + + // 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) + TEST_ASSERT(!didNotHandleKeyDownEvent); +#elif PLATFORM(WIN) + TEST_ASSERT(didNotHandleKeyDownEvent); +#endif + + TEST_ASSERT(runJSTest(webView.page(), "blurTextField()", "undefined")); + + didNotHandleKeyDownEvent = false; + webView.simulateSpacebarKeyPress(); + + TEST_ASSERT(runJSTest(webView.page(), "isDocumentScrolled()", "true")); + TEST_ASSERT(runJSTest(webView.page(), "textFieldContainsSpace()", "true")); +#if PLATFORM(MAC) + TEST_ASSERT(!didNotHandleKeyDownEvent); +#elif PLATFORM(WIN) + TEST_ASSERT(didNotHandleKeyDownEvent); +#endif +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp new file mode 100644 index 0000000..f27131c --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include +#include +#include +#include +#include + +namespace TestWebKitAPI { + +TEST(WebKit2, WKPreferencesBasic) +{ + WKPreferencesRef preference = WKPreferencesCreate(); + + TEST_ASSERT(WKGetTypeID(preference) == WKPreferencesGetTypeID()); + + WKRelease(preference); +} + +TEST(WebKit2, WKPreferencesDefaults) +{ +#if PLATFORM(WIN) + static const char* expectedStandardFontFamily = "Times New Roman"; + static const char* expectedFixedFontFamily = "Courier New"; + static const char* expectedSerifFontFamily = "Times New Roman"; + static const char* expectedSansSerifFontFamily = "Arial"; + static const char* expectedCursiveFontFamily = "Comic Sans MS"; + static const char* expectedFantasyFontFamily = "Comic Sans MS"; +#elif PLATFORM(MAC) + static const char* expectedStandardFontFamily = "Times"; + static const char* expectedFixedFontFamily = "Courier"; + static const char* expectedSerifFontFamily = "Times"; + static const char* expectedSansSerifFontFamily = "Helvetica"; + static const char* expectedCursiveFontFamily = "Apple Chancery"; + static const char* expectedFantasyFontFamily = "Papyrus"; +#endif + + WKPreferencesRef preference = WKPreferencesCreate(); + + TEST_ASSERT(WKPreferencesGetJavaScriptEnabled(preference) == true); + TEST_ASSERT(WKPreferencesGetLoadsImagesAutomatically(preference) == true); + TEST_ASSERT(WKPreferencesGetOfflineWebApplicationCacheEnabled(preference) == false); + TEST_ASSERT(WKPreferencesGetLocalStorageEnabled(preference) == true); + TEST_ASSERT(WKPreferencesGetXSSAuditorEnabled(preference) == true); + TEST_ASSERT(WKPreferencesGetFrameFlatteningEnabled(preference) == false); + TEST_ASSERT(WKPreferencesGetPluginsEnabled(preference) == true); + TEST_ASSERT(WKPreferencesGetJavaEnabled(preference) == true); + TEST_ASSERT(WKPreferencesGetJavaScriptCanOpenWindowsAutomatically(preference) == true); + TEST_ASSERT(WKPreferencesGetHyperlinkAuditingEnabled(preference) == true); + WKRetainPtr standardFontFamily(AdoptWK, WKPreferencesCopyStandardFontFamily(preference)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(standardFontFamily.get(), expectedStandardFontFamily)); + WKRetainPtr fixedFontFamily(AdoptWK, WKPreferencesCopyFixedFontFamily(preference)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(fixedFontFamily.get(), expectedFixedFontFamily)); + WKRetainPtr serifFontFamily(AdoptWK, WKPreferencesCopySerifFontFamily(preference)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(serifFontFamily.get(), expectedSerifFontFamily)); + WKRetainPtr sansSerifFontFamily(AdoptWK, WKPreferencesCopySansSerifFontFamily(preference)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(sansSerifFontFamily.get(), expectedSansSerifFontFamily)); + WKRetainPtr cursiveFontFamily(AdoptWK, WKPreferencesCopyCursiveFontFamily(preference)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(cursiveFontFamily.get(), expectedCursiveFontFamily)); + WKRetainPtr fantasyFontFamily(AdoptWK, WKPreferencesCopyFantasyFontFamily(preference)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(fantasyFontFamily.get(), expectedFantasyFontFamily)); + TEST_ASSERT(WKPreferencesGetMinimumFontSize(preference) == 0); + TEST_ASSERT(WKPreferencesGetPrivateBrowsingEnabled(preference) == false); + TEST_ASSERT(WKPreferencesGetDeveloperExtrasEnabled(preference) == false); + TEST_ASSERT(WKPreferencesGetTextAreasAreResizable(preference) == true); + TEST_ASSERT(WKPreferencesGetFontSmoothingLevel(preference) == kWKFontSmoothingLevelMedium); + TEST_ASSERT(WKPreferencesGetAcceleratedCompositingEnabled(preference) == true); + TEST_ASSERT(WKPreferencesGetCompositingBordersVisible(preference) == false); + TEST_ASSERT(WKPreferencesGetCompositingRepaintCountersVisible(preference) == false); + TEST_ASSERT(WKPreferencesGetNeedsSiteSpecificQuirks(preference) == false); + + WKRelease(preference); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp new file mode 100644 index 0000000..b0b133d --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKString.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include + +namespace TestWebKitAPI { + +TEST(WebKit2, WKString) +{ + WKStringRef string = WKStringCreateWithUTF8CString("hello"); + TEST_ASSERT(!WKStringIsEmpty(string)); + TEST_ASSERT(WKStringIsEqual(string, string)); + TEST_ASSERT(WKStringIsEqualToUTF8CString(string, "hello")); + TEST_ASSERT(WKStringGetMaximumUTF8CStringSize(string) == 16); + + size_t maxSize = WKStringGetMaximumUTF8CStringSize(string); + char* buffer = new char[maxSize]; + + size_t actualSize = WKStringGetUTF8CString(string, buffer, maxSize); + TEST_ASSERT(actualSize == 6); + TEST_ASSERT(strcmp(buffer, "hello") == 0); + + delete[] buffer; + + WKRelease(string); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKStringJSString.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKStringJSString.cpp new file mode 100644 index 0000000..0d6eca3 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKStringJSString.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include +#include +#include + +namespace TestWebKitAPI { + +TEST(WebKit2, WKStringJSString) +{ + WKStringRef wkString = WKStringCreateWithUTF8CString("hello"); + JSStringRef jsString = JSStringCreateWithUTF8CString("hello"); + + WKStringRef convertedJSString = WKStringCreateWithJSString(jsString); + TEST_ASSERT(WKStringIsEqual(wkString, convertedJSString)); + + JSStringRef convertedWKString = WKStringCopyJSString(wkString); + TEST_ASSERT(JSStringIsEqual(jsString, convertedWKString)); + + WKRelease(wkString); + WKRelease(convertedJSString); + + JSStringRelease(jsString); + JSStringRelease(convertedWKString); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/file-with-anchor.html b/Tools/TestWebKitAPI/Tests/WebKit2/file-with-anchor.html new file mode 100644 index 0000000..8ea866b --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/file-with-anchor.html @@ -0,0 +1,19 @@ + + + + + + Link to anchor
+ In between.
+ Anchor
+ After the anchor.
+ + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/find.html b/Tools/TestWebKitAPI/Tests/WebKit2/find.html new file mode 100644 index 0000000..d965911 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/find.html @@ -0,0 +1,5 @@ + + + Test search. Hello Hello Hello! + + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/icon.png b/Tools/TestWebKitAPI/Tests/WebKit2/icon.png new file mode 100644 index 0000000..79e4598 Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/WebKit2/icon.png differ diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/simple.html b/Tools/TestWebKitAPI/Tests/WebKit2/simple.html new file mode 100644 index 0000000..12cf873 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/simple.html @@ -0,0 +1,5 @@ + + + Simple HTML file. + + diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/spacebar-scrolling.html b/Tools/TestWebKitAPI/Tests/WebKit2/spacebar-scrolling.html new file mode 100644 index 0000000..8da08b3 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/spacebar-scrolling.html @@ -0,0 +1,26 @@ + + + +
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/win/AltKeyGeneratesWMSysCommand.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/win/AltKeyGeneratesWMSysCommand.cpp new file mode 100644 index 0000000..1bca89b --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/win/AltKeyGeneratesWMSysCommand.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "WindowMessageObserver.h" +#include + +namespace TestWebKitAPI { + +class WMSysCommandObserver : public WindowMessageObserver { +public: + WMSysCommandObserver() : m_windowDidReceiveWMSysCommand(false) { } + + bool windowDidReceiveWMSysCommand() const { return m_windowDidReceiveWMSysCommand; } + +private: + virtual void windowReceivedMessage(HWND, UINT message, WPARAM, LPARAM) + { + if (message == WM_SYSCOMMAND) + m_windowDidReceiveWMSysCommand = true; + } + + bool m_windowDidReceiveWMSysCommand; +}; + +static bool didNotHandleWMSysKeyUp; + +static void didNotHandleKeyEventCallback(WKPageRef, WKNativeEventPtr event, const void*) +{ + if (event->message != WM_SYSKEYUP) + return; + + didNotHandleWMSysKeyUp = true; +} + +TEST(WebKit2, AltKeyGeneratesWMSysCommand) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageUIClient uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + uiClient.didNotHandleKeyEvent = didNotHandleKeyEventCallback; + WKPageSetPageUIClient(webView.page(), &uiClient); + + WMSysCommandObserver observer; + webView.setParentWindowMessageObserver(&observer); + + webView.simulateAltKeyPress(); + + Util::run(&didNotHandleWMSysKeyUp); + + webView.setParentWindowMessageObserver(0); + + // The WM_SYSKEYUP message should have generated a WM_SYSCOMMAND message that was sent to the + // WKView's parent window. + TEST_ASSERT(observer.windowDidReceiveWMSysCommand()); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/win/WMCloseCallsUIClientClose.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/win/WMCloseCallsUIClientClose.cpp new file mode 100644 index 0000000..56e619e --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/win/WMCloseCallsUIClientClose.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2010 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 "Test.h" + +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include + +namespace TestWebKitAPI { + +static bool didReceiveClose; + +static void close(WKPageRef, const void*) +{ + didReceiveClose = true; +} + +TEST(WebKit2, WMCloseCallsUIClientClose) +{ + WKRetainPtr context(AdoptWK, WKContextCreate()); + PlatformWebView webView(context.get()); + + WKPageUIClient uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + + uiClient.close = close; + WKPageSetPageUIClient(webView.page(), &uiClient); + + ::SendMessageW(WKViewGetWindow(webView.platformView()), WM_CLOSE, 0, 0); + + Util::run(&didReceiveClose); +} + +} // namespace TestWebKitAPI -- cgit v1.1