[EFL][DRT] Normalize file:///tmp/LayoutTests in LayoutTestController::pathToLocalReso...
[WebKit-https.git] / Tools / DumpRenderTree / efl / LayoutTestControllerEfl.cpp
1 /*
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>
8  * Copyright (C) 2011 ProFUSION Embedded Systems
9  * Copyright (C) 2011 Samsung Electronics
10  * Copyright (C) 2012 Intel Corporation
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  *
16  * 1.  Redistributions of source code must retain the above copyright
17  *     notice, this list of conditions and the following disclaimer.
18  * 2.  Redistributions in binary form must reproduce the above copyright
19  *     notice, this list of conditions and the following disclaimer in the
20  *     documentation and/or other materials provided with the distribution.
21  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
22  *     its contributors may be used to endorse or promote products derived
23  *     from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
26  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
29  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #include "config.h"
38 #include "LayoutTestController.h"
39
40 #include "DumpRenderTree.h"
41 #include "DumpRenderTreeChrome.h"
42 #include "JSStringUtils.h"
43 #include "NotImplemented.h"
44 #include "WebCoreSupport/DumpRenderTreeSupportEfl.h"
45 #include "WorkQueue.h"
46 #include "WorkQueueItem.h"
47 #include "ewk_private.h"
48 #include <EWebKit.h>
49 #include <Ecore_File.h>
50 #include <JavaScriptCore/JSRetainPtr.h>
51 #include <JavaScriptCore/JSStringRef.h>
52 #include <JavaScriptCore/OpaqueJSString.h>
53 #include <KURL.h>
54 #include <editing/FindOptions.h>
55 #include <stdio.h>
56 #include <wtf/text/WTFString.h>
57
58 LayoutTestController::~LayoutTestController()
59 {
60 }
61
62 void LayoutTestController::addDisallowedURL(JSStringRef)
63 {
64     notImplemented();
65 }
66
67 void LayoutTestController::clearBackForwardList()
68 {
69     Ewk_History* history = ewk_view_history_get(browser->mainView());
70     if (!history)
71         return;
72
73     Ewk_History_Item* item = ewk_history_history_item_current_get(history);
74     ewk_history_clear(history);
75     ewk_history_history_item_add(history, item);
76     ewk_history_history_item_set(history, item);
77     ewk_history_item_free(item);
78 }
79
80 JSStringRef LayoutTestController::copyDecodedHostName(JSStringRef)
81 {
82     notImplemented();
83     return 0;
84 }
85
86 JSStringRef LayoutTestController::copyEncodedHostName(JSStringRef)
87 {
88     notImplemented();
89     return 0;
90 }
91
92 void LayoutTestController::dispatchPendingLoadRequests()
93 {
94     // FIXME: Implement for testing fix for 6727495
95     notImplemented();
96 }
97
98 void LayoutTestController::display()
99 {
100     displayWebView();
101 }
102
103 JSRetainPtr<JSStringRef> LayoutTestController::counterValueForElementById(JSStringRef id)
104 {
105     const Evas_Object* mainFrame = browser->mainFrame();
106     const String counterValue(DumpRenderTreeSupportEfl::counterValueByElementId(mainFrame, id->ustring().utf8().data()));
107     return JSRetainPtr<JSStringRef>(Adopt, JSStringCreateWithUTF8CString(counterValue.utf8().data()));
108 }
109
110 void LayoutTestController::keepWebHistory()
111 {
112     notImplemented();
113 }
114
115 JSValueRef LayoutTestController::computedStyleIncludingVisitedInfo(JSContextRef context, JSValueRef value)
116 {
117     return DumpRenderTreeSupportEfl::computedStyleIncludingVisitedInfo(context, value);
118 }
119
120 JSRetainPtr<JSStringRef> LayoutTestController::layerTreeAsText() const
121 {
122     notImplemented();
123     return JSRetainPtr<JSStringRef>(Adopt, JSStringCreateWithUTF8CString(""));
124 }
125
126 int LayoutTestController::pageNumberForElementById(JSStringRef id, float pageWidth, float pageHeight)
127 {
128     return DumpRenderTreeSupportEfl::numberOfPagesForElementId(browser->mainFrame(), id->ustring().utf8().data(), pageWidth, pageHeight);
129 }
130
131 int LayoutTestController::numberOfPages(float pageWidth, float pageHeight)
132 {
133     return DumpRenderTreeSupportEfl::numberOfPages(browser->mainFrame(), pageWidth, pageHeight);
134 }
135
136 JSRetainPtr<JSStringRef> LayoutTestController::pageProperty(const char* propertyName, int pageNumber) const
137 {
138     const String property = DumpRenderTreeSupportEfl::pageProperty(browser->mainFrame(), propertyName, pageNumber);
139     if (property.isEmpty())
140         return 0;
141
142     JSRetainPtr<JSStringRef> propertyValue(Adopt, JSStringCreateWithUTF8CString(property.utf8().data()));
143     return propertyValue;
144 }
145
146 JSRetainPtr<JSStringRef> LayoutTestController::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const
147 {
148     String pageSizeAndMargins = DumpRenderTreeSupportEfl::pageSizeAndMarginsInPixels(browser->mainFrame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
149
150     if (pageSizeAndMargins.isEmpty())
151         return 0;
152
153     JSRetainPtr<JSStringRef> returnValue(Adopt, JSStringCreateWithUTF8CString(pageSizeAndMargins.utf8().data()));
154     return returnValue;
155 }
156
157 size_t LayoutTestController::webHistoryItemCount()
158 {
159     const Ewk_History* history = ewk_view_history_get(browser->mainView());
160     if (!history)
161         return -1;
162
163     return ewk_history_back_list_length(history) + ewk_history_forward_list_length(history);
164 }
165
166 unsigned LayoutTestController::workerThreadCount() const
167 {
168     return DumpRenderTreeSupportEfl::workerThreadCount();
169 }
170
171 void LayoutTestController::notifyDone()
172 {
173     if (m_waitToDump && !topLoadingFrame && !WorkQueue::shared()->count())
174         dump();
175     m_waitToDump = false;
176     waitForPolicy = false;
177 }
178
179 JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef url)
180 {
181     String requestedUrl(url->characters());
182     String resourceRoot;
183     String requestedRoot;
184
185     if (requestedUrl.find("LayoutTests") != notFound) {
186         // If the URL contains LayoutTests we need to remap that to
187         // LOCAL_RESOURCE_ROOT which is the path of the LayoutTests directory
188         // within the WebKit source tree.
189         requestedRoot = "/tmp/LayoutTests";
190         resourceRoot = getenv("LOCAL_RESOURCE_ROOT");
191     } else if (requestedUrl.find("tmp") != notFound) {
192         // If the URL is a child of /tmp we need to convert it to be a child
193         // DUMPRENDERTREE_TEMP replace tmp with DUMPRENDERTREE_TEMP
194         requestedRoot = "/tmp";
195         resourceRoot = getenv("DUMPRENDERTREE_TEMP");
196     }
197
198     size_t indexOfRootStart = requestedUrl.reverseFind(requestedRoot);
199     size_t indexOfSeparatorAfterRoot = indexOfRootStart + requestedRoot.length();
200     String fullPathToUrl = "file://" + resourceRoot + requestedUrl.substring(indexOfSeparatorAfterRoot);
201
202     return JSStringCreateWithUTF8CString(fullPathToUrl.utf8().data());
203 }
204
205 void LayoutTestController::queueLoad(JSStringRef url, JSStringRef target)
206 {
207     WebCore::KURL baseURL(WebCore::KURL(), String::fromUTF8(ewk_frame_uri_get(browser->mainFrame())));
208     WebCore::KURL absoluteURL(baseURL, WTF::String(url->ustring().impl()));
209
210     JSRetainPtr<JSStringRef> jsAbsoluteURL(
211         Adopt, JSStringCreateWithUTF8CString(absoluteURL.string().utf8().data()));
212
213     WorkQueue::shared()->queue(new LoadItem(jsAbsoluteURL.get(), target));
214 }
215
216 void LayoutTestController::setAcceptsEditing(bool acceptsEditing)
217 {
218     ewk_view_editable_set(browser->mainView(), acceptsEditing);
219 }
220
221 void LayoutTestController::setAlwaysAcceptCookies(bool alwaysAcceptCookies)
222 {
223     ewk_cookies_policy_set(alwaysAcceptCookies ? EWK_COOKIE_JAR_ACCEPT_ALWAYS : EWK_COOKIE_JAR_ACCEPT_NEVER);
224 }
225
226 void LayoutTestController::setCustomPolicyDelegate(bool enabled, bool permissive)
227 {
228     policyDelegateEnabled = enabled;
229     policyDelegatePermissive = permissive;
230 }
231
232 void LayoutTestController::waitForPolicyDelegate()
233 {
234     setCustomPolicyDelegate(true, false);
235     waitForPolicy = true;
236     setWaitToDump(true);
237 }
238
239 void LayoutTestController::setScrollbarPolicy(JSStringRef, JSStringRef)
240 {
241     notImplemented();
242 }
243
244 void LayoutTestController::addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains)
245 {
246     WebCore::KURL kurl;
247     kurl.setProtocol(String(protocol->characters(), protocol->length()));
248     kurl.setHost(String(host->characters(), host->length()));
249
250     ewk_security_policy_whitelist_origin_add(sourceOrigin->ustring().utf8().data(), kurl.string().utf8().data(), includeSubdomains);
251 }
252
253 void LayoutTestController::removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains)
254 {
255     WebCore::KURL kurl;
256     kurl.setProtocol(String(protocol->characters(), protocol->length()));
257     kurl.setHost(String(host->characters(), host->length()));
258
259     ewk_security_policy_whitelist_origin_del(sourceOrigin->ustring().utf8().data(), kurl.string().utf8().data(), includeSubdomains);
260 }
261
262 void LayoutTestController::setMainFrameIsFirstResponder(bool)
263 {
264     notImplemented();
265 }
266
267 void LayoutTestController::setTabKeyCyclesThroughElements(bool)
268 {
269     notImplemented();
270 }
271
272 void LayoutTestController::setUseDashboardCompatibilityMode(bool)
273 {
274     notImplemented();
275 }
276
277 static CString gUserStyleSheet;
278 static bool gUserStyleSheetEnabled = true;
279
280 void LayoutTestController::setUserStyleSheetEnabled(bool flag)
281 {
282     gUserStyleSheetEnabled = flag;
283     ewk_view_setting_user_stylesheet_set(browser->mainView(), flag ? gUserStyleSheet.data() : 0);
284 }
285
286 void LayoutTestController::setUserStyleSheetLocation(JSStringRef path)
287 {
288     gUserStyleSheet = path->ustring().utf8();
289
290     if (gUserStyleSheetEnabled)
291         setUserStyleSheetEnabled(true);
292 }
293
294 void LayoutTestController::setValueForUser(JSContextRef context, JSValueRef nodeObject, JSStringRef value)
295 {
296     DumpRenderTreeSupportEfl::setValueForUser(context, nodeObject, WTF::String(value->ustring().impl()));
297 }
298
299 void LayoutTestController::setViewModeMediaFeature(JSStringRef mode)
300 {
301     Evas_Object* view = browser->mainView();
302     if (!view)
303         return;
304
305     if (equals(mode, "windowed"))
306         ewk_view_mode_set(view, EWK_VIEW_MODE_WINDOWED);
307     else if (equals(mode, "floating"))
308         ewk_view_mode_set(view, EWK_VIEW_MODE_FLOATING);
309     else if (equals(mode, "fullscreen"))
310         ewk_view_mode_set(view, EWK_VIEW_MODE_FULLSCREEN);
311     else if (equals(mode, "maximized"))
312         ewk_view_mode_set(view, EWK_VIEW_MODE_MAXIMIZED);
313     else if (equals(mode, "minimized"))
314         ewk_view_mode_set(view, EWK_VIEW_MODE_MINIMIZED);
315 }
316
317 void LayoutTestController::setWindowIsKey(bool)
318 {
319     notImplemented();
320 }
321
322 void LayoutTestController::setSmartInsertDeleteEnabled(bool flag)
323 {
324     DumpRenderTreeSupportEfl::setSmartInsertDeleteEnabled(browser->mainView(), flag);
325 }
326
327 static Eina_Bool waitToDumpWatchdogFired(void*)
328 {
329     waitToDumpWatchdog = 0;
330     gLayoutTestController->waitToDumpWatchdogTimerFired();
331     return ECORE_CALLBACK_CANCEL;
332 }
333
334 void LayoutTestController::setWaitToDump(bool waitUntilDone)
335 {
336     static const double timeoutSeconds = 30;
337
338     m_waitToDump = waitUntilDone;
339     if (m_waitToDump && !waitToDumpWatchdog)
340         waitToDumpWatchdog = ecore_timer_add(timeoutSeconds, waitToDumpWatchdogFired, 0);
341 }
342
343 int LayoutTestController::windowCount()
344 {
345     return browser->extraViews().size() + 1; // + 1 for the main view.
346 }
347
348 void LayoutTestController::setPrivateBrowsingEnabled(bool flag)
349 {
350     ewk_view_setting_private_browsing_set(browser->mainView(), flag);
351 }
352
353 void LayoutTestController::setJavaScriptCanAccessClipboard(bool flag)
354 {
355     ewk_view_setting_scripts_can_access_clipboard_set(browser->mainView(), flag);
356 }
357
358 void LayoutTestController::setXSSAuditorEnabled(bool flag)
359 {
360     ewk_view_setting_enable_xss_auditor_set(browser->mainView(), flag);
361 }
362
363 void LayoutTestController::setFrameFlatteningEnabled(bool flag)
364 {
365     ewk_view_setting_enable_frame_flattening_set(browser->mainView(), flag);
366 }
367
368 void LayoutTestController::setSpatialNavigationEnabled(bool flag)
369 {
370     ewk_view_setting_spatial_navigation_set(browser->mainView(), flag);
371 }
372
373 void LayoutTestController::setAllowUniversalAccessFromFileURLs(bool)
374 {
375     notImplemented();
376 }
377
378 void LayoutTestController::setAllowFileAccessFromFileURLs(bool)
379 {
380     notImplemented();
381 }
382
383 void LayoutTestController::setAuthorAndUserStylesEnabled(bool flag)
384 {
385     DumpRenderTreeSupportEfl::setAuthorAndUserStylesEnabled(browser->mainView(), flag);
386 }
387
388 void LayoutTestController::setAutofilled(JSContextRef context, JSValueRef nodeObject, bool autofilled)
389 {
390     DumpRenderTreeSupportEfl::setAutofilled(context, nodeObject, autofilled);
391 }
392
393 void LayoutTestController::disableImageLoading()
394 {
395     ewk_view_setting_auto_load_images_set(browser->mainView(), EINA_FALSE);
396 }
397
398 void LayoutTestController::setMockDeviceOrientation(bool, double, bool, double, bool, double)
399 {
400     // FIXME: Implement for DeviceOrientation layout tests.
401     // See https://bugs.webkit.org/show_bug.cgi?id=30335.
402     notImplemented();
403 }
404
405 void LayoutTestController::setMockGeolocationPosition(double, double, double)
406 {
407     // FIXME: Implement for Geolocation layout tests.
408     // See https://bugs.webkit.org/show_bug.cgi?id=28264.
409     notImplemented();
410 }
411
412 void LayoutTestController::setMockGeolocationError(int, JSStringRef)
413 {
414     // FIXME: Implement for Geolocation layout tests.
415     // See https://bugs.webkit.org/show_bug.cgi?id=28264.
416     notImplemented();
417 }
418
419 void LayoutTestController::setGeolocationPermission(bool allow)
420 {
421     // FIXME: Implement for Geolocation layout tests.
422     setGeolocationPermissionCommon(allow);
423 }
424
425 int LayoutTestController::numberOfPendingGeolocationPermissionRequests()
426 {
427     // FIXME: Implement for Geolocation layout tests.
428     return -1;
429 }
430
431 void LayoutTestController::addMockSpeechInputResult(JSStringRef, double, JSStringRef)
432 {
433     // FIXME: Implement for speech input layout tests.
434     // See https://bugs.webkit.org/show_bug.cgi?id=39485.
435     notImplemented();
436 }
437
438 void LayoutTestController::setMockSpeechInputDumpRect(bool)
439 {
440     // FIXME: Implement for speech input layout tests.
441     // See https://bugs.webkit.org/show_bug.cgi?id=39485.
442     notImplemented();
443 }
444
445 void LayoutTestController::startSpeechInput(JSContextRef inputElement)
446 {
447     // FIXME: Implement for speech input layout tests.
448     // See https://bugs.webkit.org/show_bug.cgi?id=39485.
449     notImplemented();
450 }
451
452 void LayoutTestController::setIconDatabaseEnabled(bool enabled)
453 {
454     ewk_settings_icon_database_path_set(0);
455
456     if (!enabled)
457         return;
458
459     String databasePath;
460     const char* tempDir = getenv("TMPDIR");
461
462     if (tempDir)
463         databasePath = String::fromUTF8(tempDir);
464     else if (tempDir = getenv("TEMP"))
465         databasePath = String::fromUTF8(tempDir);
466     else
467         databasePath = String::fromUTF8("/tmp");
468
469     databasePath.append("/DumpRenderTree/IconDatabase");
470
471     if (ecore_file_mkpath(databasePath.utf8().data()))
472         ewk_settings_icon_database_path_set(databasePath.utf8().data());
473 }
474
475 void LayoutTestController::setSelectTrailingWhitespaceEnabled(bool flag)
476 {
477     DumpRenderTreeSupportEfl::setSelectTrailingWhitespaceEnabled(browser->mainView(), flag);
478 }
479
480 void LayoutTestController::setPopupBlockingEnabled(bool flag)
481 {
482     ewk_view_setting_scripts_can_open_windows_set(browser->mainView(), !flag);
483 }
484
485 void LayoutTestController::setPluginsEnabled(bool flag)
486 {
487     ewk_view_setting_enable_plugins_set(browser->mainView(), flag);
488 }
489
490 bool LayoutTestController::elementDoesAutoCompleteForElementWithId(JSStringRef id)
491 {
492     const String elementId(id->ustring().impl());
493     const Evas_Object* mainFrame = browser->mainFrame();
494     return DumpRenderTreeSupportEfl::elementDoesAutoCompleteForElementWithId(mainFrame, elementId);
495 }
496
497 void LayoutTestController::execCommand(JSStringRef name, JSStringRef value)
498 {
499     DumpRenderTreeSupportEfl::executeCoreCommandByName(browser->mainView(), name->ustring().utf8().data(), value->ustring().utf8().data());
500 }
501
502 bool LayoutTestController::findString(JSContextRef context, JSStringRef target, JSObjectRef optionsArray)
503 {
504     JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length"));
505     JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0);
506     if (!JSValueIsNumber(context, lengthValue))
507         return false;
508
509     WebCore::FindOptions options = 0;
510
511     const size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0));
512     for (size_t i = 0; i < length; ++i) {
513         JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
514         if (!JSValueIsString(context, value))
515             continue;
516
517         JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0));
518
519         if (equals(optionName, "CaseInsensitive"))
520             options |= WebCore::CaseInsensitive;
521         else if (equals(optionName, "AtWordStarts"))
522             options |= WebCore::AtWordStarts;
523         else if (equals(optionName, "TreatMedialCapitalAsWordStart"))
524             options |= WebCore::TreatMedialCapitalAsWordStart;
525         else if (equals(optionName, "Backwards"))
526             options |= WebCore::Backwards;
527         else if (equals(optionName, "WrapAround"))
528             options |= WebCore::WrapAround;
529         else if (equals(optionName, "StartInSelection"))
530             options |= WebCore::StartInSelection;
531     }
532
533     return DumpRenderTreeSupportEfl::findString(browser->mainView(), WTF::String(target->ustring().impl()), options);
534 }
535
536 bool LayoutTestController::isCommandEnabled(JSStringRef name)
537 {
538     return DumpRenderTreeSupportEfl::isCommandEnabled(browser->mainView(), name->ustring().utf8().data());
539 }
540
541 void LayoutTestController::setCacheModel(int cacheModel)
542 {
543     unsigned int cacheTotalCapacity;
544     unsigned int cacheMinDeadCapacity;
545     unsigned int cacheMaxDeadCapacity;
546     double deadDecodedDataDeletionInterval;
547     unsigned int pageCacheCapacity;
548
549     // These constants are derived from the Mac cache model enum in Source/WebKit/mac/WebView/WebPreferences.h.
550     switch (cacheModel) {
551     case 0: // WebCacheModelDocumentViewer
552         pageCacheCapacity = 0;
553         cacheTotalCapacity = 0;
554         cacheMinDeadCapacity = 0;
555         cacheMaxDeadCapacity = 0;
556         deadDecodedDataDeletionInterval = 0;
557         break;
558     case 1: // WebCacheModelDocumentBrowser
559         pageCacheCapacity = 2;
560         cacheTotalCapacity = 16 * 1024 * 1024;
561         cacheMinDeadCapacity = cacheTotalCapacity / 8;
562         cacheMaxDeadCapacity = cacheTotalCapacity / 4;
563         deadDecodedDataDeletionInterval = 0;
564         break;
565     case 3: // WebCacheModelPrimaryWebBrowser
566         pageCacheCapacity = 3;
567         cacheTotalCapacity = 32 * 1024 * 1024;
568         cacheMinDeadCapacity = cacheTotalCapacity / 4;
569         cacheMaxDeadCapacity = cacheTotalCapacity / 2;
570         deadDecodedDataDeletionInterval = 60;
571         break;
572     default:
573         fprintf(stderr, "trying to set an invalid value %d for the Cache model.", cacheModel);
574         return;
575     }
576
577     ewk_settings_object_cache_capacity_set(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
578     DumpRenderTreeSupportEfl::setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
579     ewk_settings_page_cache_capacity_set(pageCacheCapacity);
580 }
581
582 void LayoutTestController::setPersistentUserStyleSheetLocation(JSStringRef)
583 {
584     notImplemented();
585 }
586
587 void LayoutTestController::clearPersistentUserStyleSheet()
588 {
589     notImplemented();
590 }
591
592 void LayoutTestController::clearAllApplicationCaches()
593 {
594     ewk_settings_application_cache_clear();
595 }
596
597 void LayoutTestController::setApplicationCacheOriginQuota(unsigned long long quota)
598 {
599     Ewk_Security_Origin* origin = ewk_frame_security_origin_get(browser->mainFrame());
600     ewk_security_origin_application_cache_quota_set(origin, quota);
601     ewk_security_origin_free(origin);
602 }
603
604 void LayoutTestController::clearApplicationCacheForOrigin(OpaqueJSString* url)
605 {
606     Ewk_Security_Origin* origin = ewk_security_origin_new_from_string(url->ustring().utf8().data());
607     ewk_security_origin_application_cache_clear(origin);
608     ewk_security_origin_free(origin);
609 }
610
611 long long LayoutTestController::localStorageDiskUsageForOrigin(JSStringRef)
612 {
613     // FIXME: Implement to support getting disk usage in bytes for an origin.
614     notImplemented();
615     return 0;
616 }
617
618 JSValueRef LayoutTestController::originsWithApplicationCache(JSContextRef context)
619 {
620     // FIXME: Implement to get origins that contain application caches.
621     notImplemented();
622     return JSValueMakeUndefined(context);
623 }
624
625 long long LayoutTestController::applicationCacheDiskUsageForOrigin(JSStringRef)
626 {
627     notImplemented();
628     return 0;
629 }
630
631 void LayoutTestController::clearAllDatabases()
632 {
633     ewk_web_database_remove_all();
634 }
635
636 void LayoutTestController::setDatabaseQuota(unsigned long long quota)
637 {
638     Ewk_Security_Origin* origin = ewk_frame_security_origin_get(browser->mainFrame());
639     ewk_security_origin_web_database_quota_set(origin, quota);
640     ewk_security_origin_free(origin);
641 }
642
643 JSValueRef LayoutTestController::originsWithLocalStorage(JSContextRef context)
644 {
645     notImplemented();
646     return JSValueMakeUndefined(context);
647 }
648
649 void LayoutTestController::deleteAllLocalStorage()
650 {
651     notImplemented();
652 }
653
654 void LayoutTestController::deleteLocalStorageForOrigin(JSStringRef)
655 {
656     notImplemented();
657 }
658
659 void LayoutTestController::observeStorageTrackerNotifications(unsigned)
660 {
661     notImplemented();
662 }
663
664 void LayoutTestController::syncLocalStorage()
665 {
666     notImplemented();
667 }
668
669 void LayoutTestController::setDomainRelaxationForbiddenForURLScheme(bool, JSStringRef)
670 {
671     notImplemented();
672 }
673
674 void LayoutTestController::goBack()
675 {
676     ewk_frame_back(browser->mainFrame());
677 }
678
679 void LayoutTestController::setDefersLoading(bool defers)
680 {
681     DumpRenderTreeSupportEfl::setDefersLoading(browser->mainView(), defers);
682 }
683
684 void LayoutTestController::setAppCacheMaximumSize(unsigned long long size)
685 {
686     ewk_settings_application_cache_max_quota_set(size);
687 }
688
689 bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId)
690 {
691     return DumpRenderTreeSupportEfl::pauseAnimation(browser->mainFrame(), animationName->ustring().utf8().data(), elementId->ustring().utf8().data(), time);
692 }
693
694 bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId)
695 {
696     return DumpRenderTreeSupportEfl::pauseTransition(browser->mainFrame(), propertyName->ustring().utf8().data(), elementId->ustring().utf8().data(), time);
697 }
698
699 unsigned LayoutTestController::numberOfActiveAnimations() const
700 {
701     return DumpRenderTreeSupportEfl::activeAnimationsCount(browser->mainFrame());
702 }
703
704 static inline bool toBool(JSStringRef value)
705 {
706     return equals(value, "true") || equals(value, "1");
707 }
708
709 static inline int toInt(JSStringRef value)
710 {
711     return atoi(value->ustring().utf8().data());
712 }
713
714 void LayoutTestController::overridePreference(JSStringRef key, JSStringRef value)
715 {
716     if (equals(key, "WebKitJavaScriptEnabled"))
717         ewk_view_setting_enable_scripts_set(browser->mainView(), toBool(value));
718     else if (equals(key, "WebKitDefaultFontSize"))
719         ewk_view_setting_font_default_size_set(browser->mainView(), toInt(value));
720     else if (equals(key, "WebKitMinimumFontSize"))
721         ewk_view_setting_font_minimum_size_set(browser->mainView(), toInt(value));
722     else if (equals(key, "WebKitPluginsEnabled"))
723         ewk_view_setting_enable_plugins_set(browser->mainView(), toBool(value));
724     else if (equals(key, "WebKitWebGLEnabled"))
725         ewk_view_setting_enable_webgl_set(browser->mainView(), toBool(value));
726     else if (equals(key, "WebKitEnableCaretBrowsing"))
727         ewk_view_setting_caret_browsing_set(browser->mainView(), toBool(value));
728     else if (equals(key, "WebKitUsesPageCachePreferenceKey"))
729         ewk_view_setting_page_cache_set(browser->mainView(), toBool(value));
730     else if (equals(key, "WebKitHyperlinkAuditingEnabled"))
731         ewk_view_setting_enable_hyperlink_auditing_set(browser->mainView(), toBool(value));
732     else if (equals(key, "WebKitTabToLinksPreferenceKey"))
733         ewk_view_setting_include_links_in_focus_chain_set(browser->mainView(), toBool(value));
734     else if (equals(key, "WebKitOfflineWebApplicationCacheEnabled"))
735         ewk_view_setting_application_cache_set(browser->mainView(), toBool(value));
736     else if (equals(key, "WebKitLoadSiteIconsKey"))
737         DumpRenderTreeSupportEfl::setLoadsSiteIconsIgnoringImageLoadingSetting(browser->mainView(), toBool(value));
738     else if (equals(key, "WebKitCSSGridLayoutEnabled"))
739         DumpRenderTreeSupportEfl::setCSSGridLayoutEnabled(browser->mainView(), toBool(value));
740     else if (equals(key, "WebKitWebAudioEnabled"))
741         ewk_view_setting_web_audio_set(browser->mainView(), toBool(value));
742     else
743         fprintf(stderr, "LayoutTestController::overridePreference tried to override unknown preference '%s'.\n", value->ustring().utf8().data());
744 }
745
746 void LayoutTestController::addUserScript(JSStringRef source, bool runAtStart, bool allFrames)
747 {
748     DumpRenderTreeSupportEfl::addUserScript(browser->mainView(), String(source->ustring().impl()), runAtStart, allFrames);
749 }
750
751 void LayoutTestController::addUserStyleSheet(JSStringRef source, bool allFrames)
752 {
753     DumpRenderTreeSupportEfl::addUserStyleSheet(browser->mainView(), WTF::String(source->ustring().impl()), allFrames);
754 }
755
756 void LayoutTestController::setDeveloperExtrasEnabled(bool enabled)
757 {
758     ewk_view_setting_enable_developer_extras_set(browser->mainView(), enabled);
759 }
760
761 void LayoutTestController::setAsynchronousSpellCheckingEnabled(bool)
762 {
763     notImplemented();
764 }
765
766 void LayoutTestController::showWebInspector()
767 {
768     notImplemented();
769 }
770
771 void LayoutTestController::closeWebInspector()
772 {
773     notImplemented();
774 }
775
776 void LayoutTestController::evaluateInWebInspector(long, JSStringRef)
777 {
778     notImplemented();
779 }
780
781 void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(unsigned, JSObjectRef, JSStringRef)
782 {
783     notImplemented();
784 }
785
786 void LayoutTestController::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
787 {
788     DumpRenderTreeSupportEfl::evaluateScriptInIsolatedWorld(browser->mainFrame(), worldID, globalObject, String(script->ustring().impl()));
789 }
790
791 void LayoutTestController::removeAllVisitedLinks()
792 {
793     notImplemented();
794 }
795
796 bool LayoutTestController::callShouldCloseOnWebView()
797 {
798     return DumpRenderTreeSupportEfl::callShouldCloseOnWebView(browser->mainFrame());
799 }
800
801 void LayoutTestController::apiTestNewWindowDataLoadBaseURL(JSStringRef, JSStringRef)
802 {
803     notImplemented();
804 }
805
806 void LayoutTestController::apiTestGoToCurrentBackForwardItem()
807 {
808     notImplemented();
809 }
810
811 void LayoutTestController::setWebViewEditable(bool)
812 {
813     ewk_frame_editable_set(browser->mainFrame(), EINA_TRUE);
814 }
815
816 JSRetainPtr<JSStringRef> LayoutTestController::markerTextForListItem(JSContextRef context, JSValueRef nodeObject) const
817 {
818     String markerTextChar = DumpRenderTreeSupportEfl::markerTextForListItem(context, nodeObject);
819     if (markerTextChar.isEmpty())
820         return 0;
821
822     JSRetainPtr<JSStringRef> markerText(Adopt, JSStringCreateWithUTF8CString(markerTextChar.utf8().data()));
823     return markerText;
824 }
825
826 void LayoutTestController::authenticateSession(JSStringRef, JSStringRef, JSStringRef)
827 {
828     notImplemented();
829 }
830
831 void LayoutTestController::abortModal()
832 {
833     notImplemented();
834 }
835
836 void LayoutTestController::dumpConfigurationForViewport(int deviceDPI, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight)
837 {
838     DumpRenderTreeSupportEfl::dumpConfigurationForViewport(browser->mainView(),
839             deviceDPI,
840             WebCore::IntSize(deviceWidth, deviceHeight),
841             WebCore::IntSize(availableWidth, availableHeight));
842 }
843
844 void LayoutTestController::setSerializeHTTPLoads(bool serialize)
845 {
846     DumpRenderTreeSupportEfl::setSerializeHTTPLoads(serialize);
847 }
848
849 void LayoutTestController::setMinimumTimerInterval(double minimumTimerInterval)
850 {
851     ewk_view_setting_minimum_timer_interval_set(browser->mainView(), minimumTimerInterval);
852 }
853
854 void LayoutTestController::setTextDirection(JSStringRef)
855 {
856     notImplemented();
857 }
858
859 void LayoutTestController::addChromeInputField()
860 {
861     notImplemented();
862 }
863
864 void LayoutTestController::removeChromeInputField()
865 {
866     notImplemented();
867 }
868
869 void LayoutTestController::focusWebView()
870 {
871     notImplemented();
872 }
873
874 void LayoutTestController::setBackingScaleFactor(double)
875 {
876     notImplemented();
877 }
878
879 void LayoutTestController::simulateDesktopNotificationClick(JSStringRef title)
880 {
881 }
882
883 void LayoutTestController::resetPageVisibility()
884 {
885     ewk_view_visibility_state_set(browser->mainView(), EWK_PAGE_VISIBILITY_STATE_VISIBLE, true);
886 }
887
888 void LayoutTestController::setPageVisibility(const char* visibility)
889 {
890     String newVisibility(visibility);
891     if (newVisibility == "visible")
892         ewk_view_visibility_state_set(browser->mainView(), EWK_PAGE_VISIBILITY_STATE_VISIBLE, false);
893     else if (newVisibility == "hidden")
894         ewk_view_visibility_state_set(browser->mainView(), EWK_PAGE_VISIBILITY_STATE_HIDDEN, false);
895     else if (newVisibility == "prerender")
896         ewk_view_visibility_state_set(browser->mainView(), EWK_PAGE_VISIBILITY_STATE_PRERENDER, false);
897     else if (newVisibility == "preview")
898         ewk_view_visibility_state_set(browser->mainView(), EWK_PAGE_VISIBILITY_STATE_PREVIEW, false);
899 }
900
901 void LayoutTestController::setAutomaticLinkDetectionEnabled(bool)
902 {
903     notImplemented();
904 }
905
906 void LayoutTestController::sendWebIntentResponse(JSStringRef response)
907 {
908     Ewk_Intent_Request* request = browser->currentIntentRequest();
909     if (!request)
910         return;
911
912     DumpRenderTreeSupportEfl::sendWebIntentResponse(request, response);
913 }
914
915 void LayoutTestController::deliverWebIntent(JSStringRef action, JSStringRef type, JSStringRef data)
916 {
917     DumpRenderTreeSupportEfl::deliverWebIntent(browser->mainFrame(), action, type, data);
918 }