Move testStringByEvaluatingJavaScriptFromString() from DumpRenderTree to TestWebKitAPI
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 3 Sep 2011 15:57:04 +0000 (15:57 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 3 Sep 2011 15:57:04 +0000 (15:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67559

Reviewed by Darin Adler.

* DumpRenderTree/mac/DumpRenderTree.mm:
(dumpRenderTree): Moved testStringByEvaluatingJavaScriptFromString() from here and removed
the call to it.
* TestWebKitAPI/PlatformUtilities.h: Declared Util::toSTD(NSString *)
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added StringByEvaluatingJavaScriptFromString.mm.
* TestWebKitAPI/Tests/mac/StringByEvaluatingJavaScriptFromString.mm: Added.
(TestWebKitAPI::TEST): Added. Moved testStringByEvaluatingJavaScriptFromString() to here.
* TestWebKitAPI/mac/PlatformUtilitiesMac.mm:
(TestWebKitAPI::Util::toSTD): Added.

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

Tools/ChangeLog
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/TestWebKitAPI/PlatformUtilities.h
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/mac/StringByEvaluatingJavaScriptFromString.mm [new file with mode: 0644]
Tools/TestWebKitAPI/mac/PlatformUtilitiesMac.mm

index 02d4b1275a5eb5b6584c852a1f3498e5c03bcbd7..96eee20db269f8e4f31d8553a383f65ebc3221e8 100644 (file)
@@ -1,3 +1,20 @@
+2011-09-03  Dan Bernstein  <mitz@apple.com>
+
+        Move testStringByEvaluatingJavaScriptFromString() from DumpRenderTree to TestWebKitAPI
+        https://bugs.webkit.org/show_bug.cgi?id=67559
+
+        Reviewed by Darin Adler.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (dumpRenderTree): Moved testStringByEvaluatingJavaScriptFromString() from here and removed
+        the call to it.
+        * TestWebKitAPI/PlatformUtilities.h: Declared Util::toSTD(NSString *)
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added StringByEvaluatingJavaScriptFromString.mm.
+        * TestWebKitAPI/Tests/mac/StringByEvaluatingJavaScriptFromString.mm: Added.
+        (TestWebKitAPI::TEST): Added. Moved testStringByEvaluatingJavaScriptFromString() to here.
+        * TestWebKitAPI/mac/PlatformUtilitiesMac.mm:
+        (TestWebKitAPI::Util::toSTD): Added.
+
 2011-09-03  Adam Barth  <abarth@webkit.org>
 
         garden-o-matic results view should have a better results selector
index 0806ed43179304adb0b0d733d1d84382835404fa..5f38ae4cd63403cc209621f9677a80688ca9ae0d 100644 (file)
@@ -335,46 +335,6 @@ WebView *createWebViewAndOffscreenWindow()
     return webView;
 }
 
-void testStringByEvaluatingJavaScriptFromString()
-{
-    // maps expected result <= JavaScript expression
-    NSDictionary *expressions = [NSDictionary dictionaryWithObjectsAndKeys:
-        @"0", @"0", 
-        @"0", @"'0'", 
-        @"", @"",
-        @"", @"''", 
-        @"", @"new String()", 
-        @"", @"new String('0')", 
-        @"", @"throw 1", 
-        @"", @"{ }", 
-        @"", @"[ ]", 
-        @"", @"//", 
-        @"", @"a.b.c", 
-        @"", @"(function() { throw 'error'; })()", 
-        @"", @"null",
-        @"", @"undefined",
-        @"true", @"true",
-        @"false", @"false",
-        @"", @"alert('Should not be result')",
-        nil
-    ];
-
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    WebView *webView = [[WebView alloc] initWithFrame:NSZeroRect frameName:@"" groupName:@""];
-
-    NSEnumerator *enumerator = [expressions keyEnumerator];
-    id expression;
-    while ((expression = [enumerator nextObject])) {
-        NSString *expectedResult = [expressions objectForKey:expression];
-        NSString *result = [webView stringByEvaluatingJavaScriptFromString:expression];
-        assert([result isEqualToString:expectedResult]);
-    }
-
-    [webView close];
-    [webView release];
-    [pool release];
-}
-
 static NSString *libraryPathForDumpRenderTree()
 {
     //FIXME: This may not be sufficient to prevent interactions/crashes
@@ -673,9 +633,6 @@ void dumpRenderTree(int argc, const char *argv[])
     [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:@"localhost"];
     [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:@"127.0.0.1"];
 
-    // <rdar://problem/5222911>
-    testStringByEvaluatingJavaScriptFromString();
-
     // http://webkit.org/b/32689
     testThreadIdentifierMap();
 
index 1a907a1efdd980a99ff2dea7423ff86e2cd64cfe..c3ea21e2839a1f5c52472f686dd5f3de9a932fc8 100644 (file)
 #include <WebKit2/WKRetainPtr.h>
 #include <string>
 
+#if PLATFORM(MAC)
+#if __OBJC__
+@class NSString;
+#else
+class NSString;
+#endif
+#endif
+
 namespace TestWebKitAPI {
 namespace Util {
 
@@ -54,6 +62,9 @@ bool isKeyDown(WKNativeEventPtr);
 std::string toSTD(WKStringRef);
 std::string toSTD(WKRetainPtr<WKStringRef>);
 std::string toSTD(const char*);
+#if PLATFORM(MAC)
+std::string toSTD(NSString *);
+#endif
 
 WKRetainPtr<WKStringRef> toWK(const char* utf8String);
 
index 52f806aaeca498662032b2efc56d99193238803c..b556fc688be46ceac9f9e5085e3175dd1bd3d191 100644 (file)
@@ -19,6 +19,7 @@
                33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */; };
                33E79E06137B5FD900E32D99 /* mouse-move-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */; };
                37200B9213A16230007A4FAD /* VectorReverse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37200B9113A16230007A4FAD /* VectorReverse.cpp */; };
+               3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */; };
                37DC678D140D7C5000ABCCDB /* DOMRangeOfString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */; };
                37DC6791140D7D7600ABCCDB /* DOMRangeOfString.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */; };
                4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */; };
                33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash_Bundle.cpp; sourceTree = "<group>"; };
                33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "mouse-move-listener.html"; sourceTree = "<group>"; };
                37200B9113A16230007A4FAD /* VectorReverse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VectorReverse.cpp; path = WTF/VectorReverse.cpp; sourceTree = "<group>"; };
+               3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringByEvaluatingJavaScriptFromString.mm; sourceTree = "<group>"; };
                37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMRangeOfString.mm; sourceTree = "<group>"; };
                37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DOMRangeOfString.html; sourceTree = "<group>"; };
                4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestResultNodeHandle_Bundle.cpp; sourceTree = "<group>"; };
                                37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */,
                                C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */,
                                939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */,
+                               3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                37DC678D140D7C5000ABCCDB /* DOMRangeOfString.mm in Sources */,
                                A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */,
                                939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */,
+                               3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/mac/StringByEvaluatingJavaScriptFromString.mm b/Tools/TestWebKitAPI/Tests/mac/StringByEvaluatingJavaScriptFromString.mm
new file mode 100644 (file)
index 0000000..9d8129b
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2007, 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.
+ */
+
+#import "PlatformUtilities.h"
+#import <wtf/RetainPtr.h>
+
+namespace TestWebKitAPI {
+
+TEST(WebKit1, StringByEvaluatingJavaScriptFromString)
+{
+    // maps expected result <= JavaScript expression
+    RetainPtr<NSDictionary> expressions(AdoptNS, [[NSDictionary alloc] initWithObjectsAndKeys:
+        @"0", @"0",
+        @"0", @"'0'",
+        @"", @"",
+        @"", @"''",
+        @"", @"new String()",
+        @"", @"new String('0')",
+        @"", @"throw 1",
+        @"", @"{ }",
+        @"", @"[ ]",
+        @"", @"//",
+        @"", @"a.b.c",
+        @"", @"(function() { throw 'error'; })()",
+        @"", @"null",
+        @"", @"undefined",
+        @"true", @"true",
+        @"false", @"false",
+        @"", @"alert('Should not be result')",
+        nil
+    ]);
+
+    RetainPtr<WebView> webView (AdoptNS, [[WebView alloc] initWithFrame:NSZeroRect frameName:@"" groupName:@""]);
+
+    for (id expression in expressions.get()) {
+        NSString *expectedResult = [expressions.get() objectForKey:expression];
+        NSString *result = [webView.get() stringByEvaluatingJavaScriptFromString:expression];
+        EXPECT_WK_STREQ(expectedResult, result);
+    }
+
+    [webView.get() close];
+}
+
+} // namespace TestWebKitAPI
index 69e6519d1a1e37c23b12aa46d169abc0c04f6eb4..c3869331cbba1d4edc0c6c1873520cca8ae489f5 100644 (file)
@@ -29,6 +29,7 @@
 #include <WebKit2/WKStringCF.h>
 #include <WebKit2/WKURLCF.h>
 #include <WebKit2/WKURLResponseNS.h>
+#include <wtf/OwnArrayPtr.h>
 #include <wtf/RetainPtr.h>
 
 namespace TestWebKitAPI {
@@ -74,5 +75,14 @@ bool isKeyDown(WKNativeEventPtr event)
     return [event type] == NSKeyDown;
 }
 
+std::string toSTD(NSString *string)
+{
+    size_t bufferSize = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+    OwnArrayPtr<char> buffer = adoptArrayPtr(new char[bufferSize]);
+    size_t stringLength;
+    [string getBytes:buffer.get() maxLength:bufferSize usedLength:&stringLength encoding:NSUTF8StringEncoding options:0 range:NSMakeRange(0, [string length]) remainingRange:0];
+    return std::string(buffer.get(), stringLength);
+}
+
 } // namespace Util
 } // namespace TestWebKitAPI