diff options
| author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-07 11:21:11 +0200 |
|---|---|---|
| committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-07 11:21:11 +0200 |
| commit | 2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 (patch) | |
| tree | 988e8c5b116dd0466244ae2fe5af8ee9be926d76 /Tools/TestWebKitAPI/Tests/WebKit2 | |
| parent | dd91e772430dc294e3bf478c119ef8d43c0a3358 (diff) | |
| download | qtwebkit-2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47.tar.gz | |
Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286)
Diffstat (limited to 'Tools/TestWebKitAPI/Tests/WebKit2')
12 files changed, 734 insertions, 4 deletions
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic.cpp new file mode 100644 index 000000000..b78ee91af --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic.cpp @@ -0,0 +1,148 @@ +/* + * 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" +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" +#include <WebKit2/WKRetainPtr.h> +#include <wtf/Vector.h> + +namespace TestWebKitAPI { + +static bool finished; +static int liveDOMExtensionCount; + +static const char* expectedMessages[] = { +"GlobalObjectIsAvailableForFrame called", +"GlobalObjectIsAvailableForFrame called", +"GlobalObjectIsAvailableForFrame called", +"GlobalObjectIsAvailableForFrame called", +"Subframe finished loading", +"Extension states:\nFirst page, main frame, standard world - Connected\nFirst page, main frame, non-standard world - Connected\nFirst page, subframe, standard world - Connected\nFirst page, subframe, non-standard world - Connected\nSecond page, main frame, standard world - Uncreated\nSecond page, main frame, non-standard world - Uncreated", +"Main frame finished loading", +"Extension states:\nFirst page, main frame, standard world - Connected\nFirst page, main frame, non-standard world - Connected\nFirst page, subframe, standard world - Connected\nFirst page, subframe, non-standard world - Connected\nSecond page, main frame, standard world - Uncreated\nSecond page, main frame, non-standard world - Uncreated", +"WillDisconnectDOMWindowExtensionFromGlobalObject called", +"WillDisconnectDOMWindowExtensionFromGlobalObject called", +"WillDisconnectDOMWindowExtensionFromGlobalObject called", +"WillDisconnectDOMWindowExtensionFromGlobalObject called", +"GlobalObjectIsAvailableForFrame called", +"GlobalObjectIsAvailableForFrame called", +"Main frame finished loading", +"Extension states:\nFirst page, main frame, standard world - Disconnected\nFirst page, main frame, non-standard world - Disconnected\nFirst page, subframe, standard world - Disconnected\nFirst page, subframe, non-standard world - Disconnected\nSecond page, main frame, standard world - Connected\nSecond page, main frame, non-standard world - Connected", +"WillDisconnectDOMWindowExtensionFromGlobalObject called", +"WillDisconnectDOMWindowExtensionFromGlobalObject called", +"DidReconnectDOMWindowExtensionToGlobalObject called", +"DidReconnectDOMWindowExtensionToGlobalObject called", +"DidReconnectDOMWindowExtensionToGlobalObject called", +"DidReconnectDOMWindowExtensionToGlobalObject called", +"Main frame finished loading", +"Extension states:\nFirst page, main frame, standard world - Connected\nFirst page, main frame, non-standard world - Connected\nFirst page, subframe, standard world - Connected\nFirst page, subframe, non-standard world - Connected\nSecond page, main frame, standard world - Disconnected\nSecond page, main frame, non-standard world - Disconnected", +"WillDestroyGlobalObjectForDOMWindowExtension called", +"WillDestroyGlobalObjectForDOMWindowExtension called", +"WillDestroyGlobalObjectForDOMWindowExtension called", +"WillDestroyGlobalObjectForDOMWindowExtension called", +"WillDestroyGlobalObjectForDOMWindowExtension called", +"WillDestroyGlobalObjectForDOMWindowExtension called", +"Extension states:\nFirst page, main frame, standard world - Destroyed\nFirst page, main frame, non-standard world - Destroyed\nFirst page, subframe, standard world - Destroyed\nFirst page, subframe, non-standard world - Destroyed\nSecond page, main frame, standard world - Destroyed\nSecond page, main frame, non-standard world - Destroyed", +"TestComplete" +}; + +static Vector<WKRetainPtr<WKStringRef> > messages; + +static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*) +{ + ASSERT_NOT_NULL(messageBody); + EXPECT_EQ(WKStringGetTypeID(), WKGetTypeID(messageBody)); + + WKStringRef bodyString = (WKStringRef)messageBody; + messages.append(bodyString); + + if (WKStringIsEqualToUTF8CString(messageName, "GlobalObjectIsAvailableForFrame")) + liveDOMExtensionCount++; + else if (WKStringIsEqualToUTF8CString(messageName, "WillDestroyGlobalObjectForDOMWindowExtension")) { + liveDOMExtensionCount--; + if (!liveDOMExtensionCount) + finished = true; + } else if (WKStringIsEqualToUTF8CString(messageName, "DidFinishLoadForMainFrame") || WKStringIsEqualToUTF8CString(messageName, "TestComplete")) + finished = true; + +} + +TEST(WebKit2, DOMWindowExtensionBasic) +{ + WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DOMWindowExtensionBasicPageGroup"))); + + WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("DOMWindowExtensionBasic", pageGroup.get())); + + WKContextInjectedBundleClient injectedBundleClient; + memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); + injectedBundleClient.version = 0; + injectedBundleClient.clientInfo = 0; + injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; + WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient); + + // The default cache model has a capacity of 0, so it is necessary to switch to a cache + // model that actually allows for a page cache. + WKContextSetCacheModel(context.get(), kWKCacheModelDocumentBrowser); + + PlatformWebView webView(context.get(), pageGroup.get()); + + // Make sure the extensions for each frame are installed in each world. + WKRetainPtr<WKURLRef> url1(AdoptWK, Util::createURLForResource("simple-iframe", "html")); + WKPageLoadURL(webView.page(), url1.get()); + + Util::run(&finished); + finished = false; + + // Make sure those first 4 extensions are disconnected, and 2 new ones are installed. + WKRetainPtr<WKURLRef> url2(AdoptWK, Util::createURLForResource("simple", "html")); + WKPageLoadURL(webView.page(), url2.get()); + + Util::run(&finished); + finished = false; + + // Make sure those two are disconnected, and the first four are reconnected. + WKPageGoBack(webView.page()); + + Util::run(&finished); + finished = false; + + // Make sure the 2 disconnected extensions in the page cache and the 4 active extensions are all destroyed. + WKPageClose(webView.page()); + + Util::run(&finished); + + const size_t expectedSize = sizeof(expectedMessages) / sizeof(const char*); + EXPECT_EQ(messages.size(), expectedSize); + + if (messages.size() != expectedSize) + return; + + for (size_t i = 0; i < messages.size(); ++i) + EXPECT_EQ(WKStringIsEqualToUTF8CString(messages[i].get(), expectedMessages[i]), true); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic_Bundle.cpp new file mode 100644 index 000000000..61ac1bdeb --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/DOMWindowExtensionBasic_Bundle.cpp @@ -0,0 +1,254 @@ +/* + * 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" +#include "InjectedBundleTest.h" +#include <WebKit2/WKBundleDOMWindowExtension.h> +#include <WebKit2/WKBundleFrame.h> +#include <WebKit2/WKBundlePage.h> +#include <WebKit2/WKBundlePageGroup.h> +#include <WebKit2/WKBundlePrivate.h> +#include <WebKit2/WKBundleScriptWorld.h> +#include <WebKit2/WKRetainPtr.h> +#include <wtf/HashMap.h> +#include <wtf/Vector.h> +#include <assert.h> + +namespace TestWebKitAPI { + +static void didFinishLoadForFrameCallback(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void* clientInfo); +static void globalObjectIsAvailableForFrameCallback(WKBundlePageRef, WKBundleFrameRef, WKBundleScriptWorldRef, const void* clientInfo); +static void willDisconnectDOMWindowExtensionFromGlobalObjectCallback(WKBundlePageRef, WKBundleDOMWindowExtensionRef, const void* clientInfo); +static void didReconnectDOMWindowExtensionToGlobalObjectCallback(WKBundlePageRef, WKBundleDOMWindowExtensionRef, const void* clientInfo); +static void willDestroyGlobalObjectForDOMWindowExtensionCallback(WKBundlePageRef, WKBundleDOMWindowExtensionRef, const void* clientInfo); + + +enum ExtensionState { + Uncreated = 0, Connected, Disconnected, Destroyed +}; + +const char* stateNames[4] = { + "Uncreated", + "Connected", + "Disconnected", + "Destroyed" +}; + +typedef struct { + const char* name; + ExtensionState state; +} ExtensionRecord; + +class DOMWindowExtensionBasic : public InjectedBundleTest { +public: + DOMWindowExtensionBasic(const std::string& identifier); + + virtual void initialize(WKBundleRef, WKTypeRef userData); + virtual void didCreatePage(WKBundleRef, WKBundlePageRef); + + void globalObjectIsAvailableForFrame(WKBundleFrameRef, WKBundleScriptWorldRef); + void willDisconnectDOMWindowExtensionFromGlobalObject(WKBundleDOMWindowExtensionRef); + void didReconnectDOMWindowExtensionToGlobalObject(WKBundleDOMWindowExtensionRef); + void willDestroyGlobalObjectForDOMWindowExtension(WKBundleDOMWindowExtensionRef); + + void frameLoadFinished(WKBundleFrameRef); + +private: + void updateExtensionStateRecord(WKBundleDOMWindowExtensionRef, ExtensionState); + void sendExtensionStateMessage(); + void sendBundleMessage(const char*); + + WKBundlePageGroupRef m_pageGroup; + WKBundleRef m_bundle; + ExtensionRecord m_extensionRecords[6]; + HashMap<WKBundleDOMWindowExtensionRef, int> m_extensionToRecordMap; + bool m_finishedOneMainFrameLoad; + int m_numberOfDestroyedExtensions; +}; + +static InjectedBundleTest::Register<DOMWindowExtensionBasic> registrar("DOMWindowExtensionBasic"); + +DOMWindowExtensionBasic::DOMWindowExtensionBasic(const std::string& identifier) + : InjectedBundleTest(identifier) + , m_finishedOneMainFrameLoad(false) + , m_numberOfDestroyedExtensions(0) +{ + m_extensionRecords[0].name = "First page, main frame, standard world"; + m_extensionRecords[1].name = "First page, main frame, non-standard world"; + m_extensionRecords[2].name = "First page, subframe, standard world"; + m_extensionRecords[3].name = "First page, subframe, non-standard world"; + m_extensionRecords[4].name = "Second page, main frame, standard world"; + m_extensionRecords[5].name = "Second page, main frame, non-standard world"; + + for (size_t i = 0; i < 6; ++i) + m_extensionRecords[i].state = Uncreated; +} + +void DOMWindowExtensionBasic::frameLoadFinished(WKBundleFrameRef frame) +{ + bool mainFrame = !WKBundleFrameGetParentFrame(frame); + if (mainFrame) + m_finishedOneMainFrameLoad = true; + + char body[16384]; + sprintf(body, "%s finished loading", mainFrame ? "Main frame" : "Subframe"); + + // Only consider load finished for the main frame + const char* name = mainFrame ? "DidFinishLoadForMainFrame" : "DidFinishLoadForFrame"; + + WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString(name)); + WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithUTF8CString(body)); + WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); + + sendExtensionStateMessage(); +} + +void DOMWindowExtensionBasic::sendExtensionStateMessage() +{ + char body[16384]; + sprintf(body, "Extension states:\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s", + m_extensionRecords[0].name, stateNames[m_extensionRecords[0].state], + m_extensionRecords[1].name, stateNames[m_extensionRecords[1].state], + m_extensionRecords[2].name, stateNames[m_extensionRecords[2].state], + m_extensionRecords[3].name, stateNames[m_extensionRecords[3].state], + m_extensionRecords[4].name, stateNames[m_extensionRecords[4].state], + m_extensionRecords[5].name, stateNames[m_extensionRecords[5].state]); + + WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ExtensionStates")); + WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithUTF8CString(body)); + WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get()); +} + +void DOMWindowExtensionBasic::initialize(WKBundleRef bundle, WKTypeRef userData) +{ + assert(WKGetTypeID(userData) == WKBundlePageGroupGetTypeID()); + WKBundlePageGroupRef pageGroup = static_cast<WKBundlePageGroupRef>(userData); + + WKRetainPtr<WKStringRef> source(AdoptWK, WKStringCreateWithUTF8CString("alert('Unimportant alert');")); + WKBundleAddUserScript(bundle, pageGroup, WKBundleScriptWorldCreateWorld(), source.get(), 0, 0, 0, kWKInjectAtDocumentStart, kWKInjectInAllFrames); +} + +void DOMWindowExtensionBasic::didCreatePage(WKBundleRef bundle, WKBundlePageRef page) +{ + m_bundle = bundle; + + WKBundlePageLoaderClient pageLoaderClient; + memset(&pageLoaderClient, 0, sizeof(pageLoaderClient)); + + pageLoaderClient.version = 1; + pageLoaderClient.clientInfo = this; + pageLoaderClient.didFinishLoadForFrame = didFinishLoadForFrameCallback; + pageLoaderClient.globalObjectIsAvailableForFrame = globalObjectIsAvailableForFrameCallback; + pageLoaderClient.willDisconnectDOMWindowExtensionFromGlobalObject = willDisconnectDOMWindowExtensionFromGlobalObjectCallback; + pageLoaderClient.didReconnectDOMWindowExtensionToGlobalObject = didReconnectDOMWindowExtensionToGlobalObjectCallback; + pageLoaderClient.willDestroyGlobalObjectForDOMWindowExtension = willDestroyGlobalObjectForDOMWindowExtensionCallback; + + WKBundlePageSetPageLoaderClient(page, &pageLoaderClient); +} + +void DOMWindowExtensionBasic::updateExtensionStateRecord(WKBundleDOMWindowExtensionRef extension, ExtensionState state) +{ + int index = m_extensionToRecordMap.get(extension); + m_extensionRecords[index].state = state; +} + +void DOMWindowExtensionBasic::sendBundleMessage(const char* message) +{ + WKRetainPtr<WKStringRef> wkMessage = adoptWK(WKStringCreateWithUTF8CString(message)); + WKBundlePostMessage(m_bundle, wkMessage.get(), wkMessage.get()); +} + +void DOMWindowExtensionBasic::globalObjectIsAvailableForFrame(WKBundleFrameRef frame, WKBundleScriptWorldRef world) +{ + WKBundleDOMWindowExtensionRef extension = WKBundleDOMWindowExtensionCreate(frame, world); + + int index; + bool standard; + standard = world == WKBundleScriptWorldNormalWorld(); + + if (WKBundleFrameGetParentFrame(frame)) + index = standard ? 2 : 3; + else + index = m_finishedOneMainFrameLoad ? (standard ? 4 : 5) : (standard ? 0 : 1); + + m_extensionToRecordMap.set(extension, index); + + updateExtensionStateRecord(extension, Connected); + sendBundleMessage("GlobalObjectIsAvailableForFrame called"); +} + +void DOMWindowExtensionBasic::willDisconnectDOMWindowExtensionFromGlobalObject(WKBundleDOMWindowExtensionRef extension) +{ + updateExtensionStateRecord(extension, Disconnected); + sendBundleMessage("WillDisconnectDOMWindowExtensionFromGlobalObject called"); +} + +void DOMWindowExtensionBasic::didReconnectDOMWindowExtensionToGlobalObject(WKBundleDOMWindowExtensionRef extension) +{ + updateExtensionStateRecord(extension, Connected); + sendBundleMessage("DidReconnectDOMWindowExtensionToGlobalObject called"); +} + +void DOMWindowExtensionBasic::willDestroyGlobalObjectForDOMWindowExtension(WKBundleDOMWindowExtensionRef extension) +{ + m_numberOfDestroyedExtensions++; + + updateExtensionStateRecord(extension, Destroyed); + sendBundleMessage("WillDestroyGlobalObjectForDOMWindowExtension called"); + + if (m_numberOfDestroyedExtensions == 6) { + sendExtensionStateMessage(); + sendBundleMessage("TestComplete"); + } + + WKRelease(extension); +} + +static void didFinishLoadForFrameCallback(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo) +{ + ((DOMWindowExtensionBasic*)clientInfo)->frameLoadFinished(frame); +} + +static void globalObjectIsAvailableForFrameCallback(WKBundlePageRef, WKBundleFrameRef frame, WKBundleScriptWorldRef world, const void* clientInfo) +{ + ((DOMWindowExtensionBasic*)clientInfo)->globalObjectIsAvailableForFrame(frame, world); +} + +static void willDisconnectDOMWindowExtensionFromGlobalObjectCallback(WKBundlePageRef, WKBundleDOMWindowExtensionRef extension, const void* clientInfo) +{ + ((DOMWindowExtensionBasic*)clientInfo)->willDisconnectDOMWindowExtensionFromGlobalObject(extension); +} + +static void didReconnectDOMWindowExtensionToGlobalObjectCallback(WKBundlePageRef, WKBundleDOMWindowExtensionRef extension, const void* clientInfo) +{ + ((DOMWindowExtensionBasic*)clientInfo)->didReconnectDOMWindowExtensionToGlobalObject(extension); +} + +static void willDestroyGlobalObjectForDOMWindowExtensionCallback(WKBundlePageRef, WKBundleDOMWindowExtensionRef extension , const void* clientInfo) +{ + ((DOMWindowExtensionBasic*)clientInfo)->willDestroyGlobalObjectForDOMWindowExtension(extension); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp index 99b7ff7f1..90ad04fd1 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/EvaluateJavaScript.cpp @@ -27,7 +27,6 @@ #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include <JavaScriptCore/JavaScriptCore.h> #include <WebKit2/WKRetainPtr.h> #include <WebKit2/WKSerializedScriptValue.h> diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp index 40ca269df..083a88f05 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleBasic.cpp @@ -34,7 +34,7 @@ static bool done; static bool loadDone; static bool messageReceived; -void didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo) +static void didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo) { messageReceived = true; if (loadDone) diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout.cpp index c703283f9..f90f3eb2b 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout.cpp @@ -47,7 +47,7 @@ static void setPageLoaderClient(WKPageRef page) WKPageSetPageLoaderClient(page, &loaderClient); } -TEST(WebKit2, NewFirstVisuallyNonEmptyLayout) +TEST(WebKit2, DISABLED_NewFirstVisuallyNonEmptyLayout) { WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("NewFirstVisuallyNonEmptyLayoutTest")); diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp index 4c522780d..c5acb6172 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PreventEmptyUserAgent.cpp @@ -27,7 +27,7 @@ #include "PlatformUtilities.h" #include "PlatformWebView.h" #include "Test.h" -#include <JavaScriptCore/JavaScriptCore.h> +#include <JavaScriptCore/JSContextRef.h> #include <WebKit2/WKRetainPtr.h> #include <WebKit2/WKSerializedScriptValue.h> diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp new file mode 100644 index 000000000..c13a5eb49 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp @@ -0,0 +1,92 @@ +/* + * 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" +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" + +#include <WebKit2/WKString.h> + +namespace TestWebKitAPI { + +static bool finished = false; +static bool receivedProperBackForwardCallbacks = false; + +static void didFinishLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef, const void*) +{ + // Only mark finished when the main frame loads + if (WKFrameGetParentFrame(frame)) + return; + + finished = true; +} + +static void willGoToBackForwardListItem(WKPageRef, WKBackForwardListItemRef, WKTypeRef userData, const void*) +{ + if (WKGetTypeID(userData) == WKStringGetTypeID()) { + if (WKStringIsEqualToUTF8CString((WKStringRef)userData, "shouldGoToBackForwardListItemCallback called as expected")) + receivedProperBackForwardCallbacks = true; + } + + finished = true; +} + +static void setPageLoaderClient(WKPageRef page) +{ + WKPageLoaderClient loaderClient; + memset(&loaderClient, 0, sizeof(loaderClient)); + loaderClient.version = 1; + loaderClient.clientInfo = 0; + loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + loaderClient.willGoToBackForwardListItem = willGoToBackForwardListItem; + + WKPageSetPageLoaderClient(page, &loaderClient); +} + +TEST(WebKit2, ShouldGoToBackForwardListItem) +{ + WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("ShouldGoToBackForwardListItemTest")); + // Enable the page cache so we can test the WKBundleBackForwardListItemIsInPageCache API + WKContextSetCacheModel(context.get(), kWKCacheModelDocumentBrowser); + + PlatformWebView webView(context.get()); + setPageLoaderClient(webView.page()); + + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); + Util::run(&finished); + + finished = false; + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple-iframe", "html")).get()); + Util::run(&finished); + + finished = false; + WKPageGoBack(webView.page()); + Util::run(&finished); + + EXPECT_EQ(receivedProperBackForwardCallbacks, true); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp new file mode 100644 index 000000000..0f15c477c --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp @@ -0,0 +1,70 @@ +/* + * 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" +#include "InjectedBundleTest.h" + +#include "PlatformUtilities.h" +#include <WebKit2/WKBundlePage.h> +#include <WebKit2/WKBundleBackForwardListItem.h> + +namespace TestWebKitAPI { + +class ShouldGoToBackForwardListItemTest : public InjectedBundleTest { +public: + ShouldGoToBackForwardListItemTest(const std::string& identifier); + + virtual void didCreatePage(WKBundleRef bundle, WKBundlePageRef page); +}; + +static InjectedBundleTest::Register<ShouldGoToBackForwardListItemTest> registrar("ShouldGoToBackForwardListItemTest"); + +static bool shouldGoToBackForwardListItemCallback(WKBundlePageRef, WKBundleBackForwardListItemRef item, WKTypeRef* userData, const void*) +{ + // The item should be in the page cache + if (WKBundleBackForwardListItemIsInPageCache(item)) + *userData = WKStringCreateWithUTF8CString("shouldGoToBackForwardListItemCallback called as expected"); + + return true; +} + +ShouldGoToBackForwardListItemTest::ShouldGoToBackForwardListItemTest(const std::string& identifier) + : InjectedBundleTest(identifier) +{ +} + +void ShouldGoToBackForwardListItemTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page) +{ + WKBundlePageLoaderClient pageLoaderClient; + memset(&pageLoaderClient, 0, sizeof(pageLoaderClient)); + + pageLoaderClient.version = 1; + pageLoaderClient.clientInfo = this; + pageLoaderClient.shouldGoToBackForwardListItem = shouldGoToBackForwardListItemCallback; + + WKBundlePageSetPageLoaderClient(page, &pageLoaderClient); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp index 2a181ddea..5af01ebb4 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WKPreferences.cpp @@ -57,6 +57,14 @@ TEST(WebKit2, WKPreferencesDefaults) static const char* expectedCursiveFontFamily = "Apple Chancery"; static const char* expectedFantasyFontFamily = "Papyrus"; static const char* expectedPictographFontFamily = "Apple Color Emoji"; +#elif PLATFORM(GTK) + static const char* expectedStandardFontFamily = "Times"; + static const char* expectedFixedFontFamily = "Courier New"; + 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"; #endif WKPreferencesRef preference = WKPreferencesCreate(); diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent.cpp new file mode 100644 index 000000000..671c72943 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent.cpp @@ -0,0 +1,74 @@ +/* + * 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" +#include "PlatformUtilities.h" +#include "PlatformWebView.h" +#include "Test.h" + +namespace TestWebKitAPI { + +static bool didReceiveMessage; + +static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*) +{ + didReceiveMessage = true; + + EXPECT_WK_STREQ("DidReceiveWillSendSubmitEvent", messageName); + + EXPECT_EQ(WKDictionaryGetTypeID(), WKGetTypeID(body)); + WKDictionaryRef values = static_cast<WKDictionaryRef>(body); + + WKStringRef textFieldValueWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(values, WKStringCreateWithUTF8CString("textField"))); + EXPECT_WK_STREQ("text field", textFieldValueWK); + + WKStringRef passwordFieldValueWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(values, WKStringCreateWithUTF8CString("passwordField"))); + EXPECT_WK_STREQ("password field", passwordFieldValueWK); + + // <input type="hidden"> fields are not sent. + WKStringRef hiddenFieldValueWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(values, WKStringCreateWithUTF8CString("hiddenField"))); + EXPECT_NULL(hiddenFieldValueWK); +} + +static void setInjectedBundleClient(WKContextRef context) +{ + WKContextInjectedBundleClient injectedBundleClient; + memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); + injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; + + WKContextSetInjectedBundleClient(context, &injectedBundleClient); +} + +TEST(WebKit2, WillSendSubmitEvent) +{ + WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("WillSendSubmitEventTest")); + setInjectedBundleClient(context.get()); + + PlatformWebView webView(context.get()); + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("auto-submitting-form", "html")).get()); + Util::run(&didReceiveMessage); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp new file mode 100644 index 000000000..7bbbcaf10 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp @@ -0,0 +1,65 @@ +/* + * 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" +#include "InjectedBundleTest.h" + +#include "PlatformUtilities.h" +#include <WebKit2/WKBundlePage.h> + +namespace TestWebKitAPI { + +class WillSendSubmitEventTest : public InjectedBundleTest { +public: + WillSendSubmitEventTest(const std::string& identifier); + + virtual void didCreatePage(WKBundleRef, WKBundlePageRef); +}; + +static InjectedBundleTest::Register<WillSendSubmitEventTest> registrar("WillSendSubmitEventTest"); + +static void willSendSubmitEvent(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef, WKBundleFrameRef, WKDictionaryRef values, const void*) +{ + WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("DidReceiveWillSendSubmitEvent").get(), values); +} + +WillSendSubmitEventTest::WillSendSubmitEventTest(const std::string& identifier) + : InjectedBundleTest(identifier) +{ +} + +void WillSendSubmitEventTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page) +{ + WKBundlePageFormClient formClient; + memset(&formClient, 0, sizeof(formClient)); + + formClient.version = 1; + formClient.clientInfo = this; + formClient.willSendSubmitEvent = willSendSubmitEvent; + + WKBundlePageSetFormClient(page, &formClient); +} + +} // namespace TestWebKitAPI 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 @@ +<html> + <head> + <script> + function submitFormIfNecessary() + { + if (window.location.search) + return; + document.forms[0].submit.click(); + } + </script> + </head> + <body onload="submitFormIfNecessary()"> + <form action="#" method="GET"> + <input type="text" name="textField" value="text field"> + <input type="password" name="passwordField" value="password field"> + <input type="hidden" name="hiddenField" value="hidden field"> + <input type="submit" name="submit"> + </form> + </body> +</html> |
