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