TestRunnerQt.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2010 Apple Inc. All rights reserved.
  3. * Copyright (C) 2010 University of Szeged. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  15. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  18. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  24. * THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "config.h"
  27. #include "TestRunner.h"
  28. #include "ActivateFonts.h"
  29. #include "InjectedBundle.h"
  30. #include "QtTestSupport.h"
  31. #include <QCoreApplication>
  32. #include <QDir>
  33. #include <QFontDatabase>
  34. #include <QObject>
  35. #include <QtCore/qglobal.h>
  36. #include <qwebsettings.h>
  37. namespace WTR {
  38. class WatchdogTimerHelper : public QObject {
  39. Q_OBJECT
  40. public:
  41. static WatchdogTimerHelper* instance()
  42. {
  43. static WatchdogTimerHelper* theInstance = new WatchdogTimerHelper;
  44. return theInstance;
  45. }
  46. public Q_SLOTS:
  47. void timerFired()
  48. {
  49. InjectedBundle::shared().testRunner()->waitToDumpWatchdogTimerFired();
  50. }
  51. private:
  52. WatchdogTimerHelper() {}
  53. };
  54. void TestRunner::platformInitialize()
  55. {
  56. WebKit::QtTestSupport::clearMemoryCaches();
  57. activateFonts();
  58. QObject::connect(&m_waitToDumpWatchdogTimer, SIGNAL(timeout()), WatchdogTimerHelper::instance(), SLOT(timerFired()));
  59. }
  60. void TestRunner::invalidateWaitToDumpWatchdogTimer()
  61. {
  62. m_waitToDumpWatchdogTimer.stop();
  63. }
  64. void TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded()
  65. {
  66. int timerInterval;
  67. if (qgetenv("QT_WEBKIT2_DEBUG") == "1")
  68. return;
  69. if (m_waitToDumpWatchdogTimer.isActive())
  70. return;
  71. if (m_timeout > 0)
  72. timerInterval = m_timeout;
  73. else
  74. timerInterval = waitToDumpWatchdogTimerInterval * 1000;
  75. m_waitToDumpWatchdogTimer.start(timerInterval);
  76. }
  77. JSRetainPtr<JSStringRef> TestRunner::pathToLocalResource(JSStringRef url)
  78. {
  79. QString localTmpUrl(QStringLiteral("file:///tmp/LayoutTests"));
  80. QString givenUrl(reinterpret_cast<const QChar*>(JSStringGetCharactersPtr(url)), JSStringGetLength(url));
  81. // Translate a request for /tmp/LayoutTests to the repository LayoutTests directory.
  82. // Do not rely on a symlink to be created via the test runner, which will not work on Windows.
  83. if (givenUrl.startsWith(localTmpUrl)) {
  84. // DumpRenderTree lives in WebKit/WebKitBuild/<build_mode>/bin.
  85. // Translate from WebKit/WebKitBuild/Release/bin => WebKit/LayoutTests.
  86. QFileInfo layoutTestsRoot(QCoreApplication::applicationDirPath() + QStringLiteral("/../../../LayoutTests/"));
  87. if (layoutTestsRoot.exists()) {
  88. QString path = QStringLiteral("file://") + layoutTestsRoot.absolutePath() + givenUrl.mid(localTmpUrl.length());
  89. return JSStringCreateWithCharacters(reinterpret_cast<const JSChar*>(path.constData()), path.length());
  90. }
  91. }
  92. return url;
  93. }
  94. JSRetainPtr<JSStringRef> TestRunner::platformName()
  95. {
  96. JSRetainPtr<JSStringRef> platformName(Adopt, JSStringCreateWithUTF8CString("qt"));
  97. return platformName;
  98. }
  99. } // namespace WTR
  100. #include "TestRunnerQt.moc"