Diff
Modified: branches/safari-534.53-branch/Tools/ChangeLog (100525 => 100526)
--- branches/safari-534.53-branch/Tools/ChangeLog 2011-11-17 00:39:55 UTC (rev 100525)
+++ branches/safari-534.53-branch/Tools/ChangeLog 2011-11-17 00:46:21 UTC (rev 100526)
@@ -1,3 +1,42 @@
+2011-11-16 Lucas Forschler <lforsch...@apple.com>
+
+ Merge 93052.
+
+ 2011-08-15 Adam Roben <aro...@apple.com>
+
+ Teach TestWebKitAPI/gtest how to print _javascript_ failures nicely
+
+ Failures now give output of the form: foo should be bar but is baz
+
+ Fixes <http://webkit.org/b/66240> It's hard to tell what the actual result of a failed JS
+ test is in TestWebKitAPI's output
+
+ Reviewed by David Levin.
+
+ * TestWebKitAPI/_javascript_Test.cpp:
+ (TestWebKitAPI::_javascript_CallbackContext::_javascript_CallbackContext): Removed now-unused
+ members.
+ (TestWebKitAPI::_javascript_Callback): Changed to just store the result string in the context
+ object, rather than doing any testing of it here.
+ (TestWebKitAPI::runJSTest): Made this function a gtest predicate-formatter. This allows us
+ to use a pretty error message when the test fails.
+
+ * TestWebKitAPI/_javascript_Test.h: Changed runJSTest to a predicate-formatter, and added nice
+ gtest-style macros that wrap it.
+
+ * TestWebKitAPI/Test.h: Removed now-unused TEST_ASSERT_RETURN.
+
+ * TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash.cpp:
+ (TestWebKitAPI::TEST): Changed to use the new macros.
+
+ * TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp:
+ (TestWebKitAPI::createSessionStateContainingFormData): Ditto. Note that this function no
+ longer returns 0 when the JS test fails. That shouldn't have any effect on whether or not
+ the test passes, though. Returning early seems to have been an unnecessary optimization.
+
+ * TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp:
+ (TestWebKitAPI::TEST): Changed to use the new macros.
+
2011-08-29 Lucas Forschler <lforsch...@apple.com>
Merged 92982
Modified: branches/safari-534.53-branch/Tools/TestWebKitAPI/_javascript_Test.cpp (100525 => 100526)
--- branches/safari-534.53-branch/Tools/TestWebKitAPI/_javascript_Test.cpp 2011-11-17 00:39:55 UTC (rev 100525)
+++ branches/safari-534.53-branch/Tools/TestWebKitAPI/_javascript_Test.cpp 2011-11-17 00:46:21 UTC (rev 100526)
@@ -28,17 +28,18 @@
#include "PlatformUtilities.h"
#include "Test.h"
#include <_javascript_Core/_javascript_Core.h>
+#include <_javascript_Core/JSRetainPtr.h>
#include <WebKit2/WKRetainPtr.h>
#include <WebKit2/WKSerializedScriptValue.h>
+#include <wtf/OwnArrayPtr.h>
namespace TestWebKitAPI {
struct _javascript_CallbackContext {
- _javascript_CallbackContext(const char* expectedString) : didFinish(false), expectedString(expectedString), didMatchExpectedString(false) { }
+ _javascript_CallbackContext() : didFinish(false) { }
bool didFinish;
- const char* expectedString;
- bool didMatchExpectedString;
+ JSRetainPtr<JSStringRef> actualString;
};
static void _javascript_Callback(WKSerializedScriptValueRef resultSerializedScriptValue, WKErrorRef error, void* ctx)
@@ -53,24 +54,30 @@
JSValueRef scriptValue = WKSerializedScriptValueDeserialize(resultSerializedScriptValue, scriptContext, 0);
ASSERT_NOT_NULL(scriptValue);
- JSStringRef scriptString = JSValueToStringCopy(scriptContext, scriptValue, 0);
- ASSERT_NOT_NULL(scriptString);
+ context->actualString.adopt(JSValueToStringCopy(scriptContext, scriptValue, 0));
+ ASSERT_NOT_NULL(context->actualString.get());
context->didFinish = true;
- context->didMatchExpectedString = JSStringIsEqualToUTF8CString(scriptString, context->expectedString);
- JSStringRelease(scriptString);
JSGlobalContextRelease(scriptContext);
EXPECT_NULL(error);
}
-bool runJSTest(WKPageRef page, const char* script, const char* expectedResult)
+::testing::AssertionResult runJSTest(const char*, const char*, const char*, WKPageRef page, const char* script, const char* expectedResult)
{
- _javascript_CallbackContext context(expectedResult);
+ _javascript_CallbackContext context;
WKPageRunJavaScriptInMainFrame(page, Util::toWK(script).get(), &context, _javascript_Callback);
Util::run(&context.didFinish);
- return context.didMatchExpectedString;
+
+ if (JSStringIsEqualToUTF8CString(context.actualString.get(), expectedResult))
+ return ::testing::AssertionSuccess();
+
+ size_t bufferSize = JSStringGetMaximumUTF8CStringSize(context.actualString.get());
+ OwnArrayPtr<char> buffer = adoptArrayPtr(new char[bufferSize]);
+ JSStringGetUTF8CString(context.actualString.get(), buffer.get(), bufferSize);
+
+ return ::testing::AssertionFailure() << script << " should be " << expectedResult << " but is " << buffer.get();
}
} // namespace TestWebKitAPI
Modified: branches/safari-534.53-branch/Tools/TestWebKitAPI/_javascript_Test.h (100525 => 100526)
--- branches/safari-534.53-branch/Tools/TestWebKitAPI/_javascript_Test.h 2011-11-17 00:39:55 UTC (rev 100525)
+++ branches/safari-534.53-branch/Tools/TestWebKitAPI/_javascript_Test.h 2011-11-17 00:46:21 UTC (rev 100526)
@@ -23,10 +23,16 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <gtest/gtest.h>
+
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);
+// These macros execute |script| in the page and wait until it has run, then compare its return
+// value to the expected result.
+#define EXPECT_JS_EQ(page, script, result) EXPECT_PRED_FORMAT3(runJSTest, page, script, result)
+#define EXPECT_JS_FALSE(page, script) EXPECT_JS_EQ(page, script, "false")
+#define EXPECT_JS_TRUE(page, script) EXPECT_JS_EQ(page, script, "true")
+::testing::AssertionResult runJSTest(const char* pageExpr, const char* scriptExpr, const char* expectedResultExpr, WKPageRef, const char* script, const char* expectedResult);
+
} // namespace TestWebKitAPI
Modified: branches/safari-534.53-branch/Tools/TestWebKitAPI/Test.h (100525 => 100526)
--- branches/safari-534.53-branch/Tools/TestWebKitAPI/Test.h 2011-11-17 00:39:55 UTC (rev 100525)
+++ branches/safari-534.53-branch/Tools/TestWebKitAPI/Test.h 2011-11-17 00:46:21 UTC (rev 100526)
@@ -42,14 +42,6 @@
#define ASSERT_NULL(_expression_) \
ASSERT_TRUE(!(_expression_))
-#define TEST_ASSERT_RETURN(_expression_, returnValue) \
- do { \
- if (!(_expression_)) { \
- EXPECT_FALSE(true) << #_expression_; \
- return (returnValue); \
- } \
- } while (0)
-
} // namespace TestWebKitAPI
#endif // Test_h
Modified: branches/safari-534.53-branch/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash.cpp (100525 => 100526)
--- branches/safari-534.53-branch/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash.cpp 2011-11-17 00:39:55 UTC (rev 100525)
+++ branches/safari-534.53-branch/Tools/TestWebKitAPI/Tests/WebKit2/MouseMoveAfterCrash.cpp 2011-11-17 00:46:21 UTC (rev 100526)
@@ -83,13 +83,13 @@
// Wait until we load the page a second time (via reloading the page in processDidCrash).
Util::run(&didFinishLoad);
- EXPECT_TRUE(runJSTest(webView.page(), "didMoveMouse()", "false"));
+ EXPECT_JS_FALSE(webView.page(), "didMoveMouse()");
// Once the page has reloaded, try moving the mouse to verify that we get mouse move events.
webView.simulateMouseMove(10, 10);
webView.simulateMouseMove(20, 20);
- EXPECT_TRUE(runJSTest(webView.page(), "didMoveMouse()", "true"));
+ EXPECT_JS_TRUE(webView.page(), "didMoveMouse()");
}
} // namespace TestWebKitAPI
Modified: branches/safari-534.53-branch/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp (100525 => 100526)
--- branches/safari-534.53-branch/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp 2011-11-17 00:39:55 UTC (rev 100525)
+++ branches/safari-534.53-branch/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp 2011-11-17 00:46:21 UTC (rev 100526)
@@ -57,7 +57,7 @@
Util::run(&didFinishLoad);
didFinishLoad = false;
- TEST_ASSERT_RETURN(runJSTest(webView.page(), "submitForm()", "undefined"), 0);
+ EXPECT_JS_EQ(webView.page(), "submitForm()", "undefined");
Util::run(&didFinishLoad);
didFinishLoad = false;
Modified: branches/safari-534.53-branch/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp (100525 => 100526)
--- branches/safari-534.53-branch/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp 2011-11-17 00:39:55 UTC (rev 100525)
+++ branches/safari-534.53-branch/Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp 2011-11-17 00:46:21 UTC (rev 100526)
@@ -68,13 +68,13 @@
WKPageLoadURL(webView.page(), url.get());
Util::run(&didFinishLoad);
- EXPECT_TRUE(runJSTest(webView.page(), "isDocumentScrolled()", "false"));
- EXPECT_TRUE(runJSTest(webView.page(), "textFieldContainsSpace()", "false"));
+ EXPECT_JS_FALSE(webView.page(), "isDocumentScrolled()");
+ EXPECT_JS_FALSE(webView.page(), "textFieldContainsSpace()");
webView.simulateSpacebarKeyPress();
- EXPECT_TRUE(runJSTest(webView.page(), "isDocumentScrolled()", "false"));
- EXPECT_TRUE(runJSTest(webView.page(), "textFieldContainsSpace()", "true"));
+ EXPECT_JS_FALSE(webView.page(), "isDocumentScrolled()");
+ EXPECT_JS_TRUE(webView.page(), "textFieldContainsSpace()");
// On Mac, a key down event represents both a raw key down and a key press. On Windows, a key
// down event only represents a raw key down. We expect the key press to be handled (because it
@@ -85,13 +85,13 @@
EXPECT_TRUE(didNotHandleKeyDownEvent);
#endif
- EXPECT_TRUE(runJSTest(webView.page(), "blurTextField()", "undefined"));
+ EXPECT_JS_EQ(webView.page(), "blurTextField()", "undefined");
didNotHandleKeyDownEvent = false;
webView.simulateSpacebarKeyPress();
- EXPECT_TRUE(runJSTest(webView.page(), "isDocumentScrolled()", "true"));
- EXPECT_TRUE(runJSTest(webView.page(), "textFieldContainsSpace()", "true"));
+ EXPECT_JS_TRUE(webView.page(), "isDocumentScrolled()");
+ EXPECT_JS_TRUE(webView.page(), "textFieldContainsSpace()");
#if PLATFORM(MAC)
EXPECT_FALSE(didNotHandleKeyDownEvent);