2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Igalia S.L.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
28 #include "TestRunner.h"
30 #include "InjectedBundle.h"
31 #include "InjectedBundleUtilities.h"
33 #include <wtf/gobject/GUniquePtr.h>
37 static gboolean waitToDumpWatchdogTimerCallback(gpointer)
39 InjectedBundle::shared().testRunner()->waitToDumpWatchdogTimerFired();
43 void TestRunner::platformInitialize()
45 m_waitToDumpWatchdogTimer = 0;
48 void TestRunner::invalidateWaitToDumpWatchdogTimer()
50 if (!m_waitToDumpWatchdogTimer)
52 g_source_remove(m_waitToDumpWatchdogTimer);
53 m_waitToDumpWatchdogTimer = 0;
56 void TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded()
58 if (m_waitToDumpWatchdogTimer)
61 m_waitToDumpWatchdogTimer = g_timeout_add(waitToDumpWatchdogTimerInterval * 1000,
62 waitToDumpWatchdogTimerCallback, 0);
63 g_source_set_name_by_id(m_waitToDumpWatchdogTimer, "[WebKit] waitToDumpWatchdogTimerCallback");
66 JSRetainPtr<JSStringRef> TestRunner::pathToLocalResource(JSStringRef url)
68 size_t urlSize = JSStringGetMaximumUTF8CStringSize(url);
69 GUniquePtr<gchar> urlString(static_cast<gchar*>(g_malloc(urlSize)));
70 JSStringGetUTF8CString(url, urlString.get(), urlSize);
72 if (!g_str_has_prefix(urlString.get(), "file:///tmp/LayoutTests/"))
73 return JSStringRetain(url);
75 const gchar* layoutTestsSuffix = urlString.get() + strlen("file:///tmp/");
76 GUniquePtr<gchar> testPath(g_build_filename(WTR::topLevelPath().data(), layoutTestsSuffix, nullptr));
77 GUniquePtr<gchar> testURI(g_filename_to_uri(testPath.get(), 0, 0));
78 return JSStringCreateWithUTF8CString(testURI.get());