From e14391e94c850b8bd03680c23b38978db68687a8 Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 4 Nov 2010 12:00:17 -0700 Subject: Merge Webkit at r70949: Initial merge by git. Change-Id: I77b8645c083b5d0da8dba73ed01d4014aab9848e --- .../WebKit2/DocumentStartUserScriptAlertCrash.cpp | 65 ++++++++++++++++++++++ .../DocumentStartUserScriptAlertCrash_Bundle.cpp | 50 +++++++++++++++++ .../Tests/WebKit2/EvaluateJavaScript.cpp | 61 ++++++++++++++++++++ .../TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp | 11 ++++ .../Tests/WebKit2/PreventEmptyUserAgent.cpp | 61 ++++++++++++++++++++ .../WebKit2/win/WMCloseCallsUIClientClose.cpp | 59 ++++++++++++++++++++ 6 files changed, 307 insertions(+) create mode 100644 WebKitTools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp create mode 100644 WebKitTools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp create mode 100644 WebKitTools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp create mode 100644 WebKitTools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp create mode 100644 WebKitTools/TestWebKitAPI/Tests/WebKit2/win/WMCloseCallsUIClientClose.cpp (limited to 'WebKitTools/TestWebKitAPI/Tests/WebKit2') diff --git a/WebKitTools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp b/WebKitTools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp new file mode 100644 index 0000000..5e0655e --- /dev/null +++ b/WebKitTools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash.cpp @@ -0,0 +1,65 @@ +/* + * 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 context(AdoptWK, Util::createContextForInjectedBundleTest("DocumentStartUserScriptAlertCrashTest")); + WKRetainPtr pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get())); + PlatformWebView webView(pageNamespace.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/WebKitTools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp b/WebKitTools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp new file mode 100644 index 0000000..a96bef2 --- /dev/null +++ b/WebKitTools/TestWebKitAPI/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp @@ -0,0 +1,50 @@ +/* + * 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 + +namespace TestWebKitAPI { + +class DocumentStartUserScriptAlertCrashTest : public InjectedBundleTest { +public: + DocumentStartUserScriptAlertCrashTest(const std::string& identifier) + : InjectedBundleTest(identifier) + { + } + + virtual void initialize(WKBundleRef bundle) + { + WKRetainPtr source(AdoptWK, WKStringCreateWithUTF8CString("alert('an alert');")); + WKBundleAddUserScript(bundle, WKBundleScriptWorldNormalWorld(), source.get(), 0, 0, 0, kWKInjectAtDocumentStart, kWKInjectInAllFrames); + } +}; + +static InjectedBundleTest::Register registrar("DocumentStartUserScriptAlertCrashTest"); + +} // namespace TestWebKitAPI diff --git a/WebKitTools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp b/WebKitTools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp new file mode 100644 index 0000000..bbdece3 --- /dev/null +++ b/WebKitTools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp @@ -0,0 +1,61 @@ +/* + * 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()); + WKRetainPtr pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get())); + PlatformWebView webView(pageNamespace.get()); + + WKRetainPtr javaScriptString(AdoptWK, WKStringCreateWithUTF8CString("throw 'Hello'")); + WKPageRunJavaScriptInMainFrame(webView.page(), javaScriptString.get(), reinterpret_cast(0x1234578), didRunJavaScript); + + Util::run(&testDone); +} + +} // namespace TestWebKitAPI diff --git a/WebKitTools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp b/WebKitTools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp index a0b4058..c3af543 100644 --- a/WebKitTools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp +++ b/WebKitTools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp @@ -52,8 +52,13 @@ static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WK 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; } @@ -63,6 +68,9 @@ static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef us TEST_ASSERT(state->didDecidePolicyForNavigationAction); TEST_ASSERT(state->didStartProvisionalLoadForFrame); + // The provisional URL should be null. + TEST_ASSERT(!WKFrameCopyProvisionalURL(frame)); + state->didCommitLoadForFrame = true; } @@ -73,6 +81,9 @@ static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef us TEST_ASSERT(state->didStartProvisionalLoadForFrame); TEST_ASSERT(state->didCommitLoadForFrame); + // The provisional URL should be null. + TEST_ASSERT(!WKFrameCopyProvisionalURL(frame)); + test1Done = true; } diff --git a/WebKitTools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp b/WebKitTools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp new file mode 100644 index 0000000..af3ed12 --- /dev/null +++ b/WebKitTools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp @@ -0,0 +1,61 @@ +/* + * 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()); + WKRetainPtr pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get())); + PlatformWebView webView(pageNamespace.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/WebKitTools/TestWebKitAPI/Tests/WebKit2/win/WMCloseCallsUIClientClose.cpp b/WebKitTools/TestWebKitAPI/Tests/WebKit2/win/WMCloseCallsUIClientClose.cpp new file mode 100644 index 0000000..a019f08 --- /dev/null +++ b/WebKitTools/TestWebKitAPI/Tests/WebKit2/win/WMCloseCallsUIClientClose.cpp @@ -0,0 +1,59 @@ +/* + * 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()); + WKRetainPtr pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get())); + + PlatformWebView webView(pageNamespace.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