PlatformUtilitiesQt.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this library; see the file COPYING.LIB. If not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #include "config.h"
  21. #include "PlatformUtilities.h"
  22. #include <WebKit2/WKStringQt.h>
  23. #include <WebKit2/WKNativeEvent.h>
  24. #include <WebKit2/WKURLQt.h>
  25. #include <QCoreApplication>
  26. #include <QDir>
  27. #include <QUrl>
  28. #include <QThread>
  29. namespace TestWebKitAPI {
  30. namespace Util {
  31. void run(bool* done)
  32. {
  33. while (!*done)
  34. QCoreApplication::processEvents();
  35. }
  36. void sleep(double seconds)
  37. {
  38. QThread::sleep(seconds);
  39. }
  40. WKStringRef createInjectedBundlePath()
  41. {
  42. QString path = QFileInfo(QStringLiteral(ROOT_BUILD_DIR "/lib/libTestWebKitAPIInjectedBundle")).absoluteFilePath();
  43. return WKStringCreateWithQString(path);
  44. }
  45. WKURLRef createURLForResource(const char* resource, const char* extension)
  46. {
  47. QDir path(QStringLiteral(APITEST_SOURCE_DIR));
  48. QString filename = QString::fromLocal8Bit(resource) + QStringLiteral(".") + QString::fromLocal8Bit(extension);
  49. return WKURLCreateWithQUrl(QUrl::fromLocalFile(path.absoluteFilePath(filename)));
  50. }
  51. WKURLRef URLForNonExistentResource()
  52. {
  53. return WKURLCreateWithUTF8CString("file:///does-not-exist.html");
  54. }
  55. bool isKeyDown(WKNativeEventPtr event)
  56. {
  57. return event->type() == QEvent::KeyPress;
  58. }
  59. } // namespace Util
  60. } // namespace TestWebKitAPI