2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
4 * Copyright (C) 2008 Nuanti Ltd.
5 * Copyright (C) 2009 Jan Michael Alonzo <jmalonzo@gmail.com>
6 * Copyright (C) 2009,2011 Collabora Ltd.
7 * Copyright (C) 2010 Joone Hur <joone@kldp.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
23 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "LayoutTestController.h"
37 #include "DumpRenderTree.h"
38 #include "WebCoreSupport/DumpRenderTreeSupportGtk.h"
39 #include "WorkQueue.h"
40 #include "WorkQueueItem.h"
41 #include <JavaScriptCore/JSRetainPtr.h>
42 #include <JavaScriptCore/JSStringRef.h>
48 #include <libsoup/soup.h>
49 #include <webkit/webkit.h>
50 #include <wtf/gobject/GOwnPtr.h>
53 void webkit_web_inspector_execute_script(WebKitWebInspector* inspector, long callId, const gchar* script);
56 LayoutTestController::~LayoutTestController()
61 void LayoutTestController::addDisallowedURL(JSStringRef url)
66 void LayoutTestController::clearBackForwardList()
68 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
69 WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list(webView);
70 WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_current_item(list);
73 // We clear the history by setting the back/forward list's capacity to 0
74 // then restoring it back and adding back the current item.
75 gint limit = webkit_web_back_forward_list_get_limit(list);
76 webkit_web_back_forward_list_set_limit(list, 0);
77 webkit_web_back_forward_list_set_limit(list, limit);
78 webkit_web_back_forward_list_add_item(list, item);
79 webkit_web_back_forward_list_go_to_item(list, item);
83 JSStringRef LayoutTestController::copyDecodedHostName(JSStringRef name)
89 JSStringRef LayoutTestController::copyEncodedHostName(JSStringRef name)
95 void LayoutTestController::dispatchPendingLoadRequests()
97 // FIXME: Implement for testing fix for 6727495
100 void LayoutTestController::display()
105 JSRetainPtr<JSStringRef> LayoutTestController::counterValueForElementById(JSStringRef id)
107 gchar* idGChar = JSStringCopyUTF8CString(id);
108 CString counterValueGChar = DumpRenderTreeSupportGtk::counterValueForElementById(mainFrame, idGChar);
110 if (counterValueGChar.isNull())
112 JSRetainPtr<JSStringRef> counterValue(Adopt, JSStringCreateWithUTF8CString(counterValueGChar.data()));
116 void LayoutTestController::keepWebHistory()
121 JSValueRef LayoutTestController::computedStyleIncludingVisitedInfo(JSContextRef context, JSValueRef value)
123 return DumpRenderTreeSupportGtk::computedStyleIncludingVisitedInfo(context, value);
126 JSRetainPtr<JSStringRef> LayoutTestController::layerTreeAsText() const
129 JSRetainPtr<JSStringRef> string(Adopt, JSStringCreateWithUTF8CString(""));
133 int LayoutTestController::pageNumberForElementById(JSStringRef id, float pageWidth, float pageHeight)
135 gchar* idGChar = JSStringCopyUTF8CString(id);
136 int pageNumber = DumpRenderTreeSupportGtk::pageNumberForElementById(mainFrame, idGChar, pageWidth, pageHeight);
141 int LayoutTestController::numberOfPages(float pageWidth, float pageHeight)
143 return DumpRenderTreeSupportGtk::numberOfPagesForFrame(mainFrame, pageWidth, pageHeight);
146 JSRetainPtr<JSStringRef> LayoutTestController::pageProperty(const char* propertyName, int pageNumber) const
148 JSRetainPtr<JSStringRef> propertyValue(Adopt, JSStringCreateWithUTF8CString(DumpRenderTreeSupportGtk::pageProperty(mainFrame, propertyName, pageNumber).data()));
149 return propertyValue;
152 JSRetainPtr<JSStringRef> LayoutTestController::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const
154 JSRetainPtr<JSStringRef> propertyValue(Adopt, JSStringCreateWithUTF8CString(DumpRenderTreeSupportGtk::pageSizeAndMarginsInPixels(mainFrame, pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft).data()));
155 return propertyValue;
158 size_t LayoutTestController::webHistoryItemCount()
160 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
161 WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list(webView);
166 // We do not add the current page to the total count as it's not
167 // considered in DRT tests
168 return webkit_web_back_forward_list_get_back_length(list) +
169 webkit_web_back_forward_list_get_forward_length(list);
172 unsigned LayoutTestController::workerThreadCount() const
174 return DumpRenderTreeSupportGtk::workerThreadCount();
177 JSRetainPtr<JSStringRef> LayoutTestController::platformName() const
179 JSRetainPtr<JSStringRef> platformName(Adopt, JSStringCreateWithUTF8CString("gtk"));
183 void LayoutTestController::notifyDone()
185 if (m_waitToDump && !topLoadingFrame && !WorkQueue::shared()->count())
187 m_waitToDump = false;
188 waitForPolicy = false;
191 JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef url)
193 GOwnPtr<char> urlCString(JSStringCopyUTF8CString(url));
194 if (!g_str_has_prefix(urlCString.get(), "file:///tmp/LayoutTests/"))
195 return JSStringRetain(url);
197 const char* layoutTestsSuffix = urlCString.get() + strlen("file:///tmp/");
198 GOwnPtr<char> testPath(g_build_filename(getTopLevelPath().data(), layoutTestsSuffix, NULL));
199 GOwnPtr<char> testURI(g_filename_to_uri(testPath.get(), 0, 0));
200 return JSStringCreateWithUTF8CString(testURI.get());
203 void LayoutTestController::queueLoad(JSStringRef url, JSStringRef target)
205 gchar* relativeURL = JSStringCopyUTF8CString(url);
206 SoupURI* baseURI = soup_uri_new(webkit_web_frame_get_uri(mainFrame));
208 SoupURI* absoluteURI = soup_uri_new_with_base(baseURI, relativeURL);
209 soup_uri_free(baseURI);
212 gchar* absoluteCString;
214 absoluteCString = soup_uri_to_string(absoluteURI, FALSE);
215 soup_uri_free(absoluteURI);
217 absoluteCString = JSStringCopyUTF8CString(url);
219 JSRetainPtr<JSStringRef> absoluteURL(Adopt, JSStringCreateWithUTF8CString(absoluteCString));
220 g_free(absoluteCString);
222 WorkQueue::shared()->queue(new LoadItem(absoluteURL.get(), target));
225 void LayoutTestController::setAcceptsEditing(bool acceptsEditing)
227 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
228 webkit_web_view_set_editable(webView, acceptsEditing);
231 void LayoutTestController::setAlwaysAcceptCookies(bool alwaysAcceptCookies)
233 SoupSession* session = webkit_get_default_session();
234 SoupCookieJar* jar = reinterpret_cast<SoupCookieJar*>(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR));
236 /* If the jar was not created - we create it on demand, i.e, just
237 in case we have HTTP requests - then we must create it here in
238 order to set the proper accept policy */
240 jar = soup_cookie_jar_new();
241 soup_session_add_feature(session, SOUP_SESSION_FEATURE(jar));
245 SoupCookieJarAcceptPolicy policy;
247 if (alwaysAcceptCookies)
248 policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
250 policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
252 g_object_set(G_OBJECT(jar), SOUP_COOKIE_JAR_ACCEPT_POLICY, policy, NULL);
255 void LayoutTestController::setCustomPolicyDelegate(bool setDelegate, bool permissive)
260 void LayoutTestController::waitForPolicyDelegate()
262 waitForPolicy = true;
266 void LayoutTestController::setScrollbarPolicy(JSStringRef orientation, JSStringRef policy)
271 void LayoutTestController::addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains)
273 gchar* sourceOriginGChar = JSStringCopyUTF8CString(sourceOrigin);
274 gchar* protocolGChar = JSStringCopyUTF8CString(protocol);
275 gchar* hostGChar = JSStringCopyUTF8CString(host);
276 DumpRenderTreeSupportGtk::whiteListAccessFromOrigin(sourceOriginGChar, protocolGChar, hostGChar, includeSubdomains);
277 g_free(sourceOriginGChar);
278 g_free(protocolGChar);
282 void LayoutTestController::removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains)
284 GOwnPtr<gchar> sourceOriginGChar(JSStringCopyUTF8CString(sourceOrigin));
285 GOwnPtr<gchar> protocolGChar(JSStringCopyUTF8CString(protocol));
286 GOwnPtr<gchar> hostGChar(JSStringCopyUTF8CString(host));
287 DumpRenderTreeSupportGtk::removeWhiteListAccessFromOrigin(sourceOriginGChar.get(), protocolGChar.get(), hostGChar.get(), includeSubdomains);
290 void LayoutTestController::setMainFrameIsFirstResponder(bool flag)
295 void LayoutTestController::setTabKeyCyclesThroughElements(bool cycles)
297 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
298 WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
299 g_object_set(G_OBJECT(settings), "tab-key-cycles-through-elements", cycles, NULL);
302 void LayoutTestController::setUseDashboardCompatibilityMode(bool flag)
307 static gchar* userStyleSheet = NULL;
308 static gboolean userStyleSheetEnabled = TRUE;
310 void LayoutTestController::setUserStyleSheetEnabled(bool flag)
312 userStyleSheetEnabled = flag;
314 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
315 WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
316 if (flag && userStyleSheet)
317 g_object_set(G_OBJECT(settings), "user-stylesheet-uri", userStyleSheet, NULL);
319 g_object_set(G_OBJECT(settings), "user-stylesheet-uri", "", NULL);
322 void LayoutTestController::setUserStyleSheetLocation(JSStringRef path)
324 g_free(userStyleSheet);
325 userStyleSheet = JSStringCopyUTF8CString(path);
326 if (userStyleSheetEnabled)
327 setUserStyleSheetEnabled(true);
330 void LayoutTestController::setValueForUser(JSContextRef context, JSValueRef nodeObject, JSStringRef value)
332 DumpRenderTreeSupportGtk::setValueForUser(context, nodeObject, value);
335 void LayoutTestController::setViewModeMediaFeature(JSStringRef mode)
337 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
340 char* viewMode = JSStringCopyUTF8CString(mode);
342 if (!g_strcmp0(viewMode, "windowed"))
343 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_WINDOWED);
344 else if (!g_strcmp0(viewMode, "floating"))
345 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FLOATING);
346 else if (!g_strcmp0(viewMode, "fullscreen"))
347 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FULLSCREEN);
348 else if (!g_strcmp0(viewMode, "maximized"))
349 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MAXIMIZED);
350 else if (!g_strcmp0(viewMode, "minimized"))
351 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MINIMIZED);
356 void LayoutTestController::setWindowIsKey(bool windowIsKey)
361 void LayoutTestController::setSmartInsertDeleteEnabled(bool flag)
363 DumpRenderTreeSupportGtk::setSmartInsertDeleteEnabled(webkit_web_frame_get_web_view(mainFrame), flag);
366 static gboolean waitToDumpWatchdogFired(void*)
368 setWaitToDumpWatchdog(0);
369 gLayoutTestController->waitToDumpWatchdogTimerFired();
373 void LayoutTestController::setWaitToDump(bool waitUntilDone)
375 static const int timeoutSeconds = 30;
377 m_waitToDump = waitUntilDone;
378 if (m_waitToDump && shouldSetWaitToDumpWatchdog())
379 setWaitToDumpWatchdog(g_timeout_add_seconds(timeoutSeconds, waitToDumpWatchdogFired, 0));
382 int LayoutTestController::windowCount()
384 // +1 -> including the main view
385 return g_slist_length(webViewList) + 1;
388 void LayoutTestController::setPrivateBrowsingEnabled(bool flag)
390 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
393 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
394 g_object_set(G_OBJECT(settings), "enable-private-browsing", flag, NULL);
397 void LayoutTestController::setJavaScriptCanAccessClipboard(bool flag)
399 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
402 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
403 g_object_set(G_OBJECT(settings), "javascript-can-access-clipboard", flag, NULL);
406 void LayoutTestController::setXSSAuditorEnabled(bool flag)
408 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
411 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
412 g_object_set(G_OBJECT(settings), "enable-xss-auditor", flag, NULL);
415 void LayoutTestController::setFrameFlatteningEnabled(bool flag)
417 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
420 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
421 g_object_set(G_OBJECT(settings), "enable-frame-flattening", flag, NULL);
424 void LayoutTestController::setSpatialNavigationEnabled(bool flag)
426 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
429 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
430 g_object_set(G_OBJECT(settings), "enable-spatial-navigation", flag, NULL);
433 void LayoutTestController::setAllowUniversalAccessFromFileURLs(bool flag)
435 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
438 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
439 g_object_set(G_OBJECT(settings), "enable-universal-access-from-file-uris", flag, NULL);
442 void LayoutTestController::setAllowFileAccessFromFileURLs(bool flag)
444 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
447 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
448 g_object_set(G_OBJECT(settings), "enable-file-access-from-file-uris", flag, NULL);
451 void LayoutTestController::setAuthorAndUserStylesEnabled(bool flag)
456 void LayoutTestController::setAutofilled(JSContextRef context, JSValueRef nodeObject, bool isAutofilled)
458 DumpRenderTreeSupportGtk::setAutofilled(context, nodeObject, isAutofilled);
461 void LayoutTestController::disableImageLoading()
463 // FIXME: Implement for testing fix for https://bugs.webkit.org/show_bug.cgi?id=27896
464 // Also need to make sure image loading is re-enabled for each new test.
467 void LayoutTestController::setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
469 // FIXME: Implement for DeviceOrientation layout tests.
470 // See https://bugs.webkit.org/show_bug.cgi?id=30335.
473 void LayoutTestController::setMockGeolocationPosition(double latitude, double longitude, double accuracy)
475 WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0));
477 view = webkit_web_frame_get_web_view(mainFrame);
480 DumpRenderTreeSupportGtk::setMockGeolocationPosition(view, latitude, longitude, accuracy);
483 void LayoutTestController::setMockGeolocationError(int code, JSStringRef message)
485 WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0));
487 view = webkit_web_frame_get_web_view(mainFrame);
490 GOwnPtr<gchar> cMessage(JSStringCopyUTF8CString(message));
491 DumpRenderTreeSupportGtk::setMockGeolocationError(view, code, cMessage.get());
494 void LayoutTestController::setGeolocationPermission(bool allow)
496 setGeolocationPermissionCommon(allow);
497 WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0));
499 view = webkit_web_frame_get_web_view(mainFrame);
502 DumpRenderTreeSupportGtk::setMockGeolocationPermission(view, allow);
505 int LayoutTestController::numberOfPendingGeolocationPermissionRequests()
507 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
509 view = webkit_web_frame_get_web_view(mainFrame);
512 return DumpRenderTreeSupportGtk::numberOfPendingGeolocationPermissionRequests(view);
515 void LayoutTestController::addMockSpeechInputResult(JSStringRef result, double confidence, JSStringRef language)
517 // FIXME: Implement for speech input layout tests.
518 // See https://bugs.webkit.org/show_bug.cgi?id=39485.
521 void LayoutTestController::setMockSpeechInputDumpRect(bool flag)
523 // FIXME: Implement for speech input layout tests.
524 // See https://bugs.webkit.org/show_bug.cgi?id=39485.
527 void LayoutTestController::startSpeechInput(JSContextRef inputElement)
529 // FIXME: Implement for speech input layout tests.
530 // See https://bugs.webkit.org/show_bug.cgi?id=39485.
533 void LayoutTestController::setIconDatabaseEnabled(bool enabled)
535 WebKitIconDatabase* database = webkit_get_icon_database();
537 GOwnPtr<gchar> iconDatabasePath(g_build_filename(g_get_tmp_dir(), "DumpRenderTree", "icondatabase", NULL));
538 webkit_icon_database_set_path(database, iconDatabasePath.get());
540 webkit_icon_database_set_path(database, 0);
543 void LayoutTestController::setSelectTrailingWhitespaceEnabled(bool flag)
545 DumpRenderTreeSupportGtk::setSelectTrailingWhitespaceEnabled(flag);
548 void LayoutTestController::setPopupBlockingEnabled(bool flag)
550 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
553 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
554 g_object_set(G_OBJECT(settings), "javascript-can-open-windows-automatically", !flag, NULL);
558 void LayoutTestController::setPluginsEnabled(bool flag)
560 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
563 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
564 g_object_set(G_OBJECT(settings), "enable-plugins", flag, NULL);
567 bool LayoutTestController::elementDoesAutoCompleteForElementWithId(JSStringRef id)
569 return DumpRenderTreeSupportGtk::elementDoesAutoCompleteForElementWithId(mainFrame, id);
572 void LayoutTestController::execCommand(JSStringRef name, JSStringRef value)
574 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
577 gchar* cName = JSStringCopyUTF8CString(name);
578 gchar* cValue = JSStringCopyUTF8CString(value);
579 DumpRenderTreeSupportGtk::executeCoreCommandByName(view, cName, cValue);
584 bool LayoutTestController::findString(JSContextRef context, JSStringRef target, JSObjectRef optionsArray)
586 WebKitFindOptions findOptions = 0;
587 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
590 JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length"));
591 JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0);
592 if (!JSValueIsNumber(context, lengthValue))
595 GOwnPtr<gchar> targetString(JSStringCopyUTF8CString(target));
597 size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0));
598 for (size_t i = 0; i < length; ++i) {
599 JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
600 if (!JSValueIsString(context, value))
603 JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0));
605 if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive"))
606 findOptions |= WebKit::WebFindOptionsCaseInsensitive;
607 else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts"))
608 findOptions |= WebKit::WebFindOptionsAtWordStarts;
609 else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart"))
610 findOptions |= WebKit::WebFindOptionsTreatMedialCapitalAsWordStart;
611 else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards"))
612 findOptions |= WebKit::WebFindOptionsBackwards;
613 else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround"))
614 findOptions |= WebKit::WebFindOptionsWrapAround;
615 else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection"))
616 findOptions |= WebKit::WebFindOptionsStartInSelection;
619 return DumpRenderTreeSupportGtk::findString(webView, targetString.get(), findOptions);
622 bool LayoutTestController::isCommandEnabled(JSStringRef name)
624 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
627 gchar* cName = JSStringCopyUTF8CString(name);
628 bool result = DumpRenderTreeSupportGtk::isCommandEnabled(view, cName);
633 void LayoutTestController::setCacheModel(int cacheModel)
635 // These constants are derived from the Mac cache model enum in Source/WebKit/mac/WebView/WebPreferences.h.
636 switch (cacheModel) {
638 webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
641 webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER);
644 webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER);
647 ASSERT_NOT_REACHED();
651 void LayoutTestController::setPersistentUserStyleSheetLocation(JSStringRef jsURL)
656 void LayoutTestController::clearPersistentUserStyleSheet()
661 void LayoutTestController::clearAllApplicationCaches()
663 // FIXME: Implement to support application cache quotas.
666 void LayoutTestController::setApplicationCacheOriginQuota(unsigned long long quota)
668 // FIXME: Implement to support application cache quotas.
671 void LayoutTestController::clearApplicationCacheForOrigin(OpaqueJSString*)
673 // FIXME: Implement to support deleting all application caches for an origin.
676 long long LayoutTestController::localStorageDiskUsageForOrigin(JSStringRef originIdentifier)
678 // FIXME: Implement to support getting disk usage in bytes for an origin.
682 JSValueRef LayoutTestController::originsWithApplicationCache(JSContextRef context)
684 // FIXME: Implement to get origins that contain application caches.
685 return JSValueMakeUndefined(context);
688 long long LayoutTestController::applicationCacheDiskUsageForOrigin(JSStringRef name)
694 void LayoutTestController::clearAllDatabases()
696 webkit_remove_all_web_databases();
699 void LayoutTestController::setDatabaseQuota(unsigned long long quota)
701 WebKitSecurityOrigin* origin = webkit_web_frame_get_security_origin(mainFrame);
702 webkit_security_origin_set_web_database_quota(origin, quota);
705 JSValueRef LayoutTestController::originsWithLocalStorage(JSContextRef context)
708 return JSValueMakeUndefined(context);
711 void LayoutTestController::deleteAllLocalStorage()
716 void LayoutTestController::deleteLocalStorageForOrigin(JSStringRef originIdentifier)
721 void LayoutTestController::observeStorageTrackerNotifications(unsigned number)
726 void LayoutTestController::syncLocalStorage()
731 void LayoutTestController::setDomainRelaxationForbiddenForURLScheme(bool forbidden, JSStringRef scheme)
733 GOwnPtr<gchar> urlScheme(JSStringCopyUTF8CString(scheme));
734 DumpRenderTreeSupportGtk::setDomainRelaxationForbiddenForURLScheme(forbidden, urlScheme.get());
737 void LayoutTestController::goBack()
739 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
740 webkit_web_view_go_back(webView);
743 void LayoutTestController::setDefersLoading(bool defers)
745 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
746 DumpRenderTreeSupportGtk::setDefersLoading(webView, defers);
749 void LayoutTestController::setAppCacheMaximumSize(unsigned long long size)
751 webkit_application_cache_set_maximum_size(size);
754 bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId)
756 gchar* name = JSStringCopyUTF8CString(animationName);
757 gchar* element = JSStringCopyUTF8CString(elementId);
758 bool returnValue = DumpRenderTreeSupportGtk::pauseAnimation(mainFrame, name, time, element);
764 bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId)
766 gchar* name = JSStringCopyUTF8CString(propertyName);
767 gchar* element = JSStringCopyUTF8CString(elementId);
768 bool returnValue = DumpRenderTreeSupportGtk::pauseTransition(mainFrame, name, time, element);
774 unsigned LayoutTestController::numberOfActiveAnimations() const
776 return DumpRenderTreeSupportGtk::numberOfActiveAnimations(mainFrame);
779 static gboolean booleanFromValue(gchar* value)
781 return !g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1");
784 void LayoutTestController::overridePreference(JSStringRef key, JSStringRef value)
786 GOwnPtr<gchar> originalName(JSStringCopyUTF8CString(key));
787 GOwnPtr<gchar> valueAsString(JSStringCopyUTF8CString(value));
789 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
792 // This transformation could be handled by a hash table (and it once was), but
793 // having it prominent, makes it easier for people from other ports to keep the
795 const gchar* propertyName = 0;
796 if (g_str_equal(originalName.get(), "WebKitJavaScriptEnabled"))
797 propertyName = "enable-scripts";
798 else if (g_str_equal(originalName.get(), "WebKitDefaultFontSize"))
799 propertyName = "default-font-size";
800 else if (g_str_equal(originalName.get(), "WebKitEnableCaretBrowsing"))
801 propertyName = "enable-caret-browsing";
802 else if (g_str_equal(originalName.get(), "WebKitUsesPageCachePreferenceKey"))
803 propertyName = "enable-page-cache";
804 else if (g_str_equal(originalName.get(), "WebKitPluginsEnabled"))
805 propertyName = "enable-plugins";
806 else if (g_str_equal(originalName.get(), "WebKitHyperlinkAuditingEnabled"))
807 propertyName = "enable-hyperlink-auditing";
808 else if (g_str_equal(originalName.get(), "WebKitWebGLEnabled"))
809 propertyName = "enable-webgl";
810 else if (g_str_equal(originalName.get(), "WebKitWebAudioEnabled"))
811 propertyName = "enable-webaudio";
812 else if (g_str_equal(originalName.get(), "WebKitTabToLinksPreferenceKey")) {
813 DumpRenderTreeSupportGtk::setLinksIncludedInFocusChain(booleanFromValue(valueAsString.get()));
815 } else if (g_str_equal(originalName.get(), "WebKitHixie76WebSocketProtocolEnabled")) {
816 DumpRenderTreeSupportGtk::setHixie76WebSocketProtocolEnabled(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
818 } else if (g_str_equal(originalName.get(), "WebKitPageCacheSupportsPluginsPreferenceKey")) {
819 DumpRenderTreeSupportGtk::setPageCacheSupportsPlugins(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
822 fprintf(stderr, "LayoutTestController::overridePreference tried to override "
823 "unknown preference '%s'.\n", originalName.get());
827 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
828 GParamSpec* pspec = g_object_class_find_property(G_OBJECT_CLASS(
829 WEBKIT_WEB_SETTINGS_GET_CLASS(settings)), propertyName);
830 GValue currentPropertyValue = { 0, { { 0 } } };
831 g_value_init(¤tPropertyValue, pspec->value_type);
833 if (G_VALUE_HOLDS_STRING(¤tPropertyValue))
834 g_object_set(settings, propertyName, valueAsString.get(), NULL);
835 else if (G_VALUE_HOLDS_BOOLEAN(¤tPropertyValue))
836 g_object_set(G_OBJECT(settings), propertyName, booleanFromValue(valueAsString.get()), NULL);
837 else if (G_VALUE_HOLDS_INT(¤tPropertyValue))
838 g_object_set(G_OBJECT(settings), propertyName, atoi(valueAsString.get()), NULL);
839 else if (G_VALUE_HOLDS_FLOAT(¤tPropertyValue)) {
840 gfloat newValue = g_ascii_strtod(valueAsString.get(), 0);
841 g_object_set(G_OBJECT(settings), propertyName, newValue, NULL);
843 fprintf(stderr, "LayoutTestController::overridePreference failed to override "
844 "preference '%s'.\n", originalName.get());
847 void LayoutTestController::addUserScript(JSStringRef source, bool runAtStart, bool allFrames)
849 printf("LayoutTestController::addUserScript not implemented.\n");
852 void LayoutTestController::addUserStyleSheet(JSStringRef source, bool allFrames)
854 GOwnPtr<gchar> sourceCode(JSStringCopyUTF8CString(source));
855 DumpRenderTreeSupportGtk::addUserStyleSheet(mainFrame, sourceCode.get(), allFrames);
856 // FIXME: needs more investigation why userscripts/user-style-top-frame-only.html fails when allFrames is false.
860 void LayoutTestController::setDeveloperExtrasEnabled(bool enabled)
862 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
863 WebKitWebSettings* webSettings = webkit_web_view_get_settings(webView);
865 g_object_set(webSettings, "enable-developer-extras", enabled, NULL);
868 void LayoutTestController::setAsynchronousSpellCheckingEnabled(bool)
870 // FIXME: Implement this.
873 void LayoutTestController::showWebInspector()
875 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
876 WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView);
878 webkit_web_inspector_show(inspector);
881 void LayoutTestController::closeWebInspector()
883 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
884 WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView);
886 webkit_web_inspector_close(inspector);
889 void LayoutTestController::evaluateInWebInspector(long callId, JSStringRef script)
891 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
892 WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView);
893 char* scriptString = JSStringCopyUTF8CString(script);
895 webkit_web_inspector_execute_script(inspector, callId, scriptString);
896 g_free(scriptString);
899 void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
901 // FIXME: Implement this.
904 void LayoutTestController::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
906 // FIXME: Implement this.
909 void LayoutTestController::removeAllVisitedLinks()
911 // FIXME: Implement this.
914 bool LayoutTestController::callShouldCloseOnWebView()
916 return DumpRenderTreeSupportGtk::shouldClose(mainFrame);
919 void LayoutTestController::apiTestNewWindowDataLoadBaseURL(JSStringRef utf8Data, JSStringRef baseURL)
924 void LayoutTestController::apiTestGoToCurrentBackForwardItem()
929 void LayoutTestController::setWebViewEditable(bool)
933 JSRetainPtr<JSStringRef> LayoutTestController::markerTextForListItem(JSContextRef context, JSValueRef nodeObject) const
935 CString markerTextGChar = DumpRenderTreeSupportGtk::markerTextForListItem(mainFrame, context, nodeObject);
936 if (markerTextGChar.isNull())
939 JSRetainPtr<JSStringRef> markerText(Adopt, JSStringCreateWithUTF8CString(markerTextGChar.data()));
943 void LayoutTestController::authenticateSession(JSStringRef, JSStringRef, JSStringRef)
947 void LayoutTestController::abortModal()
951 void LayoutTestController::dumpConfigurationForViewport(int deviceDPI, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight)
953 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
955 DumpRenderTreeSupportGtk::dumpConfigurationForViewport(webView, deviceDPI, deviceWidth, deviceHeight, availableWidth, availableHeight);
958 void LayoutTestController::setSerializeHTTPLoads(bool serialize)
960 DumpRenderTreeSupportGtk::setSerializeHTTPLoads(serialize);
963 void LayoutTestController::setMinimumTimerInterval(double minimumTimerInterval)
965 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
966 DumpRenderTreeSupportGtk::setMinimumTimerInterval(webView, minimumTimerInterval);
969 void LayoutTestController::setTextDirection(JSStringRef direction)
974 void LayoutTestController::addChromeInputField()
978 void LayoutTestController::removeChromeInputField()
982 void LayoutTestController::focusWebView()
986 void LayoutTestController::setBackingScaleFactor(double)
990 void LayoutTestController::simulateDesktopNotificationClick(JSStringRef title)
994 void LayoutTestController::resetPageVisibility()
996 // FIXME: Implement this.
999 void LayoutTestController::setPageVisibility(const char*)
1001 // FIXME: Implement this.
1004 void LayoutTestController::setAutomaticLinkDetectionEnabled(bool)
1006 // FIXME: Implement this.
1009 void LayoutTestController::sendWebIntentResponse(JSStringRef)
1011 // FIXME: Implement this.