Add a test case for encode/decode of FormData/FormDataElement
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 21:50:48 +0000 (21:50 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 21:50:48 +0000 (21:50 +0000)
If the fix made in r77401 is broken, this new test will crash.

Fixes <http://webkit.org/b/53616> <rdar://problem/8949883>.

Reviewed by Sam Weinig.

Tools:

* TestWebKitAPI/Test.h: Moved the bulk of TEST_ASSERT into a new _TEST_ASSERT_HELPER macro.
Added a new TEST_ASSERT_RETURN macro that can be used in functions with a return value.

* TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp: Added.
(TestWebKitAPI::didFinishLoadForFrame): Record that the load is finished.
(TestWebKitAPI::setPageLoaderClient): Hook up the loader client.
(TestWebKitAPI::createSessionStateContainingFormData): Load simple-form.html, submit the
form, an return the session state data.
(TestWebKitAPI::TEST): Create some session state that contains form data from one WKPage,
and restore it into another WKPage.

* TestWebKitAPI/Tests/WebKit2/simple-form.html: Added.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/win/TestWebKitAPI.vcproj:
* TestWebKitAPI/win/copy-resources.cmd:
Added new files.

Source/WebKit2:

Allow passing a null filter callback to WKPageCopySessionState

* UIProcess/cf/WebBackForwardListCF.cpp:
(WebKit::WebBackForwardList::createCFDictionaryRepresentation): Check if the filter is null
before calling it.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77672 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/cf/WebBackForwardListCF.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Test.h
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/simple-form.html [new file with mode: 0644]
Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj
Tools/TestWebKitAPI/win/copy-resources.cmd

index 8ea46f456fd35459a5efcff54b6b9a400726a7f0..49e92a5269efccbf3aa451f668a6fb962013f5de 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-04  Adam Roben  <aroben@apple.com>
+
+        Allow passing a null filter callback to WKPageCopySessionState
+
+        WebKit2 part of <http://webkit.org/b/53616> <rdar://problem/8949883>.
+
+        Reviewed by Sam Weinig.
+
+        * UIProcess/cf/WebBackForwardListCF.cpp:
+        (WebKit::WebBackForwardList::createCFDictionaryRepresentation): Check if the filter is null
+        before calling it.
+
 2011-02-04  Brian Weinstein  <bweinstein@apple.com>
 
         Reviewed by John Sullivan.
index 9dc96bfd27904def80adc951d9b8cd0d2e84ce00..cafa3103b98837ffe599808b873c31188796f9cd 100644 (file)
@@ -64,7 +64,7 @@ CFDictionaryRef WebBackForwardList::createCFDictionaryRepresentation(WebPageProx
 
     for (size_t i = 0; i < m_entries.size(); ++i) {
         RefPtr<WebURL> webURL = WebURL::create(m_entries[i]->url());
-        if (!filter(toAPI(m_page), WKPageGetSessionHistoryURLValueType(), toURLRef(m_entries[i]->originalURL().impl()), context))
+        if (filter && !filter(toAPI(m_page), WKPageGetSessionHistoryURLValueType(), toURLRef(m_entries[i]->originalURL().impl()), context))
             continue;
         
         RetainPtr<CFStringRef> url(AdoptCF, m_entries[i]->url().createCFString());
index 3084eaaa08f13fcb829b38824d22bb881ba21176..8918613e9ec89eda80e99e3da14d67782a821a9e 100644 (file)
@@ -1,3 +1,31 @@
+2011-02-04  Adam Roben  <aroben@apple.com>
+
+        Add a test case for encode/decode of FormData/FormDataElement
+
+        If the fix made in r77401 is broken, this new test will crash.
+
+        Fixes <http://webkit.org/b/53616> <rdar://problem/8949883>.
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/Test.h: Moved the bulk of TEST_ASSERT into a new _TEST_ASSERT_HELPER macro.
+        Added a new TEST_ASSERT_RETURN macro that can be used in functions with a return value.
+
+        * TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp: Added.
+        (TestWebKitAPI::didFinishLoadForFrame): Record that the load is finished.
+        (TestWebKitAPI::setPageLoaderClient): Hook up the loader client.
+        (TestWebKitAPI::createSessionStateContainingFormData): Load simple-form.html, submit the
+        form, an return the session state data.
+        (TestWebKitAPI::TEST): Create some session state that contains form data from one WKPage,
+        and restore it into another WKPage.
+
+        * TestWebKitAPI/Tests/WebKit2/simple-form.html: Added.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/win/TestWebKitAPI.vcproj:
+        * TestWebKitAPI/win/copy-resources.cmd:
+        Added new files.
+
 2011-02-04  Adam Roben  <aroben@apple.com>
 
         Move code to run JavaScript tests into its own files
index 93bfd8bc8cbd97599a92bae274320a5ba20464f3..ed772d5dac5962dc14bf3bd4dcd10c5515bcad7c 100644 (file)
@@ -79,7 +79,9 @@ protected:
     \
     void TEST_CLASS_NAME(testSuite, testCaseName)::run()
 
-#define TEST_ASSERT(expression) do { if (!(expression)) { TestsController::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0)
+#define _TEST_ASSERT_HELPER(expression, returnStatement) do { if (!(expression)) { TestsController::shared().testFailed(__FILE__, __LINE__, #expression); returnStatement; } } while (0)
+#define TEST_ASSERT(expression) _TEST_ASSERT_HELPER(expression, return)
+#define TEST_ASSERT_RETURN(expression, returnValue) _TEST_ASSERT_HELPER(expression, return (returnValue))
 
 } // namespace TestWebKitAPI
 
index 3bc4c4bdb6fa2784bca36a2ceba01a38db2ab2f6..99bb29f938e2aad16cffc5dbd8c0aebdb19497fd 100644 (file)
@@ -46,6 +46,8 @@
                C02B77F2126612140026BF0F /* SpacebarScrolling.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */; };
                C02B7854126613AE0026BF0F /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C02B7853126613AE0026BF0F /* Carbon.framework */; };
                C0ADBE7C12FCA4D000D2C129 /* JavaScriptTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE7A12FCA4D000D2C129 /* JavaScriptTest.cpp */; };
+               C0ADBE8312FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */; };
+               C0ADBE9612FCA79B00D2C129 /* simple-form.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C0ADBE8412FCA6B600D2C129 /* simple-form.html */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -77,6 +79,7 @@
                                BCBD3737125ABBEB00D2C29F /* icon.png in Copy Resources */,
                                1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */,
                                BC909784125571CF00083756 /* simple.html in Copy Resources */,
+                               C0ADBE9612FCA79B00D2C129 /* simple-form.html in Copy Resources */,
                                C01A23F21266156700C9ED55 /* spacebar-scrolling.html in Copy Resources */,
                                BC2D006412AA04CE00E732A3 /* file-with-anchor.html in Copy Resources */,
                        );
                C02B7882126615410026BF0F /* spacebar-scrolling.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "spacebar-scrolling.html"; sourceTree = "<group>"; };
                C0ADBE7A12FCA4D000D2C129 /* JavaScriptTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JavaScriptTest.cpp; sourceTree = "<group>"; };
                C0ADBE7B12FCA4D000D2C129 /* JavaScriptTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptTest.h; sourceTree = "<group>"; };
+               C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RestoreSessionStateContainingFormData.cpp; sourceTree = "<group>"; };
+               C0ADBE8412FCA6B600D2C129 /* simple-form.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "simple-form.html"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                                BC909779125571AB00083756 /* PageLoadBasic.cpp */,
                                BC2D004812A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp */,
                                333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */,
+                               C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */,
                                C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */,
                                BC7B619A1299FE9E00D174A4 /* WKPreferences.cpp */,
                                BC90995D12567BC100083756 /* WKString.cpp */,
                                1A02C84B125D4A5E00E3F4BD /* find.html */,
                                BCBD372E125ABBE600D2C29F /* icon.png */,
                                BC909778125571AB00083756 /* simple.html */,
+                               C0ADBE8412FCA6B600D2C129 /* simple-form.html */,
                                C02B7882126615410026BF0F /* spacebar-scrolling.html */,
                        );
                        name = Resources;
                                BC7B61AA129A038700D174A4 /* WKPreferences.cpp in Sources */,
                                BC2D004912A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp in Sources */,
                                C0ADBE7C12FCA4D000D2C129 /* JavaScriptTest.cpp in Sources */,
+                               C0ADBE8312FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp
new file mode 100644 (file)
index 0000000..7c08735
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "Test.h"
+
+#include "JavaScriptTest.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+
+namespace TestWebKitAPI {
+
+static bool didFinishLoad;
+
+static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*)
+{
+    didFinishLoad = true;
+}
+
+static void setPageLoaderClient(WKPageRef page)
+{
+    WKPageLoaderClient loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+    loaderClient.version = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+
+    WKPageSetPageLoaderClient(page, &loaderClient);
+}
+
+static WKRetainPtr<WKDataRef> createSessionStateContainingFormData(WKContextRef context)
+{
+    PlatformWebView webView(context);
+    setPageLoaderClient(webView.page());
+
+    WKPageLoadURL(webView.page(), Util::adoptWK(Util::createURLForResource("simple-form", "html")).get());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    TEST_ASSERT_RETURN(runJSTest(webView.page(), "submitForm()", "undefined"), 0);
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    return Util::adoptWK(WKPageCopySessionState(webView.page(), 0, 0));
+}
+
+TEST(WebKit2, RestoreSessionStateContainingFormData)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
+
+    // FIXME: Once <rdar://problem/8708435> is fixed, we can move the creation of this
+    // PlatformWebView after the call to createSessionStaetContainingFormData. Until then, it must
+    // remain here to avoid a race condition between the UI and web processes.
+    PlatformWebView webView(context.get());
+    setPageLoaderClient(webView.page());
+
+    WKRetainPtr<WKDataRef> data = createSessionStateContainingFormData(context.get());
+    TEST_ASSERT(data);
+
+    WKPageRestoreFromSessionState(webView.page(), data.get());
+    Util::run(&didFinishLoad);
+
+    TEST_ASSERT(WKPageCanGoBack(webView.page()));
+}
+
+} // namespace TestWebKitAPI
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/simple-form.html b/Tools/TestWebKitAPI/Tests/WebKit2/simple-form.html
new file mode 100644 (file)
index 0000000..3bf1852
--- /dev/null
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<script>
+function submitForm()
+{
+    document.forms[0].submit();
+}
+</script>
+<form method=post>
+<input name=foo value="Some unimportant data">
+<input type=submit>
+</form>
index 87cb4ba58bb8832590a8fc12fe1480843992b8ed..2e4efc027603b1e1b91bbf520a5242a8afa19f8f 100644 (file)
                                        RelativePath="..\Tests\WebKit2\PreventEmptyUserAgent.cpp"
                                        >
                                </File>
+                               <File
+                                       RelativePath="..\Tests\WebKit2\RestoreSessionStateContainingFormData.cpp"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\Tests\WebKit2\simple-form.html"
+                                       >
+                               </File>
                                <File
                                        RelativePath="..\Tests\WebKit2\simple.html"
                                        >
index dc56479113f12dbf6c88e2e1db0d19b26e0c2303..b0ef3dfdf3fea4f0c11f9191cad65bc0a6fc70e3 100755 (executable)
@@ -12,6 +12,7 @@ for %%f in (
     ..\Tests\WebKit2\find.html
     ..\Tests\WebKit2\icon.png
     ..\Tests\WebKit2\simple.html
+    ..\Tests\WebKit2\simple-form.html
     ..\Tests\WebKit2\spacebar-scrolling.html
 ) do (
     xcopy /y /d %%f "%ResourcesDirectory%"