Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

tests.js 246KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. */
  20. /* eslint-env jasmine */
  21. /* global WebKitBlobBuilder */
  22. exports.defineAutoTests = function () {
  23. /* eslint-disable no-undef */
  24. var isBrowser = (cordova.platformId === 'browser');
  25. // Use feature detection to determine current browser instead of checking user-agent
  26. var isChrome = isBrowser && window.webkitRequestFileSystem && window.webkitResolveLocalFileSystemURL;
  27. var isIE = isBrowser && (window.msIndexedDB);
  28. var isIndexedDBShim = isBrowser && !isChrome; // Firefox and IE for example
  29. var isWindows = (cordova.platformId === 'windows' || cordova.platformId === 'windows8');
  30. /* eslint-enable no-undef */
  31. var MEDIUM_TIMEOUT = 15000;
  32. describe('File API', function () {
  33. // Adding a Jasmine helper matcher, to report errors when comparing to FileError better.
  34. var fileErrorMap = {
  35. 1: 'NOT_FOUND_ERR',
  36. 2: 'SECURITY_ERR',
  37. 3: 'ABORT_ERR',
  38. 4: 'NOT_READABLE_ERR',
  39. 5: 'ENCODING_ERR',
  40. 6: 'NO_MODIFICATION_ALLOWED_ERR',
  41. 7: 'INVALID_STATE_ERR',
  42. 8: 'SYNTAX_ERR',
  43. 9: 'INVALID_MODIFICATION_ERR',
  44. 10: 'QUOTA_EXCEEDED_ERR',
  45. 11: 'TYPE_MISMATCH_ERR',
  46. 12: 'PATH_EXISTS_ERR'
  47. };
  48. var root;
  49. var temp_root;
  50. var persistent_root;
  51. beforeEach(function (done) {
  52. // Custom Matchers
  53. jasmine.Expectation.addMatchers({
  54. toBeFileError: function () {
  55. return {
  56. compare: function (error, code) {
  57. var pass = error.code === code;
  58. return {
  59. pass: pass,
  60. message: 'Expected FileError with code ' + fileErrorMap[error.code] + ' (' + error.code + ') to be ' + fileErrorMap[code] + '(' + code + ')'
  61. };
  62. }
  63. };
  64. },
  65. toCanonicallyMatch: function () {
  66. return {
  67. compare: function (currentPath, path) {
  68. var a = path.split('/').join('').split('\\').join('');
  69. var b = currentPath.split('/').join('').split('\\').join('');
  70. var pass = a === b;
  71. return {
  72. pass: pass,
  73. message: 'Expected paths to match : ' + path + ' should be ' + currentPath
  74. };
  75. }
  76. };
  77. },
  78. toFailWithMessage: function () {
  79. return {
  80. compare: function (error, message) { // eslint-disable-line handle-callback-err
  81. var pass = false;
  82. return {
  83. pass: pass,
  84. message: message
  85. };
  86. }
  87. };
  88. },
  89. toBeDataUrl: function () {
  90. return {
  91. compare: function (url) {
  92. var pass = false;
  93. // "data:application/octet-stream;base64,"
  94. var header = url.substr(0, url.indexOf(','));
  95. var headerParts = header.split(/[:;]/);
  96. if (headerParts.length === 3 &&
  97. headerParts[0] === 'data' &&
  98. headerParts[2] === 'base64') {
  99. pass = true;
  100. }
  101. var message = 'Expected ' + url + ' to be a valid data url. ' + header + ' is not valid header for data uris';
  102. return {
  103. pass: pass,
  104. message: message
  105. };
  106. }
  107. };
  108. }
  109. });
  110. // Define global variables
  111. var onError = function (e) {
  112. console.log('[ERROR] Problem setting up root filesystem for test running! Error to follow.');
  113. console.log(JSON.stringify(e));
  114. };
  115. window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) { // eslint-disable-line no-undef
  116. root = fileSystem.root;
  117. // set in file.tests.js
  118. persistent_root = root;
  119. window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) { // eslint-disable-line no-undef
  120. temp_root = fileSystem.root;
  121. // set in file.tests.js
  122. done();
  123. }, onError);
  124. }, onError);
  125. });
  126. // HELPER FUNCTIONS
  127. // deletes specified file or directory
  128. var deleteEntry = function (name, success, error) {
  129. // deletes entry, if it exists
  130. // entry.remove success callback is required: http://www.w3.org/TR/2011/WD-file-system-api-20110419/#the-entry-interface
  131. success = success || function () {};
  132. error = error || failed.bind(null, success, 'deleteEntry failed.');
  133. window.resolveLocalFileSystemURL(root.toURL() + '/' + name, function (entry) {
  134. if (entry.isDirectory === true) {
  135. entry.removeRecursively(success, error);
  136. } else {
  137. entry.remove(success, error);
  138. }
  139. }, success);
  140. };
  141. // deletes file, if it exists, then invokes callback
  142. var deleteFile = function (fileName, callback) {
  143. // entry.remove success callback is required: http://www.w3.org/TR/2011/WD-file-system-api-20110419/#the-entry-interface
  144. callback = callback || function () {};
  145. root.getFile(fileName, null, // remove file system entry
  146. function (entry) {
  147. entry.remove(callback, function () {
  148. console.log('[ERROR] deleteFile cleanup method invoked fail callback.');
  149. });
  150. }, // doesn't exist
  151. callback);
  152. };
  153. // deletes and re-creates the specified file
  154. var createFile = function (fileName, success, error) {
  155. deleteEntry(fileName, function () {
  156. root.getFile(fileName, {
  157. create: true
  158. }, success, error);
  159. }, error);
  160. };
  161. // deletes and re-creates the specified directory
  162. var createDirectory = function (dirName, success, error) {
  163. deleteEntry(dirName, function () {
  164. root.getDirectory(dirName, {
  165. create: true
  166. }, success, error);
  167. }, error);
  168. };
  169. function failed (done, msg, error) {
  170. var info = typeof msg === 'undefined' ? 'Unexpected error callback' : msg;
  171. var codeMsg = (error && error.code) ? (': ' + fileErrorMap[error.code]) : '';
  172. expect(true).toFailWithMessage(info + '\n' + JSON.stringify(error) + codeMsg);
  173. done();
  174. }
  175. var succeed = function (done, msg) {
  176. var info = typeof msg === 'undefined' ? 'Unexpected success callback' : msg;
  177. expect(true).toFailWithMessage(info);
  178. done();
  179. };
  180. var joinURL = function (base, extension) {
  181. if (base.charAt(base.length - 1) !== '/' && extension.charAt(0) !== '/') {
  182. return base + '/' + extension;
  183. }
  184. if (base.charAt(base.length - 1) === '/' && extension.charAt(0) === '/') {
  185. return base + extension.substring(1);
  186. }
  187. return base + extension;
  188. };
  189. describe('FileError object', function () {
  190. /* eslint-disable no-undef */
  191. it('file.spec.1 should define FileError constants', function () {
  192. expect(FileError.NOT_FOUND_ERR).toBe(1);
  193. expect(FileError.SECURITY_ERR).toBe(2);
  194. expect(FileError.ABORT_ERR).toBe(3);
  195. expect(FileError.NOT_READABLE_ERR).toBe(4);
  196. expect(FileError.ENCODING_ERR).toBe(5);
  197. expect(FileError.NO_MODIFICATION_ALLOWED_ERR).toBe(6);
  198. expect(FileError.INVALID_STATE_ERR).toBe(7);
  199. expect(FileError.SYNTAX_ERR).toBe(8);
  200. expect(FileError.INVALID_MODIFICATION_ERR).toBe(9);
  201. expect(FileError.QUOTA_EXCEEDED_ERR).toBe(10);
  202. expect(FileError.TYPE_MISMATCH_ERR).toBe(11);
  203. expect(FileError.PATH_EXISTS_ERR).toBe(12);
  204. });
  205. });
  206. describe('LocalFileSystem', function () {
  207. it('file.spec.2 should define LocalFileSystem constants', function () {
  208. expect(LocalFileSystem.TEMPORARY).toBe(0);
  209. expect(LocalFileSystem.PERSISTENT).toBe(1);
  210. /* eslint-enable no-undef */
  211. });
  212. describe('window.requestFileSystem', function () {
  213. it('file.spec.3 should be defined', function () {
  214. expect(window.requestFileSystem).toBeDefined();
  215. });
  216. it('file.spec.4 should be able to retrieve a PERSISTENT file system', function (done) {
  217. var win = function (fileSystem) {
  218. expect(fileSystem).toBeDefined();
  219. expect(fileSystem.name).toBeDefined();
  220. if (isChrome) {
  221. expect(fileSystem.name).toContain('Persistent');
  222. } else {
  223. expect(fileSystem.name).toBe('persistent');
  224. }
  225. expect(fileSystem.root).toBeDefined();
  226. expect(fileSystem.root.filesystem).toBeDefined();
  227. // Shouldn't use cdvfile by default.
  228. expect(fileSystem.root.toURL()).not.toMatch(/^cdvfile:/);
  229. // All DirectoryEntry URLs should always have a trailing slash.
  230. expect(fileSystem.root.toURL()).toMatch(/\/$/);
  231. done();
  232. };
  233. // Request a little bit of space on the filesystem, unless we're running in a browser where that could cause a prompt.
  234. var spaceRequired = isBrowser ? 0 : 1024;
  235. // retrieve PERSISTENT file system
  236. window.requestFileSystem(LocalFileSystem.PERSISTENT, spaceRequired, win, failed.bind(null, done, 'window.requestFileSystem - Error retrieving PERSISTENT file system')); // eslint-disable-line no-undef
  237. });
  238. it('file.spec.5 should be able to retrieve a TEMPORARY file system', function (done) {
  239. var win = function (fileSystem) {
  240. expect(fileSystem).toBeDefined();
  241. if (isChrome) {
  242. expect(fileSystem.name).toContain('Temporary');
  243. } else {
  244. expect(fileSystem.name).toBe('temporary');
  245. }
  246. expect(fileSystem.root).toBeDefined();
  247. expect(fileSystem.root.filesystem).toBeDefined();
  248. expect(fileSystem.root.filesystem).toBe(fileSystem);
  249. done();
  250. };
  251. // retrieve TEMPORARY file system
  252. window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, win, failed.bind(null, done, 'window.requestFileSystem - Error retrieving TEMPORARY file system')); // eslint-disable-line no-undef
  253. });
  254. it('file.spec.6 should error if you request a file system that is too large', function (done) {
  255. if (isBrowser) {
  256. /* window.requestFileSystem TEMPORARY and PERSISTENT filesystem quota is not limited in Chrome.
  257. Firefox filesystem size is not limited but every 50MB request user permission.
  258. IE10 allows up to 10mb of combined AppCache and IndexedDB used in implementation
  259. of filesystem without prompting, once you hit that level you will be asked if you
  260. want to allow it to be increased up to a max of 250mb per site.
  261. So `size` parameter for `requestFileSystem` function does not affect on filesystem in Firefox and IE. */
  262. pending();
  263. }
  264. var fail = function (error) {
  265. expect(error).toBeDefined();
  266. expect(error).toBeFileError(FileError.QUOTA_EXCEEDED_ERR); // eslint-disable-line no-undef
  267. done();
  268. };
  269. // win = createWin('window.requestFileSystem');
  270. // Request the file system
  271. window.requestFileSystem(LocalFileSystem.TEMPORARY, 1000000000000000, failed.bind(null, done, 'window.requestFileSystem - Error retrieving TEMPORARY file system'), fail); // eslint-disable-line no-undef
  272. });
  273. it('file.spec.7 should error out if you request a file system that does not exist', function (done) {
  274. var fail = function (error) {
  275. expect(error).toBeDefined();
  276. if (isChrome) {
  277. /* INVALID_MODIFICATION_ERR (code: 9) or ??? (code: 13) is thrown instead of SYNTAX_ERR(code: 8)
  278. on requesting of a non-existant filesystem. */
  279. // expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);
  280. } else {
  281. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  282. }
  283. done();
  284. };
  285. // Request the file system
  286. window.requestFileSystem(-1, 0, succeed.bind(null, done, 'window.requestFileSystem'), fail);
  287. });
  288. });
  289. describe('window.resolveLocalFileSystemURL', function () {
  290. it('file.spec.8 should be defined', function () {
  291. expect(window.resolveLocalFileSystemURL).toBeDefined();
  292. });
  293. it('file.spec.9 should resolve a valid file name', function (done) {
  294. var fileName = 'file.spec.9';
  295. var win = function (fileEntry) {
  296. expect(fileEntry).toBeDefined();
  297. expect(fileEntry.isFile).toBe(true);
  298. expect(fileEntry.isDirectory).toBe(false);
  299. expect(fileEntry.name).toCanonicallyMatch(fileName);
  300. expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
  301. expect(fileEntry.toURL()).not.toMatch(/\/$/, 'URL should not end with a slash');
  302. // Clean-up
  303. deleteEntry(fileName, done);
  304. };
  305. createFile(fileName, function (entry) {
  306. window.resolveLocalFileSystemURL(entry.toURL(), win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URL: ' + entry.toURL()));
  307. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName), failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  308. });
  309. it('file.spec.9.1 should resolve a file even with a terminating slash', function (done) {
  310. var fileName = 'file.spec.9.1';
  311. var win = function (fileEntry) {
  312. expect(fileEntry).toBeDefined();
  313. expect(fileEntry.isFile).toBe(true);
  314. expect(fileEntry.isDirectory).toBe(false);
  315. expect(fileEntry.name).toCanonicallyMatch(fileName);
  316. expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
  317. expect(fileEntry.toURL()).not.toMatch(/\/$/, 'URL should not end with a slash');
  318. // Clean-up
  319. deleteEntry(fileName, done);
  320. };
  321. createFile(fileName, function (entry) {
  322. var entryURL = entry.toURL() + '/';
  323. window.resolveLocalFileSystemURL(entryURL, win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URL: ' + entryURL));
  324. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName), failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  325. });
  326. it('file.spec.9.5 should resolve a directory', function (done) {
  327. var fileName = 'file.spec.9.5';
  328. var win = function (fileEntry) {
  329. expect(fileEntry).toBeDefined();
  330. expect(fileEntry.isFile).toBe(false);
  331. expect(fileEntry.isDirectory).toBe(true);
  332. expect(fileEntry.name).toCanonicallyMatch(fileName);
  333. expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
  334. expect(fileEntry.toURL()).toMatch(/\/$/, 'URL end with a slash');
  335. // cleanup
  336. deleteEntry(fileName, done);
  337. };
  338. function gotDirectory (entry) {
  339. // lookup file system entry
  340. window.resolveLocalFileSystemURL(entry.toURL(), win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving directory URL: ' + entry.toURL()));
  341. }
  342. createDirectory(fileName, gotDirectory, failed.bind(null, done, 'createDirectory - Error creating directory: ' + fileName), failed.bind(null, done, 'createDirectory - Error creating directory: ' + fileName));
  343. });
  344. it('file.spec.9.6 should resolve a directory even without a terminating slash', function (done) {
  345. var fileName = 'file.spec.9.6';
  346. var win = function (fileEntry) {
  347. expect(fileEntry).toBeDefined();
  348. expect(fileEntry.isFile).toBe(false);
  349. expect(fileEntry.isDirectory).toBe(true);
  350. expect(fileEntry.name).toCanonicallyMatch(fileName);
  351. expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
  352. expect(fileEntry.toURL()).toMatch(/\/$/, 'URL end with a slash');
  353. // cleanup
  354. deleteEntry(fileName, done);
  355. };
  356. function gotDirectory (entry) {
  357. // lookup file system entry
  358. var entryURL = entry.toURL();
  359. entryURL = entryURL.substring(0, entryURL.length - 1);
  360. window.resolveLocalFileSystemURL(entryURL, win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving directory URL: ' + entryURL));
  361. }
  362. createDirectory(fileName, gotDirectory, failed.bind(null, done, 'createDirectory - Error creating directory: ' + fileName), failed.bind(null, done, 'createDirectory - Error creating directory: ' + fileName));
  363. });
  364. it('file.spec.9.7 should resolve a file with valid nativeURL', function (done) {
  365. if (isBrowser) {
  366. pending('browsers doesn\'t return nativeURL');
  367. }
  368. var fileName = 'de.create.file';
  369. var win = function (entry) {
  370. var path = entry.nativeURL.split('///')[1];
  371. expect(/\/{2,}/.test(path)).toBeFalsy();
  372. // cleanup
  373. deleteEntry(entry.name, done);
  374. };
  375. root.getFile(fileName, {
  376. create: true
  377. }, win, succeed.bind(null, done, 'root.getFile - Error unexpected callback, file should not exists: ' + fileName));
  378. });
  379. it('file.spec.10 resolve valid file name with parameters', function (done) {
  380. var fileName = 'resolve.file.uri.params';
  381. var win = function (fileEntry) {
  382. expect(fileEntry).toBeDefined();
  383. if (fileEntry.toURL().toLowerCase().substring(0, 10) === 'cdvfile://') {
  384. expect(fileEntry.fullPath).toBe('/' + fileName + '?1234567890');
  385. }
  386. expect(fileEntry.name).toBe(fileName);
  387. // cleanup
  388. deleteEntry(fileName, done);
  389. };
  390. // create a new file entry
  391. createFile(fileName, function (entry) {
  392. window.resolveLocalFileSystemURL(entry.toURL() + '?1234567890', win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URI: ' + entry.toURL()));
  393. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  394. });
  395. it('file.spec.11 should error (NOT_FOUND_ERR) when resolving (non-existent) invalid file name', function (done) {
  396. var fileName = cordova.platformId === 'windowsphone' ? root.toURL() + '/' + 'this.is.not.a.valid.file.txt' : joinURL(root.toURL(), 'this.is.not.a.valid.file.txt'); // eslint-disable-line no-undef
  397. var fail = function (error) {
  398. expect(error).toBeDefined();
  399. if (isChrome) {
  400. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  401. } else {
  402. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  403. }
  404. done();
  405. };
  406. // lookup file system entry
  407. window.resolveLocalFileSystemURL(fileName, succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Error unexpected callback resolving file URI: ' + fileName), fail);
  408. });
  409. it('file.spec.12 should error (ENCODING_ERR) when resolving invalid URI with leading /', function (done) {
  410. var fileName = '/this.is.not.a.valid.url';
  411. var fail = function (error) {
  412. expect(error).toBeDefined();
  413. if (isChrome) {
  414. // O.o chrome returns error code 0
  415. } else {
  416. expect(error).toBeFileError(FileError.ENCODING_ERR); // eslint-disable-line no-undef
  417. }
  418. done();
  419. };
  420. // lookup file system entry
  421. window.resolveLocalFileSystemURL(fileName, succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Error unexpected callback resolving file URI: ' + fileName), fail);
  422. });
  423. });
  424. });
  425. // LocalFileSystem
  426. describe('Metadata interface', function () {
  427. it('file.spec.13 should exist and have the right properties', function () {
  428. var metadata = new Metadata(); // eslint-disable-line no-undef
  429. expect(metadata).toBeDefined();
  430. expect(metadata.modificationTime).toBeDefined();
  431. });
  432. });
  433. describe('Flags interface', function () {
  434. it('file.spec.14 should exist and have the right properties', function () {
  435. var flags = new Flags(false, true); // eslint-disable-line no-undef
  436. expect(flags).toBeDefined();
  437. expect(flags.create).toBeDefined();
  438. expect(flags.create).toBe(false);
  439. expect(flags.exclusive).toBeDefined();
  440. expect(flags.exclusive).toBe(true);
  441. });
  442. });
  443. describe('FileSystem interface', function () {
  444. it('file.spec.15 should have a root that is a DirectoryEntry', function (done) {
  445. var win = function (entry) {
  446. expect(entry).toBeDefined();
  447. expect(entry.isFile).toBe(false);
  448. expect(entry.isDirectory).toBe(true);
  449. expect(entry.name).toBeDefined();
  450. expect(entry.fullPath).toBeDefined();
  451. expect(entry.getMetadata).toBeDefined();
  452. expect(entry.moveTo).toBeDefined();
  453. expect(entry.copyTo).toBeDefined();
  454. expect(entry.toURL).toBeDefined();
  455. expect(entry.remove).toBeDefined();
  456. expect(entry.getParent).toBeDefined();
  457. expect(entry.createReader).toBeDefined();
  458. expect(entry.getFile).toBeDefined();
  459. expect(entry.getDirectory).toBeDefined();
  460. expect(entry.removeRecursively).toBeDefined();
  461. done();
  462. };
  463. window.resolveLocalFileSystemURL(root.toURL(), win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URI: ' + root.toURL()));
  464. });
  465. });
  466. describe('DirectoryEntry', function () {
  467. it('file.spec.16 getFile: get Entry for file that does not exist', function (done) {
  468. var fileName = 'de.no.file';
  469. var fail = function (error) {
  470. expect(error).toBeDefined();
  471. if (isChrome) {
  472. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  473. } else {
  474. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  475. }
  476. done();
  477. };
  478. // create:false, exclusive:false, file does not exist
  479. root.getFile(fileName, {
  480. create: false
  481. }, succeed.bind(null, done, 'root.getFile - Error unexpected callback, file should not exists: ' + fileName), fail);
  482. });
  483. it('file.spec.17 getFile: create new file', function (done) {
  484. var fileName = 'de.create.file';
  485. var filePath = joinURL(root.fullPath, fileName);
  486. var win = function (entry) {
  487. expect(entry).toBeDefined();
  488. expect(entry.isFile).toBe(true);
  489. expect(entry.isDirectory).toBe(false);
  490. expect(entry.name).toCanonicallyMatch(fileName);
  491. expect(entry.fullPath).toCanonicallyMatch(filePath);
  492. // cleanup
  493. deleteEntry(entry.name, done);
  494. };
  495. // create:true, exclusive:false, file does not exist
  496. root.getFile(fileName, {
  497. create: true
  498. }, win, succeed.bind(null, done, 'root.getFile - Error unexpected callback, file should not exists: ' + fileName));
  499. });
  500. it('file.spec.18 getFile: create new file (exclusive)', function (done) {
  501. var fileName = 'de.create.exclusive.file';
  502. var filePath = joinURL(root.fullPath, fileName);
  503. var win = function (entry) {
  504. expect(entry).toBeDefined();
  505. expect(entry.isFile).toBe(true);
  506. expect(entry.isDirectory).toBe(false);
  507. expect(entry.name).toBe(fileName);
  508. expect(entry.fullPath).toCanonicallyMatch(filePath);
  509. // cleanup
  510. deleteEntry(entry.name, done);
  511. };
  512. // create:true, exclusive:true, file does not exist
  513. root.getFile(fileName, {
  514. create: true,
  515. exclusive: true
  516. }, win, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));
  517. });
  518. it('file.spec.19 getFile: create file that already exists', function (done) {
  519. var fileName = 'de.create.existing.file';
  520. var filePath = joinURL(root.fullPath, fileName);
  521. function win (entry) {
  522. expect(entry).toBeDefined();
  523. expect(entry.isFile).toBe(true);
  524. expect(entry.isDirectory).toBe(false);
  525. expect(entry.name).toCanonicallyMatch(fileName);
  526. expect(entry.fullPath).toCanonicallyMatch(filePath);
  527. // cleanup
  528. deleteEntry(entry.name, done);
  529. }
  530. function getFile (file) {
  531. // create:true, exclusive:false, file exists
  532. root.getFile(fileName, {
  533. create: true
  534. }, win, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));
  535. }
  536. // create file to kick off it
  537. root.getFile(fileName, {
  538. create: true
  539. }, getFile, failed.bind(null, done, 'root.getFile - Error on initial creating file: ' + fileName));
  540. });
  541. it('file.spec.20 getFile: create file that already exists (exclusive)', function (done) {
  542. var fileName = 'de.create.exclusive.existing.file';
  543. var existingFile;
  544. function fail (error) {
  545. expect(error).toBeDefined();
  546. if (isChrome) {
  547. /* INVALID_MODIFICATION_ERR (code: 9) or ??? (code: 13) is thrown instead of PATH_EXISTS_ERR(code: 12)
  548. on trying to exclusively create a file, which already exists in Chrome. */
  549. // expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);
  550. } else {
  551. expect(error).toBeFileError(FileError.PATH_EXISTS_ERR); // eslint-disable-line no-undef
  552. }
  553. // cleanup
  554. deleteEntry(existingFile.name, done);
  555. }
  556. function getFile (file) {
  557. existingFile = file;
  558. // create:true, exclusive:true, file exists
  559. root.getFile(fileName, {
  560. create: true,
  561. exclusive: true
  562. }, succeed.bind(null, done, 'root.getFile - getFile function - Error unexpected callback, file should exists: ' + fileName), fail);
  563. }
  564. // create file to kick off it
  565. root.getFile(fileName, {
  566. create: true
  567. }, getFile, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));
  568. });
  569. it('file.spec.21 DirectoryEntry.getFile: get Entry for existing file', function (done) {
  570. var fileName = 'de.get.file';
  571. var filePath = joinURL(root.fullPath, fileName);
  572. var win = function (entry) {
  573. expect(entry).toBeDefined();
  574. expect(entry.isFile).toBe(true);
  575. expect(entry.isDirectory).toBe(false);
  576. expect(entry.name).toCanonicallyMatch(fileName);
  577. expect(entry.fullPath).toCanonicallyMatch(filePath);
  578. expect(entry.filesystem).toBeDefined();
  579. expect(entry.filesystem).toBe(root.filesystem);
  580. // clean up
  581. deleteEntry(entry.name, done);
  582. };
  583. var getFile = function (file) {
  584. // create:false, exclusive:false, file exists
  585. root.getFile(fileName, {
  586. create: false
  587. }, win, failed.bind(null, done, 'root.getFile - Error getting file entry: ' + fileName));
  588. };
  589. // create file to kick off it
  590. root.getFile(fileName, {
  591. create: true
  592. }, getFile, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));
  593. });
  594. it('file.spec.22 DirectoryEntry.getFile: get FileEntry for invalid path', function (done) {
  595. if (isBrowser) {
  596. /* The plugin does not follow to ["8.3 Naming restrictions"]
  597. (http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions). */
  598. pending();
  599. }
  600. var fileName = 'de:invalid:path';
  601. var fail = function (error) {
  602. expect(error).toBeDefined();
  603. expect(error).toBeFileError(FileError.ENCODING_ERR); // eslint-disable-line no-undef
  604. done();
  605. };
  606. // create:false, exclusive:false, invalid path
  607. root.getFile(fileName, {
  608. create: false
  609. }, succeed.bind(null, done, 'root.getFile - Error unexpected callback, file should not exists: ' + fileName), fail);
  610. });
  611. it('file.spec.23 DirectoryEntry.getDirectory: get Entry for directory that does not exist', function (done) {
  612. var dirName = 'de.no.dir';
  613. var fail = function (error) {
  614. expect(error).toBeDefined();
  615. if (isChrome) {
  616. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  617. } else {
  618. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  619. }
  620. done();
  621. };
  622. // create:false, exclusive:false, directory does not exist
  623. root.getDirectory(dirName, {
  624. create: false
  625. }, succeed.bind(null, done, 'root.getDirectory - Error unexpected callback, directory should not exists: ' + dirName), fail);
  626. });
  627. it('file.spec.24 DirectoryEntry.getDirectory: create new dir with space then resolveLocalFileSystemURL', function (done) {
  628. var dirName = 'de create dir';
  629. function win (directory) {
  630. expect(directory).toBeDefined();
  631. expect(directory.isFile).toBe(false);
  632. expect(directory.isDirectory).toBe(true);
  633. expect(directory.name).toCanonicallyMatch(dirName);
  634. expect(directory.fullPath).toCanonicallyMatch(joinURL(root.fullPath, dirName));
  635. // cleanup
  636. deleteEntry(directory.name, done);
  637. }
  638. function getDir (dirEntry) {
  639. expect(dirEntry.filesystem).toBeDefined();
  640. expect(dirEntry.filesystem).toBe(root.filesystem);
  641. var dirURI = dirEntry.toURL();
  642. // now encode URI and try to resolve
  643. window.resolveLocalFileSystemURL(dirURI, win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - getDir function - Error resolving directory: ' + dirURI));
  644. }
  645. // create:true, exclusive:false, directory does not exist
  646. root.getDirectory(dirName, {
  647. create: true
  648. }, getDir, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  649. });
  650. // This test is excluded, and should probably be removed. Filesystem
  651. // should always be properly encoded URLs, and *not* raw paths, and it
  652. // doesn't make sense to double-encode the URLs and expect that to be
  653. // handled by the implementation.
  654. // If a particular platform uses paths internally rather than URLs, // then that platform should careful to pass them correctly to its
  655. // backend.
  656. xit('file.spec.25 DirectoryEntry.getDirectory: create new dir with space resolveLocalFileSystemURL with encoded URI', function (done) {
  657. var dirName = 'de create dir2';
  658. var dirPath = joinURL(root.fullPath, dirName);
  659. function win (directory) {
  660. expect(directory).toBeDefined();
  661. expect(directory.isFile).toBe(false);
  662. expect(directory.isDirectory).toBe(true);
  663. expect(directory.name).toCanonicallyMatch(dirName);
  664. expect(directory.fullPath).toCanonicallyMatch(dirPath);
  665. // cleanup
  666. deleteEntry(directory.name, done);
  667. }
  668. function getDir (dirEntry) {
  669. var dirURI = dirEntry.toURL();
  670. // now encode URI and try to resolve
  671. window.resolveLocalFileSystemURL(encodeURI(dirURI), win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - getDir function - Error resolving directory: ' + dirURI));
  672. }
  673. // create:true, exclusive:false, directory does not exist
  674. root.getDirectory(dirName, {
  675. create: true
  676. }, getDir, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  677. });
  678. it('file.spec.26 DirectoryEntry.getDirectory: create new directory', function (done) {
  679. var dirName = 'de.create.dir';
  680. var dirPath = joinURL(root.fullPath, dirName);
  681. var win = function (directory) {
  682. expect(directory).toBeDefined();
  683. expect(directory.isFile).toBe(false);
  684. expect(directory.isDirectory).toBe(true);
  685. expect(directory.name).toCanonicallyMatch(dirName);
  686. expect(directory.fullPath).toCanonicallyMatch(dirPath);
  687. expect(directory.filesystem).toBeDefined();
  688. expect(directory.filesystem).toBe(root.filesystem);
  689. // cleanup
  690. deleteEntry(directory.name, done);
  691. };
  692. // create:true, exclusive:false, directory does not exist
  693. root.getDirectory(dirName, {
  694. create: true
  695. }, win, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  696. });
  697. it('file.spec.27 DirectoryEntry.getDirectory: create new directory (exclusive)', function (done) {
  698. var dirName = 'de.create.exclusive.dir';
  699. var dirPath = joinURL(root.fullPath, dirName);
  700. var win = function (directory) {
  701. expect(directory).toBeDefined();
  702. expect(directory.isFile).toBe(false);
  703. expect(directory.isDirectory).toBe(true);
  704. expect(directory.name).toCanonicallyMatch(dirName);
  705. expect(directory.fullPath).toCanonicallyMatch(dirPath);
  706. expect(directory.filesystem).toBeDefined();
  707. expect(directory.filesystem).toBe(root.filesystem);
  708. // cleanup
  709. deleteEntry(directory.name, done);
  710. };
  711. // create:true, exclusive:true, directory does not exist
  712. root.getDirectory(dirName, {
  713. create: true,
  714. exclusive: true
  715. }, win, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  716. });
  717. it('file.spec.28 DirectoryEntry.getDirectory: create directory that already exists', function (done) {
  718. var dirName = 'de.create.existing.dir';
  719. var dirPath = joinURL(root.fullPath, dirName);
  720. var win = function (directory) {
  721. expect(directory).toBeDefined();
  722. expect(directory.isFile).toBe(false);
  723. expect(directory.isDirectory).toBe(true);
  724. expect(directory.name).toCanonicallyMatch(dirName);
  725. expect(directory.fullPath).toCanonicallyMatch(dirPath);
  726. // cleanup
  727. deleteEntry(directory.name, done);
  728. };
  729. // create directory to kick off it
  730. root.getDirectory(dirName, {
  731. create: true
  732. }, function () {
  733. root.getDirectory(dirName, {
  734. create: true
  735. }, win, failed.bind(null, done, 'root.getDirectory - Error creating existent second directory : ' + dirName));
  736. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  737. });
  738. it('file.spec.29 DirectoryEntry.getDirectory: create directory that already exists (exclusive)', function (done) {
  739. var dirName = 'de.create.exclusive.existing.dir';
  740. var existingDir;
  741. var fail = function (error) {
  742. expect(error).toBeDefined();
  743. if (isChrome) {
  744. /* INVALID_MODIFICATION_ERR (code: 9) or ??? (code: 13) is thrown instead of PATH_EXISTS_ERR(code: 12)
  745. on trying to exclusively create a file or directory, which already exists (Chrome). */
  746. // expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);
  747. } else {
  748. expect(error).toBeFileError(FileError.PATH_EXISTS_ERR); // eslint-disable-line no-undef
  749. }
  750. // cleanup
  751. deleteEntry(existingDir.name, done);
  752. };
  753. // create directory to kick off it
  754. root.getDirectory(dirName, {
  755. create: true
  756. }, function (directory) {
  757. existingDir = directory;
  758. // create:true, exclusive:true, directory exists
  759. root.getDirectory(dirName, {
  760. create: true,
  761. exclusive: true
  762. }, failed.bind(null, done, 'root.getDirectory - Unexpected success callback, second directory should not be created : ' + dirName), fail);
  763. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  764. });
  765. it('file.spec.30 DirectoryEntry.getDirectory: get Entry for existing directory', function (done) {
  766. var dirName = 'de.get.dir';
  767. var dirPath = joinURL(root.fullPath, dirName);
  768. var win = function (directory) {
  769. expect(directory).toBeDefined();
  770. expect(directory.isFile).toBe(false);
  771. expect(directory.isDirectory).toBe(true);
  772. expect(directory.name).toCanonicallyMatch(dirName);
  773. expect(directory.fullPath).toCanonicallyMatch(dirPath);
  774. // cleanup
  775. deleteEntry(directory.name, done);
  776. };
  777. // create directory to kick it off
  778. root.getDirectory(dirName, {
  779. create: true
  780. }, function () {
  781. root.getDirectory(dirName, {
  782. create: false
  783. }, win, failed.bind(null, done, 'root.getDirectory - Error getting directory entry : ' + dirName));
  784. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  785. });
  786. it('file.spec.31 DirectoryEntry.getDirectory: get DirectoryEntry for invalid path', function (done) {
  787. if (isBrowser) {
  788. /* The plugin does not follow to ["8.3 Naming restrictions"]
  789. (http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions). */
  790. pending();
  791. }
  792. var dirName = 'de:invalid:path';
  793. var fail = function (error) {
  794. expect(error).toBeDefined();
  795. expect(error).toBeFileError(FileError.ENCODING_ERR); // eslint-disable-line no-undef
  796. done();
  797. };
  798. // create:false, exclusive:false, invalid path
  799. root.getDirectory(dirName, {
  800. create: false
  801. }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, directory should not exists: ' + dirName), fail);
  802. });
  803. it('file.spec.32 DirectoryEntry.getDirectory: get DirectoryEntry for existing file', function (done) {
  804. var fileName = 'de.existing.file';
  805. var existingFile;
  806. var fail = function (error) {
  807. expect(error).toBeDefined();
  808. if (isChrome) {
  809. // chrome returns an unknown error with code 17
  810. } else {
  811. expect(error).toBeFileError(FileError.TYPE_MISMATCH_ERR); // eslint-disable-line no-undef
  812. }
  813. // cleanup
  814. deleteEntry(existingFile.name, done);
  815. };
  816. // create file to kick off it
  817. root.getFile(fileName, {
  818. create: true
  819. }, function (file) {
  820. existingFile = file;
  821. root.getDirectory(fileName, {
  822. create: false
  823. }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, directory should not exists: ' + fileName), fail);
  824. }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));
  825. });
  826. it('file.spec.33 DirectoryEntry.getFile: get FileEntry for existing directory', function (done) {
  827. var dirName = 'de.existing.dir';
  828. var existingDir;
  829. var fail = function (error) {
  830. expect(error).toBeDefined();
  831. if (isChrome) {
  832. // chrome returns an unknown error with code 17
  833. } else {
  834. expect(error).toBeFileError(FileError.TYPE_MISMATCH_ERR); // eslint-disable-line no-undef
  835. }
  836. // cleanup
  837. deleteEntry(existingDir.name, done);
  838. };
  839. // create directory to kick off it
  840. root.getDirectory(dirName, {
  841. create: true
  842. }, function (directory) {
  843. existingDir = directory;
  844. root.getFile(dirName, {
  845. create: false
  846. }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, file should not exists: ' + dirName), fail);
  847. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  848. });
  849. it('file.spec.34 DirectoryEntry.removeRecursively on directory', function (done) {
  850. var dirName = 'de.removeRecursively';
  851. var subDirName = 'dir';
  852. var dirExists = function (error) {
  853. expect(error).toBeDefined();
  854. if (isChrome) {
  855. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  856. } else {
  857. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  858. }
  859. done();
  860. };
  861. // create a new directory entry to kick off it
  862. root.getDirectory(dirName, {
  863. create: true
  864. }, function (entry) {
  865. entry.getDirectory(subDirName, {
  866. create: true
  867. }, function (dir) {
  868. entry.removeRecursively(function () {
  869. root.getDirectory(dirName, {
  870. create: false
  871. }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, directory should not exists: ' + dirName), dirExists);
  872. }, failed.bind(null, done, 'entry.removeRecursively - Error removing directory recursively : ' + dirName));
  873. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + subDirName));
  874. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  875. });
  876. it('file.spec.35 createReader: create reader on existing directory', function () {
  877. // create reader for root directory
  878. var reader = root.createReader();
  879. expect(reader).toBeDefined();
  880. expect(typeof reader.readEntries).toBe('function');
  881. });
  882. it('file.spec.36 removeRecursively on root file system', function (done) {
  883. var remove = function (error) {
  884. expect(error).toBeDefined();
  885. if (isChrome) {
  886. /* INVALID_MODIFICATION_ERR (code: 9) or ??? (code: 13) is thrown instead of
  887. NO_MODIFICATION_ALLOWED_ERR(code: 6) on trying to call removeRecursively
  888. on the root file system (Chrome). */
  889. // expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);
  890. } else {
  891. expect(error).toBeFileError(FileError.NO_MODIFICATION_ALLOWED_ERR); // eslint-disable-line no-undef
  892. }
  893. done();
  894. };
  895. // remove root file system
  896. root.removeRecursively(succeed.bind(null, done, 'root.removeRecursively - Unexpected success callback, root cannot be removed'), remove);
  897. });
  898. });
  899. describe('DirectoryReader interface', function () {
  900. describe('readEntries', function () {
  901. it('file.spec.37 should read contents of existing directory', function (done) {
  902. var reader;
  903. var win = function (entries) {
  904. expect(entries).toBeDefined();
  905. expect(entries instanceof Array).toBe(true);
  906. done();
  907. };
  908. // create reader for root directory
  909. reader = root.createReader();
  910. // read entries
  911. reader.readEntries(win, failed.bind(null, done, 'reader.readEntries - Error reading entries'));
  912. });
  913. it('file.spec.37.1 should read contents of existing directory', function (done) {
  914. var dirName = 'readEntries.dir';
  915. var fileName = 'readeEntries.file';
  916. root.getDirectory(dirName, {
  917. create: true
  918. }, function (directory) {
  919. directory.getFile(fileName, {
  920. create: true
  921. }, function (fileEntry) {
  922. var reader = directory.createReader();
  923. reader.readEntries(function (entries) {
  924. expect(entries).toBeDefined();
  925. expect(entries instanceof Array).toBe(true);
  926. expect(entries.length).toBe(1);
  927. expect(entries[0].fullPath).toCanonicallyMatch(fileEntry.fullPath);
  928. expect(entries[0].filesystem).not.toBe(null);
  929. if (isChrome) {
  930. // Slicing '[object {type}]' -> '{type}'
  931. expect(entries[0].filesystem.toString().slice(8, -1)).toEqual('DOMFileSystem');
  932. } else {
  933. expect(entries[0].filesystem instanceof FileSystem).toBe(true); // eslint-disable-line no-undef
  934. }
  935. // cleanup
  936. deleteEntry(directory.name, done);
  937. }, failed.bind(null, done, 'reader.readEntries - Error reading entries from directory: ' + dirName));
  938. }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + fileName));
  939. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  940. });
  941. it('file.spec.109 should return an empty entry list on the second call', function (done) {
  942. var reader;
  943. var fileName = 'test109.txt';
  944. // Add a file to ensure the root directory is non-empty and then read the contents of the directory.
  945. root.getFile(fileName, {
  946. create: true
  947. }, function (entry) {
  948. reader = root.createReader();
  949. // First read
  950. reader.readEntries(function (entries) {
  951. expect(entries).toBeDefined();
  952. expect(entries instanceof Array).toBe(true);
  953. expect(entries.length).not.toBe(0);
  954. // Second read
  955. reader.readEntries(function (entries_) {
  956. expect(entries_).toBeDefined();
  957. expect(entries_ instanceof Array).toBe(true);
  958. expect(entries_.length).toBe(0);
  959. // Clean up
  960. deleteEntry(entry.name, done);
  961. }, failed.bind(null, done, 'reader.readEntries - Error during SECOND reading of entries from [root] directory'));
  962. }, failed.bind(null, done, 'reader.readEntries - Error during FIRST reading of entries from [root] directory'));
  963. }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));
  964. });
  965. });
  966. it('file.spec.38 should read contents of directory that has been removed', function (done) {
  967. var dirName = 'de.createReader.notfound';
  968. // create a new directory entry to kick off it
  969. root.getDirectory(dirName, {
  970. create: true
  971. }, function (directory) {
  972. directory.removeRecursively(function () {
  973. var reader = directory.createReader();
  974. reader.readEntries(succeed.bind(null, done, 'reader.readEntries - Unexpected success callback, it should not read entries from deleted dir: ' + dirName), function (error) {
  975. expect(error).toBeDefined();
  976. if (isChrome) {
  977. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  978. } else {
  979. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  980. }
  981. root.getDirectory(dirName, {
  982. create: false
  983. }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, it should not get deleted directory: ' + dirName), function (err) {
  984. expect(err).toBeDefined();
  985. if (isChrome) {
  986. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  987. } else {
  988. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  989. }
  990. done();
  991. });
  992. });
  993. }, failed.bind(null, done, 'directory.removeRecursively - Error removing directory recursively : ' + dirName));
  994. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));
  995. });
  996. });
  997. // DirectoryReader interface
  998. describe('File', function () {
  999. it('file.spec.39 constructor should be defined', function () {
  1000. expect(File).toBeDefined(); // eslint-disable-line no-undef
  1001. expect(typeof File).toBe('function');
  1002. });
  1003. it('file.spec.40 should be define File attributes', function () {
  1004. var file = new File(); // eslint-disable-line no-undef
  1005. expect(file.name).toBeDefined();
  1006. expect(file.type).toBeDefined();
  1007. expect(file.lastModifiedDate).toBeDefined();
  1008. expect(file.size).toBeDefined();
  1009. });
  1010. });
  1011. // File
  1012. describe('FileEntry', function () {
  1013. it('file.spec.41 should be define FileEntry methods', function (done) {
  1014. var fileName = 'fe.methods';
  1015. var testFileEntry = function (fileEntry) {
  1016. expect(fileEntry).toBeDefined();
  1017. expect(typeof fileEntry.createWriter).toBe('function');
  1018. expect(typeof fileEntry.file).toBe('function');
  1019. // cleanup
  1020. deleteEntry(fileEntry.name, done);
  1021. };
  1022. // create a new file entry to kick off it
  1023. root.getFile(fileName, {
  1024. create: true
  1025. }, testFileEntry, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));
  1026. });
  1027. it('file.spec.42 createWriter should return a FileWriter object', function (done) {
  1028. var fileName = 'fe.createWriter';
  1029. var testFile;
  1030. var testWriter = function (writer) {
  1031. expect(writer).toBeDefined();
  1032. if (isChrome) {
  1033. // Slicing '[object {type}]' -> '{type}'
  1034. expect(writer.toString().slice(8, -1)).toEqual('FileWriter');
  1035. } else {
  1036. expect(writer instanceof FileWriter).toBe(true); // eslint-disable-line no-undef
  1037. }
  1038. // cleanup
  1039. deleteEntry(testFile.name, done);
  1040. };
  1041. // create a new file entry to kick off it
  1042. root.getFile(fileName, {
  1043. create: true
  1044. }, function (fileEntry) {
  1045. testFile = fileEntry;
  1046. fileEntry.createWriter(testWriter, failed.bind(null, done, 'fileEntry.createWriter - Error creating Writer from entry'));
  1047. }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));
  1048. });
  1049. it('file.spec.43 file should return a File object', function (done) {
  1050. var fileName = 'fe.file';
  1051. var newFile;
  1052. var testFile = function (file) {
  1053. expect(file).toBeDefined();
  1054. if (isChrome) {
  1055. // Slicing '[object {type}]' -> '{type}'
  1056. expect(file.toString().slice(8, -1)).toEqual('File');
  1057. } else {
  1058. expect(file instanceof File).toBe(true); // eslint-disable-line no-undef
  1059. }
  1060. // cleanup
  1061. deleteEntry(newFile.name, done);
  1062. };
  1063. // create a new file entry to kick off it
  1064. root.getFile(fileName, {
  1065. create: true
  1066. }, function (fileEntry) {
  1067. newFile = fileEntry;
  1068. fileEntry.file(testFile, failed.bind(null, done, 'fileEntry.file - Error reading file using fileEntry: ' + fileEntry.name));
  1069. }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));
  1070. });
  1071. it('file.spec.44 file: on File that has been removed', function (done) {
  1072. var fileName = 'fe.no.file';
  1073. // create a new file entry to kick off it
  1074. root.getFile(fileName, {
  1075. create: true
  1076. }, function (fileEntry) {
  1077. fileEntry.remove(function () {
  1078. fileEntry.file(succeed.bind(null, done, 'fileEntry.file - Unexpected success callback, file it should not be created from removed entry'), function (error) {
  1079. expect(error).toBeDefined();
  1080. if (isChrome) {
  1081. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  1082. } else {
  1083. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1084. }
  1085. done();
  1086. });
  1087. }, failed.bind(null, done, 'fileEntry.remove - Error removing entry : ' + fileName));
  1088. }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));
  1089. });
  1090. });
  1091. // FileEntry
  1092. describe('Entry', function () {
  1093. it('file.spec.45 Entry object', function (done) {
  1094. var fileName = 'entry';
  1095. var fullPath = joinURL(root.fullPath, fileName);
  1096. var winEntry = function (entry) {
  1097. expect(entry).toBeDefined();
  1098. expect(entry.isFile).toBe(true);
  1099. expect(entry.isDirectory).toBe(false);
  1100. expect(entry.name).toCanonicallyMatch(fileName);
  1101. expect(entry.fullPath).toCanonicallyMatch(fullPath);
  1102. expect(typeof entry.getMetadata).toBe('function');
  1103. expect(typeof entry.setMetadata).toBe('function');
  1104. expect(typeof entry.moveTo).toBe('function');
  1105. expect(typeof entry.copyTo).toBe('function');
  1106. expect(typeof entry.toURL).toBe('function');
  1107. expect(typeof entry.remove).toBe('function');
  1108. expect(typeof entry.getParent).toBe('function');
  1109. expect(typeof entry.createWriter).toBe('function');
  1110. expect(typeof entry.file).toBe('function');
  1111. // Clean up
  1112. deleteEntry(fileName, done);
  1113. };
  1114. // create a new file entry
  1115. createFile(fileName, winEntry, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));
  1116. });
  1117. it('file.spec.46 Entry.getMetadata on file', function (done) {
  1118. var fileName = 'entry.metadata.file';
  1119. // create a new file entry
  1120. createFile(fileName, function (entry) {
  1121. entry.getMetadata(function (metadata) {
  1122. expect(metadata).toBeDefined();
  1123. expect(metadata.modificationTime instanceof Date).toBe(true);
  1124. expect(typeof metadata.size).toBe('number');
  1125. // cleanup
  1126. deleteEntry(fileName, done);
  1127. }, failed.bind(null, done, 'entry.getMetadata - Error getting metadata from entry : ' + fileName));
  1128. }, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));
  1129. });
  1130. it('file.spec.47 Entry.getMetadata on directory', function (done) {
  1131. if (isIndexedDBShim) {
  1132. /* Does not support metadata for directories (Firefox, IE) */
  1133. pending();
  1134. }
  1135. var dirName = 'entry.metadata.dir';
  1136. // create a new directory entry
  1137. createDirectory(dirName, function (entry) {
  1138. entry.getMetadata(function (metadata) {
  1139. expect(metadata).toBeDefined();
  1140. expect(metadata.modificationTime instanceof Date).toBe(true);
  1141. expect(typeof metadata.size).toBe('number');
  1142. expect(metadata.size).toBe(0);
  1143. // cleanup
  1144. deleteEntry(dirName, done);
  1145. }, failed.bind(null, done, 'entry.getMetadata - Error getting metadata from entry : ' + dirName));
  1146. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));
  1147. });
  1148. it('file.spec.48 Entry.getParent on file in root file system', function (done) {
  1149. var fileName = 'entry.parent.file';
  1150. var rootPath = root.fullPath;
  1151. // create a new file entry
  1152. createFile(fileName, function (entry) {
  1153. entry.getParent(function (parent) {
  1154. expect(parent).toBeDefined();
  1155. expect(parent.fullPath).toCanonicallyMatch(rootPath);
  1156. // cleanup
  1157. deleteEntry(fileName, done);
  1158. }, failed.bind(null, done, 'entry.getParent - Error getting parent directory of file : ' + fileName));
  1159. }, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));
  1160. });
  1161. it('file.spec.49 Entry.getParent on directory in root file system', function (done) {
  1162. var dirName = 'entry.parent.dir';
  1163. var rootPath = root.fullPath;
  1164. // create a new directory entry
  1165. createDirectory(dirName, function (entry) {
  1166. entry.getParent(function (parent) {
  1167. expect(parent).toBeDefined();
  1168. expect(parent.fullPath).toCanonicallyMatch(rootPath);
  1169. // cleanup
  1170. deleteEntry(dirName, done);
  1171. }, failed.bind(null, done, 'entry.getParent - Error getting parent directory of directory : ' + dirName));
  1172. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));
  1173. });
  1174. it('file.spec.50 Entry.getParent on root file system', function (done) {
  1175. var rootPath = root.fullPath;
  1176. var winParent = function (parent) {
  1177. expect(parent).toBeDefined();
  1178. expect(parent.fullPath).toCanonicallyMatch(rootPath);
  1179. done();
  1180. };
  1181. // create a new directory entry
  1182. root.getParent(winParent, failed.bind(null, done, 'root.getParent - Error getting parent directory of root'));
  1183. });
  1184. it('file.spec.51 Entry.toURL on file', function (done) {
  1185. var fileName = 'entry.uri.file';
  1186. var rootPath = root.fullPath;
  1187. var winURI = function (entry) {
  1188. var uri = entry.toURL();
  1189. expect(uri).toBeDefined();
  1190. expect(uri.indexOf(rootPath)).not.toBe(-1);
  1191. // cleanup
  1192. deleteEntry(fileName, done);
  1193. };
  1194. // create a new file entry
  1195. createFile(fileName, winURI, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));
  1196. });
  1197. it('file.spec.52 Entry.toURL on directory', function (done) {
  1198. var dirName_1 = 'num 1';
  1199. var dirName_2 = 'num 2';
  1200. var rootPath = root.fullPath;
  1201. createDirectory(dirName_1, function (entry) {
  1202. entry.getDirectory(dirName_2, {
  1203. create: true
  1204. }, function (entryFile) {
  1205. var uri = entryFile.toURL();
  1206. expect(uri).toBeDefined();
  1207. expect(uri).toContain('/num%201/num%202/');
  1208. expect(uri.indexOf(rootPath)).not.toBe(-1);
  1209. // cleanup
  1210. deleteEntry(dirName_1, done);
  1211. }, failed.bind(null, done, 'entry.getDirectory - Error creating directory : ' + dirName_2));
  1212. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName_1));
  1213. });
  1214. it('file.spec.53 Entry.remove on file', function (done) {
  1215. var fileName = 'entr .rm.file';
  1216. // create a new file entry
  1217. createFile(fileName, function (entry) {
  1218. expect(entry).toBeDefined();
  1219. entry.remove(function () {
  1220. root.getFile(fileName, null, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get deleted file : ' + fileName), function (error) {
  1221. expect(error).toBeDefined();
  1222. if (isChrome) {
  1223. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  1224. } else {
  1225. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1226. }
  1227. // cleanup
  1228. deleteEntry(fileName, done);
  1229. });
  1230. }, failed.bind(null, done, 'entry.remove - Error removing entry : ' + fileName));
  1231. }, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));
  1232. });
  1233. it('file.spec.53.1 Entry.remove on filename with #s', function (done) {
  1234. if (isBrowser) {
  1235. pending('Browsers can\'t do that');
  1236. }
  1237. var fileName = 'entry.#rm#.file';
  1238. // create a new file entry
  1239. createFile(fileName, function (entry) {
  1240. expect(entry).toBeDefined();
  1241. entry.remove(function () {
  1242. root.getFile(fileName, null, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get deleted file : ' + fileName), function (error) {
  1243. expect(error).toBeDefined();
  1244. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1245. // cleanup
  1246. deleteEntry(fileName, done);
  1247. });
  1248. }, failed.bind(null, done, 'entry.remove - Error removing entry : ' + fileName));
  1249. }, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));
  1250. });
  1251. it('file.spec.54 remove on empty directory', function (done) {
  1252. var dirName = 'entry.rm.dir';
  1253. // create a new directory entry
  1254. createDirectory(dirName, function (entry) {
  1255. expect(entry).toBeDefined();
  1256. entry.remove(function () {
  1257. root.getDirectory(dirName, null, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, it should not get deleted directory : ' + dirName), function (error) {
  1258. expect(error).toBeDefined();
  1259. if (isChrome) {
  1260. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  1261. } else {
  1262. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1263. }
  1264. // cleanup
  1265. deleteEntry(dirName, done);
  1266. });
  1267. }, failed.bind(null, done, 'entry.remove - Error removing entry : ' + dirName));
  1268. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));
  1269. });
  1270. it('file.spec.55 remove on non-empty directory', function (done) {
  1271. if (isIndexedDBShim) {
  1272. /* Both Entry.remove and directoryEntry.removeRecursively don't fail when removing
  1273. non-empty directories - directories being removed are cleaned
  1274. along with contents instead (Firefox, IE) */
  1275. pending();
  1276. }
  1277. var dirName = 'ent y.rm.dir.not.empty';
  1278. var fileName = 're ove.txt';
  1279. var fullPath = joinURL(root.fullPath, dirName);
  1280. // create a new directory entry
  1281. createDirectory(dirName, function (entry) {
  1282. entry.getFile(fileName, {
  1283. create: true
  1284. }, function (fileEntry) {
  1285. entry.remove(succeed.bind(null, done, 'entry.remove - Unexpected success callback, it should not remove a directory that contains files : ' + dirName), function (error) {
  1286. expect(error).toBeDefined();
  1287. if (isChrome) {
  1288. // chrome is returning unknown error with code 13
  1289. } else {
  1290. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  1291. }
  1292. root.getDirectory(dirName, null, function (entry) {
  1293. expect(entry).toBeDefined();
  1294. expect(entry.fullPath).toCanonicallyMatch(fullPath);
  1295. // cleanup
  1296. deleteEntry(dirName, done);
  1297. }, failed.bind(null, done, 'root.getDirectory - Error getting directory : ' + dirName));
  1298. });
  1299. }, failed.bind(null, done, 'entry.getFile - Error creating file : ' + fileName + ' inside of ' + dirName));
  1300. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));
  1301. });
  1302. it('file.spec.56 remove on root file system', function (done) {
  1303. // remove entry that doesn't exist
  1304. root.remove(succeed.bind(null, done, 'entry.remove - Unexpected success callback, it should not remove entry that it does not exists'), function (error) {
  1305. expect(error).toBeDefined();
  1306. if (isChrome) {
  1307. /* INVALID_MODIFICATION_ERR (code: 9) or ??? (code: 13) is thrown instead of
  1308. NO_MODIFICATION_ALLOWED_ERR(code: 6) on trying to call removeRecursively
  1309. on the root file system. */
  1310. // expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);
  1311. } else {
  1312. expect(error).toBeFileError(FileError.NO_MODIFICATION_ALLOWED_ERR); // eslint-disable-line no-undef
  1313. }
  1314. done();
  1315. });
  1316. });
  1317. it('file.spec.57 copyTo: file', function (done) {
  1318. var file1 = 'entry copy.file1';
  1319. var file2 = 'entry copy.file2';
  1320. var fullPath = joinURL(root.fullPath, file2);
  1321. // create a new file entry to kick off it
  1322. deleteEntry(file2, function () {
  1323. createFile(file1, function (fileEntry) {
  1324. // copy file1 to file2
  1325. fileEntry.copyTo(root, file2, function (entry) {
  1326. expect(entry).toBeDefined();
  1327. expect(entry.isFile).toBe(true);
  1328. expect(entry.isDirectory).toBe(false);
  1329. expect(entry.fullPath).toCanonicallyMatch(fullPath);
  1330. expect(entry.name).toCanonicallyMatch(file2);
  1331. root.getFile(file2, {
  1332. create: false
  1333. }, function (entry2) {
  1334. expect(entry2).toBeDefined();
  1335. expect(entry2.isFile).toBe(true);
  1336. expect(entry2.isDirectory).toBe(false);
  1337. expect(entry2.fullPath).toCanonicallyMatch(fullPath);
  1338. expect(entry2.name).toCanonicallyMatch(file2);
  1339. // cleanup
  1340. deleteEntry(file1, function () {
  1341. deleteEntry(file2, done);
  1342. });
  1343. }, failed.bind(null, done, 'root.getFile - Error getting copied file : ' + file2));
  1344. }, failed.bind(null, done, 'fileEntry.copyTo - Error copying file : ' + file2));
  1345. }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));
  1346. }, failed.bind(null, done, 'deleteEntry - Error removing file : ' + file2));
  1347. });
  1348. it('file.spec.58 copyTo: file onto itself', function (done) {
  1349. var file1 = 'entry.copy.fos.file1';
  1350. // create a new file entry to kick off it
  1351. createFile(file1, function (entry) {
  1352. // copy file1 onto itself
  1353. entry.copyTo(root, null, succeed.bind(null, done, 'entry.copyTo - Unexpected success callback, it should not copy a null file'), function (error) {
  1354. expect(error).toBeDefined();
  1355. if (isChrome) {
  1356. // chrome returns unknown error with code 13
  1357. } else {
  1358. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  1359. }
  1360. // cleanup
  1361. deleteEntry(file1, done);
  1362. });
  1363. }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));
  1364. });
  1365. it('file.spec.59 copyTo: directory', function (done) {
  1366. if (isIndexedDBShim) {
  1367. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1368. pending();
  1369. }
  1370. var file1 = 'file1';
  1371. var srcDir = 'entry.copy.srcDir';
  1372. var dstDir = 'entry.copy.dstDir';
  1373. var dstPath = joinURL(root.fullPath, dstDir);
  1374. var filePath = joinURL(dstPath, file1);
  1375. // create a new directory entry to kick off it
  1376. deleteEntry(dstDir, function () {
  1377. createDirectory(srcDir, function (directory) {
  1378. // create a file within new directory
  1379. directory.getFile(file1, {
  1380. create: true
  1381. }, function () {
  1382. directory.copyTo(root, dstDir, function (directory) {
  1383. expect(directory).toBeDefined();
  1384. expect(directory.isFile).toBe(false);
  1385. expect(directory.isDirectory).toBe(true);
  1386. expect(directory.fullPath).toCanonicallyMatch(dstPath);
  1387. expect(directory.name).toCanonicallyMatch(dstDir);
  1388. root.getDirectory(dstDir, {
  1389. create: false
  1390. }, function (dirEntry) {
  1391. expect(dirEntry).toBeDefined();
  1392. expect(dirEntry.isFile).toBe(false);
  1393. expect(dirEntry.isDirectory).toBe(true);
  1394. expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);
  1395. expect(dirEntry.name).toCanonicallyMatch(dstDir);
  1396. dirEntry.getFile(file1, {
  1397. create: false
  1398. }, function (fileEntry) {
  1399. expect(fileEntry).toBeDefined();
  1400. expect(fileEntry.isFile).toBe(true);
  1401. expect(fileEntry.isDirectory).toBe(false);
  1402. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  1403. expect(fileEntry.name).toCanonicallyMatch(file1);
  1404. // cleanup
  1405. deleteEntry(srcDir, function () {
  1406. deleteEntry(dstDir, done);
  1407. });
  1408. }, failed.bind(null, done, 'dirEntry.getFile - Error getting file : ' + file1));
  1409. }, failed.bind(null, done, 'root.getDirectory - Error getting copied directory : ' + dstDir));
  1410. }, failed.bind(null, done, 'directory.copyTo - Error copying directory : ' + srcDir + ' to :' + dstDir));
  1411. }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));
  1412. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1413. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
  1414. });
  1415. it('file.spec.60 copyTo: directory to backup at same root directory', function (done) {
  1416. if (isIndexedDBShim) {
  1417. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1418. pending();
  1419. }
  1420. var file1 = 'file1';
  1421. var srcDir = 'entry.copy srcDirSame';
  1422. var dstDir = 'entry.copy srcDirSame-backup';
  1423. var dstPath = joinURL(root.fullPath, dstDir);
  1424. var filePath = joinURL(dstPath, file1);
  1425. // create a new directory entry to kick off it
  1426. deleteEntry(dstDir, function () {
  1427. createDirectory(srcDir, function (directory) {
  1428. directory.getFile(file1, {
  1429. create: true
  1430. }, function () {
  1431. directory.copyTo(root, dstDir, function (directory) {
  1432. expect(directory).toBeDefined();
  1433. expect(directory.isFile).toBe(false);
  1434. expect(directory.isDirectory).toBe(true);
  1435. expect(directory.fullPath).toCanonicallyMatch(dstPath);
  1436. expect(directory.name).toCanonicallyMatch(dstDir);
  1437. root.getDirectory(dstDir, {
  1438. create: false
  1439. }, function (dirEntry) {
  1440. expect(dirEntry).toBeDefined();
  1441. expect(dirEntry.isFile).toBe(false);
  1442. expect(dirEntry.isDirectory).toBe(true);
  1443. expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);
  1444. expect(dirEntry.name).toCanonicallyMatch(dstDir);
  1445. dirEntry.getFile(file1, {
  1446. create: false
  1447. }, function (fileEntry) {
  1448. expect(fileEntry).toBeDefined();
  1449. expect(fileEntry.isFile).toBe(true);
  1450. expect(fileEntry.isDirectory).toBe(false);
  1451. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  1452. expect(fileEntry.name).toCanonicallyMatch(file1);
  1453. // cleanup
  1454. deleteEntry(srcDir, function () {
  1455. deleteEntry(dstDir, done);
  1456. });
  1457. }, failed.bind(null, done, 'dirEntry.getFile - Error getting file : ' + file1));
  1458. }, failed.bind(null, done, 'root.getDirectory - Error getting copied directory : ' + dstDir));
  1459. }, failed.bind(null, done, 'directory.copyTo - Error copying directory : ' + srcDir + ' to :' + dstDir));
  1460. }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));
  1461. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1462. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
  1463. });
  1464. it('file.spec.61 copyTo: directory onto itself', function (done) {
  1465. if (isIndexedDBShim) {
  1466. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1467. pending();
  1468. }
  1469. var file1 = 'file1';
  1470. var srcDir = 'entry.copy.dos.srcDir';
  1471. var srcPath = joinURL(root.fullPath, srcDir);
  1472. var filePath = joinURL(srcPath, file1);
  1473. // create a new directory entry to kick off it
  1474. createDirectory(srcDir, function (directory) {
  1475. // create a file within new directory
  1476. directory.getFile(file1, {
  1477. create: true
  1478. }, function (fileEntry) {
  1479. // copy srcDir onto itself
  1480. directory.copyTo(root, null, succeed.bind(null, done, 'directory.copyTo - Unexpected success callback, it should not copy file: ' + srcDir + ' to a null destination'), function (error) {
  1481. expect(error).toBeDefined();
  1482. if (isChrome) {
  1483. // chrome returns unknown error with code 13
  1484. } else {
  1485. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  1486. }
  1487. root.getDirectory(srcDir, {
  1488. create: false
  1489. }, function (dirEntry) {
  1490. expect(dirEntry).toBeDefined();
  1491. expect(dirEntry.fullPath).toCanonicallyMatch(srcPath);
  1492. dirEntry.getFile(file1, {
  1493. create: false
  1494. }, function (fileEntry) {
  1495. expect(fileEntry).toBeDefined();
  1496. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  1497. // cleanup
  1498. deleteEntry(srcDir, done);
  1499. }, failed.bind(null, done, 'dirEntry.getFile - Error getting file : ' + file1));
  1500. }, failed.bind(null, done, 'root.getDirectory - Error getting directory : ' + srcDir));
  1501. });
  1502. }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));
  1503. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1504. });
  1505. it('file.spec.62 copyTo: directory into itself', function (done) {
  1506. if (isIndexedDBShim) {
  1507. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1508. pending();
  1509. }
  1510. var srcDir = 'entry.copy.dis.srcDir';
  1511. var dstDir = 'entry.copy.dis.dstDir';
  1512. var srcPath = joinURL(root.fullPath, srcDir);
  1513. // create a new directory entry to kick off it
  1514. createDirectory(srcDir, function (directory) {
  1515. // copy source directory into itself
  1516. directory.copyTo(directory, dstDir, succeed.bind(null, done, 'directory.copyTo - Unexpected success callback, it should not copy a directory ' + srcDir + ' into itself'), function (error) {
  1517. expect(error).toBeDefined();
  1518. if (isChrome) {
  1519. // chrome returns unknown error with code 13
  1520. } else {
  1521. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  1522. }
  1523. root.getDirectory(srcDir, {
  1524. create: false
  1525. }, function (dirEntry) {
  1526. // returning confirms existence so just check fullPath entry
  1527. expect(dirEntry).toBeDefined();
  1528. expect(dirEntry.fullPath).toCanonicallyMatch(srcPath);
  1529. // cleanup
  1530. deleteEntry(srcDir, done);
  1531. }, failed.bind(null, done, 'root.getDirectory - Error getting directory : ' + srcDir));
  1532. });
  1533. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1534. });
  1535. it('file.spec.63 copyTo: directory that does not exist', function (done) {
  1536. var file1 = 'entry.copy.dnf.file1';
  1537. var dirName = 'dir-foo';
  1538. createFile(file1, function (fileEntry) {
  1539. createDirectory(dirName, function (dirEntry) {
  1540. dirEntry.remove(function () {
  1541. fileEntry.copyTo(dirEntry, null, succeed.bind(null, done, 'fileEntry.copyTo - Unexpected success callback, it should not copy a file ' + file1 + ' into a removed directory'), function (error) {
  1542. expect(error).toBeDefined();
  1543. if (isChrome) {
  1544. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  1545. } else {
  1546. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1547. }
  1548. done();
  1549. });
  1550. }, failed.bind(null, done, 'dirEntry.remove - Error removing directory : ' + dirName));
  1551. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));
  1552. }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));
  1553. });
  1554. it('file.spec.64 copyTo: invalid target name', function (done) {
  1555. if (isBrowser) {
  1556. /* The plugin does not follow ["8.3 Naming restrictions"]
  1557. (http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions */
  1558. pending();
  1559. }
  1560. var file1 = 'entry.copy.itn.file1';
  1561. var file2 = 'bad:file:name';
  1562. // create a new file entry
  1563. createFile(file1, function (entry) {
  1564. // copy file1 to file2
  1565. entry.copyTo(root, file2, succeed.bind(null, done, 'entry.copyTo - Unexpected success callback, it should not copy a file ' + file1 + ' to an invalid file name: ' + file2), function (error) {
  1566. expect(error).toBeDefined();
  1567. expect(error).toBeFileError(FileError.ENCODING_ERR); // eslint-disable-line no-undef
  1568. // cleanup
  1569. deleteEntry(file1, done);
  1570. });
  1571. }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));
  1572. });
  1573. it('file.spec.65 moveTo: file to same parent', function (done) {
  1574. var file1 = 'entry.move.fsp.file1';
  1575. var file2 = 'entry.move.fsp.file2';
  1576. var dstPath = joinURL(root.fullPath, file2);
  1577. // create a new file entry to kick off it
  1578. createFile(file1, function (entry) {
  1579. // move file1 to file2
  1580. entry.moveTo(root, file2, function (entry) {
  1581. expect(entry).toBeDefined();
  1582. expect(entry.isFile).toBe(true);
  1583. expect(entry.isDirectory).toBe(false);
  1584. expect(entry.fullPath).toCanonicallyMatch(dstPath);
  1585. expect(entry.name).toCanonicallyMatch(file2);
  1586. root.getFile(file2, {
  1587. create: false
  1588. }, function (fileEntry) {
  1589. expect(fileEntry).toBeDefined();
  1590. expect(fileEntry.fullPath).toCanonicallyMatch(dstPath);
  1591. root.getFile(file1, {
  1592. create: false
  1593. }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {
  1594. // expect(navigator.fileMgr.testFileExists(srcPath) === false, "original file should not exist.");
  1595. expect(error).toBeDefined();
  1596. if (isChrome) {
  1597. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  1598. } else {
  1599. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1600. }
  1601. // cleanup
  1602. deleteEntry(file1, function () {
  1603. deleteEntry(file2, done);
  1604. });
  1605. });
  1606. }, failed.bind(null, done, 'root.getFile - Error getting file : ' + file2));
  1607. }, failed.bind(null, done, 'entry.moveTo - Error moving file : ' + file1 + ' to root as: ' + file2));
  1608. }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));
  1609. });
  1610. it('file.spec.66 moveTo: file to new parent', function (done) {
  1611. var file1 = 'entry.move.fnp.file1';
  1612. var dir = 'entry.move.fnp.dir';
  1613. var dstPath = joinURL(joinURL(root.fullPath, dir), file1);
  1614. // ensure destination directory is cleaned up first
  1615. deleteEntry(dir, function () {
  1616. // create a new file entry to kick off it
  1617. createFile(file1, function (entry) {
  1618. // create a parent directory to move file to
  1619. root.getDirectory(dir, {
  1620. create: true
  1621. }, function (directory) {
  1622. // move file1 to new directory
  1623. // move the file
  1624. entry.moveTo(directory, null, function (entry) {
  1625. expect(entry).toBeDefined();
  1626. expect(entry.isFile).toBe(true);
  1627. expect(entry.isDirectory).toBe(false);
  1628. expect(entry.fullPath).toCanonicallyMatch(dstPath);
  1629. expect(entry.name).toCanonicallyMatch(file1);
  1630. // test the moved file exists
  1631. directory.getFile(file1, {
  1632. create: false
  1633. }, function (fileEntry) {
  1634. expect(fileEntry).toBeDefined();
  1635. expect(fileEntry.fullPath).toCanonicallyMatch(dstPath);
  1636. root.getFile(file1, {
  1637. create: false
  1638. }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {
  1639. expect(error).toBeDefined();
  1640. if (isChrome) {
  1641. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  1642. } else {
  1643. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1644. }
  1645. // cleanup
  1646. deleteEntry(file1, function () {
  1647. deleteEntry(dir, done);
  1648. });
  1649. });
  1650. }, failed.bind(null, done, 'directory.getFile - Error getting file : ' + file1 + ' from: ' + dir));
  1651. }, failed.bind(null, done, 'entry.moveTo - Error moving file : ' + file1 + ' to: ' + dir + ' with the same name'));
  1652. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dir));
  1653. }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));
  1654. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dir));
  1655. });
  1656. it('file.spec.67 moveTo: directory to same parent', function (done) {
  1657. if (isIndexedDBShim) {
  1658. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1659. pending();
  1660. }
  1661. var file1 = 'file1';
  1662. var srcDir = 'entry.move.dsp.srcDir';
  1663. var dstDir = 'entry.move.dsp.dstDir';
  1664. var dstPath = joinURL(root.fullPath, dstDir);
  1665. var filePath = joinURL(dstPath, file1);
  1666. // ensure destination directory is cleaned up before it
  1667. deleteEntry(dstDir, function () {
  1668. // create a new directory entry to kick off it
  1669. createDirectory(srcDir, function (directory) {
  1670. // create a file within directory
  1671. directory.getFile(file1, {
  1672. create: true
  1673. }, function () {
  1674. // move srcDir to dstDir
  1675. directory.moveTo(root, dstDir, function (directory) {
  1676. expect(directory).toBeDefined();
  1677. expect(directory.isFile).toBe(false);
  1678. expect(directory.isDirectory).toBe(true);
  1679. expect(directory.fullPath).toCanonicallyMatch(dstPath);
  1680. expect(directory.name).toCanonicallyMatch(dstDir);
  1681. // test that moved file exists in destination dir
  1682. directory.getFile(file1, {
  1683. create: false
  1684. }, function (fileEntry) {
  1685. expect(fileEntry).toBeDefined();
  1686. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  1687. // check that the moved file no longer exists in original dir
  1688. root.getFile(file1, {
  1689. create: false
  1690. }, succeed.bind(null, done, 'directory.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {
  1691. expect(error).toBeDefined();
  1692. if (isChrome) {
  1693. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  1694. } else {
  1695. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1696. }
  1697. // cleanup
  1698. deleteEntry(srcDir, function () {
  1699. deleteEntry(dstDir, done);
  1700. });
  1701. });
  1702. }, failed.bind(null, done, 'directory.getFile - Error getting file : ' + file1 + ' from: ' + srcDir));
  1703. }, failed.bind(null, done, 'entry.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));
  1704. }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));
  1705. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1706. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
  1707. });
  1708. it('file.spec.68 moveTo: directory to same parent with same name', function (done) {
  1709. if (isIndexedDBShim) {
  1710. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1711. pending();
  1712. }
  1713. var file1 = 'file1';
  1714. var srcDir = 'entry.move.dsp.srcDir';
  1715. var dstDir = 'entry.move.dsp.srcDir-backup';
  1716. var dstPath = joinURL(root.fullPath, dstDir);
  1717. var filePath = joinURL(dstPath, file1);
  1718. // ensure destination directory is cleaned up before it
  1719. deleteEntry(dstDir, function () {
  1720. // create a new directory entry to kick off it
  1721. createDirectory(srcDir, function (directory) {
  1722. // create a file within directory
  1723. directory.getFile(file1, {
  1724. create: true
  1725. }, function () {
  1726. // move srcDir to dstDir
  1727. directory.moveTo(root, dstDir, function (directory) {
  1728. expect(directory).toBeDefined();
  1729. expect(directory.isFile).toBe(false);
  1730. expect(directory.isDirectory).toBe(true);
  1731. expect(directory.fullPath).toCanonicallyMatch(dstPath);
  1732. expect(directory.name).toCanonicallyMatch(dstDir);
  1733. // check that moved file exists in destination dir
  1734. directory.getFile(file1, {
  1735. create: false
  1736. }, function (fileEntry) {
  1737. expect(fileEntry).toBeDefined();
  1738. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  1739. // check that the moved file no longer exists in original dir
  1740. root.getFile(file1, {
  1741. create: false
  1742. }, succeed.bind(null, done, 'directory.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {
  1743. expect(error).toBeDefined();
  1744. if (isChrome) {
  1745. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  1746. } else {
  1747. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1748. }
  1749. // cleanup
  1750. deleteEntry(srcDir, function () {
  1751. deleteEntry(dstDir, done);
  1752. });
  1753. });
  1754. }, failed.bind(null, done, 'directory.getFile - Error getting file : ' + file1 + ' from: ' + srcDir));
  1755. }, failed.bind(null, done, 'entry.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));
  1756. }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));
  1757. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1758. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
  1759. });
  1760. it('file.spec.69 moveTo: directory to new parent', function (done) {
  1761. if (isIndexedDBShim) {
  1762. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1763. pending();
  1764. }
  1765. var file1 = 'file1';
  1766. var srcDir = 'entry.move.dnp.srcDir';
  1767. var dstDir = 'entry.move.dnp.dstDir';
  1768. var dstPath = joinURL(root.fullPath, dstDir);
  1769. var filePath = joinURL(dstPath, file1);
  1770. // ensure destination directory is cleaned up before it
  1771. deleteEntry(dstDir, function () {
  1772. // create a new directory entry to kick off it
  1773. createDirectory(srcDir, function (directory) {
  1774. // create a file within directory
  1775. directory.getFile(file1, {
  1776. create: true
  1777. }, function () {
  1778. // move srcDir to dstDir
  1779. directory.moveTo(root, dstDir, function (dirEntry) {
  1780. expect(dirEntry).toBeDefined();
  1781. expect(dirEntry.isFile).toBe(false);
  1782. expect(dirEntry.isDirectory).toBe(true);
  1783. expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);
  1784. expect(dirEntry.name).toCanonicallyMatch(dstDir);
  1785. // test that moved file exists in destination dir
  1786. dirEntry.getFile(file1, {
  1787. create: false
  1788. }, function (fileEntry) {
  1789. expect(fileEntry).toBeDefined();
  1790. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  1791. // test that the moved file no longer exists in original dir
  1792. root.getFile(file1, {
  1793. create: false
  1794. }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {
  1795. expect(error).toBeDefined();
  1796. if (isChrome) {
  1797. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  1798. } else {
  1799. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  1800. }
  1801. // cleanup
  1802. deleteEntry(srcDir, function () {
  1803. deleteEntry(dstDir, done);
  1804. });
  1805. });
  1806. }, failed.bind(null, done, 'directory.getFile - Error getting file : ' + file1 + ' from: ' + dstDir));
  1807. }, failed.bind(null, done, 'directory.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));
  1808. }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));
  1809. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1810. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
  1811. });
  1812. it('file.spec.131 moveTo: directories tree to new parent', function (done) {
  1813. if (isIndexedDBShim) {
  1814. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1815. pending();
  1816. }
  1817. var srcDir = 'entry.move.dnp.srcDir';
  1818. var srcDirNestedFirst = 'entry.move.dnp.srcDir.Nested1';
  1819. var srcDirNestedSecond = 'entry.move.dnp.srcDir.Nested2';
  1820. var dstDir = 'entry.move.dnp.dstDir';
  1821. createDirectory(dstDir, function (dstDirectory) {
  1822. createDirectory(srcDir, function (srcDirectory) {
  1823. srcDirectory.getDirectory(srcDirNestedFirst, { create: true }, function () {
  1824. srcDirectory.getDirectory(srcDirNestedSecond, { create: true }, function () {
  1825. srcDirectory.moveTo(dstDirectory, srcDir, function successMove (transferredDirectory) {
  1826. var directoryReader = transferredDirectory.createReader();
  1827. directoryReader.readEntries(function successRead (entries) {
  1828. expect(entries.length).toBe(2);
  1829. if (!isChrome) {
  1830. expect(entries[0].name).toBe(srcDirNestedFirst);
  1831. expect(entries[1].name).toBe(srcDirNestedSecond);
  1832. }
  1833. deleteEntry(dstDir, done);
  1834. }, failed.bind(null, done, 'Error getting entries from: ' + transferredDirectory));
  1835. }, failed.bind(null, done, 'directory.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));
  1836. }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + srcDirNestedSecond));
  1837. }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + srcDirNestedFirst));
  1838. }, failed.bind(null, done, 'createDirectory - Error creating source directory : ' + srcDir));
  1839. }, failed.bind(null, done, 'createDirectory - Error creating dest directory : ' + dstDir));
  1840. });
  1841. it('file.spec.70 moveTo: directory onto itself', function (done) {
  1842. if (isIndexedDBShim) {
  1843. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1844. pending();
  1845. }
  1846. var file1 = 'file1';
  1847. var srcDir = 'entry.move.dos.srcDir';
  1848. var srcPath = joinURL(root.fullPath, srcDir);
  1849. var filePath = joinURL(srcPath, file1);
  1850. // create a new directory entry to kick off it
  1851. createDirectory(srcDir, function (directory) {
  1852. // create a file within new directory
  1853. directory.getFile(file1, {
  1854. create: true
  1855. }, function () {
  1856. // move srcDir onto itself
  1857. directory.moveTo(root, null, succeed.bind(null, done, 'directory.moveTo - Unexpected success callback, it should not move directory to invalid path'), function (error) {
  1858. expect(error).toBeDefined();
  1859. if (isChrome) {
  1860. // chrome returns unknown error with code 13
  1861. } else {
  1862. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  1863. }
  1864. // test that original dir still exists
  1865. root.getDirectory(srcDir, {
  1866. create: false
  1867. }, function (dirEntry) {
  1868. // returning confirms existence so just check fullPath entry
  1869. expect(dirEntry).toBeDefined();
  1870. expect(dirEntry.fullPath).toCanonicallyMatch(srcPath);
  1871. dirEntry.getFile(file1, {
  1872. create: false
  1873. }, function (fileEntry) {
  1874. expect(fileEntry).toBeDefined();
  1875. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  1876. // cleanup
  1877. deleteEntry(srcDir, done);
  1878. }, failed.bind(null, done, 'dirEntry.getFile - Error getting file : ' + file1 + ' from: ' + srcDir));
  1879. }, failed.bind(null, done, 'root.getDirectory - Error getting directory : ' + srcDir));
  1880. });
  1881. }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));
  1882. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1883. });
  1884. it('file.spec.71 moveTo: directory into itself', function (done) {
  1885. if (isIndexedDBShim) {
  1886. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1887. pending();
  1888. }
  1889. var srcDir = 'entry.move.dis.srcDir';
  1890. var dstDir = 'entry.move.dis.dstDir';
  1891. var srcPath = joinURL(root.fullPath, srcDir);
  1892. // create a new directory entry to kick off it
  1893. createDirectory(srcDir, function (directory) {
  1894. // move source directory into itself
  1895. directory.moveTo(directory, dstDir, succeed.bind(null, done, 'directory.moveTo - Unexpected success callback, it should not move a directory into itself: ' + srcDir), function (error) {
  1896. expect(error).toBeDefined();
  1897. if (isChrome) {
  1898. // chrome returns unknown error with code 13
  1899. } else {
  1900. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  1901. }
  1902. // make sure original directory still exists
  1903. root.getDirectory(srcDir, {
  1904. create: false
  1905. }, function (entry) {
  1906. expect(entry).toBeDefined();
  1907. expect(entry.fullPath).toCanonicallyMatch(srcPath);
  1908. // cleanup
  1909. deleteEntry(srcDir, done);
  1910. }, failed.bind(null, done, 'root.getDirectory - Error getting directory, making sure that original directory still exists: ' + srcDir));
  1911. });
  1912. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1913. });
  1914. it('file.spec.130 moveTo: directory into similar directory', function (done) {
  1915. if (isIndexedDBShim) {
  1916. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  1917. pending();
  1918. }
  1919. var srcDir = 'entry.move.dis.srcDir';
  1920. var dstDir = 'entry.move.dis.srcDir-backup';
  1921. // create a new directory entry to kick off it
  1922. createDirectory(srcDir, function (srcDirEntry) {
  1923. deleteEntry(dstDir, function () {
  1924. createDirectory(dstDir, function (dstDirEntry) {
  1925. // move source directory into itself
  1926. srcDirEntry.moveTo(dstDirEntry, 'file', function (newDirEntry) {
  1927. expect(newDirEntry).toBeDefined();
  1928. deleteEntry(dstDir, done);
  1929. }, failed.bind(null, done, 'directory.moveTo - Error moving a directory into a similarly-named directory: ' + srcDir));
  1930. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dstDir));
  1931. }, failed.bind(null, done, 'deleteEntry - Error deleting directory : ' + dstDir));
  1932. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  1933. });
  1934. it('file.spec.72 moveTo: file onto itself', function (done) {
  1935. var file1 = 'entry.move.fos.file1';
  1936. var filePath = joinURL(root.fullPath, file1);
  1937. // create a new file entry to kick off it
  1938. createFile(file1, function (entry) {
  1939. // move file1 onto itself
  1940. entry.moveTo(root, null, succeed.bind(null, done, 'entry.moveTo - Unexpected success callback, it should not move a file: ' + file1 + ' into the same parent'), function (error) {
  1941. expect(error).toBeDefined();
  1942. if (isChrome) {
  1943. // chrome returns unknown error with code 13
  1944. } else {
  1945. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  1946. }
  1947. // test that original file still exists
  1948. root.getFile(file1, {
  1949. create: false
  1950. }, function (fileEntry) {
  1951. expect(fileEntry).toBeDefined();
  1952. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  1953. // cleanup
  1954. deleteEntry(file1, done);
  1955. }, failed.bind(null, done, 'root.getFile - Error getting file, making sure that original file still exists: ' + file1));
  1956. });
  1957. }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));
  1958. });
  1959. it('file.spec.73 moveTo: file onto existing directory', function (done) {
  1960. var file1 = 'entry.move.fod.file1';
  1961. var dstDir = 'entry.move.fod.dstDir';
  1962. var subDir = 'subDir';
  1963. var dirPath = joinURL(joinURL(root.fullPath, dstDir), subDir);
  1964. var filePath = joinURL(root.fullPath, file1);
  1965. // ensure destination directory is cleaned up before it
  1966. deleteEntry(dstDir, function () {
  1967. // create a new file entry to kick off it
  1968. createFile(file1, function (entry) {
  1969. // create top level directory
  1970. root.getDirectory(dstDir, {
  1971. create: true
  1972. }, function (directory) {
  1973. // create sub-directory
  1974. directory.getDirectory(subDir, {
  1975. create: true
  1976. }, function (subDirectory) {
  1977. // move file1 onto sub-directory
  1978. entry.moveTo(directory, subDir, succeed.bind(null, done, 'entry.moveTo - Unexpected success callback, it should not move a file: ' + file1 + ' into directory: ' + dstDir + '\n' + subDir + ' directory already exists'), function (error) {
  1979. expect(error).toBeDefined();
  1980. if (isChrome) {
  1981. // chrome returns unknown error with code 13
  1982. } else {
  1983. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  1984. }
  1985. // check that original dir still exists
  1986. directory.getDirectory(subDir, {
  1987. create: false
  1988. }, function (dirEntry) {
  1989. expect(dirEntry).toBeDefined();
  1990. expect(dirEntry.fullPath).toCanonicallyMatch(dirPath);
  1991. // check that original file still exists
  1992. root.getFile(file1, {
  1993. create: false
  1994. }, function (fileEntry) {
  1995. expect(fileEntry).toBeDefined();
  1996. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  1997. // cleanup
  1998. deleteEntry(file1, function () {
  1999. deleteEntry(dstDir, done);
  2000. });
  2001. }, failed.bind(null, done, 'root.getFile - Error getting file, making sure that original file still exists: ' + file1));
  2002. }, failed.bind(null, done, 'directory.getDirectory - Error getting directory, making sure that original directory still exists: ' + subDir));
  2003. });
  2004. }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + subDir));
  2005. }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dstDir));
  2006. }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));
  2007. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
  2008. });
  2009. it('file.spec.74 moveTo: directory onto existing file', function (done) {
  2010. if (isIndexedDBShim) {
  2011. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  2012. pending();
  2013. }
  2014. var file1 = 'entry.move.dof.file1';
  2015. var srcDir = 'entry.move.dof.srcDir';
  2016. var dirPath = joinURL(root.fullPath, srcDir);
  2017. var filePath = joinURL(root.fullPath, file1);
  2018. // create a new directory entry to kick off it
  2019. createDirectory(srcDir, function (entry) {
  2020. // create file
  2021. root.getFile(file1, {
  2022. create: true
  2023. }, function (fileEntry) {
  2024. // move directory onto file
  2025. entry.moveTo(root, file1, succeed.bind(null, done, 'entry.moveTo - Unexpected success callback, it should not move : \n' + srcDir + ' into root directory renamed as ' + file1 + '\n' + file1 + ' file already exists'), function (error) {
  2026. expect(error).toBeDefined();
  2027. if (isChrome) {
  2028. // chrome returns unknown error with code 13
  2029. } else {
  2030. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  2031. }
  2032. // test that original directory exists
  2033. root.getDirectory(srcDir, {
  2034. create: false
  2035. }, function (dirEntry) {
  2036. // returning confirms existence so just check fullPath entry
  2037. expect(dirEntry).toBeDefined();
  2038. expect(dirEntry.fullPath).toCanonicallyMatch(dirPath);
  2039. // test that original file exists
  2040. root.getFile(file1, {
  2041. create: false
  2042. }, function (fileEntry) {
  2043. expect(fileEntry).toBeDefined();
  2044. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  2045. // cleanup
  2046. deleteEntry(file1, function () {
  2047. deleteEntry(srcDir, done);
  2048. });
  2049. }, failed.bind(null, done, 'root.getFile - Error getting file, making sure that original file still exists: ' + file1));
  2050. }, failed.bind(null, done, 'directory.getDirectory - Error getting directory, making sure that original directory still exists: ' + srcDir));
  2051. });
  2052. }, failed.bind(null, done, 'root.getFile - Error creating file : ' + file1));
  2053. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  2054. });
  2055. it('file.spec.75 copyTo: directory onto existing file', function (done) {
  2056. if (isIndexedDBShim) {
  2057. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  2058. pending();
  2059. }
  2060. var file1 = 'entry.copy.dof.file1';
  2061. var srcDir = 'entry.copy.dof.srcDir';
  2062. var dirPath = joinURL(root.fullPath, srcDir);
  2063. var filePath = joinURL(root.fullPath, file1);
  2064. // create a new directory entry to kick off it
  2065. createDirectory(srcDir, function (entry) {
  2066. // create file
  2067. root.getFile(file1, {
  2068. create: true
  2069. }, function () {
  2070. // copy directory onto file
  2071. entry.copyTo(root, file1, succeed.bind(null, done, 'entry.copyTo - Unexpected success callback, it should not copy : \n' + srcDir + ' into root directory renamed as ' + file1 + '\n' + file1 + ' file already exists'), function (error) {
  2072. expect(error).toBeDefined();
  2073. if (isChrome) {
  2074. // chrome returns unknown error with code 13
  2075. } else {
  2076. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  2077. }
  2078. // check that original dir still exists
  2079. root.getDirectory(srcDir, {
  2080. create: false
  2081. }, function (dirEntry) {
  2082. // returning confirms existence so just check fullPath entry
  2083. expect(dirEntry).toBeDefined();
  2084. expect(dirEntry.fullPath).toCanonicallyMatch(dirPath);
  2085. // test that original file still exists
  2086. root.getFile(file1, {
  2087. create: false
  2088. }, function (fileEntry) {
  2089. expect(fileEntry).toBeDefined();
  2090. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  2091. // cleanup
  2092. deleteEntry(file1, function () {
  2093. deleteEntry(srcDir, done);
  2094. });
  2095. }, failed.bind(null, done, 'root.getFile - Error getting file, making sure that original file still exists: ' + file1));
  2096. }, failed.bind(null, done, 'root.getDirectory - Error getting directory, making sure that original directory still exists: ' + srcDir));
  2097. });
  2098. }, failed.bind(null, done, 'root.getFile - Error creating file : ' + file1));
  2099. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  2100. });
  2101. it('file.spec.76 moveTo: directory onto directory that is not empty', function (done) {
  2102. if (isIndexedDBShim) {
  2103. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  2104. pending();
  2105. }
  2106. var srcDir = 'entry.move.dod.srcDir';
  2107. var dstDir = 'entry.move.dod.dstDir';
  2108. var subDir = 'subDir';
  2109. var srcPath = joinURL(root.fullPath, srcDir);
  2110. var dstPath = joinURL(joinURL(root.fullPath, dstDir), subDir);
  2111. // ensure destination directory is cleaned up before it
  2112. deleteEntry(dstDir, function () {
  2113. // create a new file entry to kick off it
  2114. createDirectory(srcDir, function (entry) {
  2115. // create top level directory
  2116. root.getDirectory(dstDir, {
  2117. create: true
  2118. }, function (directory) {
  2119. // create sub-directory
  2120. directory.getDirectory(subDir, {
  2121. create: true
  2122. }, function () {
  2123. // move srcDir onto dstDir (not empty)
  2124. entry.moveTo(root, dstDir, succeed.bind(null, done, 'entry.moveTo - Unexpected success callback, it should not copy : \n' + srcDir + ' into root directory renamed as ' + dstDir + '\n' + dstDir + ' directory already exists'), function (error) {
  2125. expect(error).toBeDefined();
  2126. if (isChrome) {
  2127. // chrome returns unknown error with code 13
  2128. } else {
  2129. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  2130. }
  2131. // making sure destination directory still exists
  2132. directory.getDirectory(subDir, {
  2133. create: false
  2134. }, function (dirEntry) {
  2135. // returning confirms existence so just check fullPath entry
  2136. expect(dirEntry).toBeDefined();
  2137. expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);
  2138. // making sure source directory exists
  2139. root.getDirectory(srcDir, {
  2140. create: false
  2141. }, function (srcEntry) {
  2142. expect(srcEntry).toBeDefined();
  2143. expect(srcEntry.fullPath).toCanonicallyMatch(srcPath);
  2144. // cleanup
  2145. deleteEntry(srcDir, function () {
  2146. deleteEntry(dstDir, done);
  2147. });
  2148. }, failed.bind(null, done, 'root.getDirectory - Error getting directory, making sure that original directory still exists: ' + srcDir));
  2149. }, failed.bind(null, done, 'directory.getDirectory - Error getting directory, making sure that original directory still exists: ' + subDir));
  2150. });
  2151. }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + subDir));
  2152. }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + subDir));
  2153. }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
  2154. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
  2155. });
  2156. it('file.spec.77 moveTo: file replace existing file', function (done) {
  2157. var file1 = 'entry.move.frf.file1';
  2158. var file2 = 'entry.move.frf.file2';
  2159. var file2Path = joinURL(root.fullPath, file2);
  2160. // create a new directory entry to kick off it
  2161. createFile(file1, function (entry) {
  2162. // create file
  2163. root.getFile(file2, {
  2164. create: true
  2165. }, function () {
  2166. // replace file2 with file1
  2167. entry.moveTo(root, file2, function (entry2) {
  2168. expect(entry2).toBeDefined();
  2169. expect(entry2.isFile).toBe(true);
  2170. expect(entry2.isDirectory).toBe(false);
  2171. expect(entry2.fullPath).toCanonicallyMatch(file2Path);
  2172. expect(entry2.name).toCanonicallyMatch(file2);
  2173. // old file should not exists
  2174. root.getFile(file1, {
  2175. create: false
  2176. }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, file: ' + file1 + ' should not exists'), function (error) {
  2177. expect(error).toBeDefined();
  2178. if (isChrome) {
  2179. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  2180. } else {
  2181. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  2182. }
  2183. // test that new file exists
  2184. root.getFile(file2, {
  2185. create: false
  2186. }, function (fileEntry) {
  2187. expect(fileEntry).toBeDefined();
  2188. expect(fileEntry.fullPath).toCanonicallyMatch(file2Path);
  2189. // cleanup
  2190. deleteEntry(file1, function () {
  2191. deleteEntry(file2, done);
  2192. });
  2193. }, failed.bind(null, done, 'root.getFile - Error getting moved file: ' + file2));
  2194. });
  2195. }, failed.bind(null, done, 'entry.moveTo - Error moving file : ' + file1 + ' to root as: ' + file2));
  2196. }, failed.bind(null, done, 'root.getFile - Error creating file: ' + file2));
  2197. }, failed.bind(null, done, 'createFile - Error creating file: ' + file1));
  2198. });
  2199. it('file.spec.78 moveTo: directory replace empty directory', function (done) {
  2200. if (isIndexedDBShim) {
  2201. /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */
  2202. pending();
  2203. }
  2204. var file1 = 'file1';
  2205. var srcDir = 'entry.move.drd.srcDir';
  2206. var dstDir = 'entry.move.drd.dstDir';
  2207. var dstPath = joinURL(root.fullPath, dstDir);
  2208. var filePath = dstPath + '/' + file1;
  2209. // ensure destination directory is cleaned up before it
  2210. deleteEntry(dstDir, function () {
  2211. // create a new directory entry to kick off it
  2212. createDirectory(srcDir, function (directory) {
  2213. // create a file within source directory
  2214. directory.getFile(file1, {
  2215. create: true
  2216. }, function () {
  2217. // create destination directory
  2218. root.getDirectory(dstDir, {
  2219. create: true
  2220. }, function () {
  2221. // move srcDir to dstDir
  2222. directory.moveTo(root, dstDir, function (dirEntry) {
  2223. expect(dirEntry).toBeDefined();
  2224. expect(dirEntry.isFile).toBe(false);
  2225. expect(dirEntry.isDirectory).toBe(true);
  2226. expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);
  2227. expect(dirEntry.name).toCanonicallyMatch(dstDir);
  2228. // check that old directory contents have been moved
  2229. dirEntry.getFile(file1, {
  2230. create: false
  2231. }, function (fileEntry) {
  2232. expect(fileEntry).toBeDefined();
  2233. expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
  2234. // check that old directory no longer exists
  2235. root.getDirectory(srcDir, {
  2236. create: false
  2237. }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, directory: ' + srcDir + ' should not exists'), function (error) {
  2238. expect(error).toBeDefined();
  2239. if (isChrome) {
  2240. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  2241. } else {
  2242. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  2243. }
  2244. // cleanup
  2245. deleteEntry(srcDir, function () {
  2246. deleteEntry(dstDir, done);
  2247. });
  2248. });
  2249. }, failed.bind(null, done, 'dirEntry.getFile - Error getting moved file: ' + file1));
  2250. }, failed.bind(null, done, 'entry.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));
  2251. }, failed.bind(null, done, 'root.getDirectory - Error creating directory: ' + dstDir));
  2252. }, failed.bind(null, done, 'root.getFile - Error creating file: ' + file1));
  2253. }, failed.bind(null, done, 'createDirectory - Error creating directory: ' + srcDir));
  2254. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
  2255. });
  2256. it('file.spec.79 moveTo: directory that does not exist', function (done) {
  2257. if (isChrome) {
  2258. pending('chrome freak out about non-existend dir not being a DirectoryEntry');
  2259. }
  2260. var file1 = 'entry.move.dnf.file1';
  2261. var dstDir = 'entry.move.dnf.dstDir';
  2262. var dstPath = joinURL(root.fullPath, dstDir);
  2263. // create a new file entry to kick off it
  2264. createFile(file1, function (entry) {
  2265. // move file to directory that does not exist
  2266. var directory = new DirectoryEntry(); // eslint-disable-line no-undef
  2267. directory.filesystem = root.filesystem;
  2268. directory.fullPath = dstPath;
  2269. entry.moveTo(directory, null, succeed.bind(null, done, 'entry.moveTo - Unexpected success callback, parent directory: ' + dstPath + ' should not exists'), function (error) {
  2270. expect(error).toBeDefined();
  2271. if (isChrome) {
  2272. /* INVALID_MODIFICATION_ERR (code: 9) is thrown instead of NOT_FOUND_ERR(code: 1)
  2273. on trying to moveTo directory that does not exist. */
  2274. expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR); // eslint-disable-line no-undef
  2275. } else {
  2276. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  2277. }
  2278. // cleanup
  2279. deleteEntry(file1, done);
  2280. });
  2281. }, failed.bind(null, done, 'createFile - Error creating file: ' + file1));
  2282. });
  2283. it('file.spec.80 moveTo: invalid target name', function (done) {
  2284. if (isBrowser) {
  2285. /* The plugin does not follow ["8.3 Naming restrictions"]
  2286. (http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions */
  2287. pending();
  2288. }
  2289. var file1 = 'entry.move.itn.file1';
  2290. var file2 = 'bad:file:name';
  2291. // create a new file entry to kick off it
  2292. createFile(file1, function (entry) {
  2293. // move file1 to file2
  2294. entry.moveTo(root, file2, succeed.bind(null, done, 'entry.moveTo - Unexpected success callback, : ' + file1 + ' to root as: ' + file2), function (error) {
  2295. expect(error).toBeDefined();
  2296. expect(error).toBeFileError(FileError.ENCODING_ERR); // eslint-disable-line no-undef
  2297. // cleanup
  2298. deleteEntry(file1, done);
  2299. });
  2300. }, failed.bind(null, done, 'createFile - Error creating file: ' + file1));
  2301. });
  2302. });
  2303. // Entry
  2304. describe('FileReader', function () {
  2305. it('file.spec.81 should have correct methods', function () {
  2306. var reader = new FileReader(); // eslint-disable-line no-undef
  2307. expect(reader).toBeDefined();
  2308. expect(typeof reader.readAsBinaryString).toBe('function');
  2309. expect(typeof reader.readAsDataURL).toBe('function');
  2310. expect(typeof reader.readAsText).toBe('function');
  2311. expect(typeof reader.readAsArrayBuffer).toBe('function');
  2312. expect(typeof reader.abort).toBe('function');
  2313. expect(reader.result).toBe(null);
  2314. });
  2315. });
  2316. // FileReader
  2317. describe('Read method', function () {
  2318. it('file.spec.82 should error out on non-existent file', function (done) {
  2319. var fileName = cordova.platformId === 'windowsphone' ? root.toURL() + '/' + 'somefile.txt' : 'somefile.txt'; // eslint-disable-line no-undef
  2320. var verifier = function (evt) {
  2321. expect(evt).toBeDefined();
  2322. if (isChrome) {
  2323. expect(evt.target.error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  2324. } else {
  2325. expect(evt.target.error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  2326. }
  2327. done();
  2328. };
  2329. root.getFile(fileName, {
  2330. create: true
  2331. }, function (entry) {
  2332. entry.file(function (file) {
  2333. deleteEntry(fileName, function () {
  2334. // Create FileReader
  2335. var reader = new FileReader(); // eslint-disable-line no-undef
  2336. reader.onerror = verifier;
  2337. reader.onload = succeed.bind(null, done, 'reader.onload - Unexpected success callback, file: ' + fileName + ' it should not exists');
  2338. reader.readAsText(file);
  2339. }, failed.bind(null, done, 'deleteEntry - Error removing file: ' + fileName));
  2340. }, failed.bind(null, done, 'entry.file - Error reading file: ' + fileName));
  2341. }, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));
  2342. });
  2343. it('file.spec.83 should be able to read native blob objects', function (done) {
  2344. // Skip test if blobs are not supported (e.g.: Android 2.3).
  2345. if (typeof window.Blob === 'undefined' || typeof window.Uint8Array === 'undefined') {
  2346. expect(true).toFailWithMessage('Platform does not supported this feature');
  2347. done();
  2348. }
  2349. var contents = 'asdf';
  2350. var uint8Array = new Uint8Array(contents.length);
  2351. for (var i = 0; i < contents.length; ++i) {
  2352. uint8Array[i] = contents.charCodeAt(i);
  2353. }
  2354. var Builder = window.BlobBuilder || window.WebKitBlobBuilder;
  2355. var blob;
  2356. if (Builder) {
  2357. var builder = new Builder();
  2358. builder.append(uint8Array.buffer);
  2359. builder.append(contents);
  2360. blob = builder.getBlob('text/plain');
  2361. } else {
  2362. try {
  2363. // iOS 6 does not support Views, so pass in the buffer.
  2364. blob = new Blob([uint8Array.buffer, contents]); // eslint-disable-line no-undef
  2365. } catch (e) {
  2366. // Skip the test if we can't create a blob (e.g.: iOS 5).
  2367. if (e instanceof TypeError) {
  2368. expect(true).toFailWithMessage('Platform does not supported this feature');
  2369. done();
  2370. }
  2371. throw e;
  2372. }
  2373. }
  2374. var verifier = function (evt) {
  2375. expect(evt).toBeDefined();
  2376. expect(evt.target.result).toBe('asdfasdf');
  2377. done();
  2378. };
  2379. var reader = new FileReader(); // eslint-disable-line no-undef
  2380. reader.onloadend = verifier;
  2381. reader.readAsText(blob);
  2382. });
  2383. function writeDummyFile (writeBinary, callback, done, fileContents) {
  2384. var fileName = 'dummy.txt';
  2385. var fileEntry = null;
  2386. // use default string if file data is not provided
  2387. var fileData = fileContents !== undefined ? fileContents :
  2388. '\u20AC\xEB - There is an exception to every rule. Except this one.';
  2389. var fileDataAsBinaryString = fileContents !== undefined ? fileContents :
  2390. '\xe2\x82\xac\xc3\xab - There is an exception to every rule. Except this one.';
  2391. function createWriter (fe) {
  2392. fileEntry = fe;
  2393. fileEntry.createWriter(writeFile, failed.bind(null, done, 'fileEntry.createWriter - Error reading file: ' + fileName));
  2394. }
  2395. // writes file and reads it back in
  2396. function writeFile (writer) {
  2397. writer.onwriteend = function () {
  2398. fileEntry.file(function (f) {
  2399. callback(fileEntry, f, fileData, fileDataAsBinaryString);
  2400. }, failed.bind(null, done, 'writer.onwriteend - Error writing data on file: ' + fileName));
  2401. };
  2402. writer.write(fileData);
  2403. }
  2404. fileData += writeBinary ? 'bin:\x01\x00' : '';
  2405. fileDataAsBinaryString += writeBinary ? 'bin:\x01\x00' : '';
  2406. // create a file, write to it, and read it in again
  2407. createFile(fileName, createWriter, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2408. }
  2409. function runReaderTest (funcName, writeBinary, done, progressFunc, verifierFunc, sliceStart, sliceEnd, fileContents) {
  2410. writeDummyFile(writeBinary, function (fileEntry, file, fileData, fileDataAsBinaryString) {
  2411. var verifier = function (evt) {
  2412. expect(evt).toBeDefined();
  2413. verifierFunc(evt, fileData, fileDataAsBinaryString);
  2414. };
  2415. var reader = new FileReader(); // eslint-disable-line no-undef
  2416. reader.onprogress = progressFunc;
  2417. reader.onload = verifier;
  2418. reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + file + ' using function: ' + funcName);
  2419. if (sliceEnd !== undefined) {
  2420. // 'type' is specified so that is will be preserved in the resulting file:
  2421. // http://www.w3.org/TR/FileAPI/#slice-method-algo -> "6.4.1. The slice method" -> 4. A), 6. c)
  2422. file = file.slice(sliceStart, sliceEnd, file.type);
  2423. } else if (sliceStart !== undefined) {
  2424. file = file.slice(sliceStart, file.size, file.type);
  2425. }
  2426. reader[funcName](file);
  2427. }, done, fileContents);
  2428. }
  2429. function arrayBufferEqualsString (ab, str) {
  2430. var buf = new Uint8Array(ab);
  2431. var match = buf.length === str.length;
  2432. for (var i = 0; match && i < buf.length; i++) {
  2433. match = buf[i] === str.charCodeAt(i);
  2434. }
  2435. return match;
  2436. }
  2437. it('file.spec.84 should read file properly, readAsText', function (done) {
  2438. runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2439. expect(evt.target.result).toBe(fileData);
  2440. done();
  2441. });
  2442. });
  2443. it('file.spec.84.1 should read JSON file properly, readAsText', function (done) {
  2444. var testObject = {key1: 'value1', key2: 2};
  2445. runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2446. expect(evt.target.result).toEqual(JSON.stringify(testObject));
  2447. done();
  2448. }, undefined, undefined, JSON.stringify(testObject));
  2449. });
  2450. it('file.spec.85 should read file properly, Data URI', function (done) {
  2451. runReaderTest('readAsDataURL', true, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2452. /* `readAsDataURL` function is supported, but the mediatype in Chrome depends on entry name extension,
  2453. mediatype in IE is always empty (which is the same as `text-plain` according the specification),
  2454. the mediatype in Firefox is always `application/octet-stream`.
  2455. For example, if the content is `abcdefg` then Firefox returns `data:application/octet-stream;base64,YWJjZGVmZw==`,
  2456. IE returns `data:;base64,YWJjZGVmZw==`, Chrome returns `data:<mediatype depending on extension of entry name>;base64,YWJjZGVmZw==`. */
  2457. expect(evt.target.result).toBeDataUrl();
  2458. // The atob function it is completely ignored during mobilespec execution, besides the returned object: evt
  2459. // it is encoded and the atob function is aimed to decode a string. Even with btoa (encode) the function it gets stucked
  2460. // because of the Unicode characters that contains the fileData object.
  2461. // Issue reported at JIRA with all the details: CB-7095
  2462. // expect(evt.target.result.slice(23)).toBe(atob(fileData));
  2463. done();
  2464. });
  2465. });
  2466. it('file.spec.86 should read file properly, readAsBinaryString', function (done) {
  2467. if (isIE) {
  2468. /* `readAsBinaryString` function is not supported by IE and has not the stub. */
  2469. pending();
  2470. }
  2471. runReaderTest('readAsBinaryString', true, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2472. expect(evt.target.result).toBe(fileDataAsBinaryString);
  2473. done();
  2474. });
  2475. });
  2476. it('file.spec.87 should read file properly, readAsArrayBuffer', function (done) {
  2477. // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).
  2478. if (typeof window.ArrayBuffer === 'undefined') {
  2479. expect(true).toFailWithMessage('Platform does not supported this feature');
  2480. done();
  2481. }
  2482. runReaderTest('readAsArrayBuffer', true, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2483. expect(arrayBufferEqualsString(evt.target.result, fileDataAsBinaryString)).toBe(true);
  2484. done();
  2485. });
  2486. });
  2487. it('file.spec.88 should read sliced file: readAsText', function (done) {
  2488. runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2489. expect(evt.target.result).toBe(fileDataAsBinaryString.slice(10, 40));
  2490. done();
  2491. }, 10, 40);
  2492. });
  2493. it('file.spec.89 should read sliced file: slice past eof', function (done) {
  2494. runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2495. expect(evt.target.result).toBe(fileData.slice(-5, 9999));
  2496. done();
  2497. }, -5, 9999);
  2498. });
  2499. it('file.spec.90 should read sliced file: slice to eof', function (done) {
  2500. runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2501. expect(evt.target.result).toBe(fileData.slice(-5));
  2502. done();
  2503. }, -5);
  2504. });
  2505. it('file.spec.91 should read empty slice', function (done) {
  2506. runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2507. expect(evt.target.result).toBe('');
  2508. done();
  2509. }, 0, 0);
  2510. });
  2511. it('file.spec.92 should read sliced file properly, readAsDataURL', function (done) {
  2512. runReaderTest('readAsDataURL', true, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2513. /* `readAsDataURL` function is supported, but the mediatype in Chrome depends on entry name extension,
  2514. mediatype in IE is always empty (which is the same as `text-plain` according the specification),
  2515. the mediatype in Firefox is always `application/octet-stream`.
  2516. For example, if the content is `abcdefg` then Firefox returns `data:application/octet-stream;base64,YWJjZGVmZw==`,
  2517. IE returns `data:;base64,YWJjZGVmZw==`, Chrome returns `data:<mediatype depending on extension of entry name>;base64,YWJjZGVmZw==`. */
  2518. expect(evt.target.result).toBeDataUrl();
  2519. // The atob function it is completely ignored during mobilespec execution, besides the returned object: evt
  2520. // it is encoded and the atob function is aimed to decode a string. Even with btoa (encode) the function it gets stucked
  2521. // because of the Unicode characters that contains the fileData object.
  2522. // Issue reported at JIRA with all the details: CB-7095
  2523. // expect(evt.target.result.slice(23)).toBe(atob(fileDataAsBinaryString.slice(10, -3)));
  2524. done();
  2525. }, 10, -3);
  2526. });
  2527. it('file.spec.93 should read sliced file properly, readAsBinaryString', function (done) {
  2528. if (isIE) {
  2529. /* `readAsBinaryString` function is not supported by IE and has not the stub. */
  2530. pending();
  2531. }
  2532. runReaderTest('readAsBinaryString', true, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2533. expect(evt.target.result).toBe(fileDataAsBinaryString.slice(-10, -5));
  2534. done();
  2535. }, -10, -5);
  2536. });
  2537. it('file.spec.94 should read sliced file properly, readAsArrayBuffer', function (done) {
  2538. // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).
  2539. if (typeof window.ArrayBuffer === 'undefined') {
  2540. expect(true).toFailWithMessage('Platform does not supported this feature');
  2541. done();
  2542. }
  2543. runReaderTest('readAsArrayBuffer', true, done, null, function (evt, fileData, fileDataAsBinaryString) {
  2544. expect(arrayBufferEqualsString(evt.target.result, fileDataAsBinaryString.slice(0, -1))).toBe(true);
  2545. done();
  2546. }, 0, -1);
  2547. });
  2548. it('file.spec.94.5 should read large file in multiple chunks, readAsArrayBuffer', function (done) {
  2549. // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).
  2550. if (typeof window.ArrayBuffer === 'undefined') {
  2551. expect(true).toFailWithMessage('Platform does not supported this feature');
  2552. done();
  2553. }
  2554. var largeText = '';
  2555. for (var i = 0; i < 1000; i++) {
  2556. largeText += 'Test ' + i + '\n';
  2557. }
  2558. // Set the chunk size so that the read will take 5 chunks
  2559. FileReader.READ_CHUNK_SIZE = Math.floor(largeText.length / 4) + 1; // eslint-disable-line no-undef
  2560. var chunkCount = 0;
  2561. var lastProgressValue = -1;
  2562. var progressFunc = function (evt) {
  2563. expect(evt.loaded).toBeDefined();
  2564. expect(evt.total).toBeDefined();
  2565. expect(evt.total >= largeText.length).toBe(true);
  2566. expect(evt.total <= largeText.length + 5).toBe(true);
  2567. expect(evt.loaded > lastProgressValue).toBe(true);
  2568. expect(evt.loaded <= evt.total).toBe(true);
  2569. lastProgressValue = evt.loaded;
  2570. chunkCount++;
  2571. };
  2572. runReaderTest(
  2573. 'readAsArrayBuffer', true, done, progressFunc,
  2574. function (evt, fileData, fileDataAsBinaryString) {
  2575. expect(arrayBufferEqualsString(evt.target.result, fileDataAsBinaryString.slice(0, -1))).toBe(true);
  2576. expect(lastProgressValue >= largeText.length).toBe(true);
  2577. expect(lastProgressValue <= largeText.length + 5).toBe(true);
  2578. if (!isChrome) {
  2579. // chrome downloads it in one chunk -.-
  2580. expect(chunkCount).toBe(5);
  2581. }
  2582. done();
  2583. },
  2584. 0, -1, largeText);
  2585. });
  2586. it('file.spec.94.6 should read large file in multiple chunks, readAsDataURL', function (done) {
  2587. var largeText = '';
  2588. for (var i = 0; i < 10; i++) {
  2589. largeText += 'Test ' + i + '\n';
  2590. }
  2591. // Set the chunk size so that the read will take 5 chunks
  2592. FileReader.READ_CHUNK_SIZE = Math.floor(largeText.length / 4) + 1; // eslint-disable-line no-undef
  2593. var lastProgressValue = 0;
  2594. var progressFunc = function (evt) {
  2595. expect(evt.total).toBeDefined();
  2596. expect(evt.total).toEqual(largeText.length);
  2597. expect(evt.loaded).toBeDefined();
  2598. expect(evt.loaded).toBeGreaterThan(lastProgressValue);
  2599. expect(evt.loaded).toBeLessThan(evt.total + 1);
  2600. lastProgressValue = evt.loaded;
  2601. };
  2602. runReaderTest('readAsDataURL', false, done, progressFunc,
  2603. function (evt, fileData, fileDataAsBinaryString) {
  2604. expect(function () {
  2605. // Cut off data uri prefix
  2606. var base64Data = evt.target.result.substring(evt.target.result.indexOf(',') + 1);
  2607. expect(window.atob(base64Data)).toEqual(fileData);
  2608. }).not.toThrow();
  2609. expect(lastProgressValue).toEqual(largeText.length);
  2610. done();
  2611. },
  2612. undefined, undefined, largeText);
  2613. });
  2614. });
  2615. // Read method
  2616. describe('FileWriter', function () {
  2617. it('file.spec.95 should have correct methods', function (done) {
  2618. // retrieve a FileWriter object
  2619. var fileName = 'writer.methods';
  2620. // FileWriter
  2621. root.getFile(fileName, {
  2622. create: true
  2623. }, function (fileEntry) {
  2624. fileEntry.createWriter(function (writer) {
  2625. expect(writer).toBeDefined();
  2626. expect(typeof writer.write).toBe('function');
  2627. expect(typeof writer.seek).toBe('function');
  2628. expect(typeof writer.truncate).toBe('function');
  2629. expect(typeof writer.abort).toBe('function');
  2630. // cleanup
  2631. deleteFile(fileName, done);
  2632. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2633. }, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));
  2634. });
  2635. it('file.spec.96 should be able to write and append to file, createWriter', function (done) {
  2636. var fileName = 'writer.append.createWriter'; // file content
  2637. var content = 'There is an exception to every rule.'; // for checkin file length
  2638. var exception = ' Except this one.';
  2639. var length = content.length;
  2640. // create file, then write and append to it
  2641. createFile(fileName, function (fileEntry) {
  2642. // writes initial file content
  2643. fileEntry.createWriter(function (writer) {
  2644. // Verifiers declaration
  2645. function verifier (evt) {
  2646. expect(writer.length).toBe(length);
  2647. expect(writer.position).toBe(length);
  2648. // Append some more data
  2649. writer.onwriteend = secondVerifier;
  2650. length += exception.length;
  2651. writer.seek(writer.length);
  2652. writer.write(exception);
  2653. }
  2654. function secondVerifier (evt) {
  2655. expect(writer.length).toBe(length);
  2656. expect(writer.position).toBe(length);
  2657. var reader = new FileReader(); // eslint-disable-line no-undef
  2658. reader.onloadend = thirdVerifier;
  2659. reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);
  2660. fileEntry.file(function (f) { reader.readAsText(f); });
  2661. }
  2662. function thirdVerifier (evt) {
  2663. expect(evt.target.result).toBe(content + exception);
  2664. // cleanup
  2665. deleteFile(fileName, done);
  2666. }
  2667. // Write process
  2668. writer.onwriteend = verifier;
  2669. writer.write(content);
  2670. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2671. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2672. });
  2673. it('file.spec.97 should be able to write and append to file, File object', function (done) {
  2674. var fileName = 'writer.append.File'; // file content
  2675. var content = 'There is an exception to every rule.'; // for checkin file length
  2676. var exception = ' Except this one.';
  2677. var length = content.length;
  2678. root.getFile(fileName, {
  2679. create: true
  2680. }, function (fileEntry) {
  2681. fileEntry.createWriter(function (writer) {
  2682. // Verifiers declaration
  2683. function verifier () {
  2684. expect(writer.length).toBe(length);
  2685. expect(writer.position).toBe(length);
  2686. // Append some more data
  2687. writer.onwriteend = secondVerifier;
  2688. length += exception.length;
  2689. writer.seek(writer.length);
  2690. writer.write(exception);
  2691. }
  2692. function secondVerifier () {
  2693. expect(writer.length).toBe(length);
  2694. expect(writer.position).toBe(length);
  2695. var reader = new FileReader(); // eslint-disable-line no-undef
  2696. reader.onloadend = thirdVerifier;
  2697. reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);
  2698. fileEntry.file(function (f) { reader.readAsText(f); });
  2699. }
  2700. function thirdVerifier (evt) {
  2701. expect(evt.target.result).toBe(content + exception);
  2702. // cleanup
  2703. deleteFile(fileName, done);
  2704. }
  2705. // Write process
  2706. writer.onwriteend = verifier;
  2707. writer.write(content);
  2708. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2709. }, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));
  2710. });
  2711. it('file.spec.98 should be able to seek to the middle of the file and write more data than file.length', function (done) {
  2712. var fileName = 'writer.seek.write'; // file content
  2713. var content = 'This is our sentence.'; // for checking file length
  2714. var exception = 'newer sentence.';
  2715. var length = content.length;
  2716. // create file, then write and append to it
  2717. createFile(fileName, function (fileEntry) {
  2718. fileEntry.createWriter(function (writer) {
  2719. // Verifiers declaration
  2720. function verifier (evt) {
  2721. expect(writer.length).toBe(length);
  2722. expect(writer.position).toBe(length);
  2723. // Append some more data
  2724. writer.onwriteend = secondVerifier;
  2725. length = 12 + exception.length;
  2726. writer.seek(12);
  2727. writer.write(exception);
  2728. }
  2729. function secondVerifier (evt) {
  2730. expect(writer.length).toBe(length);
  2731. expect(writer.position).toBe(length);
  2732. var reader = new FileReader(); // eslint-disable-line no-undef
  2733. reader.onloadend = thirdVerifier;
  2734. reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);
  2735. fileEntry.file(function (f) { reader.readAsText(f); });
  2736. }
  2737. function thirdVerifier (evt) {
  2738. expect(evt.target.result).toBe(content.substr(0, 12) + exception);
  2739. // cleanup
  2740. deleteFile(fileName, done);
  2741. }
  2742. // Write process
  2743. writer.onwriteend = verifier;
  2744. writer.write(content);
  2745. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2746. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2747. });
  2748. it('file.spec.99 should be able to seek to the middle of the file and write less data than file.length', function (done) {
  2749. if (isBrowser) {
  2750. /* Browser (re)writes as follows: "This is our sentence." -> "This is new.sentence.",
  2751. i.e. the length is not being changed from content.length and writer length will be equal 21 */
  2752. pending();
  2753. }
  2754. var fileName = 'writer.seek.write2'; // file content
  2755. var content = 'This is our sentence.'; // for checking file length
  2756. var exception = 'new.';
  2757. var length = content.length;
  2758. // create file, then write and append to it
  2759. createFile(fileName, function (fileEntry) {
  2760. fileEntry.createWriter(function (writer) {
  2761. // Verifiers declaration
  2762. function verifier (evt) {
  2763. expect(writer.length).toBe(length);
  2764. expect(writer.position).toBe(length);
  2765. // Append some more data
  2766. writer.onwriteend = secondVerifier;
  2767. length = 8 + exception.length;
  2768. writer.seek(8);
  2769. writer.write(exception);
  2770. }
  2771. function secondVerifier (evt) {
  2772. expect(writer.length).toBe(length);
  2773. expect(writer.position).toBe(length);
  2774. var reader = new FileReader(); // eslint-disable-line no-undef
  2775. reader.onloadend = thirdVerifier;
  2776. reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);
  2777. fileEntry.file(function (f) { reader.readAsText(f); });
  2778. }
  2779. function thirdVerifier (evt) {
  2780. expect(evt.target.result).toBe(content.substr(0, 8) + exception);
  2781. // cleanup
  2782. deleteFile(fileName, done);
  2783. }
  2784. // Write process
  2785. writer.onwriteend = verifier;
  2786. writer.write(content);
  2787. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2788. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2789. });
  2790. it('file.spec.100 should be able to write XML data', function (done) {
  2791. var fileName = 'writer.xml'; // file content
  2792. var content = '<?xml version="1.0" encoding="UTF-8"?>\n<test prop="ack">\nData\n</test>\n'; // for testing file length
  2793. var length = content.length;
  2794. // creates file, then write XML data
  2795. createFile(fileName, function (fileEntry) {
  2796. fileEntry.createWriter(function (writer) {
  2797. // Verifier content
  2798. var verifier = function (evt) {
  2799. expect(writer.length).toBe(length);
  2800. expect(writer.position).toBe(length);
  2801. // cleanup
  2802. deleteFile(fileName, done);
  2803. };
  2804. // Write process
  2805. writer.onwriteend = verifier;
  2806. writer.write(content);
  2807. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2808. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2809. });
  2810. it('file.spec.101 should be able to write JSON data', function (done) {
  2811. var fileName = 'writer.json'; // file content
  2812. var content = '{ "name": "Guy Incognito", "email": "here@there.com" }'; // for testing file length
  2813. var length = content.length;
  2814. // creates file, then write JSON content
  2815. createFile(fileName, function (fileEntry) {
  2816. fileEntry.createWriter(function (writer) {
  2817. // Verifier declaration
  2818. var verifier = function (evt) {
  2819. expect(writer.length).toBe(length);
  2820. expect(writer.position).toBe(length);
  2821. // cleanup
  2822. deleteFile(fileName, done);
  2823. };
  2824. // Write process
  2825. writer.onwriteend = verifier;
  2826. writer.write(content);
  2827. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2828. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2829. });
  2830. it('file.spec.102 should be able to seek', function (done) {
  2831. var fileName = 'writer.seek'; // file content
  2832. var content = 'There is an exception to every rule. Except this one.'; // for testing file length
  2833. var length = content.length;
  2834. // creates file, then write JSON content
  2835. createFile(fileName, function (fileEntry) {
  2836. // writes file content and tests writer.seek
  2837. fileEntry.createWriter(function (writer) {
  2838. // Verifier declaration
  2839. var verifier = function () {
  2840. expect(writer.position).toBe(length);
  2841. writer.seek(-5);
  2842. expect(writer.position).toBe(length - 5);
  2843. writer.seek(length + 100);
  2844. expect(writer.position).toBe(length);
  2845. writer.seek(10);
  2846. expect(writer.position).toBe(10);
  2847. // cleanup
  2848. deleteFile(fileName, done);
  2849. };
  2850. // Write process
  2851. writer.onwriteend = verifier;
  2852. writer.seek(-100);
  2853. expect(writer.position).toBe(0);
  2854. writer.write(content);
  2855. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2856. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2857. });
  2858. it('file.spec.103 should be able to truncate', function (done) {
  2859. if (isIndexedDBShim) {
  2860. /* `abort` and `truncate` functions are not supported (Firefox, IE) */
  2861. pending();
  2862. }
  2863. var fileName = 'writer.truncate';
  2864. var content = 'There is an exception to every rule. Except this one.';
  2865. // creates file, writes to it, then truncates it
  2866. createFile(fileName, function (fileEntry) {
  2867. fileEntry.createWriter(function (writer) {
  2868. // Verifier declaration
  2869. var verifier = function () {
  2870. expect(writer.length).toBe(36);
  2871. expect(writer.position).toBe(36);
  2872. // cleanup
  2873. deleteFile(fileName, done);
  2874. };
  2875. // Write process
  2876. writer.onwriteend = function () {
  2877. // Truncate process after write
  2878. writer.onwriteend = verifier;
  2879. writer.truncate(36);
  2880. };
  2881. writer.write(content);
  2882. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2883. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2884. });
  2885. it('file.spec.104 should be able to write binary data from an ArrayBuffer', function (done) {
  2886. // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).
  2887. if (typeof window.ArrayBuffer === 'undefined') {
  2888. expect(true).toFailWithMessage('Platform does not supported this feature');
  2889. done();
  2890. return;
  2891. }
  2892. var fileName = 'bufferwriter.bin'; // file content
  2893. var data = new ArrayBuffer(32);
  2894. var dataView = new Int8Array(data); // for verifying file length
  2895. var length = 32;
  2896. for (var i = 0; i < dataView.length; i++) {
  2897. dataView[i] = i;
  2898. }
  2899. // creates file, then write content
  2900. createFile(fileName, function (fileEntry) {
  2901. // writes file content
  2902. fileEntry.createWriter(function (writer) {
  2903. // Verifier declaration
  2904. var verifier = function () {
  2905. expect(writer.length).toBe(length);
  2906. expect(writer.position).toBe(length);
  2907. // cleanup
  2908. deleteFile(fileName, done);
  2909. };
  2910. // Write process
  2911. writer.onwriteend = verifier;
  2912. writer.write(data);
  2913. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2914. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2915. });
  2916. it('file.spec.105 should be able to write binary data from a Blob', function (done) {
  2917. // Skip test if Blobs are not supported (e.g.: Android 2.3).
  2918. if ((typeof window.Blob === 'undefined' && typeof window.WebKitBlobBuilder === 'undefined') || typeof window.ArrayBuffer === 'undefined') {
  2919. expect(true).toFailWithMessage('Platform does not supported this feature');
  2920. done();
  2921. return;
  2922. }
  2923. var fileName = 'blobwriter.bin'; // file content
  2924. var data = new ArrayBuffer(32);
  2925. var dataView = new Int8Array(data);
  2926. var blob; // for verifying file length
  2927. var length = 32;
  2928. for (var i = 0; i < dataView.length; i++) {
  2929. dataView[i] = i;
  2930. }
  2931. try {
  2932. // Mobile Safari: Use Blob constructor
  2933. blob = new Blob([data], { // eslint-disable-line no-undef
  2934. 'type': 'application/octet-stream'
  2935. });
  2936. } catch (e) {
  2937. if (window.WebKitBlobBuilder) {
  2938. // Android Browser: Use deprecated BlobBuilder
  2939. var builder = new WebKitBlobBuilder();
  2940. builder.append(data);
  2941. blob = builder.getBlob('application/octet-stream');
  2942. } else {
  2943. // We have no way defined to create a Blob, so fail
  2944. fail();
  2945. }
  2946. }
  2947. if (typeof blob !== 'undefined') {
  2948. // creates file, then write content
  2949. createFile(fileName, function (fileEntry) {
  2950. fileEntry.createWriter(function (writer) {
  2951. // Verifier declaration
  2952. var verifier = function () {
  2953. expect(writer.length).toBe(length);
  2954. expect(writer.position).toBe(length);
  2955. // cleanup
  2956. deleteFile(fileName, done);
  2957. };
  2958. // Write process
  2959. writer.onwriteend = verifier;
  2960. writer.write(blob);
  2961. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2962. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2963. }
  2964. });
  2965. it('file.spec.106 should be able to write a File to a FileWriter', function (done) {
  2966. var dummyFileName = 'dummy.txt';
  2967. var outputFileName = 'verify.txt';
  2968. var dummyFileText = 'This text should be written to two files';
  2969. var verifier = function (outputFileWriter) {
  2970. expect(outputFileWriter.length).toBe(dummyFileText.length);
  2971. expect(outputFileWriter.position).toBe(dummyFileText.length);
  2972. deleteFile(outputFileName, done);
  2973. };
  2974. var writeFile = function (fileName, fileData, win) {
  2975. var theWriter;
  2976. var write_file = function (fileEntry) {
  2977. // writes file content to new file
  2978. fileEntry.createWriter(function (writer) {
  2979. theWriter = writer;
  2980. writer.onwriteend = function (ev) {
  2981. if (typeof fileData.length !== 'undefined') {
  2982. expect(theWriter.length).toBe(fileData.length);
  2983. expect(theWriter.position).toBe(fileData.length);
  2984. }
  2985. win(theWriter);
  2986. };
  2987. writer.onerror = failed.bind(null, done, 'writer.onerror - Error writing content on file: ' + fileName);
  2988. writer.write(fileData);
  2989. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  2990. };
  2991. createFile(fileName, write_file, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  2992. };
  2993. var openFile = function (fileName, callback) {
  2994. root.getFile(fileName, {
  2995. create: false
  2996. }, function (fileEntry) {
  2997. fileEntry.file(callback, failed.bind(null, done, 'fileEntry.file - Error reading file using fileEntry: ' + fileEntry.name));
  2998. }, failed.bind(null, done, 'root.getFile - Error getting file: ' + fileName));
  2999. };
  3000. writeFile(dummyFileName, dummyFileText, function (dummyFileWriter) {
  3001. openFile(dummyFileName, function (file) {
  3002. writeFile(outputFileName, file, verifier);
  3003. });
  3004. });
  3005. });
  3006. it('file.spec.107 should be able to write a sliced File to a FileWriter', function (done) {
  3007. var dummyFileName = 'dummy2.txt';
  3008. var outputFileName = 'verify2.txt';
  3009. var dummyFileText = 'This text should be written to two files';
  3010. var verifier = function (outputFileWriter) {
  3011. expect(outputFileWriter.length).toBe(10);
  3012. expect(outputFileWriter.position).toBe(10);
  3013. deleteFile(outputFileName, done);
  3014. };
  3015. var writeFile = function (fileName, fileData, win) {
  3016. var theWriter;
  3017. var write_file = function (fileEntry) {
  3018. // writes file content to new file
  3019. fileEntry.createWriter(function (writer) {
  3020. theWriter = writer;
  3021. writer.onwriteend = function (ev) {
  3022. if (typeof fileData.length !== 'undefined') {
  3023. expect(theWriter.length).toBe(fileData.length);
  3024. expect(theWriter.position).toBe(fileData.length);
  3025. }
  3026. win(theWriter);
  3027. };
  3028. writer.onerror = failed.bind(null, done, 'writer.onerror - Error writing content on file: ' + fileName);
  3029. writer.write(fileData);
  3030. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  3031. };
  3032. createFile(fileName, write_file, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  3033. };
  3034. var openFile = function (fileName, callback) {
  3035. root.getFile(fileName, {
  3036. create: false
  3037. }, function (fileEntry) {
  3038. fileEntry.file(callback, failed.bind(null, done, 'fileEntry.file - Error reading file using fileEntry: ' + fileEntry.name));
  3039. }, failed.bind(null, done, 'root.getFile - Error getting file: ' + fileName));
  3040. };
  3041. writeFile(dummyFileName, dummyFileText, function (dummyFileWriter) {
  3042. openFile(dummyFileName, function (file) {
  3043. writeFile(outputFileName, file.slice(10, 20), verifier);
  3044. });
  3045. });
  3046. });
  3047. it('file.spec.108 should be able to write binary data from a File', function (done) {
  3048. // Skip test if Blobs are not supported (e.g.: Android 2.3).
  3049. if (typeof window.Blob === 'undefined' && typeof window.WebKitBlobBuilder === 'undefined') {
  3050. expect(true).toFailWithMessage('Platform does not supported this feature');
  3051. done();
  3052. }
  3053. var dummyFileName = 'blobwriter.bin';
  3054. var outputFileName = 'verify.bin'; // file content
  3055. var data = new ArrayBuffer(32);
  3056. var dataView = new Int8Array(data);
  3057. var blob; // for verifying file length
  3058. var length = 32;
  3059. var verifier = function (outputFileWriter) {
  3060. expect(outputFileWriter.length).toBe(length);
  3061. expect(outputFileWriter.position).toBe(length);
  3062. // cleanup
  3063. deleteFile(outputFileName);
  3064. done();
  3065. };
  3066. var writeFile = function (fileName, fileData, win) {
  3067. var theWriter;
  3068. var write_file = function (fileEntry) {
  3069. // writes file content to new file
  3070. fileEntry.createWriter(function (writer) {
  3071. theWriter = writer;
  3072. writer.onwriteend = function (ev) {
  3073. if (typeof fileData.length !== 'undefined') {
  3074. expect(theWriter.length).toBe(fileData.length);
  3075. expect(theWriter.position).toBe(fileData.length);
  3076. }
  3077. win(theWriter);
  3078. };
  3079. writer.onerror = failed.bind(null, done, 'writer.onerror - Error writing content on file: ' + fileName);
  3080. writer.write(fileData);
  3081. }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));
  3082. };
  3083. createFile(fileName, write_file, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  3084. };
  3085. var openFile = function (fileName, callback) {
  3086. root.getFile(fileName, {
  3087. create: false
  3088. }, function (fileEntry) {
  3089. fileEntry.file(callback, failed.bind(null, done, 'fileEntry.file - Error reading file using fileEntry: ' + fileEntry.name));
  3090. }, failed.bind(null, done, 'root.getFile - Error getting file: ' + fileName));
  3091. };
  3092. for (var i = 0; i < dataView.length; i++) {
  3093. dataView[i] = i;
  3094. }
  3095. try {
  3096. // Mobile Safari: Use Blob constructor
  3097. blob = new Blob([data], { // eslint-disable-line no-undef
  3098. 'type': 'application/octet-stream'
  3099. });
  3100. } catch (e) {
  3101. if (window.WebKitBlobBuilder) {
  3102. // Android Browser: Use deprecated BlobBuilder
  3103. var builder = new WebKitBlobBuilder();
  3104. builder.append(data);
  3105. blob = builder.getBlob('application/octet-stream');
  3106. } else {
  3107. // We have no way defined to create a Blob, so fail
  3108. fail();
  3109. }
  3110. }
  3111. if (typeof blob !== 'undefined') {
  3112. // creates file, then write content
  3113. writeFile(dummyFileName, blob, function (dummyFileWriter) {
  3114. openFile(dummyFileName, function (file) {
  3115. writeFile(outputFileName, file, verifier);
  3116. });
  3117. });
  3118. }
  3119. });
  3120. });
  3121. // FileWritter
  3122. describe('Backwards compatibility', function () {
  3123. /* These specs exist to test that the File plugin can still recognize file:///
  3124. * URLs, and can resolve them to FileEntry and DirectoryEntry objects.
  3125. * They rely on an undocumented interface to File which provides absolute file
  3126. * paths, which are not used internally anymore.
  3127. * If that interface is not present, then these tests will silently succeed.
  3128. */
  3129. it('file.spec.109 should be able to resolve a file:/// URL', function (done) {
  3130. var localFilename = 'file.txt';
  3131. var originalEntry;
  3132. root.getFile(localFilename, {
  3133. create: true
  3134. }, function (entry) {
  3135. originalEntry = entry;
  3136. /* This is an undocumented interface to File which exists only for testing
  3137. * backwards compatibilty. By obtaining the raw filesystem path of the download
  3138. * location, we can pass that to ft.download() to make sure that previously-stored
  3139. * paths are still valid.
  3140. */
  3141. cordova.exec(function (localPath) { // eslint-disable-line no-undef
  3142. window.resolveLocalFileSystemURL('file://' + encodeURI(localPath), function (fileEntry) {
  3143. expect(fileEntry.toURL()).toEqual(originalEntry.toURL());
  3144. // cleanup
  3145. deleteFile(localFilename);
  3146. done();
  3147. }, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving URI: file://' + encodeURI(localPath)));
  3148. }, done, 'File', '_getLocalFilesystemPath', [entry.toURL()]);
  3149. }, failed.bind(null, done, 'root.getFile - Error creating file: ' + localFilename));
  3150. });
  3151. });
  3152. // Backwards Compatibility
  3153. describe('Parent References', function () {
  3154. /* These specs verify that paths with parent references i("..") in them
  3155. * work correctly, and do not cause the application to crash.
  3156. */
  3157. it('file.spec.110 should not throw exception resolving parent refefences', function (done) {
  3158. /* This is a direct copy of file.spec.9, with the filename changed, * as reported in CB-5721.
  3159. */
  3160. var fileName = 'resolve.file.uri';
  3161. var dirName = 'resolve.dir.uri';
  3162. // create a new file entry
  3163. createDirectory(dirName, function () {
  3164. createFile(dirName + '/../' + fileName, function (entry) {
  3165. // lookup file system entry
  3166. window.resolveLocalFileSystemURL(entry.toURL(), function (fileEntry) {
  3167. expect(fileEntry).toBeDefined();
  3168. expect(fileEntry.name).toCanonicallyMatch(fileName);
  3169. // cleanup
  3170. deleteEntry(fileName, done);
  3171. }, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving URI: ' + entry.toURL()));
  3172. }, failed.bind(null, done, 'createFile - Error creating file: ../' + fileName));
  3173. }, failed.bind(null, done, 'createDirectory - Error creating directory: ' + dirName));
  3174. });
  3175. it('file.spec.111 should not traverse above above the root directory', function (done) {
  3176. var fileName = 'traverse.file.uri';
  3177. // create a new file entry
  3178. createFile(fileName, function (entry) {
  3179. // lookup file system entry
  3180. root.getFile('../' + fileName, {
  3181. create: false
  3182. }, function (fileEntry) {
  3183. // Note: we expect this to still resolve, as the correct behaviour is to ignore the ../, not to fail out.
  3184. expect(fileEntry).toBeDefined();
  3185. expect(fileEntry.name).toBe(fileName);
  3186. expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + '/' + fileName);
  3187. // cleanup
  3188. deleteEntry(fileName, done);
  3189. }, failed.bind(null, done, 'root.getFile - Error getting file: ../' + fileName));
  3190. }, failed.bind(null, done, 'createFile - Error creating file: ../' + fileName));
  3191. });
  3192. it('file.spec.112 should traverse above above the current directory', function (done) {
  3193. var fileName = 'traverse2.file.uri';
  3194. var dirName = 'traverse2.subdir';
  3195. // create a new directory and a file entry
  3196. createFile(fileName, function () {
  3197. createDirectory(dirName, function (entry) {
  3198. // lookup file system entry
  3199. entry.getFile('../' + fileName, {
  3200. create: false
  3201. }, function (fileEntry) {
  3202. expect(fileEntry).toBeDefined();
  3203. expect(fileEntry.name).toBe(fileName);
  3204. expect(fileEntry.fullPath).toCanonicallyMatch('/' + fileName);
  3205. // cleanup
  3206. deleteEntry(fileName, function () {
  3207. deleteEntry(dirName, done);
  3208. });
  3209. }, failed.bind(null, done, 'entry.getFile - Error getting file: ' + fileName + ' recently created above: ' + dirName));
  3210. }, failed.bind(null, done, 'createDirectory - Error creating directory: ' + dirName));
  3211. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  3212. });
  3213. it('file.spec.113 getFile: get Entry should error for missing file above root directory', function (done) {
  3214. var fileName = '../missing.file';
  3215. // create:false, exclusive:false, file does not exist
  3216. root.getFile(fileName, {
  3217. create: false
  3218. }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not locate nonexistent file: ' + fileName), function (error) {
  3219. expect(error).toBeDefined();
  3220. if (isChrome) {
  3221. expect(error).toBeFileError(FileError.SYNTAX_ERR); // eslint-disable-line no-undef
  3222. } else {
  3223. expect(error).toBeFileError(FileError.NOT_FOUND_ERR); // eslint-disable-line no-undef
  3224. }
  3225. done();
  3226. });
  3227. });
  3228. });
  3229. // Parent References
  3230. describe('toNativeURL interface', function () {
  3231. /* These specs verify that FileEntries have a toNativeURL method
  3232. * which appears to be sane.
  3233. */
  3234. var pathExpect = cordova.platformId === 'windowsphone' ? '//nativ' : 'file://'; // eslint-disable-line no-undef
  3235. if (isChrome) {
  3236. pathExpect = 'filesystem:http://';
  3237. }
  3238. it('file.spec.114 fileEntry should have a toNativeURL method', function (done) {
  3239. var fileName = 'native.file.uri';
  3240. if (isWindows) {
  3241. var rootPath = root.fullPath;
  3242. pathExpect = rootPath.substr(0, rootPath.indexOf(':'));
  3243. }
  3244. // create a new file entry
  3245. createFile(fileName, function (entry) {
  3246. expect(entry.toNativeURL).toBeDefined();
  3247. expect(entry.name).toCanonicallyMatch(fileName);
  3248. expect(typeof entry.toNativeURL).toBe('function');
  3249. var nativeURL = entry.toNativeURL();
  3250. expect(typeof nativeURL).toBe('string');
  3251. expect(nativeURL.substring(0, pathExpect.length)).toEqual(pathExpect);
  3252. expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
  3253. // cleanup
  3254. deleteEntry(fileName, done);
  3255. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  3256. });
  3257. it('file.spec.115 DirectoryReader should return entries with toNativeURL method', function (done) {
  3258. var dirName = 'nativeEntries.dir';
  3259. var fileName = 'nativeEntries.file';
  3260. var directory;
  3261. var checkEntries = function (entries) {
  3262. expect(entries).toBeDefined();
  3263. expect(entries instanceof Array).toBe(true);
  3264. expect(entries.length).toBe(1);
  3265. expect(entries[0].toNativeURL).toBeDefined();
  3266. expect(typeof entries[0].toNativeURL).toBe('function');
  3267. var nativeURL = entries[0].toNativeURL();
  3268. expect(typeof nativeURL).toBe('string');
  3269. expect(nativeURL.substring(0, pathExpect.length)).toEqual(pathExpect);
  3270. expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
  3271. // cleanup
  3272. directory.removeRecursively(function () {}, null);
  3273. done();
  3274. };
  3275. // create a new file entry
  3276. root.getDirectory(dirName, {
  3277. create: true
  3278. }, function (dir) {
  3279. directory = dir;
  3280. directory.getFile(fileName, {
  3281. create: true
  3282. }, function (fileEntry) {
  3283. var reader = directory.createReader();
  3284. reader.readEntries(checkEntries, failed.bind(null, done, 'reader.readEntries - Error reading entries from directory: ' + dirName));
  3285. }, failed.bind(null, done, 'directory.getFile - Error creating file: ' + fileName));
  3286. }, failed.bind(null, done, 'root.getDirectory - Error creating directory: ' + dirName));
  3287. });
  3288. it('file.spec.116 resolveLocalFileSystemURL should return entries with toNativeURL method', function (done) {
  3289. var fileName = 'native.resolve.uri';
  3290. // create a new file entry
  3291. createFile(fileName, function (entry) {
  3292. resolveLocalFileSystemURL(entry.toURL(), function (entry) { // eslint-disable-line no-undef
  3293. expect(entry.toNativeURL).toBeDefined();
  3294. expect(entry.name).toCanonicallyMatch(fileName);
  3295. expect(typeof entry.toNativeURL).toBe('function');
  3296. var nativeURL = entry.toNativeURL();
  3297. expect(typeof nativeURL).toBe('string');
  3298. expect(nativeURL.substring(0, pathExpect.length)).toEqual(pathExpect);
  3299. expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
  3300. // cleanup
  3301. deleteEntry(fileName, done);
  3302. }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + entry.toURL()));
  3303. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  3304. });
  3305. });
  3306. // toNativeURL interface
  3307. describe('resolveLocalFileSystemURL on file://', function () {
  3308. /* These specs verify that window.resolveLocalFileSystemURL works correctly on file:// URLs
  3309. */
  3310. it('file.spec.117 should not resolve native URLs outside of FS roots', function (done) {
  3311. // lookup file system entry
  3312. window.resolveLocalFileSystemURL('file:///this.is.an.invalid.url', succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Unexpected success callback, it should not resolve invalid URL: file:///this.is.an.invalid.url'), function (error) {
  3313. expect(error).toBeDefined();
  3314. done();
  3315. });
  3316. });
  3317. it('file.spec.118 should not resolve native URLs outside of FS roots', function (done) {
  3318. // lookup file system entry
  3319. window.resolveLocalFileSystemURL('file://localhost/this.is.an.invalid.url', succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Unexpected success callback, it should not resolve invalid URL: file://localhost/this.is.an.invalid.url'), function (error) {
  3320. expect(error).toBeDefined();
  3321. done();
  3322. });
  3323. });
  3324. it('file.spec.119 should not resolve invalid native URLs', function (done) {
  3325. // lookup file system entry
  3326. window.resolveLocalFileSystemURL('file://localhost', succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Unexpected success callback, it should not resolve invalid URL: file://localhost'), function (error) {
  3327. expect(error).toBeDefined();
  3328. done();
  3329. });
  3330. });
  3331. it('file.spec.120 should not resolve invalid native URLs with query strings', function (done) {
  3332. // lookup file system entry
  3333. window.resolveLocalFileSystemURL('file://localhost?test/test', succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Unexpected success callback, it should not resolve invalid URL: file://localhost?test/test'), function (error) {
  3334. expect(error).toBeDefined();
  3335. done();
  3336. });
  3337. });
  3338. it('file.spec.121 should resolve native URLs returned by API', function (done) {
  3339. var fileName = 'native.resolve.uri1';
  3340. // create a new file entry
  3341. createFile(fileName, function (entry) {
  3342. /* eslint-disable no-undef */
  3343. resolveLocalFileSystemURL(entry.toNativeURL(), function (fileEntry) {
  3344. expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + '/' + fileName);
  3345. // cleanup
  3346. deleteEntry(fileName, done);
  3347. }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + entry.toNativeURL()));
  3348. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  3349. });
  3350. it('file.spec.122 should resolve native URLs returned by API with localhost', function (done) {
  3351. var fileName = 'native.resolve.uri2';
  3352. // create a new file entry
  3353. createFile(fileName, function (entry) {
  3354. var url = entry.toNativeURL();
  3355. url = url.replace('///', '//localhost/');
  3356. resolveLocalFileSystemURL(url, function (fileEntry) {
  3357. expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + '/' + fileName);
  3358. // cleanup
  3359. deleteEntry(fileName, done);
  3360. }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + url));
  3361. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  3362. });
  3363. it('file.spec.123 should resolve native URLs returned by API with query string', function (done) {
  3364. var fileName = 'native.resolve.uri3';
  3365. // create a new file entry
  3366. createFile(fileName, function (entry) {
  3367. var url = entry.toNativeURL();
  3368. url = url + '?test/test';
  3369. resolveLocalFileSystemURL(url, function (fileEntry) {
  3370. expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + '/' + fileName);
  3371. // cleanup
  3372. deleteEntry(fileName, done);
  3373. }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + url));
  3374. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  3375. });
  3376. it('file.spec.124 should resolve native URLs returned by API with localhost and query string', function (done) {
  3377. var fileName = 'native.resolve.uri4';
  3378. // create a new file entry
  3379. createFile(fileName, function (entry) {
  3380. var url = entry.toNativeURL();
  3381. url = url.replace('///', '//localhost/') + '?test/test';
  3382. resolveLocalFileSystemURL(url, function (fileEntry) {
  3383. /* eslint-enable no-undef */
  3384. expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + '/' + fileName);
  3385. // cleanup
  3386. deleteEntry(fileName, done);
  3387. }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + url));
  3388. }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
  3389. });
  3390. });
  3391. // resolveLocalFileSystemURL on file://
  3392. describe('cross-file-system copy and move', function () {
  3393. /* These specs verify that Entry.copyTo and Entry.moveTo work correctly
  3394. * when crossing filesystem boundaries.
  3395. */
  3396. it('file.spec.125 copyTo: temporary -> persistent', function (done) {
  3397. var file1 = 'entry.copy.file1a';
  3398. var file2 = 'entry.copy.file2a';
  3399. var sourceEntry;
  3400. var fullPath = joinURL(root.fullPath, file2);
  3401. var validateFile = function (entry) {
  3402. // a bit redundant since copy returned this entry already
  3403. expect(entry).toBeDefined();
  3404. expect(entry.isFile).toBe(true);
  3405. expect(entry.isDirectory).toBe(false);
  3406. expect(entry.name).toCanonicallyMatch(file2);
  3407. expect(entry.fullPath).toCanonicallyMatch(fullPath);
  3408. expect(entry.filesystem).toBeDefined();
  3409. if (isChrome) {
  3410. expect(entry.filesystem.name).toContain('Persistent');
  3411. } else {
  3412. expect(entry.filesystem.name).toEqual('persistent');
  3413. }
  3414. // cleanup
  3415. deleteEntry(entry.name);
  3416. deleteEntry(sourceEntry.name, done);
  3417. };
  3418. var createSourceAndTransfer = function () {
  3419. temp_root.getFile(file1, {
  3420. create: true
  3421. }, function (entry) {
  3422. expect(entry.filesystem).toBeDefined();
  3423. if (isChrome) {
  3424. expect(entry.filesystem.name).toContain('Temporary');
  3425. } else {
  3426. expect(entry.filesystem.name).toEqual('temporary');
  3427. }
  3428. sourceEntry = entry;
  3429. // Save for later cleanup
  3430. entry.copyTo(persistent_root, file2, validateFile, failed.bind(null, done, 'entry.copyTo - Error copying file: ' + file1 + ' to PERSISTENT root as: ' + file2));
  3431. }, failed.bind(null, done, 'temp_root.getFile - Error creating file: ' + file1 + 'at TEMPORAL root'));
  3432. };
  3433. // Delete any existing file to start things off
  3434. persistent_root.getFile(file2, {}, function (entry) {
  3435. entry.remove(createSourceAndTransfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));
  3436. }, createSourceAndTransfer);
  3437. });
  3438. it('file.spec.126 copyTo: persistent -> temporary', function (done) {
  3439. var file1 = 'entry.copy.file1b';
  3440. var file2 = 'entry.copy.file2b';
  3441. var sourceEntry;
  3442. var fullPath = joinURL(temp_root.fullPath, file2);
  3443. var validateFile = function (entry) {
  3444. expect(entry).toBeDefined();
  3445. expect(entry.isFile).toBe(true);
  3446. expect(entry.isDirectory).toBe(false);
  3447. expect(entry.name).toCanonicallyMatch(file2);
  3448. expect(entry.fullPath).toCanonicallyMatch(fullPath);
  3449. if (isChrome) {
  3450. expect(entry.filesystem.name).toContain('Temporary');
  3451. } else {
  3452. expect(entry.filesystem.name).toEqual('temporary');
  3453. }
  3454. // cleanup
  3455. deleteEntry(entry.name);
  3456. deleteEntry(sourceEntry.name, done);
  3457. };
  3458. var createSourceAndTransfer = function () {
  3459. persistent_root.getFile(file1, {
  3460. create: true
  3461. }, function (entry) {
  3462. expect(entry).toBeDefined();
  3463. expect(entry.filesystem).toBeDefined();
  3464. if (isChrome) {
  3465. expect(entry.filesystem.name).toContain('Persistent');
  3466. } else {
  3467. expect(entry.filesystem.name).toEqual('persistent');
  3468. }
  3469. sourceEntry = entry;
  3470. // Save for later cleanup
  3471. entry.copyTo(temp_root, file2, validateFile, failed.bind(null, done, 'entry.copyTo - Error copying file: ' + file1 + ' to TEMPORAL root as: ' + file2));
  3472. }, failed.bind(null, done, 'persistent_root.getFile - Error creating file: ' + file1 + 'at PERSISTENT root'));
  3473. };
  3474. // Delete any existing file to start things off
  3475. temp_root.getFile(file2, {}, function (entry) {
  3476. entry.remove(createSourceAndTransfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));
  3477. }, createSourceAndTransfer);
  3478. });
  3479. it('file.spec.127 moveTo: temporary -> persistent', function (done) {
  3480. var file1 = 'entry.copy.file1a';
  3481. var file2 = 'entry.copy.file2a';
  3482. var sourceEntry;
  3483. var fullPath = joinURL(root.fullPath, file2);
  3484. var validateFile = function (entry) {
  3485. // a bit redundant since copy returned this entry already
  3486. expect(entry).toBeDefined();
  3487. expect(entry.isFile).toBe(true);
  3488. expect(entry.isDirectory).toBe(false);
  3489. expect(entry.name).toCanonicallyMatch(file2);
  3490. expect(entry.fullPath).toCanonicallyMatch(fullPath);
  3491. expect(entry.filesystem).toBeDefined();
  3492. if (isChrome) {
  3493. expect(entry.filesystem.name).toContain('Persistent');
  3494. } else {
  3495. expect(entry.filesystem.name).toEqual('persistent');
  3496. }
  3497. // cleanup
  3498. deleteEntry(entry.name);
  3499. deleteEntry(sourceEntry.name, done);
  3500. };
  3501. var createSourceAndTransfer = function () {
  3502. temp_root.getFile(file1, {
  3503. create: true
  3504. }, function (entry) {
  3505. expect(entry.filesystem).toBeDefined();
  3506. if (isChrome) {
  3507. expect(entry.filesystem.name).toContain('Temporary');
  3508. } else {
  3509. expect(entry.filesystem.name).toEqual('temporary');
  3510. }
  3511. sourceEntry = entry;
  3512. // Save for later cleanup
  3513. entry.moveTo(persistent_root, file2, validateFile, failed.bind(null, done, 'entry.moveTo - Error moving file: ' + file1 + ' to PERSISTENT root as: ' + file2));
  3514. }, failed.bind(null, done, 'temp_root.getFile - Error creating file: ' + file1 + 'at TEMPORAL root'));
  3515. };
  3516. // Delete any existing file to start things off
  3517. persistent_root.getFile(file2, {}, function (entry) {
  3518. entry.remove(createSourceAndTransfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));
  3519. }, createSourceAndTransfer);
  3520. });
  3521. it('file.spec.128 moveTo: persistent -> temporary', function (done) {
  3522. var file1 = 'entry.copy.file1b';
  3523. var file2 = 'entry.copy.file2b';
  3524. var sourceEntry;
  3525. var fullPath = joinURL(temp_root.fullPath, file2);
  3526. var validateFile = function (entry) {
  3527. expect(entry).toBeDefined();
  3528. expect(entry.isFile).toBe(true);
  3529. expect(entry.isDirectory).toBe(false);
  3530. expect(entry.name).toCanonicallyMatch(file2);
  3531. expect(entry.fullPath).toCanonicallyMatch(fullPath);
  3532. if (isChrome) {
  3533. expect(entry.filesystem.name).toContain('Temporary');
  3534. } else {
  3535. expect(entry.filesystem.name).toEqual('temporary');
  3536. }
  3537. // cleanup
  3538. deleteEntry(entry.name);
  3539. deleteEntry(sourceEntry.name, done);
  3540. };
  3541. var createSourceAndTransfer = function () {
  3542. persistent_root.getFile(file1, {
  3543. create: true
  3544. }, function (entry) {
  3545. expect(entry).toBeDefined();
  3546. expect(entry.filesystem).toBeDefined();
  3547. if (isChrome) {
  3548. expect(entry.filesystem.name).toContain('Persistent');
  3549. } else {
  3550. expect(entry.filesystem.name).toEqual('persistent');
  3551. }
  3552. sourceEntry = entry;
  3553. // Save for later cleanup
  3554. entry.moveTo(temp_root, file2, validateFile, failed.bind(null, done, 'entry.moveTo - Error moving file: ' + file1 + ' to TEMPORAL root as: ' + file2));
  3555. }, failed.bind(null, done, 'persistent_root.getFile - Error creating file: ' + file1 + 'at PERSISTENT root'));
  3556. };
  3557. // Delete any existing file to start things off
  3558. temp_root.getFile(file2, {}, function (entry) {
  3559. entry.remove(createSourceAndTransfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));
  3560. }, createSourceAndTransfer);
  3561. });
  3562. it('file.spec.129 cordova.file.*Directory are set', function () {
  3563. var expectedPaths = ['applicationDirectory', 'applicationStorageDirectory', 'dataDirectory', 'cacheDirectory'];
  3564. /* eslint-disable no-undef */
  3565. if (cordova.platformId === 'android' || cordova.platformId === 'amazon-fireos') {
  3566. if (cordova.file.externalApplicationStorageDirectory !== null) {
  3567. // https://issues.apache.org/jira/browse/CB-10411
  3568. // If external storage can't be mounted, the cordova.file.external* properties are null.
  3569. expectedPaths.push('externalApplicationStorageDirectory', 'externalRootDirectory', 'externalCacheDirectory', 'externalDataDirectory');
  3570. }
  3571. } else if (cordova.platformId === 'blackberry10') {
  3572. expectedPaths.push('externalRootDirectory', 'sharedDirectory');
  3573. } else if (cordova.platformId === 'ios') {
  3574. expectedPaths.push('syncedDataDirectory', 'documentsDirectory', 'tempDirectory');
  3575. } else if (cordova.platformId === 'osx') {
  3576. expectedPaths.push('documentsDirectory', 'tempDirectory', 'rootDirectory');
  3577. } else {
  3578. console.log('Skipping test due on unsupported platform.');
  3579. return;
  3580. }
  3581. for (var i = 0; i < expectedPaths.length; ++i) {
  3582. expect(typeof cordova.file[expectedPaths[i]]).toBe('string');
  3583. expect(cordova.file[expectedPaths[i]]).toMatch(/\/$/, 'Path should end with a slash');
  3584. }
  3585. });
  3586. });
  3587. describe('resolveLocalFileSystemURL on cdvfile://', function () {
  3588. it('file.spec.147 should be able to resolve cdvfile applicationDirectory fs root', function (done) {
  3589. var cdvfileApplicationDirectoryFsRootName;
  3590. if (cordova.platformId === 'android') {
  3591. cdvfileApplicationDirectoryFsRootName = 'assets';
  3592. } else if (cordova.platformId === 'ios') {
  3593. cdvfileApplicationDirectoryFsRootName = 'bundle';
  3594. } else {
  3595. pending();
  3596. }
  3597. resolveLocalFileSystemURL('cdvfile://localhost/' + cdvfileApplicationDirectoryFsRootName + '/', function (applicationDirectoryRoot) {
  3598. expect(applicationDirectoryRoot.isFile).toBe(false);
  3599. expect(applicationDirectoryRoot.isDirectory).toBe(true);
  3600. expect(applicationDirectoryRoot.name).toCanonicallyMatch('');
  3601. expect(applicationDirectoryRoot.fullPath).toCanonicallyMatch('/');
  3602. expect(applicationDirectoryRoot.filesystem.name).toEqual(cdvfileApplicationDirectoryFsRootName);
  3603. // Requires HelloCordova www assets, <allow-navigation href="cdvfile:*" /> in config.xml or
  3604. // cdvfile: in CSP and <access origin="cdvfile://*" /> in config.xml
  3605. resolveLocalFileSystemURL('cdvfile://localhost/' + cdvfileApplicationDirectoryFsRootName + '/www/img/logo.png', function (entry) {
  3606. /* eslint-enable no-undef */
  3607. expect(entry.isFile).toBe(true);
  3608. expect(entry.isDirectory).toBe(false);
  3609. expect(entry.name).toCanonicallyMatch('logo.png');
  3610. expect(entry.fullPath).toCanonicallyMatch('/www/img/logo.png');
  3611. expect(entry.filesystem.name).toEqual(cdvfileApplicationDirectoryFsRootName);
  3612. var img = new Image(); // eslint-disable-line no-undef
  3613. img.onerror = function (err) {
  3614. expect(err).not.toBeDefined();
  3615. done();
  3616. };
  3617. img.onload = function () {
  3618. done();
  3619. };
  3620. img.src = entry.toInternalURL();
  3621. }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for cdvfile applicationDirectory'));
  3622. }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for cdvfile applicationDirectory'));
  3623. });
  3624. });
  3625. // cross-file-system copy and move
  3626. describe('IndexedDB-based impl', function () {
  3627. it('file.spec.131 Nested file or nested directory should be removed when removing a parent directory', function (done) {
  3628. var parentDirName = 'deletedDir131';
  3629. var nestedDirName = 'nestedDir131';
  3630. var nestedFileName = 'nestedFile131.txt';
  3631. createDirectory(parentDirName, function (parent) {
  3632. parent.getDirectory(nestedDirName, { create: true }, function () {
  3633. parent.getFile(nestedFileName, { create: true }, function () {
  3634. parent.removeRecursively(function () {
  3635. root.getDirectory(parentDirName, { create: false }, failed.bind(this, done, 'root.getDirectory - unexpected success callback : ' + parentDirName), function () {
  3636. parent.getFile(nestedFileName, { create: false }, failed.bind(this, done, 'getFile - unexpected success callback : ' + nestedFileName), function () {
  3637. parent.getDirectory(nestedDirName, { create: false }, failed.bind(this, done, 'getDirectory - unexpected success callback : ' + nestedDirName), done);
  3638. });
  3639. });
  3640. }, failed.bind(this, done, 'removeRecursively - Error removing directory : ' + parentDirName));
  3641. }, failed.bind(this, done, 'getFile - Error creating file : ' + nestedFileName));
  3642. }, failed.bind(this, done, 'getDirectory - Error creating directory : ' + nestedDirName));
  3643. }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + parentDirName));
  3644. });
  3645. it('file.spec.132 Entry should be created succesfully when using relative paths if its parent directory exists', function (done) {
  3646. /* Directory entries have to be created successively.
  3647. For example, the call `fs.root.getDirectory('dir1/dir2', {create:true}, successCallback, errorCallback)`
  3648. will fail if dir1 did not exist. */
  3649. var parentName = 'parentName132';
  3650. var nestedName = 'nestedName132';
  3651. var path = parentName + '/' + nestedName;
  3652. var win = function (directory) {
  3653. expect(directory).toBeDefined();
  3654. expect(directory.isFile).toBe(false);
  3655. expect(directory.isDirectory).toBe(true);
  3656. expect(directory.name).toCanonicallyMatch(nestedName);
  3657. expect(directory.fullPath).toCanonicallyMatch('/' + path + '/');
  3658. deleteEntry(directory.name);
  3659. deleteEntry(parentName, done);
  3660. };
  3661. createDirectory(parentName, function () {
  3662. root.getDirectory(parentName + '/' + nestedName, {create: true}, win,
  3663. failed.bind(this, done, 'root.getDirectory - Error getting directory : ' + path));
  3664. }, failed.bind(this, done, 'root.getDirectory - Error getting directory : ' + parentName));
  3665. });
  3666. it('file.spec.133 A file being removed should not affect another file with name being a prefix of the removed file name.', function (done) {
  3667. // Names include special symbols so that we check the IndexedDB range used
  3668. var deletedFileName = 'deletedFile.0';
  3669. var secondFileName = 'deletedFile.0.1';
  3670. var win = function (fileEntry) {
  3671. expect(fileEntry).toBeDefined();
  3672. expect(fileEntry.isFile).toBe(true);
  3673. expect(fileEntry.isDirectory).toBe(false);
  3674. expect(fileEntry.name).toCanonicallyMatch(secondFileName);
  3675. deleteEntry(fileEntry.name, done);
  3676. };
  3677. createFile(deletedFileName, function (deletedFile) {
  3678. createFile(secondFileName, function () {
  3679. deletedFile.remove(function () {
  3680. root.getFile(deletedFileName, {create: false}, failed.bind(this, done, 'getFile - unexpected success callback getting deleted file : ' + deletedFileName), function () {
  3681. root.getFile(secondFileName, {create: false}, win, failed.bind(this, done, 'getFile - Error getting file after deleting deletedFile : ' + secondFileName));
  3682. });
  3683. }, failed.bind(this, done, 'remove - Error removing file : ' + deletedFileName));
  3684. }, failed.bind(this, done, 'getFile - Error creating file : ' + secondFileName));
  3685. }, failed.bind(this, done, 'getFile - Error creating file : ' + deletedFileName));
  3686. });
  3687. it('file.spec.134 A directory being removed should not affect another directory with name being a prefix of the removed directory name.', function (done) {
  3688. // Names include special symbols so that we check the IndexedDB range used
  3689. var deletedDirName = 'deletedDir.0';
  3690. var secondDirName = 'deletedDir.0.1';
  3691. var win = function (directory) {
  3692. expect(directory).toBeDefined();
  3693. expect(directory.isFile).toBe(false);
  3694. expect(directory.isDirectory).toBe(true);
  3695. expect(directory.name).toCanonicallyMatch(secondDirName);
  3696. deleteEntry(directory.name, done);
  3697. };
  3698. createDirectory(deletedDirName, function (deletedDir) {
  3699. createDirectory(secondDirName, function () {
  3700. deletedDir.remove(function () {
  3701. root.getDirectory(deletedDirName, {create: false}, failed.bind(this, done, 'getDirectory - unexpected success callback getting deleted directory : ' + deletedDirName), function () {
  3702. root.getDirectory(secondDirName, {create: false}, win, failed.bind(this, done, 'getDirectory - Error getting directory after deleting deletedDirectory : ' + secondDirName));
  3703. });
  3704. }, failed.bind(this, done, 'remove - Error removing directory : ' + deletedDirName));
  3705. }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + secondDirName));
  3706. }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + deletedDirName));
  3707. });
  3708. it('file.spec.135 Deletion of a child directory should not affect the parent directory.', function (done) {
  3709. var parentName = 'parentName135';
  3710. var childName = 'childName135';
  3711. var win = function (directory) {
  3712. expect(directory).toBeDefined();
  3713. expect(directory.isFile).toBe(false);
  3714. expect(directory.isDirectory).toBe(true);
  3715. expect(directory.name).toCanonicallyMatch(parentName);
  3716. deleteEntry(directory.name, done);
  3717. };
  3718. createDirectory(parentName, function (parent) {
  3719. parent.getDirectory(childName, {create: true}, function (child) {
  3720. child.removeRecursively(function () {
  3721. root.getDirectory(parentName, {create: false}, win, failed.bind(this, done, 'root.getDirectory - Error getting parent directory : ' + parentName));
  3722. },
  3723. failed.bind(this, done, 'getDirectory - Error removing directory : ' + childName));
  3724. }, failed.bind(this, done, 'getDirectory - Error creating directory : ' + childName));
  3725. }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + parentName));
  3726. });
  3727. it('file.spec.136 Paths should support Unicode symbols.', function (done) {
  3728. var dirName = '文件插件';
  3729. var win = function (directory) {
  3730. expect(directory).toBeDefined();
  3731. expect(directory.isFile).toBe(false);
  3732. expect(directory.isDirectory).toBe(true);
  3733. expect(directory.name).toCanonicallyMatch(dirName);
  3734. deleteEntry(directory.name, done);
  3735. };
  3736. createDirectory(dirName, function () {
  3737. root.getDirectory(dirName, {create: false}, win,
  3738. failed.bind(this, done, 'root.getDirectory - Error getting directory : ' + dirName));
  3739. }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + dirName));
  3740. });
  3741. });
  3742. // Content and Asset URLs
  3743. if (cordova.platformId === 'android') { // eslint-disable-line no-undef
  3744. describe('content: URLs', function () {
  3745. // Warning: Default HelloWorld www directory structure is required for these tests (www/index.html at least)
  3746. function testContentCopy (src, done) {
  3747. var file2 = 'entry.copy.file2b';
  3748. var fullPath = joinURL(temp_root.fullPath, file2);
  3749. var validateFile = function (entry) {
  3750. expect(entry.isFile).toBe(true);
  3751. expect(entry.isDirectory).toBe(false);
  3752. expect(entry.name).toCanonicallyMatch(file2);
  3753. expect(entry.fullPath).toCanonicallyMatch(fullPath);
  3754. expect(entry.filesystem.name).toEqual('temporary');
  3755. // cleanup
  3756. deleteEntry(entry.name, done);
  3757. };
  3758. var transfer = function () {
  3759. resolveLocalFileSystemURL(src, function (entry) { // eslint-disable-line no-undef
  3760. expect(entry).toBeDefined();
  3761. expect(entry.filesystem.name).toEqual('content');
  3762. entry.copyTo(temp_root, file2, validateFile, failed.bind(null, done, 'entry.copyTo - Error copying file: ' + entry.toURL() + ' to TEMPORAL root as: ' + file2));
  3763. }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for content provider'));
  3764. };
  3765. // Delete any existing file to start things off
  3766. temp_root.getFile(file2, {}, function (entry) {
  3767. entry.remove(transfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));
  3768. }, transfer);
  3769. }
  3770. it('file.spec.138 copyTo: content', function (done) {
  3771. testContentCopy('content://org.apache.cordova.file.testprovider/www/index.html', done);
  3772. });
  3773. it('file.spec.139 copyTo: content /w space and query', function (done) {
  3774. testContentCopy('content://org.apache.cordova.file.testprovider/?name=foo%20bar&realPath=%2Fwww%2Findex.html', done);
  3775. });
  3776. it('file.spec.140 delete: content should fail', function (done) {
  3777. resolveLocalFileSystemURL('content://org.apache.cordova.file.testprovider/www/index.html', function (entry) { // eslint-disable-line no-undef
  3778. entry.remove(failed.bind(null, done, 'expected delete to fail'), done);
  3779. }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for content provider'));
  3780. });
  3781. });
  3782. // these tests ensure that you can read and copy from android_asset folder
  3783. // for details see https://issues.apache.org/jira/browse/CB-6428
  3784. // and https://mail-archives.apache.org/mod_mbox/cordova-dev/201508.mbox/%3C782154441.8406572.1440182722528.JavaMail.yahoo%40mail.yahoo.com%3E
  3785. describe('asset: URLs', function () {
  3786. it('file.spec.141 filePaths.applicationStorage', function () {
  3787. expect(cordova.file.applicationDirectory).toEqual('file:///android_asset/'); // eslint-disable-line no-undef
  3788. }, MEDIUM_TIMEOUT);
  3789. it('file.spec.142 assets should be enumerable', function (done) {
  3790. resolveLocalFileSystemURL('file:///android_asset/www/fixtures/asset-test', function (entry) { // eslint-disable-line no-undef
  3791. var reader = entry.createReader();
  3792. reader.readEntries(function (entries) {
  3793. expect(entries.length).not.toBe(0);
  3794. done();
  3795. }, failed.bind(null, done, 'reader.readEntries - Error during reading of entries from assets directory'));
  3796. }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for assets'));
  3797. }, MEDIUM_TIMEOUT);
  3798. it('file.spec.145 asset subdirectories should be obtainable', function (done) {
  3799. resolveLocalFileSystemURL('file:///android_asset/www/fixtures', function (entry) { // eslint-disable-line no-undef
  3800. entry.getDirectory('asset-test', { create: false }, function (subDir) {
  3801. expect(subDir).toBeDefined();
  3802. expect(subDir.isFile).toBe(false);
  3803. expect(subDir.isDirectory).toBe(true);
  3804. expect(subDir.name).toCanonicallyMatch('asset-test');
  3805. done();
  3806. }, failed.bind(null, done, 'entry.getDirectory - Error getting asset subdirectory'));
  3807. }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for assets'));
  3808. }, MEDIUM_TIMEOUT);
  3809. it('file.spec.146 asset files should be readable', function (done) {
  3810. resolveLocalFileSystemURL('file:///android_asset/www/fixtures/asset-test/asset-test.txt', function (entry) { // eslint-disable-line no-undef
  3811. expect(entry.isFile).toBe(true);
  3812. entry.file(function (file) {
  3813. expect(file).toBeDefined();
  3814. var reader = new FileReader(); // eslint-disable-line no-undef
  3815. reader.onerror = failed.bind(null, done, 'reader.readAsText - Error reading asset text file');
  3816. reader.onloadend = function () {
  3817. expect(this.result).toBeDefined();
  3818. expect(this.result.length).not.toBe(0);
  3819. done();
  3820. };
  3821. reader.readAsText(file);
  3822. }, failed.bind(null, done, 'entry.file - Error reading asset file'));
  3823. }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for assets'));
  3824. }, MEDIUM_TIMEOUT);
  3825. it('file.spec.143 copyTo: asset -> temporary', function (done) {
  3826. var file2 = 'entry.copy.file2b';
  3827. var fullPath = joinURL(temp_root.fullPath, file2);
  3828. var validateFile = function (entry) {
  3829. expect(entry.isFile).toBe(true);
  3830. expect(entry.isDirectory).toBe(false);
  3831. expect(entry.name).toCanonicallyMatch(file2);
  3832. expect(entry.fullPath).toCanonicallyMatch(fullPath);
  3833. expect(entry.filesystem.name).toEqual('temporary');
  3834. // cleanup
  3835. deleteEntry(entry.name, done);
  3836. };
  3837. var transfer = function () {
  3838. resolveLocalFileSystemURL('file:///android_asset/www/index.html', function (entry) { // eslint-disable-line no-undef
  3839. expect(entry.filesystem.name).toEqual('assets');
  3840. entry.copyTo(temp_root, file2, validateFile, failed.bind(null, done, 'entry.copyTo - Error copying file: ' + entry.toURL() + ' to TEMPORAL root as: ' + file2));
  3841. }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for assets'));
  3842. };
  3843. // Delete any existing file to start things off
  3844. temp_root.getFile(file2, {}, function (entry) {
  3845. entry.remove(transfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));
  3846. }, transfer);
  3847. }, MEDIUM_TIMEOUT);
  3848. });
  3849. it('file.spec.144 copyTo: asset directory', function (done) {
  3850. var srcUrl = 'file:///android_asset/www/fixtures/asset-test';
  3851. var dstDir = 'entry.copy.dstDir';
  3852. var dstPath = joinURL(root.fullPath, dstDir);
  3853. // create a new directory entry to kick off it
  3854. deleteEntry(dstDir, function () {
  3855. resolveLocalFileSystemURL(srcUrl, function (directory) { // eslint-disable-line no-undef
  3856. directory.copyTo(root, dstDir, function (directory) {
  3857. expect(directory).toBeDefined();
  3858. expect(directory.isFile).toBe(false);
  3859. expect(directory.isDirectory).toBe(true);
  3860. expect(directory.fullPath).toCanonicallyMatch(dstPath);
  3861. expect(directory.name).toCanonicallyMatch(dstDir);
  3862. root.getDirectory(dstDir, {
  3863. create: false
  3864. }, function (dirEntry) {
  3865. expect(dirEntry).toBeDefined();
  3866. expect(dirEntry.isFile).toBe(false);
  3867. expect(dirEntry.isDirectory).toBe(true);
  3868. expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);
  3869. expect(dirEntry.name).toCanonicallyMatch(dstDir);
  3870. dirEntry.getFile('asset-test.txt', {
  3871. create: false
  3872. }, function (fileEntry) {
  3873. expect(fileEntry).toBeDefined();
  3874. expect(fileEntry.isFile).toBe(true);
  3875. // cleanup
  3876. deleteEntry(dstDir, done);
  3877. }, failed.bind(null, done, 'dirEntry.getFile - Error getting subfile'));
  3878. }, failed.bind(null, done, 'root.getDirectory - Error getting copied directory'));
  3879. }, failed.bind(null, done, 'directory.copyTo - Error copying directory'));
  3880. }, failed.bind(null, done, 'resolving src dir'));
  3881. }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
  3882. }, MEDIUM_TIMEOUT);
  3883. }
  3884. });
  3885. };
  3886. //* *****************************************************************************************
  3887. //* **************************************Manual Tests***************************************
  3888. //* *****************************************************************************************
  3889. exports.defineManualTests = function (contentEl, createActionButton) {
  3890. function resolveFs (fsname) {
  3891. var fsURL = 'cdvfile://localhost/' + fsname + '/';
  3892. logMessage('Resolving URL: ' + fsURL);
  3893. /* eslint-disable no-undef */
  3894. resolveLocalFileSystemURL(fsURL, function (entry) {
  3895. logMessage('Success', 'green');
  3896. logMessage(entry.toURL(), 'blue');
  3897. logMessage(entry.toInternalURL(), 'blue');
  3898. logMessage('Resolving URL: ' + entry.toURL());
  3899. resolveLocalFileSystemURL(entry.toURL(), function (entry2) {
  3900. logMessage('Success', 'green');
  3901. logMessage(entry2.toURL(), 'blue');
  3902. logMessage(entry2.toInternalURL(), 'blue');
  3903. }, logError('resolveLocalFileSystemURL'));
  3904. }, logError('resolveLocalFileSystemURL'));
  3905. }
  3906. function testPrivateURL () {
  3907. requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) {
  3908. logMessage('Temporary root is at ' + fileSystem.root.toNativeURL());
  3909. fileSystem.root.getFile('testfile', {
  3910. create: true
  3911. }, function (entry) {
  3912. logMessage('Temporary file is at ' + entry.toNativeURL());
  3913. if (entry.toNativeURL().substring(0, 12) === 'file:///var/') {
  3914. logMessage('File starts with /var/, trying /private/var');
  3915. var newURL = 'file://localhost/private/var/' + entry.toNativeURL().substring(12) + '?and=another_thing';
  3916. // var newURL = entry.toNativeURL();
  3917. logMessage(newURL, 'blue');
  3918. resolveLocalFileSystemURL(newURL, function (newEntry) {
  3919. logMessage('Successfully resolved.', 'green');
  3920. logMessage(newEntry.toURL(), 'blue');
  3921. logMessage(newEntry.toNativeURL(), 'blue');
  3922. }, logError('resolveLocalFileSystemURL'));
  3923. }
  3924. }, logError('getFile'));
  3925. }, logError('requestFileSystem'));
  3926. }
  3927. function resolveFsContactImage () {
  3928. navigator.contacts.pickContact(function (contact) {
  3929. var logBox = document.getElementById('logContactBox');
  3930. logBox.innerHTML = '';
  3931. var resolveResult = document.createElement('p');
  3932. if (contact.photos) {
  3933. var photoURL = contact.photos[0].value;
  3934. resolveLocalFileSystemURL(photoURL, function (entry) {
  3935. /* eslint-enable no-undef */
  3936. var contactImage = document.createElement('img');
  3937. var contactLabelImage = document.createElement('p');
  3938. contactLabelImage.innerHTML = 'Result contact image';
  3939. contactImage.setAttribute('src', entry.toURL());
  3940. resolveResult.innerHTML = 'Success resolve\n' + entry.toURL();
  3941. logBox.appendChild(contactLabelImage);
  3942. logBox.appendChild(contactImage);
  3943. logBox.appendChild(resolveResult);
  3944. },
  3945. function (err) {
  3946. console.log('resolve error' + err);
  3947. });
  3948. } else {
  3949. resolveResult.innerHTML = 'Contact has no photos';
  3950. logBox.appendChild(resolveResult);
  3951. }
  3952. },
  3953. function (err) {
  3954. console.log('contact pick error' + err);
  3955. });
  3956. }
  3957. function clearLog () {
  3958. var log = document.getElementById('info');
  3959. log.innerHTML = '';
  3960. }
  3961. function logMessage (message, color) {
  3962. var log = document.getElementById('info');
  3963. var logLine = document.createElement('div');
  3964. if (color) {
  3965. logLine.style.color = color;
  3966. }
  3967. logLine.innerHTML = message;
  3968. log.appendChild(logLine);
  3969. }
  3970. function logError (serviceName) {
  3971. return function (err) {
  3972. logMessage('ERROR: ' + serviceName + ' ' + JSON.stringify(err), 'red');
  3973. };
  3974. }
  3975. var fsRoots = {
  3976. 'ios': 'library,library-nosync,documents,documents-nosync,cache,bundle,root,private',
  3977. 'osx': 'library,library-nosync,documents,documents-nosync,cache,bundle,root,private',
  3978. 'android': 'files,files-external,documents,sdcard,cache,cache-external,assets,root',
  3979. 'amazon-fireos': 'files,files-external,documents,sdcard,cache,cache-external,root',
  3980. 'windows': 'temporary,persistent'
  3981. };
  3982. // Add title and align to content
  3983. var div = document.createElement('h2');
  3984. div.appendChild(document.createTextNode('File Systems'));
  3985. div.setAttribute('align', 'center');
  3986. contentEl.appendChild(div);
  3987. div = document.createElement('h3');
  3988. div.appendChild(document.createTextNode('Results are displayed in yellow status box below with expected results noted under that'));
  3989. div.setAttribute('align', 'center');
  3990. contentEl.appendChild(div);
  3991. div = document.createElement('div');
  3992. div.setAttribute('id', 'button');
  3993. div.setAttribute('align', 'center');
  3994. contentEl.appendChild(div);
  3995. /* eslint-disable no-undef */
  3996. if (fsRoots.hasOwnProperty(cordova.platformId)) {
  3997. (fsRoots[cordova.platformId].split(',')).forEach(function (fs) {
  3998. if (cordova.platformId === 'ios' && fs === 'private') {
  3999. /* eslint-enable no-undef */
  4000. createActionButton('Test private URL (iOS)', function () {
  4001. clearLog();
  4002. testPrivateURL();
  4003. }, 'button');
  4004. } else {
  4005. createActionButton(fs, function () {
  4006. clearLog();
  4007. resolveFs(fs);
  4008. }, 'button');
  4009. }
  4010. });
  4011. }
  4012. div = document.createElement('div');
  4013. div.setAttribute('id', 'info');
  4014. div.setAttribute('align', 'center');
  4015. contentEl.appendChild(div);
  4016. div = document.createElement('h3');
  4017. div.appendChild(document.createTextNode('For each test above, file or directory should be successfully found. ' +
  4018. 'Status box should say Resolving URL was Success. The first URL resolved is the internal URL. ' +
  4019. 'The second URL resolved is the absolute URL. Blue URLs must match.'));
  4020. contentEl.appendChild(div);
  4021. div = document.createElement('h3');
  4022. div.appendChild(document.createTextNode('For Test private URL (iOS), the private URL (first blue URL in status box) ' +
  4023. 'should be successfully resolved. Status box should say Successfully resolved. Both blue URLs below ' +
  4024. 'that should match.'));
  4025. contentEl.appendChild(div);
  4026. div = document.createElement('h2');
  4027. div.appendChild(document.createTextNode('Resolving content urls'));
  4028. div.setAttribute('align', 'center');
  4029. contentEl.appendChild(div);
  4030. div = document.createElement('div');
  4031. div.setAttribute('id', 'contactButton');
  4032. div.setAttribute('align', 'center');
  4033. contentEl.appendChild(div);
  4034. div = document.createElement('div');
  4035. div.setAttribute('id', 'logContactBox');
  4036. div.setAttribute('align', 'center');
  4037. contentEl.appendChild(div);
  4038. createActionButton('show-contact-image', function () {
  4039. resolveFsContactImage();
  4040. }, 'contactButton');
  4041. };