[Qt] Add test specific platform plugin to achieve unified layout test results
authorkbalazs@webkit.org <kbalazs@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 May 2012 11:49:00 +0000 (11:49 +0000)
committerkbalazs@webkit.org <kbalazs@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 May 2012 11:49:00 +0000 (11:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80996

Reviewed by Simon Hausmann.

Source/WebKit2:

Initialize the test platform plugin before initializing
the web process if we are in a WTR run.
It is necessary to place this initialization here as we
cannot control wich platform plugin will be used after
the instantiation of the QApplication.

* qt/MainQt.cpp:
(initializeTestPlatformPluginForWTRIfRequired):
(main):

Tools:

Added QtTestPlatformPlugin as a new project under Tools.
This is a Qt5-ish platform plugin that can be used to tweak the
platform support interfaces in order to unify layout test results.
For now it only overrides the font database on Mac and redirects
everything else to the real platform plugin. The font database it
provides mimics the way how we set up test fonts with fontconfig on Linux.
Make DumpRenderTree and WebKitTestRunner use this platform plugin.

* DumpRenderTree/qt/DumpRenderTree.pro:
* DumpRenderTree/qt/main.cpp:
(initializeTestPlatformPlugin):
(main):
* QtTestPlatformPlugin/QtTestPlatformPlugin.pro: Added.
* QtTestPlatformPlugin/TestIntegration.cpp: Added.
(TestIntegration::TestIntegration):
(TestIntegration::fontDatabase):
* QtTestPlatformPlugin/TestIntegration.h: Added.
(TestIntegration):
(TestIntegration::hasCapability):
(TestIntegration::createPlatformPixmap):
(TestIntegration::createPlatformWindow):
(TestIntegration::createPlatformBackingStore):
(TestIntegration::createPlatformOpenGLContext):
(TestIntegration::createPlatformSharedGraphicsCache):
(TestIntegration::guiThreadEventDispatcher):
(TestIntegration::clipboard):
(TestIntegration::drag):
(TestIntegration::inputContext):
(TestIntegration::accessibility):
(TestIntegration::nativeInterface):
(TestIntegration::services):
(TestIntegration::styleHint):
(TestIntegration::platformTheme):
* QtTestPlatformPlugin/mac/TestFontDatabase.h: Added.
(TestFontDatabase):
* QtTestPlatformPlugin/mac/TestFontDatabase.mm: Added.
(TestFontDatabase::populateFontDatabase):
* QtTestPlatformPlugin/mac/TestIntegrationMac.mm: Added.
(TestIntegration::fontDatabase):
* QtTestPlatformPlugin/main.cpp: Added.
(TestIntegrationPlugin::keys):
(TestIntegrationPlugin::create):
(TestIntegrationPlugin::initialize):
* QtTestPlatformPlugin/testplatform.json: Added.
* Tools.pro:
* WebKitTestRunner/Target.pri:
* WebKitTestRunner/qt/main.cpp:
(main):

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

16 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/qt/MainQt.cpp
Tools/ChangeLog
Tools/DumpRenderTree/qt/DumpRenderTree.pro
Tools/DumpRenderTree/qt/main.cpp
Tools/QtTestPlatformPlugin/QtTestPlatformPlugin.pro [new file with mode: 0644]
Tools/QtTestPlatformPlugin/TestIntegration.cpp [new file with mode: 0644]
Tools/QtTestPlatformPlugin/TestIntegration.h [new file with mode: 0644]
Tools/QtTestPlatformPlugin/mac/TestFontDatabase.h [new file with mode: 0644]
Tools/QtTestPlatformPlugin/mac/TestFontDatabase.mm [new file with mode: 0644]
Tools/QtTestPlatformPlugin/mac/TestIntegrationMac.mm [new file with mode: 0644]
Tools/QtTestPlatformPlugin/main.cpp [new file with mode: 0644]
Tools/QtTestPlatformPlugin/testplatform.json [new file with mode: 0644]
Tools/Tools.pro
Tools/WebKitTestRunner/Target.pri
Tools/WebKitTestRunner/qt/main.cpp

index 03d1095..3b73221 100644 (file)
@@ -1,3 +1,20 @@
+2012-05-07  Balazs Kelemen  <kbalazs@webkit.org>
+
+        [Qt] Add test specific platform plugin to achieve unified layout test results
+        https://bugs.webkit.org/show_bug.cgi?id=80996
+
+        Reviewed by Simon Hausmann.
+
+        Initialize the test platform plugin before initializing
+        the web process if we are in a WTR run.
+        It is necessary to place this initialization here as we
+        cannot control wich platform plugin will be used after
+        the instantiation of the QApplication.
+
+        * qt/MainQt.cpp:
+        (initializeTestPlatformPluginForWTRIfRequired):
+        (main):
+
 2012-05-06  MORITA Hajime  <morrita@google.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=85265
index def1b3f..2543d29 100644 (file)
  */
 
 #include <QApplication>
-
+#include <QByteArray>
+#include <QFile>
+#include <QPlatformIntegration>
+#include <QPlatformIntegrationPlugin>
+#include <QPluginLoader>
 #include <stdio.h>
 
 namespace WebKit {
@@ -43,6 +47,21 @@ static void messageHandler(QtMsgType type, const char* message)
     // Do nothing
 }
 
+static void initializeTestPlatformPluginForWTRIfRequired()
+{
+    QByteArray pluginPath = qgetenv("QT_WEBKIT2_TEST_PLATFORM_PLUGIN_PATH");
+    if (pluginPath.isEmpty())
+        return;
+
+    QPluginLoader loader(QFile::decodeName(pluginPath.data()));
+    QPlatformIntegrationPlugin* plugin = qobject_cast<QPlatformIntegrationPlugin*>(loader.instance());
+    if (!plugin)
+        qFatal("cannot initialize test platform plugin\n");
+
+    qputenv("QT_QPA_PLATFORM_PLUGIN_PATH", pluginPath);
+    qputenv("QT_QPA_PLATFORM", "testplatform");
+}
+
 // The framework entry point.
 // We call our platform specific entry point directly rather than WebKitMain because it makes little sense
 // to reimplement the handling of command line arguments from QApplication.
@@ -56,6 +75,7 @@ int main(int argc, char** argv)
     }
 #endif
 
+    initializeTestPlatformPluginForWTRIfRequired();
     WebKit::initializeWebKit2Theme();
 
     // Has to be done before QApplication is constructed in case
index 3394f9f..8296644 100644 (file)
@@ -1,3 +1,59 @@
+2012-05-07  Balazs Kelemen  <kbalazs@webkit.org>
+
+        [Qt] Add test specific platform plugin to achieve unified layout test results
+        https://bugs.webkit.org/show_bug.cgi?id=80996
+
+        Reviewed by Simon Hausmann.
+
+        Added QtTestPlatformPlugin as a new project under Tools.
+        This is a Qt5-ish platform plugin that can be used to tweak the
+        platform support interfaces in order to unify layout test results.
+        For now it only overrides the font database on Mac and redirects
+        everything else to the real platform plugin. The font database it
+        provides mimics the way how we set up test fonts with fontconfig on Linux.
+        Make DumpRenderTree and WebKitTestRunner use this platform plugin.
+
+        * DumpRenderTree/qt/DumpRenderTree.pro:
+        * DumpRenderTree/qt/main.cpp:
+        (initializeTestPlatformPlugin):
+        (main):
+        * QtTestPlatformPlugin/QtTestPlatformPlugin.pro: Added.
+        * QtTestPlatformPlugin/TestIntegration.cpp: Added.
+        (TestIntegration::TestIntegration):
+        (TestIntegration::fontDatabase):
+        * QtTestPlatformPlugin/TestIntegration.h: Added.
+        (TestIntegration):
+        (TestIntegration::hasCapability):
+        (TestIntegration::createPlatformPixmap):
+        (TestIntegration::createPlatformWindow):
+        (TestIntegration::createPlatformBackingStore):
+        (TestIntegration::createPlatformOpenGLContext):
+        (TestIntegration::createPlatformSharedGraphicsCache):
+        (TestIntegration::guiThreadEventDispatcher):
+        (TestIntegration::clipboard):
+        (TestIntegration::drag):
+        (TestIntegration::inputContext):
+        (TestIntegration::accessibility):
+        (TestIntegration::nativeInterface):
+        (TestIntegration::services):
+        (TestIntegration::styleHint):
+        (TestIntegration::platformTheme):
+        * QtTestPlatformPlugin/mac/TestFontDatabase.h: Added.
+        (TestFontDatabase):
+        * QtTestPlatformPlugin/mac/TestFontDatabase.mm: Added.
+        (TestFontDatabase::populateFontDatabase):
+        * QtTestPlatformPlugin/mac/TestIntegrationMac.mm: Added.
+        (TestIntegration::fontDatabase):
+        * QtTestPlatformPlugin/main.cpp: Added.
+        (TestIntegrationPlugin::keys):
+        (TestIntegrationPlugin::create):
+        (TestIntegrationPlugin::initialize):
+        * QtTestPlatformPlugin/testplatform.json: Added.
+        * Tools.pro:
+        * WebKitTestRunner/Target.pri:
+        * WebKitTestRunner/qt/main.cpp:
+        (main):
+
 2012-05-07  Christophe Dumez  <christophe.dumez@intel.com>
 
         [EFL] media/video-poster-blocked-by-willsendrequest.html is flaky
index 2aa54cd..a6a2559 100644 (file)
@@ -57,4 +57,9 @@ wince*: {
 DEFINES -= USE_SYSTEM_MALLOC=0
 DEFINES += USE_SYSTEM_MALLOC=1
 
+mac: LIB_SUFFIX=.dylib
+win: LIB_SUFFIX=.dll
+unix:!mac: LIB_SUFFIX=.so
+DEFINES += TEST_PLATFORM_PLUGIN_PATH=\"\\\"$${ROOT_BUILD_DIR}$${QMAKE_DIR_SEP}lib$${QMAKE_DIR_SEP}libtestplatform$${LIB_SUFFIX}\\\"\"
+
 RESOURCES = DumpRenderTree.qrc
index 1763367..519808b 100644 (file)
 
 #include "QtInitializeTestFonts.h"
 
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#include <QPlatformIntegration>
+#include <QPlatformIntegrationPlugin>
+#include <QPluginLoader>
+#endif
+
 #include <wtf/AlwaysInline.h>
 
 #include <qstringlist.h>
@@ -123,6 +129,32 @@ static void WTFCrashHook()
 }
 #endif
 
+static void initializeTestPlatformPlugin(int argc, char* argv[] const)
+{
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+    QPluginLoader loader(TEST_PLATFORM_PLUGIN_PATH);
+    QPlatformIntegrationPlugin* plugin = qobject_cast<QPlatformIntegrationPlugin*>(loader.instance());
+    if (!plugin)
+        qFatal("cannot initialize test platform plugin\n");
+
+    QByteArray platform = qgetenv("QT_QPA_PLATFORM");
+    QByteArray platformPluginPath = qgetenv("QT_QPA_PLATFORM_PLUGIN_PATH");
+    for (int i = 0; i < argc; ++i) {
+        if (QByteArray(argv[i]) == "-platform" && i + 1 < argc)
+            platform = argv[i + 1];
+        else if (QByteArray(argv[i]) == "-platformpluginpath" && i + 1 < argc)
+            platformPluginPath = argv[i + 1];
+    }
+    if (!platform.isEmpty())
+        qputenv("QT_WEBKIT_ORIGINAL_PLATFORM", platform);
+    if (!platformPluginPath.isEmpty())
+        qputenv("QT_WEBKIT_ORIGINAL_PLATFORM_PLUGIN_PATH", platformPluginPath);
+
+    qputenv("QT_QPA_PLATFORM_PLUGIN_PATH", TEST_PLATFORM_PLUGIN_PATH);
+    qputenv("QT_QPA_PLATFORM", "testplatform");
+#endif
+}
+
 int main(int argc, char* argv[])
 {
 #ifdef Q_OS_WIN
@@ -146,6 +178,8 @@ int main(int argc, char* argv[])
 
     WebKit::initializeTestFonts();
 
+    initializeTestPlatformPlugin(argc, argv);
+
     QApplication::setGraphicsSystem("raster");
     QApplication::setStyle(new QWindowsStyle);
 
diff --git a/Tools/QtTestPlatformPlugin/QtTestPlatformPlugin.pro b/Tools/QtTestPlatformPlugin/QtTestPlatformPlugin.pro
new file mode 100644 (file)
index 0000000..c9528a6
--- /dev/null
@@ -0,0 +1,20 @@
+TARGET = testplatform
+DESTDIR = $$ROOT_BUILD_DIR/lib
+
+load(qt_plugin)
+QT = core gui core-private gui-private platformsupport-private
+
+HEADERS = \
+    TestIntegration.h \
+
+SOURCES = \
+    main.cpp \
+    TestIntegration.cpp \
+
+mac {
+    LIBS += -framework Foundation
+    OBJECTIVE_HEADERS += mac/TestFontDatabase.h
+    OBJECTIVE_SOURCES += \
+        mac/TestFontDatabase.mm \
+        mac/TestIntegrationMac.mm \
+}
diff --git a/Tools/QtTestPlatformPlugin/TestIntegration.cpp b/Tools/QtTestPlatformPlugin/TestIntegration.cpp
new file mode 100644 (file)
index 0000000..1430c6a
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2012 University of Szeged. 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 UNIVERSITY OF SZEGED ``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 UNIVERSITY OF SZEGED OR
+ * 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 "TestIntegration.h"
+#include <QCoreApplication>
+#include <QStringList>
+#include <QtGlobal>
+#include <QtGui/private/qplatformintegrationfactory_qpa_p.h>
+#include <qsystemdetection.h>
+
+TestIntegration::TestIntegration()
+{
+    QString defaultPlatform =
+#if defined(Q_OS_MAC)
+        QLatin1String("cocoa");
+#elif defined (Q_OS_WIN)
+        QLatin1String("windows");
+#elif !defined (QT_NO_XCB)
+        QLatin1String("xcb");
+#elif !defined (QT_NO_WAYLAND)
+        QLatin1String("wayland");
+#else
+        QLatin1String("minimal");
+#endif
+
+    QByteArray originalPlatform = qgetenv("QT_WEBKIT_ORIGINAL_PLATFORM");
+    QByteArray originalPluginPath = qgetenv("QT_WEBKIT_ORIGINAL_PLATFORM_PLUGIN_PATH");
+    QString platform = originalPlatform.isEmpty() ? defaultPlatform : QString::fromLatin1(originalPlatform.data());
+    QString pluginPath = originalPluginPath.isEmpty() ? QString() : QString::fromLatin1(originalPluginPath.data());
+
+    m_integration.reset(QPlatformIntegrationFactory::create(platform, pluginPath));
+}
+
+#if !defined(Q_OS_MAC)
+QPlatformFontDatabase* TestIntegration::fontDatabase() const
+{
+    return m_integration->fontDatabase();
+}
+#endif
diff --git a/Tools/QtTestPlatformPlugin/TestIntegration.h b/Tools/QtTestPlatformPlugin/TestIntegration.h
new file mode 100644 (file)
index 0000000..9e48e15
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 University of Szeged. 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 UNIVERSITY OF SZEGED ``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 UNIVERSITY OF SZEGED OR
+ * 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.
+ */
+
+#ifndef TestIntegration_h
+#define TestIntegration_h
+
+#include <QPlatformFontDatabase>
+#include <QPlatformIntegration>
+#include <QPlatformScreen>
+
+class TestIntegration : public QPlatformIntegration {
+public:
+    TestIntegration();
+private:
+    virtual QPlatformFontDatabase *fontDatabase() const;
+
+    // Redirecting everything else.
+    virtual bool hasCapability(Capability cap) { return m_integration->hasCapability(cap); }
+    virtual QPlatformPixmap* createPlatformPixmap(QPlatformPixmap::PixelType type) const { return m_integration->createPlatformPixmap(type); }
+    virtual QPlatformWindow* createPlatformWindow(QWindow *window) const { return m_integration->createPlatformWindow(window); }
+    virtual QPlatformBackingStore* createPlatformBackingStore(QWindow *window) const { return m_integration->createPlatformBackingStore(window); }
+#ifndef QT_NO_OPENGL
+    virtual QPlatformOpenGLContext* createPlatformOpenGLContext(QOpenGLContext *context) const { return m_integration->createPlatformOpenGLContext(context); }
+#endif
+    virtual QPlatformSharedGraphicsCache* createPlatformSharedGraphicsCache(const char *cacheId) const { return m_integration->createPlatformSharedGraphicsCache(cacheId); }
+    virtual QAbstractEventDispatcher* guiThreadEventDispatcher() const { return m_integration->guiThreadEventDispatcher(); }
+#ifndef QT_NO_CLIPBOARD
+    virtual QPlatformClipboard* clipboard() const { return m_integration->clipboard(); }
+#endif
+#ifndef QT_NO_DRAGANDDROP
+    virtual QPlatformDrag* drag() const { return m_integration->drag(); }
+#endif
+    virtual QPlatformInputContext* inputContext() const { return m_integration->inputContext(); }
+    virtual QPlatformAccessibility* accessibility() const { return m_integration->accessibility(); }
+    virtual QPlatformNativeInterface* nativeInterface() const { return m_integration->nativeInterface(); }
+    virtual QPlatformServices* services() const { return m_integration->services(); }
+    virtual QVariant styleHint(StyleHint hint) const { return m_integration->styleHint(hint); }
+    virtual QPlatformTheme* createPlatformTheme(const QString& name) const { return m_integration->createPlatformTheme(name); }
+
+    QScopedPointer<QPlatformIntegration> m_integration;
+#if defined(Q_OS_MAC)
+    mutable QScopedPointer<QPlatformFontDatabase> m_fontDatabase;
+#endif
+};
+
+#endif
diff --git a/Tools/QtTestPlatformPlugin/mac/TestFontDatabase.h b/Tools/QtTestPlatformPlugin/mac/TestFontDatabase.h
new file mode 100644 (file)
index 0000000..a08ae52
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2012 University of Szeged. All rights reserved.
+ *
+ * GNU Lesser General Public License Usage
+ * This file may be used under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ * Please review the following information to ensure the GNU Lesser
+ * General Public License version 2.1 requirements will be met:
+ * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ *
+ * GNU General Public License Usage
+ * Alternatively, this file may be used under the terms of the GNU General
+ * Public License version 3.0 as published by the Free Software Foundation.
+ * Please review the following information to ensure the GNU General Public
+ * License version 3.0 requirements will be met:
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ */
+
+#ifndef TestFontDatabase_h
+#define TestFontDatabase_h
+
+#include <QFont>
+#include <QtPlatformSupport/private/qcoretextfontdatabase_p.h>
+
+class TestFontDatabase : public QCoreTextFontDatabase {
+private:
+    virtual void populateFontDatabase();
+    virtual QFont defaultFont() const;
+};
+
+#endif
diff --git a/Tools/QtTestPlatformPlugin/mac/TestFontDatabase.mm b/Tools/QtTestPlatformPlugin/mac/TestFontDatabase.mm
new file mode 100644 (file)
index 0000000..eb267fe
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2012 University of Szeged. All rights reserved.
+ *
+ * GNU Lesser General Public License Usage
+ * This file may be used under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ * Please review the following information to ensure the GNU Lesser
+ * General Public License version 2.1 requirements will be met:
+ * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ *
+ * GNU General Public License Usage
+ * Alternatively, this file may be used under the terms of the GNU General
+ * Public License version 3.0 as published by the Free Software Foundation.
+ * Please review the following information to ensure the GNU General Public
+ * License version 3.0 requirements will be met:
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ */
+
+#include "TestFontDatabase.h"
+#include <QtCore/QDir>
+#include <QtCore/QFileInfo>
+#include <QtCore/private/qcore_mac_p.h>
+#include <QtPlatformSupport/private/qfontengine_coretext_p.h>
+#import <Foundation/Foundation.h>
+
+// From Qt.
+static const char *languageForWritingSystem[] = {
+    0,     // Any
+    "en",  // Latin
+    "el",  // Greek
+    "ru",  // Cyrillic
+    "hy",  // Armenian
+    "he",  // Hebrew
+    "ar",  // Arabic
+    "syr", // Syriac
+    "div", // Thaana
+    "hi",  // Devanagari
+    "bn",  // Bengali
+    "pa",  // Gurmukhi
+    "gu",  // Gujarati
+    "or",  // Oriya
+    "ta",  // Tamil
+    "te",  // Telugu
+    "kn",  // Kannada
+    "ml",  // Malayalam
+    "si",  // Sinhala
+    "th",  // Thai
+    "lo",  // Lao
+    "bo",  // Tibetan
+    "my",  // Myanmar
+    "ka",  // Georgian
+    "km",  // Khmer
+    "zh-cn", // SimplifiedChinese
+    "zh-tw", // TraditionalChinese
+    "ja",  // Japanese
+    "ko",  // Korean
+    "vi",  // Vietnamese
+    0, // Symbol
+    0, // Ogham
+    0, // Runic
+    0 // N'Ko
+};
+enum { LanguageCount = sizeof(languageForWritingSystem) / sizeof(const char*) };
+
+QFont TestFontDatabase::defaultFont() const
+{
+    return QFont(QStringLiteral("Nimbus Sans L"));
+}
+
+void TestFontDatabase::populateFontDatabase()
+{
+    // Determine the set of default system fonts in order to filter them out.
+    QCFType<CTFontCollectionRef> systemCollection(CTFontCollectionCreateFromAvailableFonts(0));
+    QCFType<CFArrayRef> systemFonts = systemCollection ? CTFontCollectionCreateMatchingFontDescriptors(systemCollection) : 0;
+    if (!systemFonts)
+        qFatal("Cannot get system fonts\n");
+
+    QByteArray testFontsVar = getenv("WEBKIT_TESTFONTS");
+    QDir fontsDir(QString::fromLatin1(testFontsVar));
+    if (testFontsVar.isEmpty() || !fontsDir.exists()) {
+        qFatal("\n\n"
+                "----------------------------------------------------------------------\n"
+                "QCoreTextFontDatabaseWKTest:\n"
+                "WEBKIT_TESTFONTS environment variable is not set correctly.\n"
+                "This variable has to point to the directory containing the fonts\n"
+                "you can clone from git://gitorious.org/qtwebkit/testfonts.git\n"
+                "----------------------------------------------------------------------\n"
+               );
+    }
+
+    QCFType<CFMutableSetRef> systemFontSet(CFSetCreateMutable(0, 0, &kCFTypeSetCallBacks));
+    for (int i = 0; i < CFArrayGetCount(systemFonts); ++i) {
+        CTFontDescriptorRef font = static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(systemFonts, i));
+        CFSetAddValue(systemFontSet, font);
+    }
+
+    // Add the test fonts to the set.
+    QStringList filters;
+    filters << QStringLiteral("*.ttf");
+    QFileInfoList files = fontsDir.entryInfoList(filters, QDir::Files);
+    foreach (QFileInfo file, files) {
+        QByteArray path = QFile::encodeName(file.canonicalFilePath());
+        QCFType<CFURLRef> fontFile(CFURLCreateFromFileSystemRepresentation(0, reinterpret_cast<const UInt8*>(path.constData()), path.length(), false));
+        CFErrorRef error;
+        if (!CTFontManagerRegisterFontsForURL(fontFile, kCTFontManagerScopeProcess, &error)) {
+            CFRelease(error);
+            qFatal("Failed registering font file: %s\n", path.constData());
+        }
+    }
+
+    // This substitution is done via fonts.conf on Linux.
+    QFont::insertSubstitution(QStringLiteral("Helvetica"), QString::fromLatin1(defaultWebKitTestFontFamily));
+
+    // ----------------------------------------------------------------------------
+    // This is a copy of QCoretextFontDatabase::populateFontDatabase from Qt except
+    // we filter out the system fonts.
+
+    QCFType<CTFontCollectionRef> collection = CTFontCollectionCreateFromAvailableFonts(0);
+    QCFType<CFArrayRef> fonts = CTFontCollectionCreateMatchingFontDescriptors(collection);
+
+    QString foundryName = QLatin1String("CoreText");
+    const int numFonts = CFArrayGetCount(fonts);
+    QHash<QString, QString> psNameToFamily;
+    for (int i = 0; i < numFonts; ++i) {
+        CTFontDescriptorRef font = static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(fonts, i));
+        if (CFSetGetCountOfValue(systemFontSet, font))
+            continue;
+        QCFString familyName = static_cast<CFStringRef>(CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL));
+        QCFType<CFDictionaryRef> styles = static_cast<CFDictionaryRef>(CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute));
+        QFont::Weight weight = QFont::Normal;
+        QFont::Style style = QFont::StyleNormal;
+        QFont::Stretch stretch = QFont::Unstretched;
+        bool fixedPitch = false;
+
+        if (styles) {
+            if (CFNumberRef weightValue = static_cast<CFNumberRef>(CFDictionaryGetValue(styles, kCTFontWeightTrait))) {
+                Q_ASSERT(CFNumberIsFloatType(weightValue));
+                double d;
+                if (CFNumberGetValue(weightValue, kCFNumberDoubleType, &d))
+                    weight = (d > 0.0) ? QFont::Bold : QFont::Normal;
+            }
+            if (CFNumberRef italic = static_cast<CFNumberRef>(CFDictionaryGetValue(styles, kCTFontSlantTrait))) {
+                Q_ASSERT(CFNumberIsFloatType(italic));
+                double d;
+                if (CFNumberGetValue(italic, kCFNumberDoubleType, &d)) {
+                    if (d > 0.0)
+                        style = QFont::StyleItalic;
+                }
+            }
+            if (CFNumberRef symbolic = static_cast<CFNumberRef>(CFDictionaryGetValue(styles, kCTFontSymbolicTrait))) {
+                int d;
+                if (CFNumberGetValue(symbolic, kCFNumberSInt32Type, &d)) {
+                    if (d & kCTFontMonoSpaceTrait)
+                        fixedPitch = true;
+                    if (d & kCTFontExpandedTrait)
+                        stretch = QFont::Expanded;
+                    else if (d & kCTFontCondensedTrait)
+                        stretch = QFont::Condensed;
+                }
+            }
+        }
+
+        int pixelSize = 0;
+        if (QCFType<CFNumberRef> size = static_cast<CFNumberRef>(CTFontDescriptorCopyAttribute(font, kCTFontSizeAttribute))) {
+            if (CFNumberIsFloatType(size)) {
+                double d;
+                CFNumberGetValue(size, kCFNumberDoubleType, &d);
+                pixelSize = d;
+            } else {
+                CFNumberGetValue(size, kCFNumberIntType, &pixelSize);
+            }
+        }
+
+        QSupportedWritingSystems writingSystems;
+        if (QCFType<CFArrayRef> languages = static_cast<CFArrayRef>(CTFontDescriptorCopyAttribute(font, kCTFontLanguagesAttribute))) {
+            CFIndex length = CFArrayGetCount(languages);
+            for (int i = 1; i < LanguageCount; ++i) {
+                if (!languageForWritingSystem[i])
+                    continue;
+                QCFString lang = CFStringCreateWithCString(NULL, languageForWritingSystem[i], kCFStringEncodingASCII);
+                if (CFArrayContainsValue(languages, CFRangeMake(0, length), lang))
+                    writingSystems.setSupported(QFontDatabase::WritingSystem(i));
+            }
+        }
+
+        CFRetain(font);
+        QPlatformFontDatabase::registerFont(familyName, foundryName, weight, style, stretch,
+                                            true /* antialiased */, true /* scalable */,
+                                            pixelSize, fixedPitch, writingSystems, (void *) font);
+        CFStringRef psName = static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(font, kCTFontNameAttribute));
+        // we need PostScript Name to family name mapping for fallback list construction
+        psNameToFamily[QCFString::toQString((NSString *) psName)] = familyName;
+        CFRelease(psName);
+    }
+    // ----------------------------------------------------------------------------
+}
diff --git a/Tools/QtTestPlatformPlugin/mac/TestIntegrationMac.mm b/Tools/QtTestPlatformPlugin/mac/TestIntegrationMac.mm
new file mode 100644 (file)
index 0000000..f3786c9
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 University of Szeged. 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 UNIVERSITY OF SZEGED ``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 UNIVERSITY OF SZEGED OR
+ * 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 "../TestIntegration.h"
+#include "TestFontDatabase.h"
+
+QPlatformFontDatabase* TestIntegration::fontDatabase() const
+{
+    if (!m_fontDatabase)
+        m_fontDatabase.reset(new TestFontDatabase);
+    return m_fontDatabase.data();
+}
diff --git a/Tools/QtTestPlatformPlugin/main.cpp b/Tools/QtTestPlatformPlugin/main.cpp
new file mode 100644 (file)
index 0000000..4f577f4
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2012 University of Szeged. All rights reserved.
+ *
+ * GNU Lesser General Public License Usage
+ * This file may be used under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ * Please review the following information to ensure the GNU Lesser
+ * General Public License version 2.1 requirements will be met:
+ * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ *
+ * GNU General Public License Usage
+ * Alternatively, this file may be used under the terms of the GNU General
+ * Public License version 3.0 as published by the Free Software Foundation.
+ * Please review the following information to ensure the GNU General Public
+ * License version 3.0 requirements will be met:
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ */
+
+#include "TestIntegration.h"
+#include <QPlatformIntegrationPlugin>
+#include <QtGlobal>
+
+class Q_DECL_EXPORT TestIntegrationPlugin : public QPlatformIntegrationPlugin {
+    Q_OBJECT
+    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPlatformIntegrationFactoryInterface" FILE "testplatform.json")
+public:
+    QStringList keys() const;
+    QPlatformIntegration* create(const QString&, const QStringList&);
+
+    static void initialize();
+};
+
+QStringList TestIntegrationPlugin::keys() const
+{
+    QStringList list;
+    list << QStringLiteral("testplatform");
+    return list;
+}
+
+QPlatformIntegration* TestIntegrationPlugin::create(const QString& system, const QStringList& parameters)
+{
+    if (!system.compare(QStringLiteral("testplatform"), Qt::CaseInsensitive))
+        return new TestIntegration();
+
+    return 0;
+}
+
+#include "main.moc"
+
+void TestIntegrationPlugin::initialize()
+{
+    QStaticPlugin plugin;
+    plugin.instance = &qt_plugin_instance;
+    plugin.metaData = &qt_plugin_query_metadata;
+    qRegisterStaticPluginFunction(plugin);
+}
+
+static void constructorFunction()
+{
+    TestIntegrationPlugin::initialize();
+}
+
+Q_CONSTRUCTOR_FUNCTION(constructorFunction);
diff --git a/Tools/QtTestPlatformPlugin/testplatform.json b/Tools/QtTestPlatformPlugin/testplatform.json
new file mode 100644 (file)
index 0000000..830bb62
--- /dev/null
@@ -0,0 +1,3 @@
+{
+    "Keys": [ "testplatform" ]
+}
index aa4d591..a23c1be 100644 (file)
@@ -13,6 +13,8 @@ SUBDIRS += QtTestBrowser/QtTestBrowser.pro
 SUBDIRS += DumpRenderTree/qt/DumpRenderTree.pro
 SUBDIRS += DumpRenderTree/qt/ImageDiff.pro
 
+haveQt(5): SUBDIRS += QtTestPlatformPlugin/QtTestPlatformPlugin.pro
+
 !no_webkit2 {
     SUBDIRS += MiniBrowser/qt/MiniBrowser.pro \
                WebKitTestRunner/WebKitTestRunner.pro
index b9e7a8b..d3938dc 100644 (file)
@@ -37,4 +37,9 @@ PREFIX_HEADER = WebKitTestRunnerPrefix.h
 *-g++*:QMAKE_CXXFLAGS += "-include $$PREFIX_HEADER"
 *-clang*:QMAKE_CXXFLAGS += "-include $$PREFIX_HEADER"
 
+mac: LIB_SUFFIX=.dylib
+win: LIB_SUFFIX=.dll
+unix:!mac: LIB_SUFFIX=.so
+DEFINES += TEST_PLATFORM_PLUGIN_PATH=\"\\\"$${ROOT_BUILD_DIR}$${QMAKE_DIR_SEP}lib$${QMAKE_DIR_SEP}libtestplatform$${LIB_SUFFIX}\\\"\"
+
 RESOURCES = qt/WebKitTestRunner.qrc
index 3eb2873..7e8b604 100644 (file)
@@ -102,6 +102,22 @@ int main(int argc, char** argv)
 
     qputenv("QT_WEBKIT_THEME_NAME", "qstyle");
 
+    QByteArray platform = qgetenv("QT_QPA_PLATFORM");
+    QByteArray platformPluginPath = qgetenv("QT_QPA_PLATFORM_PLUGIN_PATH");
+    for (int i = 0; i < argc; ++i) {
+        if (QByteArray(argv[i]) == "-platform" && i + 1 < argc)
+            platform = argv[i + 1];
+        else if (QByteArray(argv[i]) == "-platformpluginpath" && i + 1 < argc)
+            platformPluginPath = argv[i + 1];
+    }
+    if (!platform.isEmpty())
+        qputenv("QT_WEBKIT_ORIGINAL_PLATFORM", platform);
+    if (!platformPluginPath.isEmpty())
+        qputenv("QT_WEBKIT_ORIGINAL_PLATFORM_PLUGIN_PATH", platformPluginPath);
+
+    // Tell the web process that we want to use the test platform plugin.
+    qputenv("QT_WEBKIT2_TEST_PLATFORM_PLUGIN_PATH", TEST_PLATFORM_PLUGIN_PATH);
+
     QQuickWebViewExperimental::setFlickableViewportEnabled(false);
     QApplication app(argc, argv);
     Launcher launcher(argc, argv);