Title: [94488] trunk/Tools
Revision
94488
Author
m...@apple.com
Date
2011-09-03 08:57:04 -0700 (Sat, 03 Sep 2011)

Log Message

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.

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (94487 => 94488)


--- trunk/Tools/ChangeLog	2011-09-03 08:29:32 UTC (rev 94487)
+++ trunk/Tools/ChangeLog	2011-09-03 15:57:04 UTC (rev 94488)
@@ -1,3 +1,20 @@
+2011-09-03  Dan Bernstein  <m...@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  <aba...@webkit.org>
 
         garden-o-matic results view should have a better results selector

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (94487 => 94488)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2011-09-03 08:29:32 UTC (rev 94487)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2011-09-03 15:57:04 UTC (rev 94488)
@@ -335,46 +335,6 @@
     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 @@
     [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:@"localhost"];
     [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:@"127.0.0.1"];
 
-    // <rdar://problem/5222911>
-    testStringByEvaluatingJavaScriptFromString();
-
     // http://webkit.org/b/32689
     testThreadIdentifierMap();
 

Modified: trunk/Tools/TestWebKitAPI/PlatformUtilities.h (94487 => 94488)


--- trunk/Tools/TestWebKitAPI/PlatformUtilities.h	2011-09-03 08:29:32 UTC (rev 94487)
+++ trunk/Tools/TestWebKitAPI/PlatformUtilities.h	2011-09-03 15:57:04 UTC (rev 94488)
@@ -29,6 +29,14 @@
 #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 @@
 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);
 

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (94487 => 94488)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2011-09-03 08:29:32 UTC (rev 94487)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2011-09-03 15:57:04 UTC (rev 94488)
@@ -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 */; };
@@ -136,6 +137,7 @@
 		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>"; };
@@ -416,6 +418,7 @@
 				37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */,
 				C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */,
 				939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */,
+				3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -566,6 +569,7 @@
 				37DC678D140D7C5000ABCCDB /* DOMRangeOfString.mm in Sources */,
 				A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */,
 				939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */,
+				3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: trunk/Tools/TestWebKitAPI/Tests/mac/StringByEvaluatingJavaScriptFromString.mm (0 => 94488)


--- trunk/Tools/TestWebKitAPI/Tests/mac/StringByEvaluatingJavaScriptFromString.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/StringByEvaluatingJavaScriptFromString.mm	2011-09-03 15:57:04 UTC (rev 94488)
@@ -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

Modified: trunk/Tools/TestWebKitAPI/mac/PlatformUtilitiesMac.mm (94487 => 94488)


--- trunk/Tools/TestWebKitAPI/mac/PlatformUtilitiesMac.mm	2011-09-03 08:29:32 UTC (rev 94487)
+++ trunk/Tools/TestWebKitAPI/mac/PlatformUtilitiesMac.mm	2011-09-03 15:57:04 UTC (rev 94488)
@@ -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 @@
     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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to