Move code to run JavaScript tests into its own files
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 21:50:09 +0000 (21:50 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 21:50:09 +0000 (21:50 +0000)
This will allow other tests to use this mechanism.

Fixes <http://webkit.org/b/53806> SpacebarScrolling should share its JavaScript-fu with the
world

Reviewed by Sam Weinig.

* TestWebKitAPI/JavaScriptTest.cpp: Added.
* TestWebKitAPI/JavaScriptTest.h: Added.
Moved code here...

* TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp: ...from here.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/win/TestWebKitAPI.vcproj:
Added the new files.

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

Tools/ChangeLog
Tools/TestWebKitAPI/JavaScriptTest.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/JavaScriptTest.h [new file with mode: 0644]
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp
Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj

index 3d4422835a59ae89cdc9f3ae230a537740954954..3084eaaa08f13fcb829b38824d22bb881ba21176 100644 (file)
@@ -1,3 +1,24 @@
+2011-02-04  Adam Roben  <aroben@apple.com>
+
+        Move code to run JavaScript tests into its own files
+
+        This will allow other tests to use this mechanism.
+
+        Fixes <http://webkit.org/b/53806> SpacebarScrolling should share its JavaScript-fu with the
+        world
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/JavaScriptTest.cpp: Added.
+        * TestWebKitAPI/JavaScriptTest.h: Added.
+        Moved code here...
+
+        * TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp: ...from here.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/win/TestWebKitAPI.vcproj:
+        Added the new files.
+
 2011-02-04  Dirk Pranke  <dpranke@chromium.org>
 
         Reviewed by Mihai Parparita.
diff --git a/Tools/TestWebKitAPI/JavaScriptTest.cpp b/Tools/TestWebKitAPI/JavaScriptTest.cpp
new file mode 100644 (file)
index 0000000..08418c2
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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 "JavaScriptTest.h"
+
+#include "PlatformUtilities.h"
+#include "Test.h"
+#include <WebKit2/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+struct JavaScriptCallbackContext {
+    JavaScriptCallbackContext(const char* expectedString) : didFinish(false), expectedString(expectedString), didMatchExpectedString(false) { }
+
+    bool didFinish;
+    const char* expectedString;
+    bool didMatchExpectedString;
+};
+
+static void javaScriptCallback(WKStringRef string, WKErrorRef error, void* ctx)
+{
+    JavaScriptCallbackContext* context = static_cast<JavaScriptCallbackContext*>(ctx);
+
+    context->didFinish = true;
+    context->didMatchExpectedString = WKStringIsEqualToUTF8CString(string, context->expectedString);
+
+    TEST_ASSERT(!error);
+}
+
+static WKRetainPtr<WKStringRef> wk(const char* utf8String)
+{
+    return WKRetainPtr<WKStringRef>(AdoptWK, WKStringCreateWithUTF8CString(utf8String));
+}
+
+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;
+}
+
+} // namespace TestWebKitAPI
diff --git a/Tools/TestWebKitAPI/JavaScriptTest.h b/Tools/TestWebKitAPI/JavaScriptTest.h
new file mode 100644 (file)
index 0000000..e01fcd5
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+namespace TestWebKitAPI {
+
+// Executes |script| in the page and waits until it has run. Returns true if the script's output
+// matches |expectedResult|, false otherwise. Asserts if an error occurs.
+bool runJSTest(WKPageRef, const char* script, const char* expectedResult);
+
+} // namespace TestWebKitAPI
index 0aca6861c6f5ccf19310cd9fb0d87d4155f8d41a..3bc4c4bdb6fa2784bca36a2ceba01a38db2ab2f6 100644 (file)
@@ -45,6 +45,7 @@
                C01A23F21266156700C9ED55 /* spacebar-scrolling.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C02B7882126615410026BF0F /* spacebar-scrolling.html */; };
                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 */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
                C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpacebarScrolling.cpp; sourceTree = "<group>"; };
                C02B7853126613AE0026BF0F /* Carbon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Carbon.framework; sourceTree = SDKROOT; };
                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>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                        children = (
                                BCA61C3A11700B9400460D1E /* mac */,
                                BC575944126E733C006F0F12 /* InjectedBundle */,
+                               C0ADBE7A12FCA4D000D2C129 /* JavaScriptTest.cpp */,
+                               C0ADBE7B12FCA4D000D2C129 /* JavaScriptTest.h */,
                                BC131A9E1171317C00B69727 /* TestWebKitAPIPrefix.h */,
                                BC575BBF126F5752006F0F12 /* PlatformUtilities.cpp */,
                                BC131883117114A800B69727 /* PlatformUtilities.h */,
                                333B9CE21277F23100FEFCE3 /* PreventEmptyUserAgent.cpp in Sources */,
                                BC7B61AA129A038700D174A4 /* WKPreferences.cpp in Sources */,
                                BC2D004912A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp in Sources */,
+                               C0ADBE7C12FCA4D000D2C129 /* JavaScriptTest.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 6d4783c1e447ea4565b832ce245950d120b7bf26..e3c6b207aabeebd18e1532499b7abd776b1e0fb3 100644 (file)
 
 #include "Test.h"
 
+#include "JavaScriptTest.h"
 #include "PlatformUtilities.h"
 #include "PlatformWebView.h"
 #include <WebKit2/WKRetainPtr.h>
 
 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;
 
@@ -53,29 +46,6 @@ static void didNotHandleKeyEventCallback(WKPageRef, WKNativeEventPtr event, cons
         didNotHandleKeyDownEvent = true;
 }
 
-static void javaScriptCallback(WKStringRef string, WKErrorRef error, void* ctx)
-{
-    JavaScriptCallbackContext* context = static_cast<JavaScriptCallbackContext*>(ctx);
-
-    context->didFinish = true;
-    context->didMatchExpectedString = WKStringIsEqualToUTF8CString(string, context->expectedString);
-
-    TEST_ASSERT(!error);
-}
-
-static WKRetainPtr<WKStringRef> wk(const char* utf8String)
-{
-    return WKRetainPtr<WKStringRef>(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<WKContextRef> context(AdoptWK, WKContextCreate());
index a2412ef78af2758cc43118793e5c89e3bfbecc2b..87cb4ba58bb8832590a8fc12fe1480843992b8ed 100644 (file)
                                </File>
                        </Filter>
                </Filter>
+               <File
+                       RelativePath="..\JavaScriptTest.cpp"
+                       >
+               </File>
+               <File
+                       RelativePath="..\JavaScriptTest.h"
+                       >
+               </File>
                <File
                        RelativePath="..\PlatformUtilities.cpp"
                        >