TestRunner.cpp 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259
  1. /*
  2. * Copyright (C) 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved.
  3. * Copyright (C) 2010 Joone Hur <joone@kldp.org>
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  15. * its contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "config.h"
  30. #include "TestRunner.h"
  31. #include "WorkQueue.h"
  32. #include "WorkQueueItem.h"
  33. #include <cstring>
  34. #include <JavaScriptCore/JSContextRef.h>
  35. #include <JavaScriptCore/JSObjectRef.h>
  36. #include <JavaScriptCore/JSRetainPtr.h>
  37. #include <locale.h>
  38. #include <stdio.h>
  39. #include <wtf/Assertions.h>
  40. #include <wtf/CurrentTime.h>
  41. #include <wtf/MathExtras.h>
  42. #include <wtf/OwnArrayPtr.h>
  43. #include <wtf/RefPtr.h>
  44. #if PLATFORM(MAC)
  45. #include <Carbon/Carbon.h>
  46. #endif
  47. const unsigned TestRunner::viewWidth = 800;
  48. const unsigned TestRunner::viewHeight = 600;
  49. const unsigned TestRunner::w3cSVGViewWidth = 480;
  50. const unsigned TestRunner::w3cSVGViewHeight = 360;
  51. TestRunner::TestRunner(const std::string& testPathOrURL, const std::string& expectedPixelHash)
  52. : m_disallowIncreaseForApplicationCacheQuota(false)
  53. , m_dumpApplicationCacheDelegateCallbacks(false)
  54. , m_dumpAsAudio(false)
  55. , m_dumpAsPDF(false)
  56. , m_dumpAsText(false)
  57. , m_dumpBackForwardList(false)
  58. , m_dumpChildFrameScrollPositions(false)
  59. , m_dumpChildFramesAsText(false)
  60. , m_dumpDOMAsWebArchive(false)
  61. , m_dumpDatabaseCallbacks(false)
  62. , m_dumpEditingCallbacks(false)
  63. , m_dumpFrameLoadCallbacks(false)
  64. , m_dumpProgressFinishedCallback(false)
  65. , m_dumpUserGestureInFrameLoadCallbacks(false)
  66. , m_dumpHistoryDelegateCallbacks(false)
  67. , m_dumpResourceLoadCallbacks(false)
  68. , m_dumpResourceResponseMIMETypes(false)
  69. , m_dumpSelectionRect(false)
  70. , m_dumpSourceAsWebArchive(false)
  71. , m_dumpStatusCallbacks(false)
  72. , m_dumpTitleChanges(false)
  73. , m_dumpIconChanges(false)
  74. , m_dumpVisitedLinksCallback(false)
  75. , m_dumpWillCacheResponse(false)
  76. , m_generatePixelResults(true)
  77. , m_callCloseOnWebViews(true)
  78. , m_canOpenWindows(false)
  79. , m_closeRemainingWindowsWhenComplete(true)
  80. , m_newWindowsCopyBackForwardList(false)
  81. , m_stopProvisionalFrameLoads(false)
  82. , m_testOnscreen(false)
  83. , m_testRepaint(false)
  84. , m_testRepaintSweepHorizontally(false)
  85. , m_waitToDump(false)
  86. , m_willSendRequestReturnsNull(false)
  87. , m_willSendRequestReturnsNullOnRedirect(false)
  88. , m_windowIsKey(true)
  89. , m_alwaysAcceptCookies(false)
  90. , m_globalFlag(false)
  91. , m_isGeolocationPermissionSet(false)
  92. , m_geolocationPermission(false)
  93. , m_handlesAuthenticationChallenges(false)
  94. , m_isPrinting(false)
  95. , m_deferMainResourceDataLoad(true)
  96. , m_useDeferredFrameLoading(false)
  97. , m_shouldPaintBrokenImage(true)
  98. , m_shouldStayOnPageAfterHandlingBeforeUnload(false)
  99. , m_areLegacyWebNotificationPermissionRequestsIgnored(false)
  100. , m_customFullScreenBehavior(false)
  101. , m_hasPendingWebNotificationClick(false)
  102. , m_testPathOrURL(testPathOrURL)
  103. , m_expectedPixelHash(expectedPixelHash)
  104. , m_titleTextDirection("ltr")
  105. {
  106. }
  107. PassRefPtr<TestRunner> TestRunner::create(const std::string& testPathOrURL, const std::string& expectedPixelHash)
  108. {
  109. return adoptRef(new TestRunner(testPathOrURL, expectedPixelHash));
  110. }
  111. // Static Functions
  112. static JSValueRef disallowIncreaseForApplicationCacheQuotaCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  113. {
  114. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  115. controller->setDisallowIncreaseForApplicationCacheQuota(true);
  116. return JSValueMakeUndefined(context);
  117. }
  118. static JSValueRef dumpApplicationCacheDelegateCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  119. {
  120. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  121. controller->setDumpApplicationCacheDelegateCallbacks(true);
  122. return JSValueMakeUndefined(context);
  123. }
  124. static JSValueRef dumpAsPDFCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  125. {
  126. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  127. controller->setDumpAsPDF(true);
  128. return JSValueMakeUndefined(context);
  129. }
  130. static JSValueRef dumpAsTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  131. {
  132. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  133. controller->setDumpAsText(true);
  134. // Optional paramater, describing whether it's allowed to dump pixel results in dumpAsText mode.
  135. controller->setGeneratePixelResults(argumentCount > 0 ? JSValueToBoolean(context, arguments[0]) : false);
  136. return JSValueMakeUndefined(context);
  137. }
  138. static JSValueRef dumpBackForwardListCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  139. {
  140. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  141. controller->setDumpBackForwardList(true);
  142. return JSValueMakeUndefined(context);
  143. }
  144. static JSValueRef dumpChildFramesAsTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  145. {
  146. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  147. controller->setDumpChildFramesAsText(true);
  148. return JSValueMakeUndefined(context);
  149. }
  150. static JSValueRef dumpChildFrameScrollPositionsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  151. {
  152. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  153. controller->setDumpChildFrameScrollPositions(true);
  154. return JSValueMakeUndefined(context);
  155. }
  156. static JSValueRef dumpDatabaseCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  157. {
  158. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  159. controller->setDumpDatabaseCallbacks(true);
  160. return JSValueMakeUndefined(context);
  161. }
  162. static JSValueRef dumpDOMAsWebArchiveCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  163. {
  164. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  165. controller->setDumpDOMAsWebArchive(true);
  166. return JSValueMakeUndefined(context);
  167. }
  168. static JSValueRef dumpEditingCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  169. {
  170. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  171. controller->setDumpEditingCallbacks(true);
  172. return JSValueMakeUndefined(context);
  173. }
  174. static JSValueRef dumpFrameLoadCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  175. {
  176. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  177. controller->setDumpFrameLoadCallbacks(true);
  178. return JSValueMakeUndefined(context);
  179. }
  180. static JSValueRef dumpProgressFinishedCallbackCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  181. {
  182. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  183. controller->setDumpProgressFinishedCallback(true);
  184. return JSValueMakeUndefined(context);
  185. }
  186. static JSValueRef dumpUserGestureInFrameLoadCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  187. {
  188. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  189. controller->setDumpUserGestureInFrameLoadCallbacks(true);
  190. return JSValueMakeUndefined(context);
  191. }
  192. static JSValueRef dumpResourceLoadCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  193. {
  194. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  195. controller->setDumpResourceLoadCallbacks(true);
  196. return JSValueMakeUndefined(context);
  197. }
  198. static JSValueRef dumpResourceResponseMIMETypesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  199. {
  200. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  201. controller->setDumpResourceResponseMIMETypes(true);
  202. return JSValueMakeUndefined(context);
  203. }
  204. static JSValueRef dumpSelectionRectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  205. {
  206. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  207. controller->setDumpSelectionRect(true);
  208. return JSValueMakeUndefined(context);
  209. }
  210. static JSValueRef dumpSourceAsWebArchiveCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  211. {
  212. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  213. controller->setDumpSourceAsWebArchive(true);
  214. return JSValueMakeUndefined(context);
  215. }
  216. static JSValueRef dumpStatusCallbacksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  217. {
  218. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  219. controller->setDumpStatusCallbacks(true);
  220. return JSValueMakeUndefined(context);
  221. }
  222. static JSValueRef dumpTitleChangesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  223. {
  224. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  225. controller->setDumpTitleChanges(true);
  226. return JSValueMakeUndefined(context);
  227. }
  228. static JSValueRef dumpIconChangesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  229. {
  230. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  231. controller->setDumpIconChanges(true);
  232. return JSValueMakeUndefined(context);
  233. }
  234. static JSValueRef dumpWillCacheResponseCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  235. {
  236. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  237. controller->setDumpWillCacheResponse(true);
  238. return JSValueMakeUndefined(context);
  239. }
  240. static JSValueRef pathToLocalResourceCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  241. {
  242. if (argumentCount < 1)
  243. return JSValueMakeUndefined(context);
  244. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  245. JSRetainPtr<JSStringRef> localPath(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  246. ASSERT(!*exception);
  247. JSRetainPtr<JSStringRef> convertedPath(Adopt, controller->pathToLocalResource(context, localPath.get()));
  248. if (!convertedPath)
  249. return JSValueMakeUndefined(context);
  250. return JSValueMakeString(context, convertedPath.get());
  251. }
  252. static JSValueRef removeAllVisitedLinksCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  253. {
  254. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  255. controller->setDumpVisitedLinksCallback(true);
  256. controller->removeAllVisitedLinks();
  257. return JSValueMakeUndefined(context);
  258. }
  259. static JSValueRef repaintSweepHorizontallyCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  260. {
  261. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  262. controller->setTestRepaintSweepHorizontally(true);
  263. return JSValueMakeUndefined(context);
  264. }
  265. static JSValueRef setCallCloseOnWebViewsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  266. {
  267. if (argumentCount < 1)
  268. return JSValueMakeUndefined(context);
  269. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  270. controller->setCallCloseOnWebViews(JSValueToBoolean(context, arguments[0]));
  271. return JSValueMakeUndefined(context);
  272. }
  273. static JSValueRef setCanOpenWindowsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  274. {
  275. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  276. controller->setCanOpenWindows(true);
  277. return JSValueMakeUndefined(context);
  278. }
  279. static JSValueRef setCloseRemainingWindowsWhenCompleteCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  280. {
  281. if (argumentCount < 1)
  282. return JSValueMakeUndefined(context);
  283. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  284. controller->setCloseRemainingWindowsWhenComplete(JSValueToBoolean(context, arguments[0]));
  285. return JSValueMakeUndefined(context);
  286. }
  287. static JSValueRef setEncodedAudioDataCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  288. {
  289. if (argumentCount < 1)
  290. return JSValueMakeUndefined(context);
  291. JSRetainPtr<JSStringRef> encodedAudioData(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  292. ASSERT(!*exception);
  293. size_t maxLength = JSStringGetMaximumUTF8CStringSize(encodedAudioData.get());
  294. OwnArrayPtr<char> encodedAudioDataBuffer = adoptArrayPtr(new char[maxLength + 1]);
  295. JSStringGetUTF8CString(encodedAudioData.get(), encodedAudioDataBuffer.get(), maxLength + 1);
  296. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  297. controller->setEncodedAudioData(encodedAudioDataBuffer.get());
  298. controller->setDumpAsAudio(true);
  299. return JSValueMakeUndefined(context);
  300. }
  301. static JSValueRef testOnscreenCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  302. {
  303. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  304. controller->setTestOnscreen(true);
  305. return JSValueMakeUndefined(context);
  306. }
  307. static JSValueRef testRepaintCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  308. {
  309. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  310. controller->setTestRepaint(true);
  311. return JSValueMakeUndefined(context);
  312. }
  313. static JSValueRef addDisallowedURLCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  314. {
  315. // Has mac implementation
  316. if (argumentCount < 1)
  317. return JSValueMakeUndefined(context);
  318. JSRetainPtr<JSStringRef> url(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  319. ASSERT(!*exception);
  320. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  321. controller->addDisallowedURL(url.get());
  322. return JSValueMakeUndefined(context);
  323. }
  324. static JSValueRef addURLToRedirectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  325. {
  326. if (argumentCount < 2)
  327. return JSValueMakeUndefined(context);
  328. JSRetainPtr<JSStringRef> origin(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  329. ASSERT(!*exception);
  330. JSRetainPtr<JSStringRef> destination(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  331. ASSERT(!*exception);
  332. size_t maxLength = JSStringGetMaximumUTF8CStringSize(origin.get());
  333. OwnArrayPtr<char> originBuffer = adoptArrayPtr(new char[maxLength + 1]);
  334. JSStringGetUTF8CString(origin.get(), originBuffer.get(), maxLength + 1);
  335. maxLength = JSStringGetMaximumUTF8CStringSize(destination.get());
  336. OwnArrayPtr<char> destinationBuffer = adoptArrayPtr(new char[maxLength + 1]);
  337. JSStringGetUTF8CString(destination.get(), destinationBuffer.get(), maxLength + 1);
  338. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  339. controller->addURLToRedirect(originBuffer.get(), destinationBuffer.get());
  340. return JSValueMakeUndefined(context);
  341. }
  342. static JSValueRef callShouldCloseOnWebViewCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  343. {
  344. // Has mac & windows implementation
  345. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  346. return JSValueMakeBoolean(context, controller->callShouldCloseOnWebView());
  347. }
  348. static JSValueRef clearAllApplicationCachesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  349. {
  350. // Has mac implementation
  351. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  352. controller->clearAllApplicationCaches();
  353. return JSValueMakeUndefined(context);
  354. }
  355. static JSValueRef clearApplicationCacheForOriginCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  356. {
  357. if (argumentCount < 1)
  358. return JSValueMakeUndefined(context);
  359. JSRetainPtr<JSStringRef> originURL(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  360. ASSERT(!*exception);
  361. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  362. controller->clearApplicationCacheForOrigin(originURL.get());
  363. return JSValueMakeUndefined(context);
  364. }
  365. static JSValueRef applicationCacheDiskUsageForOriginCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  366. {
  367. if (argumentCount < 1)
  368. return JSValueMakeUndefined(context);
  369. JSRetainPtr<JSStringRef> originURL(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  370. ASSERT(!*exception);
  371. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  372. return JSValueMakeNumber(context, controller->applicationCacheDiskUsageForOrigin(originURL.get()));
  373. }
  374. static JSValueRef originsWithApplicationCacheCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  375. {
  376. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  377. return controller->originsWithApplicationCache(context);
  378. }
  379. static JSValueRef clearAllDatabasesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  380. {
  381. // Has mac & windows implementation
  382. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  383. controller->clearAllDatabases();
  384. return JSValueMakeUndefined(context);
  385. }
  386. static JSValueRef syncLocalStorageCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  387. {
  388. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  389. controller->syncLocalStorage();
  390. return JSValueMakeUndefined(context);
  391. }
  392. static JSValueRef observeStorageTrackerNotificationsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  393. {
  394. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  395. if (argumentCount < 1)
  396. return JSValueMakeUndefined(context);
  397. unsigned numNotifications = JSValueToNumber(context, arguments[0], exception);
  398. ASSERT(!*exception);
  399. controller->observeStorageTrackerNotifications(numNotifications);
  400. return JSValueMakeUndefined(context);
  401. }
  402. static JSValueRef deleteAllLocalStorageCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  403. {
  404. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  405. controller->deleteAllLocalStorage();
  406. return JSValueMakeUndefined(context);
  407. }
  408. static JSValueRef deleteLocalStorageForOriginCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  409. {
  410. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  411. if (argumentCount < 1)
  412. return JSValueMakeUndefined(context);
  413. JSRetainPtr<JSStringRef> url(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  414. ASSERT(!*exception);
  415. controller->deleteLocalStorageForOrigin(url.get());
  416. return JSValueMakeUndefined(context);
  417. }
  418. static JSValueRef localStorageDiskUsageForOriginCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  419. {
  420. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  421. if (argumentCount < 1)
  422. return JSValueMakeUndefined(context);
  423. JSRetainPtr<JSStringRef> originURL(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  424. ASSERT(!*exception);
  425. return JSValueMakeNumber(context, controller->localStorageDiskUsageForOrigin(originURL.get()));
  426. }
  427. static JSValueRef originsWithLocalStorageCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  428. {
  429. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  430. return controller->originsWithLocalStorage(context);
  431. }
  432. static JSValueRef clearBackForwardListCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  433. {
  434. // Has mac & windows implementation
  435. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  436. controller->clearBackForwardList();
  437. return JSValueMakeUndefined(context);
  438. }
  439. static JSValueRef clearPersistentUserStyleSheetCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  440. {
  441. // Has mac & windows implementation
  442. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  443. controller->clearPersistentUserStyleSheet();
  444. return JSValueMakeUndefined(context);
  445. }
  446. static JSValueRef decodeHostNameCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  447. {
  448. // Has mac implementation
  449. if (argumentCount < 1)
  450. return JSValueMakeUndefined(context);
  451. JSRetainPtr<JSStringRef> name(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  452. ASSERT(!*exception);
  453. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  454. JSRetainPtr<JSStringRef> decodedHostName(Adopt, controller->copyDecodedHostName(name.get()));
  455. return JSValueMakeString(context, decodedHostName.get());
  456. }
  457. static JSValueRef dispatchPendingLoadRequestsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  458. {
  459. // Has mac implementation, needs windows implementation
  460. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  461. controller->dispatchPendingLoadRequests();
  462. return JSValueMakeUndefined(context);
  463. }
  464. static JSValueRef displayCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  465. {
  466. // Has mac & windows implementation
  467. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  468. controller->display();
  469. return JSValueMakeUndefined(context);
  470. }
  471. static JSValueRef displayInvalidatedRegionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  472. {
  473. // Has mac & windows implementation
  474. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  475. // TestRunner::display() only renders the invalidated region so
  476. // we can just use that.
  477. controller->display();
  478. return JSValueMakeUndefined(context);
  479. }
  480. static JSValueRef encodeHostNameCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  481. {
  482. // Has mac implementation
  483. if (argumentCount < 1)
  484. return JSValueMakeUndefined(context);
  485. JSRetainPtr<JSStringRef> name(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  486. ASSERT(!*exception);
  487. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  488. JSRetainPtr<JSStringRef> encodedHostName(Adopt, controller->copyEncodedHostName(name.get()));
  489. return JSValueMakeString(context, encodedHostName.get());
  490. }
  491. static JSValueRef execCommandCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  492. {
  493. // Has Mac & Windows implementations.
  494. if (argumentCount < 1)
  495. return JSValueMakeUndefined(context);
  496. JSRetainPtr<JSStringRef> name(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  497. ASSERT(!*exception);
  498. // Ignoring the second parameter (userInterface), as this command emulates a manual action.
  499. JSRetainPtr<JSStringRef> value;
  500. if (argumentCount >= 3) {
  501. value.adopt(JSValueToStringCopy(context, arguments[2], exception));
  502. ASSERT(!*exception);
  503. } else
  504. value.adopt(JSStringCreateWithUTF8CString(""));
  505. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  506. controller->execCommand(name.get(), value.get());
  507. return JSValueMakeUndefined(context);
  508. }
  509. static JSValueRef findStringCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  510. {
  511. // Has Mac implementation.
  512. if (argumentCount < 2)
  513. return JSValueMakeUndefined(context);
  514. JSRetainPtr<JSStringRef> target(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  515. ASSERT(!*exception);
  516. JSObjectRef options = JSValueToObject(context, arguments[1], exception);
  517. ASSERT(!*exception);
  518. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  519. return JSValueMakeBoolean(context, controller->findString(context, target.get(), options));
  520. }
  521. static JSValueRef goBackCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  522. {
  523. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  524. controller->goBack();
  525. return JSValueMakeUndefined(context);
  526. }
  527. static JSValueRef isCommandEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  528. {
  529. // Has Mac implementation.
  530. if (argumentCount < 1)
  531. return JSValueMakeUndefined(context);
  532. JSRetainPtr<JSStringRef> name(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  533. ASSERT(!*exception);
  534. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  535. return JSValueMakeBoolean(context, controller->isCommandEnabled(name.get()));
  536. }
  537. static JSValueRef overridePreferenceCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  538. {
  539. if (argumentCount < 2)
  540. return JSValueMakeUndefined(context);
  541. JSRetainPtr<JSStringRef> key(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  542. ASSERT(!*exception);
  543. JSRetainPtr<JSStringRef> value(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  544. ASSERT(!*exception);
  545. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  546. controller->overridePreference(key.get(), value.get());
  547. return JSValueMakeUndefined(context);
  548. }
  549. static JSValueRef keepWebHistoryCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  550. {
  551. // Has mac implementation
  552. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  553. controller->keepWebHistory();
  554. return JSValueMakeUndefined(context);
  555. }
  556. static JSValueRef notifyDoneCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  557. {
  558. // Has mac & windows implementation
  559. // May be able to be made platform independant by using shared WorkQueue
  560. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  561. controller->notifyDone();
  562. return JSValueMakeUndefined(context);
  563. }
  564. static JSValueRef numberOfPendingGeolocationPermissionRequestsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  565. {
  566. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  567. return JSValueMakeNumber(context, controller->numberOfPendingGeolocationPermissionRequests());
  568. }
  569. static JSValueRef queueBackNavigationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  570. {
  571. // Has mac & windows implementation
  572. // May be able to be made platform independant by using shared WorkQueue
  573. if (argumentCount < 1)
  574. return JSValueMakeUndefined(context);
  575. double howFarBackDouble = JSValueToNumber(context, arguments[0], exception);
  576. ASSERT(!*exception);
  577. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  578. controller->queueBackNavigation(static_cast<int>(howFarBackDouble));
  579. return JSValueMakeUndefined(context);
  580. }
  581. static JSValueRef queueForwardNavigationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  582. {
  583. // Has mac & windows implementation
  584. // May be able to be made platform independant by using shared WorkQueue
  585. if (argumentCount < 1)
  586. return JSValueMakeUndefined(context);
  587. double howFarForwardDouble = JSValueToNumber(context, arguments[0], exception);
  588. ASSERT(!*exception);
  589. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  590. controller->queueForwardNavigation(static_cast<int>(howFarForwardDouble));
  591. return JSValueMakeUndefined(context);
  592. }
  593. static JSValueRef queueLoadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  594. {
  595. // Has mac & windows implementation
  596. // May be able to be made platform independant by using shared WorkQueue
  597. if (argumentCount < 1)
  598. return JSValueMakeUndefined(context);
  599. JSRetainPtr<JSStringRef> url(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  600. ASSERT(!*exception);
  601. JSRetainPtr<JSStringRef> target;
  602. if (argumentCount >= 2) {
  603. target.adopt(JSValueToStringCopy(context, arguments[1], exception));
  604. ASSERT(!*exception);
  605. } else
  606. target.adopt(JSStringCreateWithUTF8CString(""));
  607. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  608. controller->queueLoad(url.get(), target.get());
  609. return JSValueMakeUndefined(context);
  610. }
  611. static JSValueRef queueLoadHTMLStringCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  612. {
  613. // Has Mac & Windows implementation
  614. if (argumentCount < 1)
  615. return JSValueMakeUndefined(context);
  616. JSRetainPtr<JSStringRef> content(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  617. ASSERT(!*exception);
  618. JSRetainPtr<JSStringRef> baseURL;
  619. if (argumentCount >= 2) {
  620. baseURL.adopt(JSValueToStringCopy(context, arguments[1], exception));
  621. ASSERT(!*exception);
  622. } else
  623. baseURL.adopt(JSStringCreateWithUTF8CString(""));
  624. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  625. if (argumentCount >= 3) {
  626. JSRetainPtr<JSStringRef> unreachableURL;
  627. unreachableURL.adopt(JSValueToStringCopy(context, arguments[2], exception));
  628. ASSERT(!*exception);
  629. controller->queueLoadAlternateHTMLString(content.get(), baseURL.get(), unreachableURL.get());
  630. return JSValueMakeUndefined(context);
  631. }
  632. controller->queueLoadHTMLString(content.get(), baseURL.get());
  633. return JSValueMakeUndefined(context);
  634. }
  635. static JSValueRef queueReloadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  636. {
  637. // Has mac & windows implementation
  638. // May be able to be made platform independant by using shared WorkQueue
  639. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  640. controller->queueReload();
  641. return JSValueMakeUndefined(context);
  642. }
  643. static JSValueRef queueLoadingScriptCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  644. {
  645. // Has mac & windows implementation
  646. // May be able to be made platform independant by using shared WorkQueue
  647. if (argumentCount < 1)
  648. return JSValueMakeUndefined(context);
  649. JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  650. ASSERT(!*exception);
  651. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  652. controller->queueLoadingScript(script.get());
  653. return JSValueMakeUndefined(context);
  654. }
  655. static JSValueRef queueNonLoadingScriptCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  656. {
  657. // Has mac & windows implementation
  658. // May be able to be made platform independant by using shared WorkQueue
  659. if (argumentCount < 1)
  660. return JSValueMakeUndefined(context);
  661. JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  662. ASSERT(!*exception);
  663. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  664. controller->queueNonLoadingScript(script.get());
  665. return JSValueMakeUndefined(context);
  666. }
  667. static JSValueRef setAcceptsEditingCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  668. {
  669. // Has mac & windows implementation
  670. if (argumentCount < 1)
  671. return JSValueMakeUndefined(context);
  672. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  673. controller->setAcceptsEditing(JSValueToBoolean(context, arguments[0]));
  674. return JSValueMakeUndefined(context);
  675. }
  676. static JSValueRef setAlwaysAcceptCookiesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  677. {
  678. // Has mac & windows implementation
  679. if (argumentCount < 1)
  680. return JSValueMakeUndefined(context);
  681. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  682. controller->setAlwaysAcceptCookies(JSValueToBoolean(context, arguments[0]));
  683. return JSValueMakeUndefined(context);
  684. }
  685. static JSValueRef setAppCacheMaximumSizeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  686. {
  687. // Has mac implementation
  688. if (argumentCount < 1)
  689. return JSValueMakeUndefined(context);
  690. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  691. double size = JSValueToNumber(context, arguments[0], NULL);
  692. if (!std::isnan(size))
  693. controller->setAppCacheMaximumSize(static_cast<unsigned long long>(size));
  694. return JSValueMakeUndefined(context);
  695. }
  696. static JSValueRef setApplicationCacheOriginQuotaCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  697. {
  698. // Has mac implementation
  699. if (argumentCount < 1)
  700. return JSValueMakeUndefined(context);
  701. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  702. double size = JSValueToNumber(context, arguments[0], NULL);
  703. if (!std::isnan(size))
  704. controller->setApplicationCacheOriginQuota(static_cast<unsigned long long>(size));
  705. return JSValueMakeUndefined(context);
  706. }
  707. static JSValueRef setAuthenticationPasswordCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  708. {
  709. // Has mac & windows implementation
  710. if (argumentCount < 1)
  711. return JSValueMakeUndefined(context);
  712. JSRetainPtr<JSStringRef> password(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  713. ASSERT(!*exception);
  714. size_t maxLength = JSStringGetMaximumUTF8CStringSize(password.get());
  715. char* passwordBuffer = new char[maxLength + 1];
  716. JSStringGetUTF8CString(password.get(), passwordBuffer, maxLength + 1);
  717. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  718. controller->setAuthenticationPassword(passwordBuffer);
  719. delete[] passwordBuffer;
  720. return JSValueMakeUndefined(context);
  721. }
  722. static JSValueRef setAuthenticationUsernameCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  723. {
  724. // Has mac & windows implementation
  725. if (argumentCount < 1)
  726. return JSValueMakeUndefined(context);
  727. JSRetainPtr<JSStringRef> username(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  728. ASSERT(!*exception);
  729. size_t maxLength = JSStringGetMaximumUTF8CStringSize(username.get());
  730. char* usernameBuffer = new char[maxLength + 1];
  731. JSStringGetUTF8CString(username.get(), usernameBuffer, maxLength + 1);
  732. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  733. controller->setAuthenticationUsername(usernameBuffer);
  734. delete[] usernameBuffer;
  735. return JSValueMakeUndefined(context);
  736. }
  737. static JSValueRef setAuthorAndUserStylesEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  738. {
  739. // Has mac & windows implementation
  740. if (argumentCount < 1)
  741. return JSValueMakeUndefined(context);
  742. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  743. controller->setAuthorAndUserStylesEnabled(JSValueToBoolean(context, arguments[0]));
  744. return JSValueMakeUndefined(context);
  745. }
  746. static JSValueRef setCacheModelCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  747. {
  748. // Has Mac implementation.
  749. if (argumentCount < 1)
  750. return JSValueMakeUndefined(context);
  751. int cacheModel = JSValueToNumber(context, arguments[0], exception);
  752. ASSERT(!*exception);
  753. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  754. controller->setCacheModel(cacheModel);
  755. return JSValueMakeUndefined(context);
  756. }
  757. static JSValueRef setCustomPolicyDelegateCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  758. {
  759. // Has mac implementation
  760. if (argumentCount < 1)
  761. return JSValueMakeUndefined(context);
  762. bool permissive = false;
  763. if (argumentCount >= 2)
  764. permissive = JSValueToBoolean(context, arguments[1]);
  765. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  766. controller->setCustomPolicyDelegate(JSValueToBoolean(context, arguments[0]), permissive);
  767. return JSValueMakeUndefined(context);
  768. }
  769. static JSValueRef setDatabaseQuotaCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  770. {
  771. // Has mac implementation
  772. if (argumentCount < 1)
  773. return JSValueMakeUndefined(context);
  774. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  775. double quota = JSValueToNumber(context, arguments[0], NULL);
  776. if (!std::isnan(quota))
  777. controller->setDatabaseQuota(static_cast<unsigned long long>(quota));
  778. return JSValueMakeUndefined(context);
  779. }
  780. static JSValueRef setDeferMainResourceDataLoadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  781. {
  782. // Has Mac and Windows implementation
  783. if (argumentCount < 1)
  784. return JSValueMakeUndefined(context);
  785. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  786. controller->setDeferMainResourceDataLoad(JSValueToBoolean(context, arguments[0]));
  787. return JSValueMakeUndefined(context);
  788. }
  789. static JSValueRef setDefersLoadingCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  790. {
  791. if (argumentCount < 1)
  792. return JSValueMakeUndefined(context);
  793. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  794. controller->setDefersLoading(JSValueToBoolean(context, arguments[0]));
  795. return JSValueMakeUndefined(context);
  796. }
  797. static JSValueRef setUseDeferredFrameLoadingCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  798. {
  799. if (argumentCount < 1)
  800. return JSValueMakeUndefined(context);
  801. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  802. controller->setUseDeferredFrameLoading(JSValueToBoolean(context, arguments[0]));
  803. return JSValueMakeUndefined(context);
  804. }
  805. static JSValueRef setDomainRelaxationForbiddenForURLSchemeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  806. {
  807. // Has Mac and Windows implementation
  808. if (argumentCount < 2)
  809. return JSValueMakeUndefined(context);
  810. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  811. bool forbidden = JSValueToBoolean(context, arguments[0]);
  812. JSRetainPtr<JSStringRef> scheme(Adopt, JSValueToStringCopy(context, arguments[1], 0));
  813. controller->setDomainRelaxationForbiddenForURLScheme(forbidden, scheme.get());
  814. return JSValueMakeUndefined(context);
  815. }
  816. static JSValueRef setMockDeviceOrientationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  817. {
  818. if (argumentCount < 6)
  819. return JSValueMakeUndefined(context);
  820. bool canProvideAlpha = JSValueToBoolean(context, arguments[0]);
  821. double alpha = JSValueToNumber(context, arguments[1], exception);
  822. ASSERT(!*exception);
  823. bool canProvideBeta = JSValueToBoolean(context, arguments[2]);
  824. double beta = JSValueToNumber(context, arguments[3], exception);
  825. ASSERT(!*exception);
  826. bool canProvideGamma = JSValueToBoolean(context, arguments[4]);
  827. double gamma = JSValueToNumber(context, arguments[5], exception);
  828. ASSERT(!*exception);
  829. TestRunner* controller = reinterpret_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  830. controller->setMockDeviceOrientation(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
  831. return JSValueMakeUndefined(context);
  832. }
  833. static JSValueRef setMockGeolocationPositionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  834. {
  835. if (argumentCount < 3)
  836. return JSValueMakeUndefined(context);
  837. double latitude = JSValueToNumber(context, arguments[0], 0);
  838. double longitude = JSValueToNumber(context, arguments[1], 0);
  839. double accuracy = JSValueToNumber(context, arguments[2], 0);
  840. bool canProvideAltitude = false;
  841. double altitude = 0.;
  842. if (argumentCount > 3 && !JSValueIsUndefined(context, arguments[3])) {
  843. canProvideAltitude = true;
  844. altitude = JSValueToNumber(context, arguments[3], 0);
  845. }
  846. bool canProvideAltitudeAccuracy = false;
  847. double altitudeAccuracy = 0.;
  848. if (argumentCount > 4 && !JSValueIsUndefined(context, arguments[4])) {
  849. canProvideAltitudeAccuracy = true;
  850. altitudeAccuracy = JSValueToNumber(context, arguments[4], 0);
  851. }
  852. bool canProvideHeading = false;
  853. double heading = 0.;
  854. if (argumentCount > 5 && !JSValueIsUndefined(context, arguments[5])) {
  855. canProvideHeading = true;
  856. heading = JSValueToNumber(context, arguments[5], 0);
  857. }
  858. bool canProvideSpeed = false;
  859. double speed = 0.;
  860. if (argumentCount > 6 && !JSValueIsUndefined(context, arguments[6])) {
  861. canProvideSpeed = true;
  862. speed = JSValueToNumber(context, arguments[6], 0);
  863. }
  864. TestRunner* controller = reinterpret_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  865. controller->setMockGeolocationPosition(latitude, longitude, accuracy, canProvideAltitude, altitude, canProvideAltitudeAccuracy, altitudeAccuracy, canProvideHeading, heading, canProvideSpeed, speed);
  866. return JSValueMakeUndefined(context);
  867. }
  868. static JSValueRef setMockGeolocationPositionUnavailableErrorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  869. {
  870. if (argumentCount != 1)
  871. return JSValueMakeUndefined(context);
  872. JSRetainPtr<JSStringRef> message(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  873. ASSERT(!*exception);
  874. TestRunner* controller = reinterpret_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  875. controller->setMockGeolocationPositionUnavailableError(message.get());
  876. return JSValueMakeUndefined(context);
  877. }
  878. static JSValueRef addMockSpeechInputResultCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  879. {
  880. if (argumentCount < 3)
  881. return JSValueMakeUndefined(context);
  882. JSRetainPtr<JSStringRef> result(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  883. ASSERT(!*exception);
  884. double confidence = JSValueToNumber(context, arguments[1], exception);
  885. JSRetainPtr<JSStringRef> language(Adopt, JSValueToStringCopy(context, arguments[2], exception));
  886. ASSERT(!*exception);
  887. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  888. controller->addMockSpeechInputResult(result.get(), confidence, language.get());
  889. return JSValueMakeUndefined(context);
  890. }
  891. static JSValueRef setMockSpeechInputDumpRectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  892. {
  893. if (argumentCount < 1)
  894. return JSValueMakeUndefined(context);
  895. bool dumpRect = JSValueToBoolean(context, arguments[0]);
  896. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  897. controller->setMockSpeechInputDumpRect(dumpRect);
  898. return JSValueMakeUndefined(context);
  899. }
  900. static JSValueRef setNewWindowsCopyBackForwardListCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  901. {
  902. // Has mac implementation
  903. if (argumentCount < 1)
  904. return JSValueMakeUndefined(context);
  905. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  906. controller->setNewWindowsCopyBackForwardList(JSValueToBoolean(context, arguments[0]));
  907. return JSValueMakeUndefined(context);
  908. }
  909. static JSValueRef setGeolocationPermissionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  910. {
  911. // Has mac implementation
  912. if (argumentCount < 1)
  913. return JSValueMakeUndefined(context);
  914. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  915. controller->setGeolocationPermission(JSValueToBoolean(context, arguments[0]));
  916. return JSValueMakeUndefined(context);
  917. }
  918. static JSValueRef setHandlesAuthenticationChallengesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  919. {
  920. // Has mac & windows implementation
  921. if (argumentCount < 1)
  922. return JSValueMakeUndefined(context);
  923. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  924. controller->setHandlesAuthenticationChallenges(JSValueToBoolean(context, arguments[0]));
  925. return JSValueMakeUndefined(context);
  926. }
  927. static JSValueRef setPOSIXLocaleCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  928. {
  929. if (argumentCount < 1)
  930. return JSValueMakeUndefined(context);
  931. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  932. JSRetainPtr<JSStringRef> locale(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  933. ASSERT(!*exception);
  934. controller->setPOSIXLocale(locale.get());
  935. return JSValueMakeUndefined(context);
  936. }
  937. static JSValueRef setIconDatabaseEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  938. {
  939. // Has mac & windows implementation
  940. if (argumentCount < 1)
  941. return JSValueMakeUndefined(context);
  942. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  943. controller->setIconDatabaseEnabled(JSValueToBoolean(context, arguments[0]));
  944. return JSValueMakeUndefined(context);
  945. }
  946. static JSValueRef setMainFrameIsFirstResponderCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  947. {
  948. // Has mac implementation
  949. if (argumentCount < 1)
  950. return JSValueMakeUndefined(context);
  951. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  952. controller->setMainFrameIsFirstResponder(JSValueToBoolean(context, arguments[0]));
  953. return JSValueMakeUndefined(context);
  954. }
  955. static JSValueRef setPersistentUserStyleSheetLocationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  956. {
  957. // Has mac implementation
  958. if (argumentCount < 1)
  959. return JSValueMakeUndefined(context);
  960. JSRetainPtr<JSStringRef> path(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  961. ASSERT(!*exception);
  962. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  963. controller->setPersistentUserStyleSheetLocation(path.get());
  964. return JSValueMakeUndefined(context);
  965. }
  966. static JSValueRef setPrivateBrowsingEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  967. {
  968. // Has mac & windows implementation
  969. if (argumentCount < 1)
  970. return JSValueMakeUndefined(context);
  971. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  972. controller->setPrivateBrowsingEnabled(JSValueToBoolean(context, arguments[0]));
  973. return JSValueMakeUndefined(context);
  974. }
  975. static JSValueRef setJavaScriptCanAccessClipboardCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  976. {
  977. // Has mac & windows implementation
  978. if (argumentCount < 1)
  979. return JSValueMakeUndefined(context);
  980. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  981. controller->setJavaScriptCanAccessClipboard(JSValueToBoolean(context, arguments[0]));
  982. return JSValueMakeUndefined(context);
  983. }
  984. static JSValueRef setXSSAuditorEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  985. {
  986. // Has mac & windows implementation
  987. if (argumentCount < 1)
  988. return JSValueMakeUndefined(context);
  989. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  990. controller->setXSSAuditorEnabled(JSValueToBoolean(context, arguments[0]));
  991. return JSValueMakeUndefined(context);
  992. }
  993. static JSValueRef setSpatialNavigationEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  994. {
  995. // Has mac implementation.
  996. if (argumentCount < 1)
  997. return JSValueMakeUndefined(context);
  998. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  999. controller->setSpatialNavigationEnabled(JSValueToBoolean(context, arguments[0]));
  1000. return JSValueMakeUndefined(context);
  1001. }
  1002. static JSValueRef setPrintingCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1003. {
  1004. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1005. controller->setIsPrinting(true);
  1006. return JSValueMakeUndefined(context);
  1007. }
  1008. static JSValueRef setAllowUniversalAccessFromFileURLsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1009. {
  1010. // Has mac & windows implementation
  1011. if (argumentCount < 1)
  1012. return JSValueMakeUndefined(context);
  1013. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1014. controller->setAllowUniversalAccessFromFileURLs(JSValueToBoolean(context, arguments[0]));
  1015. return JSValueMakeUndefined(context);
  1016. }
  1017. static JSValueRef setAllowFileAccessFromFileURLsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1018. {
  1019. // Has mac & windows implementation
  1020. if (argumentCount < 1)
  1021. return JSValueMakeUndefined(context);
  1022. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1023. controller->setAllowFileAccessFromFileURLs(JSValueToBoolean(context, arguments[0]));
  1024. return JSValueMakeUndefined(context);
  1025. }
  1026. static JSValueRef setTabKeyCyclesThroughElementsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1027. {
  1028. // Has mac & windows implementation
  1029. if (argumentCount < 1)
  1030. return JSValueMakeUndefined(context);
  1031. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1032. controller->setTabKeyCyclesThroughElements(JSValueToBoolean(context, arguments[0]));
  1033. return JSValueMakeUndefined(context);
  1034. }
  1035. static JSValueRef setUseDashboardCompatibilityModeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1036. {
  1037. // Has mac implementation
  1038. if (argumentCount < 1)
  1039. return JSValueMakeUndefined(context);
  1040. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1041. controller->setUseDashboardCompatibilityMode(JSValueToBoolean(context, arguments[0]));
  1042. return JSValueMakeUndefined(context);
  1043. }
  1044. static JSValueRef setUserStyleSheetEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1045. {
  1046. // Has mac implementation
  1047. if (argumentCount < 1)
  1048. return JSValueMakeUndefined(context);
  1049. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1050. controller->setUserStyleSheetEnabled(JSValueToBoolean(context, arguments[0]));
  1051. return JSValueMakeUndefined(context);
  1052. }
  1053. static JSValueRef setUserStyleSheetLocationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1054. {
  1055. // Has mac implementation
  1056. if (argumentCount < 1)
  1057. return JSValueMakeUndefined(context);
  1058. JSRetainPtr<JSStringRef> path(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1059. ASSERT(!*exception);
  1060. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1061. controller->setUserStyleSheetLocation(path.get());
  1062. return JSValueMakeUndefined(context);
  1063. }
  1064. static JSValueRef setValueForUserCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1065. {
  1066. // Has mac implementation
  1067. if (argumentCount != 2)
  1068. return JSValueMakeUndefined(context);
  1069. JSRetainPtr<JSStringRef> value(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  1070. ASSERT(!*exception);
  1071. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1072. controller->setValueForUser(context, arguments[0], value.get());
  1073. return JSValueMakeUndefined(context);
  1074. }
  1075. static JSValueRef setViewModeMediaFeatureCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1076. {
  1077. // Has mac implementation
  1078. if (argumentCount < 1)
  1079. return JSValueMakeUndefined(context);
  1080. JSRetainPtr<JSStringRef> mode(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1081. ASSERT(!*exception);
  1082. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1083. controller->setViewModeMediaFeature(mode.get());
  1084. return JSValueMakeUndefined(context);
  1085. }
  1086. static JSValueRef setWillSendRequestClearHeaderCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1087. {
  1088. // Has mac & windows implementation
  1089. if (argumentCount < 1)
  1090. return JSValueMakeUndefined(context);
  1091. JSRetainPtr<JSStringRef> header(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1092. ASSERT(!*exception);
  1093. size_t maxLength = JSStringGetMaximumUTF8CStringSize(header.get());
  1094. OwnArrayPtr<char> headerBuffer = adoptArrayPtr(new char[maxLength + 1]);
  1095. JSStringGetUTF8CString(header.get(), headerBuffer.get(), maxLength + 1);
  1096. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1097. controller->setWillSendRequestClearHeader(headerBuffer.get());
  1098. return JSValueMakeUndefined(context);
  1099. }
  1100. static JSValueRef setWillSendRequestReturnsNullCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1101. {
  1102. // Has cross-platform implementation
  1103. if (argumentCount < 1)
  1104. return JSValueMakeUndefined(context);
  1105. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1106. controller->setWillSendRequestReturnsNull(JSValueToBoolean(context, arguments[0]));
  1107. return JSValueMakeUndefined(context);
  1108. }
  1109. static JSValueRef setWillSendRequestReturnsNullOnRedirectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1110. {
  1111. // Has cross-platform implementation
  1112. if (argumentCount < 1)
  1113. return JSValueMakeUndefined(context);
  1114. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1115. controller->setWillSendRequestReturnsNullOnRedirect(JSValueToBoolean(context, arguments[0]));
  1116. return JSValueMakeUndefined(context);
  1117. }
  1118. static JSValueRef setWindowIsKeyCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1119. {
  1120. // Has mac implementation
  1121. if (argumentCount < 1)
  1122. return JSValueMakeUndefined(context);
  1123. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1124. controller->setWindowIsKey(JSValueToBoolean(context, arguments[0]));
  1125. return JSValueMakeUndefined(context);
  1126. }
  1127. static JSValueRef waitUntilDoneCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1128. {
  1129. // Has mac & windows implementation
  1130. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1131. controller->setWaitToDump(true);
  1132. return JSValueMakeUndefined(context);
  1133. }
  1134. static JSValueRef windowCountCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1135. {
  1136. // Has mac implementation
  1137. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1138. int windows = controller->windowCount();
  1139. return JSValueMakeNumber(context, windows);
  1140. }
  1141. static JSValueRef setPopupBlockingEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1142. {
  1143. // Has mac & windows implementation
  1144. if (argumentCount < 1)
  1145. return JSValueMakeUndefined(context);
  1146. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1147. controller->setPopupBlockingEnabled(JSValueToBoolean(context, arguments[0]));
  1148. return JSValueMakeUndefined(context);
  1149. }
  1150. static JSValueRef setPluginsEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1151. {
  1152. // Has mac & windows implementation
  1153. if (argumentCount < 1)
  1154. return JSValueMakeUndefined(context);
  1155. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1156. controller->setPluginsEnabled(JSValueToBoolean(context, arguments[0]));
  1157. return JSValueMakeUndefined(context);
  1158. }
  1159. static JSValueRef setPageVisibilityCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1160. {
  1161. // Has mac & windows implementation
  1162. if (argumentCount < 1)
  1163. return JSValueMakeUndefined(context);
  1164. JSRetainPtr<JSStringRef> visibility(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1165. ASSERT(!*exception);
  1166. size_t maxLength = JSStringGetMaximumUTF8CStringSize(visibility.get());
  1167. char* visibilityBuffer = new char[maxLength + 1];
  1168. JSStringGetUTF8CString(visibility.get(), visibilityBuffer, maxLength + 1);
  1169. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1170. controller->setPageVisibility(visibilityBuffer);
  1171. delete[] visibilityBuffer;
  1172. return JSValueMakeUndefined(context);
  1173. }
  1174. static JSValueRef resetPageVisibilityCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1175. {
  1176. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1177. controller->resetPageVisibility();
  1178. return JSValueMakeUndefined(context);
  1179. }
  1180. static JSValueRef setAutomaticLinkDetectionEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1181. {
  1182. if (argumentCount < 1)
  1183. return JSValueMakeUndefined(context);
  1184. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1185. controller->setAutomaticLinkDetectionEnabled(JSValueToBoolean(context, arguments[0]));
  1186. return JSValueMakeUndefined(context);
  1187. }
  1188. static JSValueRef setStopProvisionalFrameLoadsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1189. {
  1190. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1191. controller->setStopProvisionalFrameLoads(true);
  1192. return JSValueMakeUndefined(context);
  1193. }
  1194. static JSValueRef showWebInspectorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1195. {
  1196. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1197. controller->showWebInspector();
  1198. return JSValueMakeUndefined(context);
  1199. }
  1200. static JSValueRef closeWebInspectorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1201. {
  1202. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1203. controller->closeWebInspector();
  1204. return JSValueMakeUndefined(context);
  1205. }
  1206. static JSValueRef evaluateInWebInspectorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1207. {
  1208. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1209. double callId = JSValueToNumber(context, arguments[0], exception);
  1210. ASSERT(!*exception);
  1211. JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  1212. ASSERT(!*exception);
  1213. controller->evaluateInWebInspector(static_cast<long>(callId), script.get());
  1214. return JSValueMakeUndefined(context);
  1215. }
  1216. static JSValueRef evaluateScriptInIsolatedWorldCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1217. {
  1218. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1219. double worldID = JSValueToNumber(context, arguments[0], exception);
  1220. ASSERT(!*exception);
  1221. JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  1222. ASSERT(!*exception);
  1223. controller->evaluateScriptInIsolatedWorld(static_cast<unsigned>(worldID), JSContextGetGlobalObject(context), script.get());
  1224. return JSValueMakeUndefined(context);
  1225. }
  1226. static JSValueRef evaluateScriptInIsolatedWorldAndReturnValueCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1227. {
  1228. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1229. double worldID = JSValueToNumber(context, arguments[0], exception);
  1230. ASSERT(!*exception);
  1231. JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  1232. ASSERT(!*exception);
  1233. controller->evaluateScriptInIsolatedWorldAndReturnValue(static_cast<unsigned>(worldID), JSContextGetGlobalObject(context), script.get());
  1234. return JSValueMakeUndefined(context);
  1235. }
  1236. static JSValueRef waitForPolicyDelegateCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*)
  1237. {
  1238. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1239. controller->waitForPolicyDelegate();
  1240. return JSValueMakeUndefined(context);
  1241. }
  1242. static JSValueRef addOriginAccessWhitelistEntryCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1243. {
  1244. if (argumentCount != 4)
  1245. return JSValueMakeUndefined(context);
  1246. JSRetainPtr<JSStringRef> sourceOrigin(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1247. ASSERT(!*exception);
  1248. JSRetainPtr<JSStringRef> destinationProtocol(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  1249. ASSERT(!*exception);
  1250. JSRetainPtr<JSStringRef> destinationHost(Adopt, JSValueToStringCopy(context, arguments[2], exception));
  1251. ASSERT(!*exception);
  1252. bool allowDestinationSubdomains = JSValueToBoolean(context, arguments[3]);
  1253. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1254. controller->addOriginAccessWhitelistEntry(sourceOrigin.get(), destinationProtocol.get(), destinationHost.get(), allowDestinationSubdomains);
  1255. return JSValueMakeUndefined(context);
  1256. }
  1257. static JSValueRef removeOriginAccessWhitelistEntryCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1258. {
  1259. if (argumentCount != 4)
  1260. return JSValueMakeUndefined(context);
  1261. JSRetainPtr<JSStringRef> sourceOrigin(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1262. ASSERT(!*exception);
  1263. JSRetainPtr<JSStringRef> destinationProtocol(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  1264. ASSERT(!*exception);
  1265. JSRetainPtr<JSStringRef> destinationHost(Adopt, JSValueToStringCopy(context, arguments[2], exception));
  1266. ASSERT(!*exception);
  1267. bool allowDestinationSubdomains = JSValueToBoolean(context, arguments[3]);
  1268. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1269. controller->removeOriginAccessWhitelistEntry(sourceOrigin.get(), destinationProtocol.get(), destinationHost.get(), allowDestinationSubdomains);
  1270. return JSValueMakeUndefined(context);
  1271. }
  1272. static JSValueRef setScrollbarPolicyCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1273. {
  1274. if (argumentCount != 2)
  1275. return JSValueMakeUndefined(context);
  1276. JSRetainPtr<JSStringRef> orientation(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1277. ASSERT(!*exception);
  1278. JSRetainPtr<JSStringRef> policy(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  1279. ASSERT(!*exception);
  1280. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1281. controller->setScrollbarPolicy(orientation.get(), policy.get());
  1282. return JSValueMakeUndefined(context);
  1283. }
  1284. static JSValueRef addUserScriptCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1285. {
  1286. if (argumentCount != 3)
  1287. return JSValueMakeUndefined(context);
  1288. JSRetainPtr<JSStringRef> source(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1289. ASSERT(!*exception);
  1290. bool runAtStart = JSValueToBoolean(context, arguments[1]);
  1291. bool allFrames = JSValueToBoolean(context, arguments[2]);
  1292. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1293. controller->addUserScript(source.get(), runAtStart, allFrames);
  1294. return JSValueMakeUndefined(context);
  1295. }
  1296. static JSValueRef addUserStyleSheetCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1297. {
  1298. if (argumentCount != 2)
  1299. return JSValueMakeUndefined(context);
  1300. JSRetainPtr<JSStringRef> source(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1301. ASSERT(!*exception);
  1302. bool allFrames = JSValueToBoolean(context, arguments[1]);
  1303. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1304. controller->addUserStyleSheet(source.get(), allFrames);
  1305. return JSValueMakeUndefined(context);
  1306. }
  1307. static JSValueRef setShouldPaintBrokenImageCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1308. {
  1309. // Has Mac implementation
  1310. if (argumentCount < 1)
  1311. return JSValueMakeUndefined(context);
  1312. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1313. controller->setShouldPaintBrokenImage(JSValueToBoolean(context, arguments[0]));
  1314. return JSValueMakeUndefined(context);
  1315. }
  1316. static JSValueRef apiTestNewWindowDataLoadBaseURLCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1317. {
  1318. if (argumentCount != 2)
  1319. return JSValueMakeUndefined(context);
  1320. JSRetainPtr<JSStringRef> utf8Data(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1321. ASSERT(!*exception);
  1322. JSRetainPtr<JSStringRef> baseURL(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  1323. ASSERT(!*exception);
  1324. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1325. controller->apiTestNewWindowDataLoadBaseURL(utf8Data.get(), baseURL.get());
  1326. return JSValueMakeUndefined(context);
  1327. }
  1328. static JSValueRef apiTestGoToCurrentBackForwardItemCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1329. {
  1330. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1331. controller->apiTestGoToCurrentBackForwardItem();
  1332. return JSValueMakeUndefined(context);
  1333. }
  1334. static JSValueRef setWebViewEditableCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1335. {
  1336. // Has Mac implementation
  1337. if (argumentCount < 1)
  1338. return JSValueMakeUndefined(context);
  1339. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1340. controller->setWebViewEditable(JSValueToBoolean(context, arguments[0]));
  1341. return JSValueMakeUndefined(context);
  1342. }
  1343. static JSValueRef abortModalCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1344. {
  1345. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1346. controller->abortModal();
  1347. return JSValueMakeUndefined(context);
  1348. }
  1349. static JSValueRef authenticateSessionCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1350. {
  1351. // authenticateSession(url, username, password)
  1352. if (argumentCount != 3)
  1353. return JSValueMakeUndefined(context);
  1354. JSRetainPtr<JSStringRef> url(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1355. ASSERT(!*exception);
  1356. JSRetainPtr<JSStringRef> username(Adopt, JSValueToStringCopy(context, arguments[1], exception));
  1357. ASSERT(!*exception);
  1358. JSRetainPtr<JSStringRef> password(Adopt, JSValueToStringCopy(context, arguments[2], exception));
  1359. ASSERT(!*exception);
  1360. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1361. controller->authenticateSession(url.get(), username.get(), password.get());
  1362. return JSValueMakeUndefined(context);
  1363. }
  1364. static JSValueRef setSerializeHTTPLoadsCallback(JSContextRef context, JSObjectRef, JSObjectRef, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1365. {
  1366. bool serialize = true;
  1367. if (argumentCount == 1)
  1368. serialize = JSValueToBoolean(context, arguments[0]);
  1369. TestRunner::setSerializeHTTPLoads(serialize);
  1370. return JSValueMakeUndefined(context);
  1371. }
  1372. static JSValueRef setShouldStayOnPageAfterHandlingBeforeUnloadCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1373. {
  1374. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1375. if (argumentCount == 1)
  1376. controller->setShouldStayOnPageAfterHandlingBeforeUnload(JSValueToBoolean(context, arguments[0]));
  1377. return JSValueMakeUndefined(context);
  1378. }
  1379. static JSValueRef addChromeInputFieldCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1380. {
  1381. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1382. controller->addChromeInputField();
  1383. // the first argument is a callback that is called once the input field has been added
  1384. if (argumentCount == 1)
  1385. JSObjectCallAsFunction(context, JSValueToObject(context, arguments[0], 0), thisObject, 0, 0, 0);
  1386. return JSValueMakeUndefined(context);
  1387. }
  1388. static JSValueRef removeChromeInputFieldCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1389. {
  1390. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1391. controller->removeChromeInputField();
  1392. // the first argument is a callback that is called once the input field has been added
  1393. if (argumentCount == 1)
  1394. JSObjectCallAsFunction(context, JSValueToObject(context, arguments[0], 0), thisObject, 0, 0, 0);
  1395. return JSValueMakeUndefined(context);
  1396. }
  1397. static JSValueRef focusWebViewCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1398. {
  1399. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1400. controller->focusWebView();
  1401. // the first argument is a callback that is called once the input field has been added
  1402. if (argumentCount == 1)
  1403. JSObjectCallAsFunction(context, JSValueToObject(context, arguments[0], 0), thisObject, 0, 0, 0);
  1404. return JSValueMakeUndefined(context);
  1405. }
  1406. static JSValueRef setBackingScaleFactorCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1407. {
  1408. if (argumentCount != 2)
  1409. return JSValueMakeUndefined(context);
  1410. double backingScaleFactor = JSValueToNumber(context, arguments[0], exception);
  1411. ASSERT(!*exception);
  1412. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1413. controller->setBackingScaleFactor(backingScaleFactor);
  1414. // The second argument is a callback that is called once the backing scale factor has been set.
  1415. JSObjectCallAsFunction(context, JSValueToObject(context, arguments[1], 0), thisObject, 0, 0, 0);
  1416. return JSValueMakeUndefined(context);
  1417. }
  1418. static JSValueRef preciseTimeCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1419. {
  1420. return JSValueMakeNumber(context, WTF::currentTime());
  1421. }
  1422. // Static Values
  1423. static JSValueRef getGlobalFlagCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
  1424. {
  1425. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1426. return JSValueMakeBoolean(context, controller->globalFlag());
  1427. }
  1428. static JSValueRef getWebHistoryItemCountCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
  1429. {
  1430. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1431. return JSValueMakeNumber(context, controller->webHistoryItemCount());
  1432. }
  1433. #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(WIN) || PLATFORM(EFL)
  1434. static JSValueRef getPlatformNameCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
  1435. {
  1436. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1437. JSRetainPtr<JSStringRef> platformName(controller->platformName());
  1438. if (!platformName.get())
  1439. return JSValueMakeUndefined(context);
  1440. return JSValueMakeString(context, platformName.get());
  1441. }
  1442. #endif
  1443. static JSValueRef getSecureEventInputIsEnabledCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
  1444. {
  1445. #if PLATFORM(MAC)
  1446. return JSValueMakeBoolean(context, IsSecureEventInputEnabled());
  1447. #else
  1448. return JSValueMakeBoolean(context, false);
  1449. #endif
  1450. }
  1451. static JSValueRef getTitleTextDirectionCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
  1452. {
  1453. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1454. JSRetainPtr<JSStringRef> titleDirection(Adopt, JSStringCreateWithUTF8CString(controller->titleTextDirection().c_str()));
  1455. return JSValueMakeString(context, titleDirection.get());
  1456. }
  1457. static bool setGlobalFlagCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
  1458. {
  1459. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1460. controller->setGlobalFlag(JSValueToBoolean(context, value));
  1461. return true;
  1462. }
  1463. static JSValueRef ignoreLegacyWebNotificationPermissionRequestsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1464. {
  1465. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1466. controller->ignoreLegacyWebNotificationPermissionRequests();
  1467. return JSValueMakeUndefined(context);
  1468. }
  1469. static JSValueRef simulateLegacyWebNotificationClickCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1470. {
  1471. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1472. JSRetainPtr<JSStringRef> title(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1473. controller->simulateLegacyWebNotificationClick(title.get());
  1474. return JSValueMakeUndefined(context);
  1475. }
  1476. static JSValueRef setTextDirectionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1477. {
  1478. if (argumentCount == 1) {
  1479. JSRetainPtr<JSStringRef> direction(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1480. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1481. controller->setTextDirection(direction.get());
  1482. }
  1483. return JSValueMakeUndefined(context);
  1484. }
  1485. static JSValueRef setHasCustomFullScreenBehaviorCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1486. {
  1487. if (argumentCount == 1) {
  1488. bool hasCustomBehavior = JSValueToBoolean(context, arguments[0]);
  1489. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1490. controller->setHasCustomFullScreenBehavior(hasCustomBehavior);
  1491. }
  1492. return JSValueMakeUndefined(context);
  1493. }
  1494. static JSValueRef setStorageDatabaseIdleIntervalCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1495. {
  1496. if (argumentCount != 1)
  1497. return JSValueMakeUndefined(context);
  1498. double interval = JSValueToNumber(context, arguments[0], exception);
  1499. ASSERT(!*exception);
  1500. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1501. controller->setStorageDatabaseIdleInterval(interval);
  1502. return JSValueMakeUndefined(context);
  1503. }
  1504. static JSValueRef closeIdleLocalStorageDatabasesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1505. {
  1506. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1507. controller->closeIdleLocalStorageDatabases();
  1508. return JSValueMakeUndefined(context);
  1509. }
  1510. static JSValueRef grantWebNotificationPermissionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1511. {
  1512. if (argumentCount < 1)
  1513. return JSValueMakeUndefined(context);
  1514. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1515. JSRetainPtr<JSStringRef> origin(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1516. ASSERT(!*exception);
  1517. controller->grantWebNotificationPermission(origin.get());
  1518. return JSValueMakeUndefined(context);
  1519. }
  1520. static JSValueRef denyWebNotificationPermissionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1521. {
  1522. if (argumentCount < 1)
  1523. return JSValueMakeUndefined(context);
  1524. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1525. JSRetainPtr<JSStringRef> origin(Adopt, JSValueToStringCopy(context, arguments[0], exception));
  1526. ASSERT(!*exception);
  1527. controller->denyWebNotificationPermission(origin.get());
  1528. return JSValueMakeUndefined(context);
  1529. }
  1530. static JSValueRef removeAllWebNotificationPermissionsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1531. {
  1532. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1533. controller->removeAllWebNotificationPermissions();
  1534. return JSValueMakeUndefined(context);
  1535. }
  1536. static JSValueRef simulateWebNotificationClickCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  1537. {
  1538. // Has Windows implementation
  1539. if (argumentCount < 1)
  1540. return JSValueMakeUndefined(context);
  1541. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
  1542. controller->simulateWebNotificationClick(arguments[0]);
  1543. return JSValueMakeUndefined(context);
  1544. }
  1545. static void testRunnerObjectFinalize(JSObjectRef object)
  1546. {
  1547. TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(object));
  1548. controller->deref();
  1549. }
  1550. // Object Creation
  1551. void TestRunner::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
  1552. {
  1553. JSRetainPtr<JSStringRef> testRunnerStr(Adopt, JSStringCreateWithUTF8CString("testRunner"));
  1554. ref();
  1555. JSClassRef classRef = getJSClass();
  1556. JSValueRef layoutTestContollerObject = JSObjectMake(context, classRef, this);
  1557. JSClassRelease(classRef);
  1558. JSObjectSetProperty(context, windowObject, testRunnerStr.get(), layoutTestContollerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
  1559. }
  1560. JSClassRef TestRunner::getJSClass()
  1561. {
  1562. static JSStaticValue* staticValues = TestRunner::staticValues();
  1563. static JSStaticFunction* staticFunctions = TestRunner::staticFunctions();
  1564. static JSClassDefinition classDefinition = {
  1565. 0, kJSClassAttributeNone, "TestRunner", 0, staticValues, staticFunctions,
  1566. 0, testRunnerObjectFinalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
  1567. };
  1568. return JSClassCreate(&classDefinition);
  1569. }
  1570. JSStaticValue* TestRunner::staticValues()
  1571. {
  1572. static JSStaticValue staticValues[] = {
  1573. { "globalFlag", getGlobalFlagCallback, setGlobalFlagCallback, kJSPropertyAttributeNone },
  1574. { "webHistoryItemCount", getWebHistoryItemCountCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1575. #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(WIN) || PLATFORM(EFL)
  1576. { "platformName", getPlatformNameCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1577. #endif
  1578. { "secureEventInputIsEnabled", getSecureEventInputIsEnabledCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1579. { "titleTextDirection", getTitleTextDirectionCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1580. { 0, 0, 0, 0 }
  1581. };
  1582. return staticValues;
  1583. }
  1584. JSStaticFunction* TestRunner::staticFunctions()
  1585. {
  1586. static JSStaticFunction staticFunctions[] = {
  1587. { "abortModal", abortModalCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1588. { "addDisallowedURL", addDisallowedURLCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1589. { "addURLToRedirect", addURLToRedirectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1590. { "addUserScript", addUserScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1591. { "addUserStyleSheet", addUserStyleSheetCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1592. { "apiTestNewWindowDataLoadBaseURL", apiTestNewWindowDataLoadBaseURLCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1593. { "apiTestGoToCurrentBackForwardItem", apiTestGoToCurrentBackForwardItemCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1594. { "applicationCacheDiskUsageForOrigin", applicationCacheDiskUsageForOriginCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1595. { "callShouldCloseOnWebView", callShouldCloseOnWebViewCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1596. { "clearAllApplicationCaches", clearAllApplicationCachesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1597. { "clearAllDatabases", clearAllDatabasesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1598. { "clearApplicationCacheForOrigin", clearApplicationCacheForOriginCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1599. { "clearBackForwardList", clearBackForwardListCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1600. { "clearPersistentUserStyleSheet", clearPersistentUserStyleSheetCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1601. { "closeWebInspector", closeWebInspectorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1602. { "decodeHostName", decodeHostNameCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1603. { "disallowIncreaseForApplicationCacheQuota", disallowIncreaseForApplicationCacheQuotaCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1604. { "dispatchPendingLoadRequests", dispatchPendingLoadRequestsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1605. { "display", displayCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1606. { "displayInvalidatedRegion", displayInvalidatedRegionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1607. { "dumpApplicationCacheDelegateCallbacks", dumpApplicationCacheDelegateCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1608. { "dumpAsText", dumpAsTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1609. { "dumpBackForwardList", dumpBackForwardListCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1610. { "dumpChildFrameScrollPositions", dumpChildFrameScrollPositionsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1611. { "dumpChildFramesAsText", dumpChildFramesAsTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1612. { "dumpDOMAsWebArchive", dumpDOMAsWebArchiveCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1613. { "dumpDatabaseCallbacks", dumpDatabaseCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1614. { "dumpEditingCallbacks", dumpEditingCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1615. { "dumpFrameLoadCallbacks", dumpFrameLoadCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1616. { "dumpProgressFinishedCallback", dumpProgressFinishedCallbackCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1617. { "dumpUserGestureInFrameLoadCallbacks", dumpUserGestureInFrameLoadCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1618. { "dumpResourceLoadCallbacks", dumpResourceLoadCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1619. { "dumpResourceResponseMIMETypes", dumpResourceResponseMIMETypesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1620. { "dumpSelectionRect", dumpSelectionRectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1621. { "dumpSourceAsWebArchive", dumpSourceAsWebArchiveCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1622. { "dumpStatusCallbacks", dumpStatusCallbacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1623. { "dumpTitleChanges", dumpTitleChangesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1624. { "dumpIconChanges", dumpIconChangesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1625. { "dumpWillCacheResponse", dumpWillCacheResponseCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1626. { "encodeHostName", encodeHostNameCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1627. { "evaluateInWebInspector", evaluateInWebInspectorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1628. { "evaluateScriptInIsolatedWorldAndReturnValue", evaluateScriptInIsolatedWorldAndReturnValueCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1629. { "evaluateScriptInIsolatedWorld", evaluateScriptInIsolatedWorldCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1630. { "execCommand", execCommandCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1631. { "findString", findStringCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1632. { "originsWithApplicationCache", originsWithApplicationCacheCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1633. { "goBack", goBackCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1634. { "ignoreLegacyWebNotificationPermissionRequests", ignoreLegacyWebNotificationPermissionRequestsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1635. { "isCommandEnabled", isCommandEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1636. { "keepWebHistory", keepWebHistoryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1637. { "numberOfPendingGeolocationPermissionRequests", numberOfPendingGeolocationPermissionRequestsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1638. { "notifyDone", notifyDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1639. { "overridePreference", overridePreferenceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1640. { "pathToLocalResource", pathToLocalResourceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1641. { "printToPDF", dumpAsPDFCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1642. { "queueBackNavigation", queueBackNavigationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1643. { "queueForwardNavigation", queueForwardNavigationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1644. { "queueLoad", queueLoadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1645. { "queueLoadHTMLString", queueLoadHTMLStringCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1646. { "queueLoadingScript", queueLoadingScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1647. { "queueNonLoadingScript", queueNonLoadingScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1648. { "queueReload", queueReloadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1649. { "removeAllVisitedLinks", removeAllVisitedLinksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1650. { "removeOriginAccessWhitelistEntry", removeOriginAccessWhitelistEntryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1651. { "repaintSweepHorizontally", repaintSweepHorizontallyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1652. { "resetPageVisibility", resetPageVisibilityCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1653. { "setAcceptsEditing", setAcceptsEditingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1654. { "setAllowUniversalAccessFromFileURLs", setAllowUniversalAccessFromFileURLsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1655. { "setAllowFileAccessFromFileURLs", setAllowFileAccessFromFileURLsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1656. { "setAlwaysAcceptCookies", setAlwaysAcceptCookiesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1657. { "setAppCacheMaximumSize", setAppCacheMaximumSizeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1658. { "setApplicationCacheOriginQuota", setApplicationCacheOriginQuotaCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1659. { "setEncodedAudioData", setEncodedAudioDataCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1660. { "setAuthenticationPassword", setAuthenticationPasswordCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1661. { "setAuthenticationUsername", setAuthenticationUsernameCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1662. { "setAuthorAndUserStylesEnabled", setAuthorAndUserStylesEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1663. { "setCacheModel", setCacheModelCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1664. { "setCallCloseOnWebViews", setCallCloseOnWebViewsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1665. { "setCanOpenWindows", setCanOpenWindowsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1666. { "setCloseRemainingWindowsWhenComplete", setCloseRemainingWindowsWhenCompleteCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1667. { "setCustomPolicyDelegate", setCustomPolicyDelegateCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1668. { "setDatabaseQuota", setDatabaseQuotaCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1669. { "setDeferMainResourceDataLoad", setDeferMainResourceDataLoadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1670. { "setDefersLoading", setDefersLoadingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1671. { "setUseDeferredFrameLoading", setUseDeferredFrameLoadingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1672. { "setDomainRelaxationForbiddenForURLScheme", setDomainRelaxationForbiddenForURLSchemeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1673. { "setGeolocationPermission", setGeolocationPermissionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1674. { "setHandlesAuthenticationChallenges", setHandlesAuthenticationChallengesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1675. { "setIconDatabaseEnabled", setIconDatabaseEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1676. { "setAutomaticLinkDetectionEnabled", setAutomaticLinkDetectionEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1677. { "setMainFrameIsFirstResponder", setMainFrameIsFirstResponderCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1678. { "setMockDeviceOrientation", setMockDeviceOrientationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1679. { "setMockGeolocationPositionUnavailableError", setMockGeolocationPositionUnavailableErrorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1680. { "setMockGeolocationPosition", setMockGeolocationPositionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1681. { "addMockSpeechInputResult", addMockSpeechInputResultCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1682. { "setMockSpeechInputDumpRect", setMockSpeechInputDumpRectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1683. { "setNewWindowsCopyBackForwardList", setNewWindowsCopyBackForwardListCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1684. { "setPageVisibility", setPageVisibilityCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1685. { "setPOSIXLocale", setPOSIXLocaleCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1686. { "setPersistentUserStyleSheetLocation", setPersistentUserStyleSheetLocationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1687. { "setPopupBlockingEnabled", setPopupBlockingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1688. { "setPluginsEnabled", setPluginsEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1689. { "setPrinting", setPrintingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1690. { "setPrivateBrowsingEnabled", setPrivateBrowsingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1691. { "setSerializeHTTPLoads", setSerializeHTTPLoadsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1692. { "setSpatialNavigationEnabled", setSpatialNavigationEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1693. { "setStopProvisionalFrameLoads", setStopProvisionalFrameLoadsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1694. { "setTabKeyCyclesThroughElements", setTabKeyCyclesThroughElementsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1695. { "setUseDashboardCompatibilityMode", setUseDashboardCompatibilityModeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1696. { "setUserStyleSheetEnabled", setUserStyleSheetEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1697. { "setUserStyleSheetLocation", setUserStyleSheetLocationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1698. { "setValueForUser", setValueForUserCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1699. { "setViewModeMediaFeature", setViewModeMediaFeatureCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1700. { "setWebViewEditable", setWebViewEditableCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1701. { "setWillSendRequestClearHeader", setWillSendRequestClearHeaderCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1702. { "setWillSendRequestReturnsNull", setWillSendRequestReturnsNullCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1703. { "setWillSendRequestReturnsNullOnRedirect", setWillSendRequestReturnsNullOnRedirectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1704. { "setWindowIsKey", setWindowIsKeyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1705. { "setJavaScriptCanAccessClipboard", setJavaScriptCanAccessClipboardCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1706. { "setXSSAuditorEnabled", setXSSAuditorEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1707. { "showWebInspector", showWebInspectorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1708. { "simulateLegacyWebNotificationClick", simulateLegacyWebNotificationClickCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1709. { "testOnscreen", testOnscreenCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1710. { "testRepaint", testRepaintCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1711. { "waitForPolicyDelegate", waitForPolicyDelegateCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1712. { "waitUntilDone", waitUntilDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1713. { "windowCount", windowCountCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1714. { "addOriginAccessWhitelistEntry", addOriginAccessWhitelistEntryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1715. { "setScrollbarPolicy", setScrollbarPolicyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1716. { "authenticateSession", authenticateSessionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1717. { "deleteAllLocalStorage", deleteAllLocalStorageCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1718. { "syncLocalStorage", syncLocalStorageCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1719. { "observeStorageTrackerNotifications", observeStorageTrackerNotificationsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1720. { "deleteLocalStorageForOrigin", deleteLocalStorageForOriginCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1721. { "localStorageDiskUsageForOrigin", localStorageDiskUsageForOriginCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1722. { "originsWithLocalStorage", originsWithLocalStorageCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1723. { "setShouldPaintBrokenImage", setShouldPaintBrokenImageCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1724. { "setTextDirection", setTextDirectionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1725. { "setShouldStayOnPageAfterHandlingBeforeUnload", setShouldStayOnPageAfterHandlingBeforeUnloadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1726. { "addChromeInputField", addChromeInputFieldCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1727. { "removeChromeInputField", removeChromeInputFieldCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1728. { "focusWebView", focusWebViewCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1729. { "setBackingScaleFactor", setBackingScaleFactorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1730. { "preciseTime", preciseTimeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1731. { "setHasCustomFullScreenBehavior", setHasCustomFullScreenBehaviorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1732. { "setStorageDatabaseIdleInterval", setStorageDatabaseIdleIntervalCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1733. { "closeIdleLocalStorageDatabases", closeIdleLocalStorageDatabasesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1734. { "grantWebNotificationPermission", grantWebNotificationPermissionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1735. { "denyWebNotificationPermission", denyWebNotificationPermissionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1736. { "removeAllWebNotificationPermissions", removeAllWebNotificationPermissionsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1737. { "simulateWebNotificationClick", simulateWebNotificationClickCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  1738. { 0, 0, 0 }
  1739. };
  1740. return staticFunctions;
  1741. }
  1742. void TestRunner::queueLoadHTMLString(JSStringRef content, JSStringRef baseURL)
  1743. {
  1744. WorkQueue::shared()->queue(new LoadHTMLStringItem(content, baseURL));
  1745. }
  1746. void TestRunner::queueLoadAlternateHTMLString(JSStringRef content, JSStringRef baseURL, JSStringRef unreachableURL)
  1747. {
  1748. WorkQueue::shared()->queue(new LoadHTMLStringItem(content, baseURL, unreachableURL));
  1749. }
  1750. void TestRunner::queueBackNavigation(int howFarBack)
  1751. {
  1752. WorkQueue::shared()->queue(new BackItem(howFarBack));
  1753. }
  1754. void TestRunner::queueForwardNavigation(int howFarForward)
  1755. {
  1756. WorkQueue::shared()->queue(new ForwardItem(howFarForward));
  1757. }
  1758. void TestRunner::queueLoadingScript(JSStringRef script)
  1759. {
  1760. WorkQueue::shared()->queue(new LoadingScriptItem(script));
  1761. }
  1762. void TestRunner::queueNonLoadingScript(JSStringRef script)
  1763. {
  1764. WorkQueue::shared()->queue(new NonLoadingScriptItem(script));
  1765. }
  1766. void TestRunner::queueReload()
  1767. {
  1768. WorkQueue::shared()->queue(new ReloadItem);
  1769. }
  1770. void TestRunner::ignoreLegacyWebNotificationPermissionRequests()
  1771. {
  1772. m_areLegacyWebNotificationPermissionRequestsIgnored = false;
  1773. }
  1774. void TestRunner::waitToDumpWatchdogTimerFired()
  1775. {
  1776. const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
  1777. fprintf(stderr, "%s", message);
  1778. fprintf(stdout, "%s", message);
  1779. notifyDone();
  1780. }
  1781. void TestRunner::setGeolocationPermissionCommon(bool allow)
  1782. {
  1783. m_isGeolocationPermissionSet = true;
  1784. m_geolocationPermission = allow;
  1785. }
  1786. void TestRunner::setPOSIXLocale(JSStringRef locale)
  1787. {
  1788. char localeBuf[32];
  1789. JSStringGetUTF8CString(locale, localeBuf, sizeof(localeBuf));
  1790. setlocale(LC_ALL, localeBuf);
  1791. }
  1792. void TestRunner::addURLToRedirect(std::string origin, std::string destination)
  1793. {
  1794. m_URLsToRedirect[origin] = destination;
  1795. }
  1796. const std::string& TestRunner::redirectionDestinationForURL(std::string origin)
  1797. {
  1798. return m_URLsToRedirect[origin];
  1799. }
  1800. void TestRunner::setShouldPaintBrokenImage(bool shouldPaintBrokenImage)
  1801. {
  1802. m_shouldPaintBrokenImage = shouldPaintBrokenImage;
  1803. }