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 void LayoutTestController::keepWebHistory()
110 JSValueRef LayoutTestController::computedStyleIncludingVisitedInfo(JSContextRef context, JSValueRef value)
112 return DumpRenderTreeSupportGtk::computedStyleIncludingVisitedInfo(context, value);
115 JSRetainPtr<JSStringRef> LayoutTestController::layerTreeAsText() const
118 JSRetainPtr<JSStringRef> string(Adopt, JSStringCreateWithUTF8CString(""));
122 int LayoutTestController::numberOfPages(float pageWidth, float pageHeight)
124 return DumpRenderTreeSupportGtk::numberOfPagesForFrame(mainFrame, pageWidth, pageHeight);
127 JSRetainPtr<JSStringRef> LayoutTestController::pageProperty(const char* propertyName, int pageNumber) const
129 JSRetainPtr<JSStringRef> propertyValue(Adopt, JSStringCreateWithUTF8CString(DumpRenderTreeSupportGtk::pageProperty(mainFrame, propertyName, pageNumber).data()));
130 return propertyValue;
133 JSRetainPtr<JSStringRef> LayoutTestController::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const
135 JSRetainPtr<JSStringRef> propertyValue(Adopt, JSStringCreateWithUTF8CString(DumpRenderTreeSupportGtk::pageSizeAndMarginsInPixels(mainFrame, pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft).data()));
136 return propertyValue;
139 size_t LayoutTestController::webHistoryItemCount()
141 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
142 WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list(webView);
147 // We do not add the current page to the total count as it's not
148 // considered in DRT tests
149 return webkit_web_back_forward_list_get_back_length(list) +
150 webkit_web_back_forward_list_get_forward_length(list);
153 unsigned LayoutTestController::workerThreadCount() const
155 return DumpRenderTreeSupportGtk::workerThreadCount();
158 JSRetainPtr<JSStringRef> LayoutTestController::platformName() const
160 JSRetainPtr<JSStringRef> platformName(Adopt, JSStringCreateWithUTF8CString("gtk"));
164 void LayoutTestController::notifyDone()
166 if (m_waitToDump && !topLoadingFrame && !WorkQueue::shared()->count())
168 m_waitToDump = false;
169 waitForPolicy = false;
172 JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef url)
174 GOwnPtr<char> urlCString(JSStringCopyUTF8CString(url));
175 if (!g_str_has_prefix(urlCString.get(), "file:///tmp/LayoutTests/"))
176 return JSStringRetain(url);
178 const char* layoutTestsSuffix = urlCString.get() + strlen("file:///tmp/");
179 GOwnPtr<char> testPath(g_build_filename(getTopLevelPath().data(), layoutTestsSuffix, NULL));
180 GOwnPtr<char> testURI(g_filename_to_uri(testPath.get(), 0, 0));
181 return JSStringCreateWithUTF8CString(testURI.get());
184 void LayoutTestController::queueLoad(JSStringRef url, JSStringRef target)
186 gchar* relativeURL = JSStringCopyUTF8CString(url);
187 SoupURI* baseURI = soup_uri_new(webkit_web_frame_get_uri(mainFrame));
189 SoupURI* absoluteURI = soup_uri_new_with_base(baseURI, relativeURL);
190 soup_uri_free(baseURI);
193 gchar* absoluteCString;
195 absoluteCString = soup_uri_to_string(absoluteURI, FALSE);
196 soup_uri_free(absoluteURI);
198 absoluteCString = JSStringCopyUTF8CString(url);
200 JSRetainPtr<JSStringRef> absoluteURL(Adopt, JSStringCreateWithUTF8CString(absoluteCString));
201 g_free(absoluteCString);
203 WorkQueue::shared()->queue(new LoadItem(absoluteURL.get(), target));
206 void LayoutTestController::setAcceptsEditing(bool acceptsEditing)
208 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
209 webkit_web_view_set_editable(webView, acceptsEditing);
212 void LayoutTestController::setAlwaysAcceptCookies(bool alwaysAcceptCookies)
214 SoupSession* session = webkit_get_default_session();
215 SoupCookieJar* jar = reinterpret_cast<SoupCookieJar*>(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR));
217 /* If the jar was not created - we create it on demand, i.e, just
218 in case we have HTTP requests - then we must create it here in
219 order to set the proper accept policy */
221 jar = soup_cookie_jar_new();
222 soup_session_add_feature(session, SOUP_SESSION_FEATURE(jar));
226 SoupCookieJarAcceptPolicy policy;
228 if (alwaysAcceptCookies)
229 policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
231 policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
233 g_object_set(G_OBJECT(jar), SOUP_COOKIE_JAR_ACCEPT_POLICY, policy, NULL);
236 void LayoutTestController::setCustomPolicyDelegate(bool setDelegate, bool permissive)
241 void LayoutTestController::waitForPolicyDelegate()
243 waitForPolicy = true;
247 void LayoutTestController::setScrollbarPolicy(JSStringRef orientation, JSStringRef policy)
252 void LayoutTestController::addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains)
254 gchar* sourceOriginGChar = JSStringCopyUTF8CString(sourceOrigin);
255 gchar* protocolGChar = JSStringCopyUTF8CString(protocol);
256 gchar* hostGChar = JSStringCopyUTF8CString(host);
257 DumpRenderTreeSupportGtk::whiteListAccessFromOrigin(sourceOriginGChar, protocolGChar, hostGChar, includeSubdomains);
258 g_free(sourceOriginGChar);
259 g_free(protocolGChar);
263 void LayoutTestController::removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains)
265 GOwnPtr<gchar> sourceOriginGChar(JSStringCopyUTF8CString(sourceOrigin));
266 GOwnPtr<gchar> protocolGChar(JSStringCopyUTF8CString(protocol));
267 GOwnPtr<gchar> hostGChar(JSStringCopyUTF8CString(host));
268 DumpRenderTreeSupportGtk::removeWhiteListAccessFromOrigin(sourceOriginGChar.get(), protocolGChar.get(), hostGChar.get(), includeSubdomains);
271 void LayoutTestController::setMainFrameIsFirstResponder(bool flag)
276 void LayoutTestController::setTabKeyCyclesThroughElements(bool cycles)
278 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
279 WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
280 g_object_set(G_OBJECT(settings), "tab-key-cycles-through-elements", cycles, NULL);
283 void LayoutTestController::setUseDashboardCompatibilityMode(bool flag)
288 static gchar* userStyleSheet = NULL;
289 static gboolean userStyleSheetEnabled = TRUE;
291 void LayoutTestController::setUserStyleSheetEnabled(bool flag)
293 userStyleSheetEnabled = flag;
295 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
296 WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
297 if (flag && userStyleSheet)
298 g_object_set(G_OBJECT(settings), "user-stylesheet-uri", userStyleSheet, NULL);
300 g_object_set(G_OBJECT(settings), "user-stylesheet-uri", "", NULL);
303 void LayoutTestController::setUserStyleSheetLocation(JSStringRef path)
305 g_free(userStyleSheet);
306 userStyleSheet = JSStringCopyUTF8CString(path);
307 if (userStyleSheetEnabled)
308 setUserStyleSheetEnabled(true);
311 void LayoutTestController::setValueForUser(JSContextRef context, JSValueRef nodeObject, JSStringRef value)
313 DumpRenderTreeSupportGtk::setValueForUser(context, nodeObject, value);
316 void LayoutTestController::setViewModeMediaFeature(JSStringRef mode)
318 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
321 char* viewMode = JSStringCopyUTF8CString(mode);
323 if (!g_strcmp0(viewMode, "windowed"))
324 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_WINDOWED);
325 else if (!g_strcmp0(viewMode, "floating"))
326 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FLOATING);
327 else if (!g_strcmp0(viewMode, "fullscreen"))
328 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FULLSCREEN);
329 else if (!g_strcmp0(viewMode, "maximized"))
330 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MAXIMIZED);
331 else if (!g_strcmp0(viewMode, "minimized"))
332 webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MINIMIZED);
337 void LayoutTestController::setWindowIsKey(bool windowIsKey)
342 void LayoutTestController::setSmartInsertDeleteEnabled(bool flag)
344 DumpRenderTreeSupportGtk::setSmartInsertDeleteEnabled(webkit_web_frame_get_web_view(mainFrame), flag);
347 static gboolean waitToDumpWatchdogFired(void*)
349 setWaitToDumpWatchdog(0);
350 gLayoutTestController->waitToDumpWatchdogTimerFired();
354 void LayoutTestController::setWaitToDump(bool waitUntilDone)
356 static const int timeoutSeconds = 30;
358 m_waitToDump = waitUntilDone;
359 if (m_waitToDump && shouldSetWaitToDumpWatchdog())
360 setWaitToDumpWatchdog(g_timeout_add_seconds(timeoutSeconds, waitToDumpWatchdogFired, 0));
363 int LayoutTestController::windowCount()
365 // +1 -> including the main view
366 return g_slist_length(webViewList) + 1;
369 void LayoutTestController::setPrivateBrowsingEnabled(bool flag)
371 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
374 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
375 g_object_set(G_OBJECT(settings), "enable-private-browsing", flag, NULL);
378 void LayoutTestController::setJavaScriptCanAccessClipboard(bool flag)
380 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
383 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
384 g_object_set(G_OBJECT(settings), "javascript-can-access-clipboard", flag, NULL);
387 void LayoutTestController::setXSSAuditorEnabled(bool flag)
389 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
392 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
393 g_object_set(G_OBJECT(settings), "enable-xss-auditor", flag, NULL);
396 void LayoutTestController::setFrameFlatteningEnabled(bool flag)
398 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
401 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
402 g_object_set(G_OBJECT(settings), "enable-frame-flattening", flag, NULL);
405 void LayoutTestController::setSpatialNavigationEnabled(bool flag)
407 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
410 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
411 g_object_set(G_OBJECT(settings), "enable-spatial-navigation", flag, NULL);
414 void LayoutTestController::setAllowUniversalAccessFromFileURLs(bool flag)
416 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
419 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
420 g_object_set(G_OBJECT(settings), "enable-universal-access-from-file-uris", flag, NULL);
423 void LayoutTestController::setAllowFileAccessFromFileURLs(bool flag)
425 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
428 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
429 g_object_set(G_OBJECT(settings), "enable-file-access-from-file-uris", flag, NULL);
432 void LayoutTestController::setAuthorAndUserStylesEnabled(bool flag)
437 void LayoutTestController::setAutofilled(JSContextRef context, JSValueRef nodeObject, bool isAutofilled)
439 DumpRenderTreeSupportGtk::setAutofilled(context, nodeObject, isAutofilled);
442 void LayoutTestController::disableImageLoading()
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), "auto-load-images", FALSE, NULL);
451 void LayoutTestController::setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
453 // FIXME: Implement for DeviceOrientation layout tests.
454 // See https://bugs.webkit.org/show_bug.cgi?id=30335.
457 void LayoutTestController::setMockGeolocationPosition(double latitude, double longitude, double accuracy)
459 WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0));
461 view = webkit_web_frame_get_web_view(mainFrame);
464 DumpRenderTreeSupportGtk::setMockGeolocationPosition(view, latitude, longitude, accuracy);
467 void LayoutTestController::setMockGeolocationError(int code, JSStringRef message)
469 WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0));
471 view = webkit_web_frame_get_web_view(mainFrame);
474 GOwnPtr<gchar> cMessage(JSStringCopyUTF8CString(message));
475 DumpRenderTreeSupportGtk::setMockGeolocationError(view, code, cMessage.get());
478 void LayoutTestController::setGeolocationPermission(bool allow)
480 setGeolocationPermissionCommon(allow);
481 WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0));
483 view = webkit_web_frame_get_web_view(mainFrame);
486 DumpRenderTreeSupportGtk::setMockGeolocationPermission(view, allow);
489 int LayoutTestController::numberOfPendingGeolocationPermissionRequests()
491 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
493 view = webkit_web_frame_get_web_view(mainFrame);
496 return DumpRenderTreeSupportGtk::numberOfPendingGeolocationPermissionRequests(view);
499 void LayoutTestController::addMockSpeechInputResult(JSStringRef result, double confidence, JSStringRef language)
501 // FIXME: Implement for speech input layout tests.
502 // See https://bugs.webkit.org/show_bug.cgi?id=39485.
505 void LayoutTestController::setMockSpeechInputDumpRect(bool flag)
507 // FIXME: Implement for speech input layout tests.
508 // See https://bugs.webkit.org/show_bug.cgi?id=39485.
511 void LayoutTestController::startSpeechInput(JSContextRef inputElement)
513 // FIXME: Implement for speech input layout tests.
514 // See https://bugs.webkit.org/show_bug.cgi?id=39485.
517 void LayoutTestController::setIconDatabaseEnabled(bool enabled)
519 WebKitIconDatabase* database = webkit_get_icon_database();
521 GOwnPtr<gchar> iconDatabasePath(g_build_filename(g_get_tmp_dir(), "DumpRenderTree", "icondatabase", NULL));
522 webkit_icon_database_set_path(database, iconDatabasePath.get());
524 webkit_icon_database_set_path(database, 0);
527 void LayoutTestController::setSelectTrailingWhitespaceEnabled(bool flag)
529 DumpRenderTreeSupportGtk::setSelectTrailingWhitespaceEnabled(flag);
532 void LayoutTestController::setPopupBlockingEnabled(bool flag)
534 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
537 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
538 g_object_set(G_OBJECT(settings), "javascript-can-open-windows-automatically", !flag, NULL);
542 void LayoutTestController::setPluginsEnabled(bool flag)
544 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
547 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
548 g_object_set(G_OBJECT(settings), "enable-plugins", flag, NULL);
551 bool LayoutTestController::elementDoesAutoCompleteForElementWithId(JSStringRef id)
553 return DumpRenderTreeSupportGtk::elementDoesAutoCompleteForElementWithId(mainFrame, id);
556 void LayoutTestController::execCommand(JSStringRef name, JSStringRef value)
558 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
561 gchar* cName = JSStringCopyUTF8CString(name);
562 gchar* cValue = JSStringCopyUTF8CString(value);
563 DumpRenderTreeSupportGtk::executeCoreCommandByName(view, cName, cValue);
568 bool LayoutTestController::findString(JSContextRef context, JSStringRef target, JSObjectRef optionsArray)
570 WebKitFindOptions findOptions = 0;
571 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
574 JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length"));
575 JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0);
576 if (!JSValueIsNumber(context, lengthValue))
579 GOwnPtr<gchar> targetString(JSStringCopyUTF8CString(target));
581 size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0));
582 for (size_t i = 0; i < length; ++i) {
583 JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
584 if (!JSValueIsString(context, value))
587 JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0));
589 if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive"))
590 findOptions |= WebKit::WebFindOptionsCaseInsensitive;
591 else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts"))
592 findOptions |= WebKit::WebFindOptionsAtWordStarts;
593 else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart"))
594 findOptions |= WebKit::WebFindOptionsTreatMedialCapitalAsWordStart;
595 else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards"))
596 findOptions |= WebKit::WebFindOptionsBackwards;
597 else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround"))
598 findOptions |= WebKit::WebFindOptionsWrapAround;
599 else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection"))
600 findOptions |= WebKit::WebFindOptionsStartInSelection;
603 return DumpRenderTreeSupportGtk::findString(webView, targetString.get(), findOptions);
606 bool LayoutTestController::isCommandEnabled(JSStringRef name)
608 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
611 gchar* cName = JSStringCopyUTF8CString(name);
612 bool result = DumpRenderTreeSupportGtk::isCommandEnabled(view, cName);
617 void LayoutTestController::setCacheModel(int cacheModel)
619 // These constants are derived from the Mac cache model enum in Source/WebKit/mac/WebView/WebPreferences.h.
620 switch (cacheModel) {
622 webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
625 webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER);
628 webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER);
631 ASSERT_NOT_REACHED();
635 void LayoutTestController::setPersistentUserStyleSheetLocation(JSStringRef jsURL)
640 void LayoutTestController::clearPersistentUserStyleSheet()
645 void LayoutTestController::clearAllApplicationCaches()
647 // FIXME: Implement to support application cache quotas.
650 void LayoutTestController::setApplicationCacheOriginQuota(unsigned long long quota)
652 // FIXME: Implement to support application cache quotas.
655 void LayoutTestController::clearApplicationCacheForOrigin(OpaqueJSString*)
657 // FIXME: Implement to support deleting all application caches for an origin.
660 long long LayoutTestController::localStorageDiskUsageForOrigin(JSStringRef originIdentifier)
662 // FIXME: Implement to support getting disk usage in bytes for an origin.
666 JSValueRef LayoutTestController::originsWithApplicationCache(JSContextRef context)
668 // FIXME: Implement to get origins that contain application caches.
669 return JSValueMakeUndefined(context);
672 long long LayoutTestController::applicationCacheDiskUsageForOrigin(JSStringRef name)
678 void LayoutTestController::clearAllDatabases()
680 webkit_remove_all_web_databases();
683 void LayoutTestController::setDatabaseQuota(unsigned long long quota)
685 WebKitSecurityOrigin* origin = webkit_web_frame_get_security_origin(mainFrame);
686 webkit_security_origin_set_web_database_quota(origin, quota);
689 JSValueRef LayoutTestController::originsWithLocalStorage(JSContextRef context)
692 return JSValueMakeUndefined(context);
695 void LayoutTestController::deleteAllLocalStorage()
700 void LayoutTestController::deleteLocalStorageForOrigin(JSStringRef originIdentifier)
705 void LayoutTestController::observeStorageTrackerNotifications(unsigned number)
710 void LayoutTestController::syncLocalStorage()
715 void LayoutTestController::setDomainRelaxationForbiddenForURLScheme(bool forbidden, JSStringRef scheme)
717 GOwnPtr<gchar> urlScheme(JSStringCopyUTF8CString(scheme));
718 DumpRenderTreeSupportGtk::setDomainRelaxationForbiddenForURLScheme(forbidden, urlScheme.get());
721 void LayoutTestController::goBack()
723 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
724 webkit_web_view_go_back(webView);
727 void LayoutTestController::setDefersLoading(bool defers)
729 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
730 DumpRenderTreeSupportGtk::setDefersLoading(webView, defers);
733 void LayoutTestController::setAppCacheMaximumSize(unsigned long long size)
735 webkit_application_cache_set_maximum_size(size);
738 bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId)
740 gchar* name = JSStringCopyUTF8CString(animationName);
741 gchar* element = JSStringCopyUTF8CString(elementId);
742 bool returnValue = DumpRenderTreeSupportGtk::pauseAnimation(mainFrame, name, time, element);
748 bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId)
750 gchar* name = JSStringCopyUTF8CString(propertyName);
751 gchar* element = JSStringCopyUTF8CString(elementId);
752 bool returnValue = DumpRenderTreeSupportGtk::pauseTransition(mainFrame, name, time, element);
758 unsigned LayoutTestController::numberOfActiveAnimations() const
760 return DumpRenderTreeSupportGtk::numberOfActiveAnimations(mainFrame);
763 static gboolean booleanFromValue(gchar* value)
765 return !g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1");
768 void LayoutTestController::overridePreference(JSStringRef key, JSStringRef value)
770 GOwnPtr<gchar> originalName(JSStringCopyUTF8CString(key));
771 GOwnPtr<gchar> valueAsString(JSStringCopyUTF8CString(value));
773 WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
776 // This transformation could be handled by a hash table (and it once was), but
777 // having it prominent, makes it easier for people from other ports to keep the
779 const gchar* propertyName = 0;
780 if (g_str_equal(originalName.get(), "WebKitJavaScriptEnabled"))
781 propertyName = "enable-scripts";
782 else if (g_str_equal(originalName.get(), "WebKitDefaultFontSize"))
783 propertyName = "default-font-size";
784 else if (g_str_equal(originalName.get(), "WebKitEnableCaretBrowsing"))
785 propertyName = "enable-caret-browsing";
786 else if (g_str_equal(originalName.get(), "WebKitUsesPageCachePreferenceKey"))
787 propertyName = "enable-page-cache";
788 else if (g_str_equal(originalName.get(), "WebKitPluginsEnabled"))
789 propertyName = "enable-plugins";
790 else if (g_str_equal(originalName.get(), "WebKitHyperlinkAuditingEnabled"))
791 propertyName = "enable-hyperlink-auditing";
792 else if (g_str_equal(originalName.get(), "WebKitWebGLEnabled"))
793 propertyName = "enable-webgl";
794 else if (g_str_equal(originalName.get(), "WebKitWebAudioEnabled"))
795 propertyName = "enable-webaudio";
796 else if (g_str_equal(originalName.get(), "WebKitTabToLinksPreferenceKey")) {
797 DumpRenderTreeSupportGtk::setLinksIncludedInFocusChain(booleanFromValue(valueAsString.get()));
799 } else if (g_str_equal(originalName.get(), "WebKitPageCacheSupportsPluginsPreferenceKey")) {
800 DumpRenderTreeSupportGtk::setPageCacheSupportsPlugins(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
802 } else if (g_str_equal(originalName.get(), "WebKitCSSGridLayoutEnabled")) {
803 DumpRenderTreeSupportGtk::setCSSGridLayoutEnabled(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
805 } else if (g_str_equal(originalName.get(), "WebKitCSSRegionsEnabled")) {
806 DumpRenderTreeSupportGtk::setCSSRegionsEnabled(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
809 fprintf(stderr, "LayoutTestController::overridePreference tried to override "
810 "unknown preference '%s'.\n", originalName.get());
814 WebKitWebSettings* settings = webkit_web_view_get_settings(view);
815 GParamSpec* pspec = g_object_class_find_property(G_OBJECT_CLASS(
816 WEBKIT_WEB_SETTINGS_GET_CLASS(settings)), propertyName);
817 GValue currentPropertyValue = { 0, { { 0 } } };
818 g_value_init(¤tPropertyValue, pspec->value_type);
820 if (G_VALUE_HOLDS_STRING(¤tPropertyValue))
821 g_object_set(settings, propertyName, valueAsString.get(), NULL);
822 else if (G_VALUE_HOLDS_BOOLEAN(¤tPropertyValue))
823 g_object_set(G_OBJECT(settings), propertyName, booleanFromValue(valueAsString.get()), NULL);
824 else if (G_VALUE_HOLDS_INT(¤tPropertyValue))
825 g_object_set(G_OBJECT(settings), propertyName, atoi(valueAsString.get()), NULL);
826 else if (G_VALUE_HOLDS_FLOAT(¤tPropertyValue)) {
827 gfloat newValue = g_ascii_strtod(valueAsString.get(), 0);
828 g_object_set(G_OBJECT(settings), propertyName, newValue, NULL);
830 fprintf(stderr, "LayoutTestController::overridePreference failed to override "
831 "preference '%s'.\n", originalName.get());
834 void LayoutTestController::addUserScript(JSStringRef source, bool runAtStart, bool allFrames)
836 printf("LayoutTestController::addUserScript not implemented.\n");
839 void LayoutTestController::addUserStyleSheet(JSStringRef source, bool allFrames)
841 GOwnPtr<gchar> sourceCode(JSStringCopyUTF8CString(source));
842 DumpRenderTreeSupportGtk::addUserStyleSheet(mainFrame, sourceCode.get(), allFrames);
843 // FIXME: needs more investigation why userscripts/user-style-top-frame-only.html fails when allFrames is false.
847 void LayoutTestController::setDeveloperExtrasEnabled(bool enabled)
849 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
850 WebKitWebSettings* webSettings = webkit_web_view_get_settings(webView);
852 g_object_set(webSettings, "enable-developer-extras", enabled, NULL);
855 void LayoutTestController::setAsynchronousSpellCheckingEnabled(bool)
857 // FIXME: Implement this.
860 void LayoutTestController::showWebInspector()
862 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
863 WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView);
865 webkit_web_inspector_show(inspector);
868 void LayoutTestController::closeWebInspector()
870 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
871 WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView);
873 webkit_web_inspector_close(inspector);
876 void LayoutTestController::evaluateInWebInspector(long callId, JSStringRef script)
878 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
879 WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView);
880 char* scriptString = JSStringCopyUTF8CString(script);
882 webkit_web_inspector_execute_script(inspector, callId, scriptString);
883 g_free(scriptString);
886 void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
888 // FIXME: Implement this.
891 void LayoutTestController::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
893 // FIXME: Implement this.
896 void LayoutTestController::removeAllVisitedLinks()
898 // FIXME: Implement this.
901 bool LayoutTestController::callShouldCloseOnWebView()
903 return DumpRenderTreeSupportGtk::shouldClose(mainFrame);
906 void LayoutTestController::apiTestNewWindowDataLoadBaseURL(JSStringRef utf8Data, JSStringRef baseURL)
911 void LayoutTestController::apiTestGoToCurrentBackForwardItem()
916 void LayoutTestController::setWebViewEditable(bool)
920 JSRetainPtr<JSStringRef> LayoutTestController::markerTextForListItem(JSContextRef context, JSValueRef nodeObject) const
922 CString markerTextGChar = DumpRenderTreeSupportGtk::markerTextForListItem(mainFrame, context, nodeObject);
923 if (markerTextGChar.isNull())
926 JSRetainPtr<JSStringRef> markerText(Adopt, JSStringCreateWithUTF8CString(markerTextGChar.data()));
930 void LayoutTestController::authenticateSession(JSStringRef, JSStringRef, JSStringRef)
934 void LayoutTestController::abortModal()
938 void LayoutTestController::setSerializeHTTPLoads(bool serialize)
940 DumpRenderTreeSupportGtk::setSerializeHTTPLoads(serialize);
943 void LayoutTestController::setMinimumTimerInterval(double minimumTimerInterval)
945 WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
946 DumpRenderTreeSupportGtk::setMinimumTimerInterval(webView, minimumTimerInterval);
949 void LayoutTestController::setTextDirection(JSStringRef direction)
954 void LayoutTestController::addChromeInputField()
958 void LayoutTestController::removeChromeInputField()
962 void LayoutTestController::focusWebView()
966 void LayoutTestController::setBackingScaleFactor(double)
970 void LayoutTestController::simulateDesktopNotificationClick(JSStringRef title)
974 void LayoutTestController::resetPageVisibility()
976 // FIXME: Implement this.
979 void LayoutTestController::setPageVisibility(const char*)
981 // FIXME: Implement this.
984 void LayoutTestController::setAutomaticLinkDetectionEnabled(bool)
986 // FIXME: Implement this.
989 void LayoutTestController::sendWebIntentResponse(JSStringRef)
991 // FIXME: Implement this.
994 void LayoutTestController::deliverWebIntent(JSStringRef, JSStringRef, JSStringRef)
996 // FIXME: Implement this.
999 void LayoutTestController::setStorageDatabaseIdleInterval(double)
1001 // FIXME: Implement this.