TestRunnerGtk.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. /*
  2. * Copyright (C) 2007, 2012 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. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  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.
  21. *
  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.
  32. */
  33. #include "config.h"
  34. #include "TestRunner.h"
  35. #include "DumpRenderTree.h"
  36. #include "WebCoreSupport/DumpRenderTreeSupportGtk.h"
  37. #include "WorkQueue.h"
  38. #include "WorkQueueItem.h"
  39. #include <JavaScriptCore/JSRetainPtr.h>
  40. #include <JavaScriptCore/JSStringRef.h>
  41. #include <cstring>
  42. #include <iostream>
  43. #include <sstream>
  44. #include <stdio.h>
  45. #include <glib.h>
  46. #include <libsoup/soup.h>
  47. #include <webkit/webkit.h>
  48. #include <wtf/gobject/GOwnPtr.h>
  49. #include <wtf/text/WTFString.h>
  50. extern "C" {
  51. void webkit_web_inspector_execute_script(WebKitWebInspector* inspector, long callId, const gchar* script);
  52. }
  53. TestRunner::~TestRunner()
  54. {
  55. // FIXME: implement
  56. }
  57. void TestRunner::addDisallowedURL(JSStringRef url)
  58. {
  59. // FIXME: implement
  60. }
  61. void TestRunner::clearBackForwardList()
  62. {
  63. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  64. WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list(webView);
  65. WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_current_item(list);
  66. g_object_ref(item);
  67. // We clear the history by setting the back/forward list's capacity to 0
  68. // then restoring it back and adding back the current item.
  69. gint limit = webkit_web_back_forward_list_get_limit(list);
  70. webkit_web_back_forward_list_set_limit(list, 0);
  71. webkit_web_back_forward_list_set_limit(list, limit);
  72. webkit_web_back_forward_list_add_item(list, item);
  73. webkit_web_back_forward_list_go_to_item(list, item);
  74. g_object_unref(item);
  75. }
  76. JSStringRef TestRunner::copyDecodedHostName(JSStringRef name)
  77. {
  78. // FIXME: implement
  79. return 0;
  80. }
  81. JSStringRef TestRunner::copyEncodedHostName(JSStringRef name)
  82. {
  83. // FIXME: implement
  84. return 0;
  85. }
  86. void TestRunner::dispatchPendingLoadRequests()
  87. {
  88. // FIXME: Implement for testing fix for 6727495
  89. }
  90. void TestRunner::display()
  91. {
  92. displayWebView();
  93. }
  94. void TestRunner::keepWebHistory()
  95. {
  96. // FIXME: implement
  97. }
  98. size_t TestRunner::webHistoryItemCount()
  99. {
  100. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  101. WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list(webView);
  102. if (!list)
  103. return -1;
  104. // We do not add the current page to the total count as it's not
  105. // considered in DRT tests
  106. return webkit_web_back_forward_list_get_back_length(list) +
  107. webkit_web_back_forward_list_get_forward_length(list);
  108. }
  109. JSRetainPtr<JSStringRef> TestRunner::platformName() const
  110. {
  111. JSRetainPtr<JSStringRef> platformName(Adopt, JSStringCreateWithUTF8CString("gtk"));
  112. return platformName;
  113. }
  114. void TestRunner::notifyDone()
  115. {
  116. if (m_waitToDump && !topLoadingFrame && !WorkQueue::shared()->count())
  117. dump();
  118. m_waitToDump = false;
  119. waitForPolicy = false;
  120. }
  121. JSStringRef TestRunner::pathToLocalResource(JSContextRef context, JSStringRef url)
  122. {
  123. GOwnPtr<char> urlCString(JSStringCopyUTF8CString(url));
  124. if (!g_str_has_prefix(urlCString.get(), "file:///tmp/LayoutTests/"))
  125. return JSStringRetain(url);
  126. const char* layoutTestsSuffix = urlCString.get() + strlen("file:///tmp/");
  127. GOwnPtr<char> testPath(g_build_filename(getTopLevelPath().data(), layoutTestsSuffix, NULL));
  128. GOwnPtr<char> testURI(g_filename_to_uri(testPath.get(), 0, 0));
  129. return JSStringCreateWithUTF8CString(testURI.get());
  130. }
  131. static CString soupURIToStringPreservingPassword(SoupURI* soupURI)
  132. {
  133. if (!soupURI->password) {
  134. GOwnPtr<char> uriString(soup_uri_to_string(soupURI, FALSE));
  135. return uriString.get();
  136. }
  137. // soup_uri_to_string does not insert the password into the string, so we need to create the
  138. // URI string and then reinsert any credentials that were present in the SoupURI. All tests that
  139. // use URL-embedded credentials use HTTP, so it's safe here.
  140. GOwnPtr<char> password(soupURI->password);
  141. GOwnPtr<char> user(soupURI->user);
  142. soupURI->password = 0;
  143. soupURI->user = 0;
  144. GOwnPtr<char> uriString(soup_uri_to_string(soupURI, FALSE));
  145. String absoluteURIWithoutCredentialString = String::fromUTF8(uriString.get());
  146. String protocolAndCredential = String::format("http://%s:%s@", user ? user.get() : "", password.get());
  147. return absoluteURIWithoutCredentialString.replace("http://", protocolAndCredential).utf8();
  148. }
  149. void TestRunner::queueLoad(JSStringRef url, JSStringRef target)
  150. {
  151. GOwnPtr<gchar> relativeURL(JSStringCopyUTF8CString(url));
  152. SoupURI* baseURI = soup_uri_new(webkit_web_frame_get_uri(mainFrame));
  153. SoupURI* absoluteURI = soup_uri_new_with_base(baseURI, relativeURL.get());
  154. soup_uri_free(baseURI);
  155. if (!absoluteURI) {
  156. WorkQueue::shared()->queue(new LoadItem(url, target));
  157. return;
  158. }
  159. CString absoluteURIString = soupURIToStringPreservingPassword(absoluteURI);
  160. JSRetainPtr<JSStringRef> absoluteURL(Adopt, JSStringCreateWithUTF8CString(absoluteURIString.data()));
  161. WorkQueue::shared()->queue(new LoadItem(absoluteURL.get(), target));
  162. soup_uri_free(absoluteURI);
  163. }
  164. void TestRunner::setAcceptsEditing(bool acceptsEditing)
  165. {
  166. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  167. webkit_web_view_set_editable(webView, acceptsEditing);
  168. }
  169. void TestRunner::setAlwaysAcceptCookies(bool alwaysAcceptCookies)
  170. {
  171. SoupSession* session = webkit_get_default_session();
  172. SoupCookieJar* jar = reinterpret_cast<SoupCookieJar*>(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR));
  173. /* If the jar was not created - we create it on demand, i.e, just
  174. in case we have HTTP requests - then we must create it here in
  175. order to set the proper accept policy */
  176. if (!jar) {
  177. jar = soup_cookie_jar_new();
  178. soup_session_add_feature(session, SOUP_SESSION_FEATURE(jar));
  179. g_object_unref(jar);
  180. }
  181. SoupCookieJarAcceptPolicy policy;
  182. if (alwaysAcceptCookies)
  183. policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
  184. else
  185. policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
  186. g_object_set(G_OBJECT(jar), SOUP_COOKIE_JAR_ACCEPT_POLICY, policy, NULL);
  187. }
  188. void TestRunner::setCustomPolicyDelegate(bool setDelegate, bool permissive)
  189. {
  190. // FIXME: implement
  191. }
  192. void TestRunner::waitForPolicyDelegate()
  193. {
  194. waitForPolicy = true;
  195. setWaitToDump(true);
  196. }
  197. void TestRunner::setScrollbarPolicy(JSStringRef orientation, JSStringRef policy)
  198. {
  199. // FIXME: implement
  200. }
  201. void TestRunner::addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains)
  202. {
  203. gchar* sourceOriginGChar = JSStringCopyUTF8CString(sourceOrigin);
  204. gchar* protocolGChar = JSStringCopyUTF8CString(protocol);
  205. gchar* hostGChar = JSStringCopyUTF8CString(host);
  206. DumpRenderTreeSupportGtk::whiteListAccessFromOrigin(sourceOriginGChar, protocolGChar, hostGChar, includeSubdomains);
  207. g_free(sourceOriginGChar);
  208. g_free(protocolGChar);
  209. g_free(hostGChar);
  210. }
  211. void TestRunner::removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains)
  212. {
  213. GOwnPtr<gchar> sourceOriginGChar(JSStringCopyUTF8CString(sourceOrigin));
  214. GOwnPtr<gchar> protocolGChar(JSStringCopyUTF8CString(protocol));
  215. GOwnPtr<gchar> hostGChar(JSStringCopyUTF8CString(host));
  216. DumpRenderTreeSupportGtk::removeWhiteListAccessFromOrigin(sourceOriginGChar.get(), protocolGChar.get(), hostGChar.get(), includeSubdomains);
  217. }
  218. void TestRunner::setMainFrameIsFirstResponder(bool flag)
  219. {
  220. // FIXME: implement
  221. }
  222. void TestRunner::setTabKeyCyclesThroughElements(bool cycles)
  223. {
  224. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  225. WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
  226. g_object_set(G_OBJECT(settings), "tab-key-cycles-through-elements", cycles, NULL);
  227. }
  228. void TestRunner::setUseDashboardCompatibilityMode(bool flag)
  229. {
  230. // FIXME: implement
  231. }
  232. static gchar* userStyleSheet = NULL;
  233. static gboolean userStyleSheetEnabled = TRUE;
  234. void TestRunner::setUserStyleSheetEnabled(bool flag)
  235. {
  236. userStyleSheetEnabled = flag;
  237. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  238. WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
  239. if (flag && userStyleSheet)
  240. g_object_set(G_OBJECT(settings), "user-stylesheet-uri", userStyleSheet, NULL);
  241. else
  242. g_object_set(G_OBJECT(settings), "user-stylesheet-uri", "", NULL);
  243. }
  244. void TestRunner::setUserStyleSheetLocation(JSStringRef path)
  245. {
  246. g_free(userStyleSheet);
  247. userStyleSheet = JSStringCopyUTF8CString(path);
  248. if (userStyleSheetEnabled)
  249. setUserStyleSheetEnabled(true);
  250. }
  251. void TestRunner::setValueForUser(JSContextRef context, JSValueRef nodeObject, JSStringRef value)
  252. {
  253. DumpRenderTreeSupportGtk::setValueForUser(context, nodeObject, value);
  254. }
  255. void TestRunner::setViewModeMediaFeature(JSStringRef mode)
  256. {
  257. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  258. ASSERT(view);
  259. char* viewMode = JSStringCopyUTF8CString(mode);
  260. if (!g_strcmp0(viewMode, "windowed"))
  261. webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_WINDOWED);
  262. else if (!g_strcmp0(viewMode, "floating"))
  263. webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FLOATING);
  264. else if (!g_strcmp0(viewMode, "fullscreen"))
  265. webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FULLSCREEN);
  266. else if (!g_strcmp0(viewMode, "maximized"))
  267. webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MAXIMIZED);
  268. else if (!g_strcmp0(viewMode, "minimized"))
  269. webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MINIMIZED);
  270. g_free(viewMode);
  271. }
  272. void TestRunner::setWindowIsKey(bool windowIsKey)
  273. {
  274. // FIXME: implement
  275. }
  276. static gboolean waitToDumpWatchdogFired(void*)
  277. {
  278. setWaitToDumpWatchdog(0);
  279. gTestRunner->waitToDumpWatchdogTimerFired();
  280. return FALSE;
  281. }
  282. void TestRunner::setWaitToDump(bool waitUntilDone)
  283. {
  284. static const int timeoutSeconds = 30;
  285. m_waitToDump = waitUntilDone;
  286. if (m_waitToDump && shouldSetWaitToDumpWatchdog())
  287. setWaitToDumpWatchdog(g_timeout_add_seconds(timeoutSeconds, waitToDumpWatchdogFired, 0));
  288. }
  289. int TestRunner::windowCount()
  290. {
  291. // +1 -> including the main view
  292. return g_slist_length(webViewList) + 1;
  293. }
  294. void TestRunner::setPrivateBrowsingEnabled(bool flag)
  295. {
  296. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  297. ASSERT(view);
  298. WebKitWebSettings* settings = webkit_web_view_get_settings(view);
  299. g_object_set(G_OBJECT(settings), "enable-private-browsing", flag, NULL);
  300. }
  301. void TestRunner::setJavaScriptCanAccessClipboard(bool flag)
  302. {
  303. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  304. ASSERT(view);
  305. WebKitWebSettings* settings = webkit_web_view_get_settings(view);
  306. g_object_set(G_OBJECT(settings), "javascript-can-access-clipboard", flag, NULL);
  307. }
  308. void TestRunner::setXSSAuditorEnabled(bool flag)
  309. {
  310. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  311. ASSERT(view);
  312. WebKitWebSettings* settings = webkit_web_view_get_settings(view);
  313. g_object_set(G_OBJECT(settings), "enable-xss-auditor", flag, NULL);
  314. }
  315. void TestRunner::setSpatialNavigationEnabled(bool flag)
  316. {
  317. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  318. ASSERT(view);
  319. WebKitWebSettings* settings = webkit_web_view_get_settings(view);
  320. g_object_set(G_OBJECT(settings), "enable-spatial-navigation", flag, NULL);
  321. }
  322. void TestRunner::setAllowUniversalAccessFromFileURLs(bool flag)
  323. {
  324. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  325. ASSERT(view);
  326. WebKitWebSettings* settings = webkit_web_view_get_settings(view);
  327. g_object_set(G_OBJECT(settings), "enable-universal-access-from-file-uris", flag, NULL);
  328. }
  329. void TestRunner::setAllowFileAccessFromFileURLs(bool flag)
  330. {
  331. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  332. ASSERT(view);
  333. WebKitWebSettings* settings = webkit_web_view_get_settings(view);
  334. g_object_set(G_OBJECT(settings), "enable-file-access-from-file-uris", flag, NULL);
  335. }
  336. void TestRunner::setAuthorAndUserStylesEnabled(bool flag)
  337. {
  338. // FIXME: implement
  339. }
  340. void TestRunner::setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
  341. {
  342. // FIXME: Implement for DeviceOrientation layout tests.
  343. // See https://bugs.webkit.org/show_bug.cgi?id=30335.
  344. }
  345. void TestRunner::setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool, double, bool, double, bool, double, bool, double)
  346. {
  347. WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0));
  348. if (!view)
  349. view = webkit_web_frame_get_web_view(mainFrame);
  350. ASSERT(view);
  351. DumpRenderTreeSupportGtk::setMockGeolocationPosition(view, latitude, longitude, accuracy);
  352. }
  353. void TestRunner::setMockGeolocationPositionUnavailableError(JSStringRef message)
  354. {
  355. WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0));
  356. if (!view)
  357. view = webkit_web_frame_get_web_view(mainFrame);
  358. ASSERT(view);
  359. GOwnPtr<gchar> cMessage(JSStringCopyUTF8CString(message));
  360. DumpRenderTreeSupportGtk::setMockGeolocationPositionUnavailableError(view, cMessage.get());
  361. }
  362. void TestRunner::setGeolocationPermission(bool allow)
  363. {
  364. setGeolocationPermissionCommon(allow);
  365. WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0));
  366. if (!view)
  367. view = webkit_web_frame_get_web_view(mainFrame);
  368. ASSERT(view);
  369. DumpRenderTreeSupportGtk::setMockGeolocationPermission(view, allow);
  370. }
  371. int TestRunner::numberOfPendingGeolocationPermissionRequests()
  372. {
  373. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  374. if (!view)
  375. view = webkit_web_frame_get_web_view(mainFrame);
  376. ASSERT(view);
  377. return DumpRenderTreeSupportGtk::numberOfPendingGeolocationPermissionRequests(view);
  378. }
  379. void TestRunner::addMockSpeechInputResult(JSStringRef result, double confidence, JSStringRef language)
  380. {
  381. // FIXME: Implement for speech input layout tests.
  382. // See https://bugs.webkit.org/show_bug.cgi?id=39485.
  383. }
  384. void TestRunner::setMockSpeechInputDumpRect(bool flag)
  385. {
  386. // FIXME: Implement for speech input layout tests.
  387. // See https://bugs.webkit.org/show_bug.cgi?id=39485.
  388. }
  389. void TestRunner::startSpeechInput(JSContextRef inputElement)
  390. {
  391. // FIXME: Implement for speech input layout tests.
  392. // See https://bugs.webkit.org/show_bug.cgi?id=39485.
  393. }
  394. void TestRunner::setIconDatabaseEnabled(bool enabled)
  395. {
  396. WebKitIconDatabase* database = webkit_get_icon_database();
  397. if (enabled) {
  398. GOwnPtr<gchar> iconDatabasePath(g_build_filename(g_get_tmp_dir(), "DumpRenderTree", "icondatabase", NULL));
  399. webkit_icon_database_set_path(database, iconDatabasePath.get());
  400. } else
  401. webkit_icon_database_set_path(database, 0);
  402. }
  403. void TestRunner::setPopupBlockingEnabled(bool flag)
  404. {
  405. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  406. ASSERT(view);
  407. WebKitWebSettings* settings = webkit_web_view_get_settings(view);
  408. g_object_set(G_OBJECT(settings), "javascript-can-open-windows-automatically", !flag, NULL);
  409. }
  410. void TestRunner::setPluginsEnabled(bool flag)
  411. {
  412. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  413. ASSERT(view);
  414. WebKitWebSettings* settings = webkit_web_view_get_settings(view);
  415. g_object_set(G_OBJECT(settings), "enable-plugins", flag, NULL);
  416. }
  417. void TestRunner::execCommand(JSStringRef name, JSStringRef value)
  418. {
  419. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  420. ASSERT(view);
  421. gchar* cName = JSStringCopyUTF8CString(name);
  422. gchar* cValue = JSStringCopyUTF8CString(value);
  423. DumpRenderTreeSupportGtk::executeCoreCommandByName(view, cName, cValue);
  424. g_free(cName);
  425. g_free(cValue);
  426. }
  427. bool TestRunner::findString(JSContextRef context, JSStringRef target, JSObjectRef optionsArray)
  428. {
  429. WebKitFindOptions findOptions = 0;
  430. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  431. ASSERT(webView);
  432. JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length"));
  433. JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0);
  434. if (!JSValueIsNumber(context, lengthValue))
  435. return false;
  436. GOwnPtr<gchar> targetString(JSStringCopyUTF8CString(target));
  437. size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0));
  438. for (size_t i = 0; i < length; ++i) {
  439. JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
  440. if (!JSValueIsString(context, value))
  441. continue;
  442. JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0));
  443. if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive"))
  444. findOptions |= WebKit::WebFindOptionsCaseInsensitive;
  445. else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts"))
  446. findOptions |= WebKit::WebFindOptionsAtWordStarts;
  447. else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart"))
  448. findOptions |= WebKit::WebFindOptionsTreatMedialCapitalAsWordStart;
  449. else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards"))
  450. findOptions |= WebKit::WebFindOptionsBackwards;
  451. else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround"))
  452. findOptions |= WebKit::WebFindOptionsWrapAround;
  453. else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection"))
  454. findOptions |= WebKit::WebFindOptionsStartInSelection;
  455. }
  456. return DumpRenderTreeSupportGtk::findString(webView, targetString.get(), findOptions);
  457. }
  458. bool TestRunner::isCommandEnabled(JSStringRef name)
  459. {
  460. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  461. ASSERT(view);
  462. gchar* cName = JSStringCopyUTF8CString(name);
  463. bool result = DumpRenderTreeSupportGtk::isCommandEnabled(view, cName);
  464. g_free(cName);
  465. return result;
  466. }
  467. void TestRunner::setCacheModel(int cacheModel)
  468. {
  469. // These constants are derived from the Mac cache model enum in Source/WebKit/mac/WebView/WebPreferences.h.
  470. switch (cacheModel) {
  471. case 0:
  472. webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
  473. break;
  474. case 1:
  475. webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER);
  476. break;
  477. case 2:
  478. webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER);
  479. break;
  480. default:
  481. ASSERT_NOT_REACHED();
  482. }
  483. }
  484. void TestRunner::setPersistentUserStyleSheetLocation(JSStringRef jsURL)
  485. {
  486. // FIXME: implement
  487. }
  488. void TestRunner::clearPersistentUserStyleSheet()
  489. {
  490. // FIXME: implement
  491. }
  492. void TestRunner::clearAllApplicationCaches()
  493. {
  494. // FIXME: Implement to support application cache quotas.
  495. }
  496. void TestRunner::setApplicationCacheOriginQuota(unsigned long long quota)
  497. {
  498. // FIXME: Implement to support application cache quotas.
  499. }
  500. void TestRunner::clearApplicationCacheForOrigin(OpaqueJSString*)
  501. {
  502. // FIXME: Implement to support deleting all application caches for an origin.
  503. }
  504. long long TestRunner::localStorageDiskUsageForOrigin(JSStringRef originIdentifier)
  505. {
  506. // FIXME: Implement to support getting disk usage in bytes for an origin.
  507. return 0;
  508. }
  509. JSValueRef TestRunner::originsWithApplicationCache(JSContextRef context)
  510. {
  511. // FIXME: Implement to get origins that contain application caches.
  512. return JSValueMakeUndefined(context);
  513. }
  514. long long TestRunner::applicationCacheDiskUsageForOrigin(JSStringRef name)
  515. {
  516. // FIXME: implement
  517. return 0;
  518. }
  519. void TestRunner::clearAllDatabases()
  520. {
  521. webkit_remove_all_web_databases();
  522. }
  523. void TestRunner::setDatabaseQuota(unsigned long long quota)
  524. {
  525. WebKitSecurityOrigin* origin = webkit_web_frame_get_security_origin(mainFrame);
  526. webkit_security_origin_set_web_database_quota(origin, quota);
  527. }
  528. JSValueRef TestRunner::originsWithLocalStorage(JSContextRef context)
  529. {
  530. // FIXME: implement
  531. return JSValueMakeUndefined(context);
  532. }
  533. void TestRunner::deleteAllLocalStorage()
  534. {
  535. // FIXME: implement
  536. }
  537. void TestRunner::deleteLocalStorageForOrigin(JSStringRef originIdentifier)
  538. {
  539. // FIXME: implement
  540. }
  541. void TestRunner::observeStorageTrackerNotifications(unsigned number)
  542. {
  543. // FIXME: implement
  544. }
  545. void TestRunner::syncLocalStorage()
  546. {
  547. // FIXME: implement
  548. }
  549. void TestRunner::setDomainRelaxationForbiddenForURLScheme(bool forbidden, JSStringRef scheme)
  550. {
  551. GOwnPtr<gchar> urlScheme(JSStringCopyUTF8CString(scheme));
  552. DumpRenderTreeSupportGtk::setDomainRelaxationForbiddenForURLScheme(forbidden, urlScheme.get());
  553. }
  554. void TestRunner::goBack()
  555. {
  556. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  557. webkit_web_view_go_back(webView);
  558. }
  559. void TestRunner::setDefersLoading(bool defers)
  560. {
  561. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  562. DumpRenderTreeSupportGtk::setDefersLoading(webView, defers);
  563. }
  564. void TestRunner::setAppCacheMaximumSize(unsigned long long size)
  565. {
  566. webkit_application_cache_set_maximum_size(size);
  567. }
  568. static gboolean booleanFromValue(gchar* value)
  569. {
  570. return !g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1");
  571. }
  572. void TestRunner::overridePreference(JSStringRef key, JSStringRef value)
  573. {
  574. GOwnPtr<gchar> originalName(JSStringCopyUTF8CString(key));
  575. GOwnPtr<gchar> valueAsString(JSStringCopyUTF8CString(value));
  576. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  577. ASSERT(view);
  578. // This transformation could be handled by a hash table (and it once was), but
  579. // having it prominent, makes it easier for people from other ports to keep the
  580. // list up to date.
  581. const gchar* propertyName = 0;
  582. if (g_str_equal(originalName.get(), "WebKitJavaScriptEnabled"))
  583. propertyName = "enable-scripts";
  584. else if (g_str_equal(originalName.get(), "WebKitDefaultFontSize"))
  585. propertyName = "default-font-size";
  586. else if (g_str_equal(originalName.get(), "WebKitEnableCaretBrowsing"))
  587. propertyName = "enable-caret-browsing";
  588. else if (g_str_equal(originalName.get(), "WebKitUsesPageCachePreferenceKey"))
  589. propertyName = "enable-page-cache";
  590. else if (g_str_equal(originalName.get(), "WebKitPluginsEnabled"))
  591. propertyName = "enable-plugins";
  592. else if (g_str_equal(originalName.get(), "WebKitHyperlinkAuditingEnabled"))
  593. propertyName = "enable-hyperlink-auditing";
  594. else if (g_str_equal(originalName.get(), "WebKitWebGLEnabled"))
  595. propertyName = "enable-webgl";
  596. else if (g_str_equal(originalName.get(), "WebKitWebAudioEnabled"))
  597. propertyName = "enable-webaudio";
  598. else if (g_str_equal(originalName.get(), "WebKitDisplayImagesKey"))
  599. propertyName = "auto-load-images";
  600. else if (g_str_equal(originalName.get(), "WebKitTabToLinksPreferenceKey")) {
  601. DumpRenderTreeSupportGtk::setLinksIncludedInFocusChain(booleanFromValue(valueAsString.get()));
  602. return;
  603. } else if (g_str_equal(originalName.get(), "WebKitPageCacheSupportsPluginsPreferenceKey")) {
  604. DumpRenderTreeSupportGtk::setPageCacheSupportsPlugins(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
  605. return;
  606. } else if (g_str_equal(originalName.get(), "WebKitCSSGridLayoutEnabled")) {
  607. DumpRenderTreeSupportGtk::setCSSGridLayoutEnabled(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
  608. return;
  609. } else if (g_str_equal(originalName.get(), "WebKitCSSRegionsEnabled")) {
  610. DumpRenderTreeSupportGtk::setCSSRegionsEnabled(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
  611. return;
  612. } else if (g_str_equal(originalName.get(), "WebKitCSSCustomFilterEnabled")) {
  613. DumpRenderTreeSupportGtk::setCSSCustomFilterEnabled(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
  614. return;
  615. } else {
  616. fprintf(stderr, "TestRunner::overridePreference tried to override "
  617. "unknown preference '%s'.\n", originalName.get());
  618. return;
  619. }
  620. WebKitWebSettings* settings = webkit_web_view_get_settings(view);
  621. GParamSpec* pspec = g_object_class_find_property(G_OBJECT_CLASS(
  622. WEBKIT_WEB_SETTINGS_GET_CLASS(settings)), propertyName);
  623. GValue currentPropertyValue = { 0, { { 0 } } };
  624. g_value_init(&currentPropertyValue, pspec->value_type);
  625. if (G_VALUE_HOLDS_STRING(&currentPropertyValue))
  626. g_object_set(settings, propertyName, valueAsString.get(), NULL);
  627. else if (G_VALUE_HOLDS_BOOLEAN(&currentPropertyValue))
  628. g_object_set(G_OBJECT(settings), propertyName, booleanFromValue(valueAsString.get()), NULL);
  629. else if (G_VALUE_HOLDS_INT(&currentPropertyValue))
  630. g_object_set(G_OBJECT(settings), propertyName, atoi(valueAsString.get()), NULL);
  631. else if (G_VALUE_HOLDS_FLOAT(&currentPropertyValue)) {
  632. gfloat newValue = g_ascii_strtod(valueAsString.get(), 0);
  633. g_object_set(G_OBJECT(settings), propertyName, newValue, NULL);
  634. } else
  635. fprintf(stderr, "TestRunner::overridePreference failed to override "
  636. "preference '%s'.\n", originalName.get());
  637. }
  638. void TestRunner::addUserScript(JSStringRef source, bool runAtStart, bool allFrames)
  639. {
  640. GOwnPtr<gchar> sourceCode(JSStringCopyUTF8CString(source));
  641. DumpRenderTreeSupportGtk::addUserScript(mainFrame, sourceCode.get(), runAtStart, allFrames);
  642. }
  643. void TestRunner::addUserStyleSheet(JSStringRef source, bool allFrames)
  644. {
  645. GOwnPtr<gchar> sourceCode(JSStringCopyUTF8CString(source));
  646. DumpRenderTreeSupportGtk::addUserStyleSheet(mainFrame, sourceCode.get(), allFrames);
  647. // FIXME: needs more investigation why userscripts/user-style-top-frame-only.html fails when allFrames is false.
  648. }
  649. void TestRunner::setDeveloperExtrasEnabled(bool enabled)
  650. {
  651. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  652. WebKitWebSettings* webSettings = webkit_web_view_get_settings(webView);
  653. g_object_set(webSettings, "enable-developer-extras", enabled, NULL);
  654. }
  655. void TestRunner::showWebInspector()
  656. {
  657. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  658. WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView);
  659. webkit_web_inspector_show(inspector);
  660. }
  661. void TestRunner::closeWebInspector()
  662. {
  663. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  664. WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView);
  665. webkit_web_inspector_close(inspector);
  666. }
  667. void TestRunner::evaluateInWebInspector(long callId, JSStringRef script)
  668. {
  669. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  670. WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView);
  671. char* scriptString = JSStringCopyUTF8CString(script);
  672. webkit_web_inspector_execute_script(inspector, callId, scriptString);
  673. g_free(scriptString);
  674. }
  675. void TestRunner::evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
  676. {
  677. // FIXME: Implement this.
  678. }
  679. void TestRunner::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
  680. {
  681. // FIXME: Implement this.
  682. }
  683. void TestRunner::removeAllVisitedLinks()
  684. {
  685. // FIXME: Implement this.
  686. }
  687. bool TestRunner::callShouldCloseOnWebView()
  688. {
  689. return DumpRenderTreeSupportGtk::shouldClose(mainFrame);
  690. }
  691. void TestRunner::apiTestNewWindowDataLoadBaseURL(JSStringRef utf8Data, JSStringRef baseURL)
  692. {
  693. }
  694. void TestRunner::apiTestGoToCurrentBackForwardItem()
  695. {
  696. }
  697. void TestRunner::setWebViewEditable(bool)
  698. {
  699. }
  700. void TestRunner::authenticateSession(JSStringRef, JSStringRef, JSStringRef)
  701. {
  702. }
  703. void TestRunner::abortModal()
  704. {
  705. }
  706. void TestRunner::setSerializeHTTPLoads(bool serialize)
  707. {
  708. DumpRenderTreeSupportGtk::setSerializeHTTPLoads(serialize);
  709. }
  710. void TestRunner::setTextDirection(JSStringRef direction)
  711. {
  712. GOwnPtr<gchar> writingDirection(JSStringCopyUTF8CString(direction));
  713. WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
  714. ASSERT(view);
  715. if (g_str_equal(writingDirection.get(), "auto"))
  716. gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_NONE);
  717. else if (g_str_equal(writingDirection.get(), "ltr"))
  718. gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_LTR);
  719. else if (g_str_equal(writingDirection.get(), "rtl"))
  720. gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_RTL);
  721. else
  722. fprintf(stderr, "TestRunner::setTextDirection called with unknown direction: '%s'.\n", writingDirection.get());
  723. }
  724. void TestRunner::addChromeInputField()
  725. {
  726. }
  727. void TestRunner::removeChromeInputField()
  728. {
  729. }
  730. void TestRunner::focusWebView()
  731. {
  732. }
  733. void TestRunner::setBackingScaleFactor(double)
  734. {
  735. }
  736. void TestRunner::grantWebNotificationPermission(JSStringRef origin)
  737. {
  738. }
  739. void TestRunner::denyWebNotificationPermission(JSStringRef jsOrigin)
  740. {
  741. }
  742. void TestRunner::removeAllWebNotificationPermissions()
  743. {
  744. }
  745. void TestRunner::simulateWebNotificationClick(JSValueRef jsNotification)
  746. {
  747. }
  748. void TestRunner::simulateLegacyWebNotificationClick(JSStringRef title)
  749. {
  750. }
  751. void TestRunner::resetPageVisibility()
  752. {
  753. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  754. DumpRenderTreeSupportGtk::setPageVisibility(webView, WebCore::PageVisibilityStateVisible, true);
  755. }
  756. void TestRunner::setPageVisibility(const char* visibility)
  757. {
  758. WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame);
  759. String visibilityString(visibility);
  760. WebCore::PageVisibilityState visibilityState = WebCore::PageVisibilityStateVisible;
  761. if (visibilityString == "visible")
  762. visibilityState = WebCore::PageVisibilityStateVisible;
  763. else if (visibilityString == "hidden")
  764. visibilityState = WebCore::PageVisibilityStateHidden;
  765. else
  766. return;
  767. DumpRenderTreeSupportGtk::setPageVisibility(webView, visibilityState, false);
  768. }
  769. void TestRunner::setAutomaticLinkDetectionEnabled(bool)
  770. {
  771. // FIXME: Implement this.
  772. }
  773. void TestRunner::setStorageDatabaseIdleInterval(double)
  774. {
  775. // FIXME: Implement this.
  776. }
  777. void TestRunner::closeIdleLocalStorageDatabases()
  778. {
  779. }