Commit 3f98da78 authored by weinig@apple.com's avatar weinig@apple.com

Add basic pixel testing support to WebKitTestRunner

https://bugs.webkit.org/show_bug.cgi?id=55161

Reviewed by Darin Adler.

* Scripts/old-run-webkit-tests:
Don't print color space information when using WebKitTestRunner since
we don't need to change the screen.

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::initialize):
Add call to initializePlatformDefaults.
        
(WTR::InjectedBundle::done):
Return a dictionary on completion with both the text output and pixel dump override.

* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
Add declaration for initializePlatformDefaults.

* WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
(WTR::LayoutTestController::LayoutTestController):
(WTR::LayoutTestController::dumpAsText):
* WebKitTestRunner/InjectedBundle/LayoutTestController.h:
(WTR::LayoutTestController::shouldDumpPixels):
Make setting dumpAsText override the dump pixels preference.

* WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm: Added.
(WTR::InjectedBundle::initializePlatformDefaults):
Set platform defaults matching DumpRenderTree.

* WebKitTestRunner/InjectedBundle/qt/InjectedBundleQt.cpp: Added.
(WTR::InjectedBundle::initializePlatformDefaults):
* WebKitTestRunner/InjectedBundle/win/InjectedBundleWin.cpp: Added.
(WTR::InjectedBundle::initializePlatformDefaults):
Add stubs for initializePlatformDefaults.

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::runTest):
(WTR::TestController::runTestingServerLoop):
(WTR::TestController::run):
Parse expected pixel results out of stdin and setup the invocation with it.

* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::TestInvocation):
Initialize new members.

(WTR::TestInvocation::~TestInvocation):
(WTR::TestInvocation::setIsPixelTest):
(WTR::sizeWebViewForCurrentTest):
(WTR::TestInvocation::invoke):
(WTR::TestInvocation::dump):
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
* WebKitTestRunner/TestInvocation.h:
Dump pixels in addition to text by calling dumpPixelsAndCompareWithExpected.

* WebKitTestRunner/mac/PlatformWebViewMac.mm:
(WTR::PlatformWebView::PlatformWebView):
Use -[NSColorSpace genericRGBColorSpace] instead of the main screen color space.

* WebKitTestRunner/mac/TestInvocationMac.mm: Added.
(WTR::createCGContextFromPlatformView):
(WTR::computeMD5HashStringForContext):
(WTR::dumpBitmap):
(WTR::forceRepaintFunction):
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected):
Add mac specific pixel dumping support. Right now, we always pull pixels
from the window server.

* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
* WebKitTestRunner/InjectedBundle/qt/InjectedBundle.pro:
* WebKitTestRunner/qt/WebKitTestRunner.pro:
* WebKitTestRunner/win/InjectedBundle.vcproj:
* WebKitTestRunner/win/WebKitTestRunner.vcproj:
Add new files.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@79612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 062302ba
2011-02-24 Sam Weinig <sam@webkit.org>
Reviewed by Darin Adler.
Add basic pixel testing support to WebKitTestRunner
https://bugs.webkit.org/show_bug.cgi?id=55161
* Scripts/old-run-webkit-tests:
Don't print color space information when using WebKitTestRunner since
we don't need to change the screen.
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::initialize):
Add call to initializePlatformDefaults.
(WTR::InjectedBundle::done):
Return a dictionary on completion with both the text output and pixel dump override.
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
Add declaration for initializePlatformDefaults.
* WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
(WTR::LayoutTestController::LayoutTestController):
(WTR::LayoutTestController::dumpAsText):
* WebKitTestRunner/InjectedBundle/LayoutTestController.h:
(WTR::LayoutTestController::shouldDumpPixels):
Make setting dumpAsText override the dump pixels preference.
* WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm: Added.
(WTR::InjectedBundle::initializePlatformDefaults):
Set platform defaults matching DumpRenderTree.
* WebKitTestRunner/InjectedBundle/qt/InjectedBundleQt.cpp: Added.
(WTR::InjectedBundle::initializePlatformDefaults):
* WebKitTestRunner/InjectedBundle/win/InjectedBundleWin.cpp: Added.
(WTR::InjectedBundle::initializePlatformDefaults):
Add stubs for initializePlatformDefaults.
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::runTest):
(WTR::TestController::runTestingServerLoop):
(WTR::TestController::run):
Parse expected pixel results out of stdin and setup the invocation with it.
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::TestInvocation):
Initialize new members.
(WTR::TestInvocation::~TestInvocation):
(WTR::TestInvocation::setIsPixelTest):
(WTR::sizeWebViewForCurrentTest):
(WTR::TestInvocation::invoke):
(WTR::TestInvocation::dump):
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
* WebKitTestRunner/TestInvocation.h:
Dump pixels in addition to text by calling dumpPixelsAndCompareWithExpected.
* WebKitTestRunner/mac/PlatformWebViewMac.mm:
(WTR::PlatformWebView::PlatformWebView):
Use -[NSColorSpace genericRGBColorSpace] instead of the main screen color space.
* WebKitTestRunner/mac/TestInvocationMac.mm: Added.
(WTR::createCGContextFromPlatformView):
(WTR::computeMD5HashStringForContext):
(WTR::dumpBitmap):
(WTR::forceRepaintFunction):
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected):
Add mac specific pixel dumping support. Right now, we always pull pixels
from the window server.
* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
* WebKitTestRunner/InjectedBundle/qt/InjectedBundle.pro:
* WebKitTestRunner/qt/WebKitTestRunner.pro:
* WebKitTestRunner/win/InjectedBundle.vcproj:
* WebKitTestRunner/win/WebKitTestRunner.vcproj:
Add new files.
2011-02-24 Chang Shu <cshu@webkit.org>
Reviewed by Kenneth Rohde Christiansen.
......
......@@ -471,10 +471,12 @@ print "Running tests from $testDirectory\n";
if ($pixelTests) {
print "Enabling pixel tests with a tolerance of $tolerance%\n";
if (isDarwin()) {
print "WARNING: Temporarily changing the main display color profile:\n";
print "\tThe colors on your screen will change for the duration of the testing.\n";
print "\tThis allows the pixel tests to have consistent color values across all machines.\n";
if (!$useWebKitTestRunner) {
print "WARNING: Temporarily changing the main display color profile:\n";
print "\tThe colors on your screen will change for the duration of the testing.\n";
print "\tThis allows the pixel tests to have consistent color values across all machines.\n";
}
if (isPerianInstalled()) {
print "WARNING: Perian's QuickTime component is installed and this may affect pixel test results!\n";
print "\tYou should avoid generating new pixel results in this environment.\n";
......
......@@ -86,6 +86,8 @@ void InjectedBundle::initialize(WKBundleRef bundle)
};
WKBundleSetClient(m_bundle, &client);
initializePlatformDefaults();
activateFonts();
WKBundleActivateMacFontAscentHack(m_bundle);
}
......@@ -173,7 +175,15 @@ void InjectedBundle::done()
setTopLoadingFrame(0);
WKRetainPtr<WKStringRef> doneMessageName(AdoptWK, WKStringCreateWithUTF8CString("Done"));
WKRetainPtr<WKStringRef> doneMessageBody(AdoptWK, WKStringCreateWithUTF8CString(m_outputStream.str().c_str()));
WKRetainPtr<WKMutableDictionaryRef> doneMessageBody(AdoptWK, WKMutableDictionaryCreate());
WKRetainPtr<WKStringRef> textOutputKey(AdoptWK, WKStringCreateWithUTF8CString("TextOutput"));
WKRetainPtr<WKStringRef> textOutput(AdoptWK, WKStringCreateWithUTF8CString(m_outputStream.str().c_str()));
WKDictionaryAddItem(doneMessageBody.get(), textOutputKey.get(), textOutput.get());
WKRetainPtr<WKStringRef> textOnlyKey(AdoptWK, WKStringCreateWithUTF8CString("TextOnly"));
WKRetainPtr<WKBooleanRef> textOnly(AdoptWK, WKBooleanCreate(!m_layoutTestController->shouldDumpPixels()));
WKDictionaryAddItem(doneMessageBody.get(), textOnlyKey.get(), textOnly.get());
WKBundlePostMessage(m_bundle, doneMessageName.get(), doneMessageBody.get());
......
......@@ -82,6 +82,7 @@ private:
void didInitializePageGroup(WKBundlePageGroupRef);
void didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody);
void initializePlatformDefaults();
void resetLocalSettings();
void beginTesting();
......
......@@ -94,6 +94,7 @@ LayoutTestController::LayoutTestController()
, m_dumpEditingCallbacks(false)
, m_dumpStatusCallbacks(false)
, m_dumpTitleChanges(false)
, m_dumpPixels(true)
, m_waitToDump(false)
, m_testRepaint(false)
, m_testRepaintSweepHorizontally(false)
......@@ -116,6 +117,12 @@ void LayoutTestController::display()
// FIXME: actually implement, once we want pixel tests
}
void LayoutTestController::dumpAsText()
{
m_whatToDump = MainFrameText;
m_dumpPixels = false;
}
void LayoutTestController::waitUntilDone()
{
m_waitToDump = true;
......
......@@ -55,7 +55,7 @@ public:
void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
// The basics.
void dumpAsText() { m_whatToDump = MainFrameText; }
void dumpAsText();
void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
void waitUntilDone();
void notifyDone();
......@@ -114,6 +114,7 @@ public:
bool shouldDumpMainFrameScrollPosition() const { return m_whatToDump == RenderTree; }
bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
bool shouldDumpPixels() const { return m_dumpPixels; }
bool waitToDump() const { return m_waitToDump; }
void waitToDumpWatchdogTimerFired();
......@@ -154,6 +155,7 @@ private:
bool m_dumpEditingCallbacks;
bool m_dumpStatusCallbacks;
bool m_dumpTitleChanges;
bool m_dumpPixels;
bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
bool m_testRepaint;
bool m_testRepaintSweepHorizontally;
......
/*
* 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 "InjectedBundle.h"
namespace WTR {
void InjectedBundle::initializePlatformDefaults()
{
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:4], @"AppleAntiAliasingThreshold",
[NSNumber numberWithInteger:0], @"AppleFontSmoothing",
[NSNumber numberWithBool:NO], @"AppleScrollAnimationEnabled",
[NSNumber numberWithBool:NO], @"NSOverlayScrollersEnabled",
@"Always", @"AppleShowScrollBars",
nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
}
} // namespace WTR
......@@ -24,6 +24,7 @@ SOURCES += \
../LayoutTestController.h \
../Bindings/JSWrapper.cpp \
ActivateFontsQt.cpp \
InjectedBundleQt.cpp \
LayoutTestControllerQt.cpp \
$$GENERATED_SOURCES_DIR/JSEventSendingController.cpp \
$$GENERATED_SOURCES_DIR/JSGCController.cpp \
......
/*
* 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 "InjectedBundle.h"
namespace WTR {
void InjectedBundle::initializePlatformDefaults()
{
}
} // namespace WTR
/*
* 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 "InjectedBundle.h"
namespace WTR {
void InjectedBundle::initializePlatformDefaults()
{
}
} // namespace WTR
......@@ -384,8 +384,20 @@ bool TestController::runTest(const char* test)
return false;
}
std::string pathOrURL(test);
std::string expectedPixelHash;
size_t separatorPos = pathOrURL.find("'");
if (separatorPos != std::string::npos) {
pathOrURL = std::string(std::string(test), 0, separatorPos);
expectedPixelHash = std::string(std::string(test), separatorPos + 1);
}
m_state = RunningTest;
m_currentInvocation.set(new TestInvocation(test));
m_currentInvocation.set(new TestInvocation(pathOrURL));
if (m_dumpPixels)
m_currentInvocation->setIsPixelTest(expectedPixelHash);
m_currentInvocation->invoke();
m_currentInvocation.clear();
......@@ -396,7 +408,7 @@ void TestController::runTestingServerLoop()
{
char filenameBuffer[2048];
while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) {
char *newLineCharacter = strchr(filenameBuffer, '\n');
char* newLineCharacter = strchr(filenameBuffer, '\n');
if (newLineCharacter)
*newLineCharacter = '\0';
......@@ -418,7 +430,6 @@ void TestController::run()
break;
}
}
}
void TestController::runUntil(bool& done, TimeoutDuration timeoutDuration)
......
......@@ -85,18 +85,25 @@ static WKURLRef createWKURL(const char* pathOrURL)
return WKURLCreateWithUTF8CString(buffer.get());
}
TestInvocation::TestInvocation(const char* pathOrURL)
: m_url(AdoptWK, createWKURL(pathOrURL))
, m_pathOrURL(fastStrDup(pathOrURL))
TestInvocation::TestInvocation(const std::string& pathOrURL)
: m_url(AdoptWK, createWKURL(pathOrURL.c_str()))
, m_pathOrURL(pathOrURL)
, m_dumpPixels(false)
, m_gotInitialResponse(false)
, m_gotFinalMessage(false)
, m_gotRepaint(false)
, m_error(false)
{
}
TestInvocation::~TestInvocation()
{
fastFree(m_pathOrURL);
}
void TestInvocation::setIsPixelTest(const std::string& expectedPixelHash)
{
m_dumpPixels = true;
m_expectedPixelHash = expectedPixelHash;
}
static const unsigned w3cSVGWidth = 480;
......@@ -104,7 +111,7 @@ static const unsigned w3cSVGHeight = 360;
static const unsigned normalWidth = 800;
static const unsigned normalHeight = 600;
static void sizeWebViewForCurrentTest(char* pathOrURL)
static void sizeWebViewForCurrentTest(const char* pathOrURL)
{
bool isSVGW3CTest = strstr(pathOrURL, "svg/W3C-SVG-1.1") || strstr(pathOrURL, "svg\\W3C-SVG-1.1");
......@@ -121,7 +128,7 @@ static bool shouldOpenWebInspector(const char* pathOrURL)
void TestInvocation::invoke()
{
sizeWebViewForCurrentTest(m_pathOrURL);
sizeWebViewForCurrentTest(m_pathOrURL.c_str());
WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("BeginTest"));
WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), 0);
......@@ -136,7 +143,7 @@ void TestInvocation::invoke()
return;
}
if (shouldOpenWebInspector(m_pathOrURL))
if (shouldOpenWebInspector(m_pathOrURL.c_str()))
WKInspectorShow(WKPageGetInspector(TestController::shared().mainWebView()->page()));
WKPageLoadURL(TestController::shared().mainWebView()->page(), m_url.get());
......@@ -155,12 +162,8 @@ void TestInvocation::dump(const char* stringToDump)
printf("Content-Type: text/plain\n");
printf("%s", stringToDump);
fputs("#EOF\n", stdout);
fputs("#EOF\n", stdout);
fputs("#EOF\n", stderr);
fflush(stdout);
fflush(stderr);
}
void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
......@@ -187,11 +190,26 @@ void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName
}
if (WKStringIsEqualToUTF8CString(messageName, "Done")) {
ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
WKStringRef messageBodyString = static_cast<WKStringRef>(messageBody);
ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
WKRetainPtr<WKStringRef> textOutputKey(AdoptWK, WKStringCreateWithUTF8CString("TextOutput"));
WKStringRef textOutput = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, textOutputKey.get()));
WKRetainPtr<WKStringRef> textOnlyKey(AdoptWK, WKStringCreateWithUTF8CString("TextOnly"));
bool textOnly = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, textOnlyKey.get())));
// Dump text.
dump(toSTD(textOutput).c_str());
dump(toSTD(messageBodyString).c_str());
// Dump pixels (if necessary).
if (m_dumpPixels && !textOnly)
dumpPixelsAndCompareWithExpected();
fputs("#EOF\n", stdout);
fflush(stdout);
fflush(stderr);
m_gotFinalMessage = true;
TestController::shared().notifyDone();
return;
......
......@@ -26,6 +26,7 @@
#ifndef TestInvocation_h
#define TestInvocation_h
#include <string>
#include <WebKit2/WKRetainPtr.h>
#include <wtf/Noncopyable.h>
......@@ -34,22 +35,29 @@ namespace WTR {
class TestInvocation {
WTF_MAKE_NONCOPYABLE(TestInvocation);
public:
TestInvocation(const char*);
TestInvocation(const std::string& pathOrURL);
~TestInvocation();
void setIsPixelTest(const std::string& expectedPixelHash);
void invoke();
void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
private:
void dump(const char*);
void dumpPixelsAndCompareWithExpected();
WKRetainPtr<WKURLRef> m_url;
char* m_pathOrURL;
std::string m_pathOrURL;
bool m_dumpPixels;
std::string m_expectedPixelHash;
// Invocation state
bool m_gotInitialResponse;
bool m_gotFinalMessage;
bool m_gotRepaint;
bool m_error;
};
......
......@@ -47,6 +47,8 @@
BC7934AC1190658C005EA8E2 /* WebKit2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC7934AB1190658C005EA8E2 /* WebKit2.framework */; };
BC7934E811906846005EA8E2 /* PlatformWebViewMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC7934E711906846005EA8E2 /* PlatformWebViewMac.mm */; };
BC8C795C11D2785D004535A1 /* TestControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC8C795B11D2785D004535A1 /* TestControllerMac.mm */; };
BC8DAD5D1315C0EC00EC96FC /* TestInvocationMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC8DAD5B1315C0EC00EC96FC /* TestInvocationMac.mm */; };
BC8DAD7B1316D91000EC96FC /* InjectedBundleMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC8DAD771316D7B900EC96FC /* InjectedBundleMac.mm */; };
BC8FD8CA120E527F00F3E71A /* EventSendingController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC8FD8C9120E527F00F3E71A /* EventSendingController.cpp */; };
BC8FD8D2120E545B00F3E71A /* JSEventSendingController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC8FD8D0120E545B00F3E71A /* JSEventSendingController.cpp */; };
BC952C0D11F3B965003398B4 /* JSWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC952C0C11F3B965003398B4 /* JSWrapper.cpp */; };
......@@ -113,6 +115,8 @@
BC7934DD119066EC005EA8E2 /* PlatformWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformWebView.h; sourceTree = "<group>"; };
BC7934E711906846005EA8E2 /* PlatformWebViewMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformWebViewMac.mm; sourceTree = "<group>"; };
BC8C795B11D2785D004535A1 /* TestControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestControllerMac.mm; sourceTree = "<group>"; };
BC8DAD5B1315C0EC00EC96FC /* TestInvocationMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestInvocationMac.mm; sourceTree = "<group>"; };
BC8DAD771316D7B900EC96FC /* InjectedBundleMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InjectedBundleMac.mm; sourceTree = "<group>"; };
BC8FD8C8120E527F00F3E71A /* EventSendingController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventSendingController.h; sourceTree = "<group>"; };
BC8FD8C9120E527F00F3E71A /* EventSendingController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventSendingController.cpp; sourceTree = "<group>"; };
BC8FD8CB120E52B000F3E71A /* EventSendingController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = EventSendingController.idl; sourceTree = "<group>"; };
......@@ -218,6 +222,7 @@
isa = PBXGroup;
children = (
65EB859F11EC67CC0034D300 /* ActivateFonts.mm */,
BC8DAD771316D7B900EC96FC /* InjectedBundleMac.mm */,
);
path = mac;
sourceTree = "<group>";
......@@ -278,6 +283,7 @@
BC7933FF118F7C84005EA8E2 /* main.mm */,
BC7934E711906846005EA8E2 /* PlatformWebViewMac.mm */,
BC8C795B11D2785D004535A1 /* TestControllerMac.mm */,
BC8DAD5B1315C0EC00EC96FC /* TestInvocationMac.mm */,
);
path = mac;
sourceTree = "<group>";
......@@ -440,6 +446,7 @@
BC793431118F7F19005EA8E2 /* TestController.cpp in Sources */,
BC7934E811906846005EA8E2 /* PlatformWebViewMac.mm in Sources */,
BCD7D2F811921278006DB7EE /* TestInvocation.cpp in Sources */,
BC8DAD5D1315C0EC00EC96FC /* TestInvocationMac.mm in Sources */,
BC8C795C11D2785D004535A1 /* TestControllerMac.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -457,6 +464,7 @@
BC952F1F11F3C652003398B4 /* JSLayoutTestController.cpp in Sources */,
BC14E4DB120E02D000826C0C /* GCController.cpp in Sources */,
BC14E4EA120E03D800826C0C /* JSGCController.cpp in Sources */,
BC8DAD7B1316D91000EC96FC /* InjectedBundleMac.mm in Sources */,
BC8FD8CA120E527F00F3E71A /* EventSendingController.cpp in Sources */,
BC8FD8D2120E545B00F3E71A /* JSEventSendingController.cpp in Sources */,
C0CE720B1247C93300BC0EC4 /* LayoutTestControllerMac.mm in Sources */,
......
......@@ -34,7 +34,7 @@ PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGro
NSRect windowRect = NSOffsetRect(rect, -10000, [[[NSScreen screens] objectAtIndex:0] frame].size.height - rect.size.height + 10000);
m_window = [[NSWindow alloc] initWithContentRect:windowRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
[m_window setColorSpace:[[NSScreen mainScreen] colorSpace]];
[m_window setColorSpace:[NSColorSpace genericRGBColorSpace]];
[[m_window contentView] addSubview:m_view];
[m_window orderBack:nil];
[m_window setAutodisplay:NO];
......
/*
* 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 "TestInvocation.h"
#include "PlatformWebView.h"
#include "TestController.h"
#include <ImageIO/CGImageDestination.h>
#include <LaunchServices/UTCoreTypes.h>
#include <WebKit2/WKPage.h>
#include <wtf/RetainPtr.h>
#define COMMON_DIGEST_FOR_OPENSSL
#include <CommonCrypto/CommonDigest.h>
namespace WTR {
static CGContextRef createCGContextFromPlatformView(PlatformWebView* platformWebView)
{
WKView* view = platformWebView->platformView();
[view display];
NSSize webViewSize = [view frame].size;
size_t pixelsWide = static_cast<size_t>(webViewSize.width);
size_t pixelsHigh = static_cast<size_t>(webViewSize.height);
size_t rowBytes = (4 * pixelsWide + 63) & ~63;
void* buffer = calloc(pixelsHigh, rowBytes);
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGContextRef context = CGBitmapContextCreate(buffer, pixelsWide, pixelsHigh, 8, rowBytes, colorSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
CGColorSpaceRelease(colorSpace);
CGImageRef image = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, [[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque);
CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image);
CGImageRelease(image);
return context;
}
void computeMD5HashStringForContext(CGContextRef bitmapContext, char hashString[33])
{
ASSERT(CGBitmapContextGetBitsPerPixel(bitmapContext) == 32); // ImageDiff assumes 32 bit RGBA, we must as well.
size_t pixelsHigh = CGBitmapContextGetHeight(bitmapContext);
size_t pixelsWide = CGBitmapContextGetWidth(bitmapContext);
size_t bytesPerRow = CGBitmapContextGetBytesPerRow(bitmapContext);
// We need to swap the bytes to ensure consistent hashes independently of endianness
MD5_CTX md5Context;
MD5_Init(&md5Context);
unsigned char* bitmapData = static_cast<unsigned char*>(CGBitmapContextGetData(bitmapContext));
if ((CGBitmapContextGetBitmapInfo(bitmapContext) & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Big) {
for (unsigned row = 0; row < pixelsHigh; row++) {
uint32_t buffer[pixelsWide];
for