+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.
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
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;
};
#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;
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());
</File>
</Filter>
</Filter>
+ <File
+ RelativePath="..\JavaScriptTest.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\JavaScriptTest.h"
+ >
+ </File>
<File
RelativePath="..\PlatformUtilities.cpp"
>