TestControllerGtk.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2010 Apple Inc. All rights reserved.
  3. * Copyright (C) 2010 Igalia S.L.
  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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  18. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "config.h"
  27. #include "TestController.h"
  28. #include <gtk/gtk.h>
  29. #include <wtf/Platform.h>
  30. #include <wtf/gobject/GOwnPtr.h>
  31. #include <wtf/text/WTFString.h>
  32. namespace WTR {
  33. static guint gTimeoutSourceId = 0;
  34. static void cancelTimeout()
  35. {
  36. if (!gTimeoutSourceId)
  37. return;
  38. g_source_remove(gTimeoutSourceId);
  39. gTimeoutSourceId = 0;
  40. }
  41. void TestController::notifyDone()
  42. {
  43. gtk_main_quit();
  44. cancelTimeout();
  45. }
  46. void TestController::platformInitialize()
  47. {
  48. }
  49. void TestController::platformDestroy()
  50. {
  51. }
  52. static gboolean timeoutCallback(gpointer)
  53. {
  54. fprintf(stderr, "FAIL: TestControllerRunLoop timed out.\n");
  55. gtk_main_quit();
  56. return FALSE;
  57. }
  58. void TestController::platformRunUntil(bool&, double timeout)
  59. {
  60. cancelTimeout();
  61. if (timeout != m_noTimeout)
  62. gTimeoutSourceId = g_timeout_add(timeout * 1000, timeoutCallback, 0);
  63. gtk_main();
  64. }
  65. static char* getEnvironmentVariableAsUTF8String(const char* variableName)
  66. {
  67. const char* value = g_getenv(variableName);
  68. if (!value) {
  69. fprintf(stderr, "%s environment variable not found\n", variableName);
  70. exit(0);
  71. }
  72. gsize bytesWritten;
  73. return g_filename_to_utf8(value, -1, 0, &bytesWritten, 0);
  74. }
  75. void TestController::initializeInjectedBundlePath()
  76. {
  77. GOwnPtr<char> utf8BundlePath(getEnvironmentVariableAsUTF8String("TEST_RUNNER_INJECTED_BUNDLE_FILENAME"));
  78. m_injectedBundlePath.adopt(WKStringCreateWithUTF8CString(utf8BundlePath.get()));
  79. }
  80. void TestController::initializeTestPluginDirectory()
  81. {
  82. GOwnPtr<char> testPluginPath(getEnvironmentVariableAsUTF8String("TEST_RUNNER_TEST_PLUGIN_PATH"));
  83. m_testPluginDirectory.adopt(WKStringCreateWithUTF8CString(testPluginPath.get()));
  84. }
  85. void TestController::platformInitializeContext()
  86. {
  87. }
  88. void TestController::runModal(PlatformWebView*)
  89. {
  90. // FIXME: Need to implement this to test showModalDialog.
  91. }
  92. const char* TestController::platformLibraryPathForTesting()
  93. {
  94. return 0;
  95. }
  96. } // namespace WTR