How to use deleteEntry method in Playwright Internal

Best JavaScript code snippet using playwright-internal

tests.js

Source:tests.js Github

copy

Full Screen

...149 callback);150 };151 // deletes and re-creates the specified file152 var createFile = function (fileName, success, error) {153 deleteEntry(fileName, function () {154 root.getFile(fileName, {155 create : true156 }, success, error);157 }, error);158 };159 // deletes and re-creates the specified directory160 var createDirectory = function (dirName, success, error) {161 deleteEntry(dirName, function () {162 root.getDirectory(dirName, {163 create : true164 }, success, error);165 }, error);166 };167 function failed(done, msg, error) {168 var info = typeof msg == 'undefined' ? 'Unexpected error callback' : msg;169 var codeMsg = (error && error.code) ? (': ' + fileErrorMap[error.code]) : '';170 expect(true).toFailWithMessage(info + '\n' + JSON.stringify(error) + codeMsg);171 done();172 }173 var succeed = function (done, msg) {174 var info = typeof msg == 'undefined' ? 'Unexpected success callback' : msg;175 expect(true).toFailWithMessage(info);176 done();177 };178 var joinURL = function (base, extension) {179 if (base.charAt(base.length - 1) !== '/' && extension.charAt(0) !== '/') {180 return base + '/' + extension;181 }182 if (base.charAt(base.length - 1) === '/' && extension.charAt(0) === '/') {183 return base + extension.substring(1);184 }185 return base + extension;186 };187 describe('FileError object', function () {188 it("file.spec.1 should define FileError constants", function () {189 expect(FileError.NOT_FOUND_ERR).toBe(1);190 expect(FileError.SECURITY_ERR).toBe(2);191 expect(FileError.ABORT_ERR).toBe(3);192 expect(FileError.NOT_READABLE_ERR).toBe(4);193 expect(FileError.ENCODING_ERR).toBe(5);194 expect(FileError.NO_MODIFICATION_ALLOWED_ERR).toBe(6);195 expect(FileError.INVALID_STATE_ERR).toBe(7);196 expect(FileError.SYNTAX_ERR).toBe(8);197 expect(FileError.INVALID_MODIFICATION_ERR).toBe(9);198 expect(FileError.QUOTA_EXCEEDED_ERR).toBe(10);199 expect(FileError.TYPE_MISMATCH_ERR).toBe(11);200 expect(FileError.PATH_EXISTS_ERR).toBe(12);201 });202 });203 describe('LocalFileSystem', function () {204 it("file.spec.2 should define LocalFileSystem constants", function () {205 expect(LocalFileSystem.TEMPORARY).toBe(0);206 expect(LocalFileSystem.PERSISTENT).toBe(1);207 });208 describe('window.requestFileSystem', function () {209 it("file.spec.3 should be defined", function () {210 expect(window.requestFileSystem).toBeDefined();211 });212 it("file.spec.4 should be able to retrieve a PERSISTENT file system", function (done) {213 var win = function (fileSystem) {214 expect(fileSystem).toBeDefined();215 expect(fileSystem.name).toBeDefined();216 if (isChrome) {217 expect(fileSystem.name).toContain("Persistent");218 } else {219 expect(fileSystem.name).toBe("persistent");220 }221 expect(fileSystem.root).toBeDefined();222 expect(fileSystem.root.filesystem).toBeDefined();223 // Shouldn't use cdvfile by default.224 expect(fileSystem.root.toURL()).not.toMatch(/^cdvfile:/);225 // All DirectoryEntry URLs should always have a trailing slash.226 expect(fileSystem.root.toURL()).toMatch(/\/$/);227 done();228 };229 // Request a little bit of space on the filesystem, unless we're running in a browser where that could cause a prompt.230 var spaceRequired = isBrowser ? 0 : 1024;231 // retrieve PERSISTENT file system232 window.requestFileSystem(LocalFileSystem.PERSISTENT, spaceRequired, win, failed.bind(null, done, 'window.requestFileSystem - Error retrieving PERSISTENT file system'));233 });234 it("file.spec.5 should be able to retrieve a TEMPORARY file system", function (done) {235 var win = function (fileSystem) {236 expect(fileSystem).toBeDefined();237 if (isChrome) {238 expect(fileSystem.name).toContain("Temporary");239 } else {240 expect(fileSystem.name).toBe("temporary");241 }242 expect(fileSystem.root).toBeDefined();243 expect(fileSystem.root.filesystem).toBeDefined();244 expect(fileSystem.root.filesystem).toBe(fileSystem);245 done();246 };247 //retrieve TEMPORARY file system248 window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, win, failed.bind(null, done, 'window.requestFileSystem - Error retrieving TEMPORARY file system'));249 });250 it("file.spec.6 should error if you request a file system that is too large", function (done) {251 if (isBrowser) {252 /*window.requestFileSystem TEMPORARY and PERSISTENT filesystem quota is not limited in Chrome.253 Firefox filesystem size is not limited but every 50MB request user permission.254 IE10 allows up to 10mb of combined AppCache and IndexedDB used in implementation255 of filesystem without prompting, once you hit that level you will be asked if you256 want to allow it to be increased up to a max of 250mb per site.257 So `size` parameter for `requestFileSystem` function does not affect on filesystem in Firefox and IE.*/258 pending();259 }260 var fail = function (error) {261 expect(error).toBeDefined();262 expect(error).toBeFileError(FileError.QUOTA_EXCEEDED_ERR);263 done();264 };265 //win = createWin('window.requestFileSystem');266 // Request the file system267 window.requestFileSystem(LocalFileSystem.TEMPORARY, 1000000000000000, failed.bind(null, done, 'window.requestFileSystem - Error retrieving TEMPORARY file system'), fail);268 });269 it("file.spec.7 should error out if you request a file system that does not exist", function (done) {270 var fail = function (error) {271 expect(error).toBeDefined();272 if (isChrome) {273 /*INVALID_MODIFICATION_ERR (code: 9) is thrown instead of SYNTAX_ERR(code: 8)274 on requesting of a non-existant filesystem.*/275 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);276 } else {277 expect(error).toBeFileError(FileError.SYNTAX_ERR);278 }279 done();280 };281 // Request the file system282 window.requestFileSystem(-1, 0, succeed.bind(null, done, 'window.requestFileSystem'), fail);283 });284 });285 describe('window.resolveLocalFileSystemURL', function () {286 it("file.spec.8 should be defined", function () {287 expect(window.resolveLocalFileSystemURL).toBeDefined();288 });289 it("file.spec.9 should resolve a valid file name", function (done) {290 var fileName = 'file.spec.9';291 var win = function (fileEntry) {292 expect(fileEntry).toBeDefined();293 expect(fileEntry.isFile).toBe(true);294 expect(fileEntry.isDirectory).toBe(false);295 expect(fileEntry.name).toCanonicallyMatch(fileName);296 expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');297 expect(fileEntry.toURL()).not.toMatch(/\/$/, 'URL should not end with a slash');298 // Clean-up299 deleteEntry(fileName, done);300 };301 createFile(fileName, function (entry) {302 window.resolveLocalFileSystemURL(entry.toURL(), win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URL: ' + entry.toURL()));303 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName), failed.bind(null, done, 'createFile - Error creating file: ' + fileName));304 });305 it("file.spec.9.1 should resolve a file even with a terminating slash", function (done) {306 var fileName = 'file.spec.9.1';307 var win = function (fileEntry) {308 expect(fileEntry).toBeDefined();309 expect(fileEntry.isFile).toBe(true);310 expect(fileEntry.isDirectory).toBe(false);311 expect(fileEntry.name).toCanonicallyMatch(fileName);312 expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');313 expect(fileEntry.toURL()).not.toMatch(/\/$/, 'URL should not end with a slash');314 // Clean-up315 deleteEntry(fileName, done);316 };317 createFile(fileName, function (entry) {318 var entryURL = entry.toURL() + '/';319 window.resolveLocalFileSystemURL(entryURL, win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URL: ' + entryURL));320 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName), failed.bind(null, done, 'createFile - Error creating file: ' + fileName));321 });322 it("file.spec.9.5 should resolve a directory", function (done) {323 var fileName = 'file.spec.9.5';324 var win = function (fileEntry) {325 expect(fileEntry).toBeDefined();326 expect(fileEntry.isFile).toBe(false);327 expect(fileEntry.isDirectory).toBe(true);328 expect(fileEntry.name).toCanonicallyMatch(fileName);329 expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');330 expect(fileEntry.toURL()).toMatch(/\/$/, 'URL end with a slash');331 // cleanup332 deleteEntry(fileName, done);333 };334 function gotDirectory(entry) {335 // lookup file system entry336 window.resolveLocalFileSystemURL(entry.toURL(), win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving directory URL: ' + entry.toURL()));337 }338 createDirectory(fileName, gotDirectory, failed.bind(null, done, 'createDirectory - Error creating directory: ' + fileName), failed.bind(null, done, 'createDirectory - Error creating directory: ' + fileName));339 });340 it("file.spec.9.6 should resolve a directory even without a terminating slash", function (done) {341 var fileName = 'file.spec.9.6';342 var win = function (fileEntry) {343 expect(fileEntry).toBeDefined();344 expect(fileEntry.isFile).toBe(false);345 expect(fileEntry.isDirectory).toBe(true);346 expect(fileEntry.name).toCanonicallyMatch(fileName);347 expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');348 expect(fileEntry.toURL()).toMatch(/\/$/, 'URL end with a slash');349 // cleanup350 deleteEntry(fileName, done);351 };352 function gotDirectory(entry) {353 // lookup file system entry354 var entryURL = entry.toURL();355 entryURL = entryURL.substring(0, entryURL.length - 1);356 window.resolveLocalFileSystemURL(entryURL, win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving directory URL: ' + entryURL));357 }358 createDirectory(fileName, gotDirectory, failed.bind(null, done, 'createDirectory - Error creating directory: ' + fileName), failed.bind(null, done, 'createDirectory - Error creating directory: ' + fileName));359 });360 it("file.spec.9.7 should resolve a file with valid nativeURL", function (done) {361 var fileName = "de.create.file",362 win = function (entry) {363 var path = entry.nativeURL.split('///')[1];364 expect(/\/{2,}/.test(path)).toBeFalsy();365 // cleanup366 deleteEntry(entry.name, done);367 };368 root.getFile(fileName, {369 create: true370 }, win, succeed.bind(null, done, 'root.getFile - Error unexpected callback, file should not exists: ' + fileName));371 });372 it("file.spec.10 resolve valid file name with parameters", function (done) {373 var fileName = "resolve.file.uri.params",374 win = function (fileEntry) {375 expect(fileEntry).toBeDefined();376 if (fileEntry.toURL().toLowerCase().substring(0, 10) === "cdvfile://") {377 expect(fileEntry.fullPath).toBe("/" + fileName + "?1234567890");378 }379 expect(fileEntry.name).toBe(fileName);380 // cleanup381 deleteEntry(fileName, done);382 };383 // create a new file entry384 createFile(fileName, function (entry) {385 window.resolveLocalFileSystemURL(entry.toURL() + "?1234567890", win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URI: ' + entry.toURL()));386 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));387 });388 it("file.spec.11 should error (NOT_FOUND_ERR) when resolving (non-existent) invalid file name", function (done) {389 var fileName = cordova.platformId === 'windowsphone' ? root.toURL() + "/" + "this.is.not.a.valid.file.txt" : joinURL(root.toURL(), "this.is.not.a.valid.file.txt"),390 fail = function (error) {391 expect(error).toBeDefined();392 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);393 done();394 };395 // lookup file system entry396 window.resolveLocalFileSystemURL(fileName, succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Error unexpected callback resolving file URI: ' + fileName), fail);397 });398 it("file.spec.12 should error (ENCODING_ERR) when resolving invalid URI with leading /", function (done) {399 var fileName = "/this.is.not.a.valid.url",400 fail = function (error) {401 expect(error).toBeDefined();402 expect(error).toBeFileError(FileError.ENCODING_ERR);403 done();404 };405 // lookup file system entry406 window.resolveLocalFileSystemURL(fileName, succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Error unexpected callback resolving file URI: ' + fileName), fail);407 });408 });409 });410 //LocalFileSystem411 describe('Metadata interface', function () {412 it("file.spec.13 should exist and have the right properties", function () {413 var metadata = new Metadata();414 expect(metadata).toBeDefined();415 expect(metadata.modificationTime).toBeDefined();416 });417 });418 describe('Flags interface', function () {419 it("file.spec.14 should exist and have the right properties", function () {420 var flags = new Flags(false, true);421 expect(flags).toBeDefined();422 expect(flags.create).toBeDefined();423 expect(flags.create).toBe(false);424 expect(flags.exclusive).toBeDefined();425 expect(flags.exclusive).toBe(true);426 });427 });428 describe('FileSystem interface', function () {429 it("file.spec.15 should have a root that is a DirectoryEntry", function (done) {430 var win = function (entry) {431 expect(entry).toBeDefined();432 expect(entry.isFile).toBe(false);433 expect(entry.isDirectory).toBe(true);434 expect(entry.name).toBeDefined();435 expect(entry.fullPath).toBeDefined();436 expect(entry.getMetadata).toBeDefined();437 expect(entry.moveTo).toBeDefined();438 expect(entry.copyTo).toBeDefined();439 expect(entry.toURL).toBeDefined();440 expect(entry.remove).toBeDefined();441 expect(entry.getParent).toBeDefined();442 expect(entry.createReader).toBeDefined();443 expect(entry.getFile).toBeDefined();444 expect(entry.getDirectory).toBeDefined();445 expect(entry.removeRecursively).toBeDefined();446 done();447 };448 window.resolveLocalFileSystemURL(root.toURL(), win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URI: ' + root.toURL()));449 });450 });451 describe('DirectoryEntry', function () {452 it("file.spec.16 getFile: get Entry for file that does not exist", function (done) {453 var fileName = "de.no.file",454 fail = function (error) {455 expect(error).toBeDefined();456 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);457 done();458 };459 // create:false, exclusive:false, file does not exist460 root.getFile(fileName, {461 create : false462 }, succeed.bind(null, done, 'root.getFile - Error unexpected callback, file should not exists: ' + fileName), fail);463 });464 it("file.spec.17 getFile: create new file", function (done) {465 var fileName = "de.create.file",466 filePath = joinURL(root.fullPath, fileName),467 win = function (entry) {468 expect(entry).toBeDefined();469 expect(entry.isFile).toBe(true);470 expect(entry.isDirectory).toBe(false);471 expect(entry.name).toCanonicallyMatch(fileName);472 expect(entry.fullPath).toCanonicallyMatch(filePath);473 // cleanup474 deleteEntry(entry.name, done);475 };476 // create:true, exclusive:false, file does not exist477 root.getFile(fileName, {478 create : true479 }, win, succeed.bind(null, done, 'root.getFile - Error unexpected callback, file should not exists: ' + fileName));480 });481 it("file.spec.18 getFile: create new file (exclusive)", function (done) {482 var fileName = "de.create.exclusive.file",483 filePath = joinURL(root.fullPath, fileName),484 win = function (entry) {485 expect(entry).toBeDefined();486 expect(entry.isFile).toBe(true);487 expect(entry.isDirectory).toBe(false);488 expect(entry.name).toBe(fileName);489 expect(entry.fullPath).toCanonicallyMatch(filePath);490 // cleanup491 deleteEntry(entry.name, done);492 };493 // create:true, exclusive:true, file does not exist494 root.getFile(fileName, {495 create : true,496 exclusive : true497 }, win, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));498 });499 it("file.spec.19 getFile: create file that already exists", function (done) {500 var fileName = "de.create.existing.file",501 filePath = joinURL(root.fullPath, fileName);502 function win(entry) {503 expect(entry).toBeDefined();504 expect(entry.isFile).toBe(true);505 expect(entry.isDirectory).toBe(false);506 expect(entry.name).toCanonicallyMatch(fileName);507 expect(entry.fullPath).toCanonicallyMatch(filePath);508 // cleanup509 deleteEntry(entry.name, done);510 }511 function getFile(file) {512 // create:true, exclusive:false, file exists513 root.getFile(fileName, {514 create : true515 }, win, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));516 }517 // create file to kick off it518 root.getFile(fileName, {519 create : true520 }, getFile, failed.bind(null, done, 'root.getFile - Error on initial creating file: ' + fileName));521 });522 it("file.spec.20 getFile: create file that already exists (exclusive)", function (done) {523 var fileName = "de.create.exclusive.existing.file",524 existingFile;525 function fail(error) {526 expect(error).toBeDefined();527 if (isChrome) {528 /*INVALID_MODIFICATION_ERR (code: 9) is thrown instead of PATH_EXISTS_ERR(code: 12)529 on trying to exclusively create a file, which already exists in Chrome.*/530 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);531 } else {532 expect(error).toBeFileError(FileError.PATH_EXISTS_ERR);533 }534 // cleanup535 deleteEntry(existingFile.name, done);536 }537 function getFile(file) {538 existingFile = file;539 // create:true, exclusive:true, file exists540 root.getFile(fileName, {541 create : true,542 exclusive : true543 }, succeed.bind(null, done, 'root.getFile - getFile function - Error unexpected callback, file should exists: ' + fileName), fail);544 }545 // create file to kick off it546 root.getFile(fileName, {547 create : true548 }, getFile, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));549 });550 it("file.spec.21 DirectoryEntry.getFile: get Entry for existing file", function (done) {551 var fileName = "de.get.file",552 filePath = joinURL(root.fullPath, fileName),553 win = function (entry) {554 expect(entry).toBeDefined();555 expect(entry.isFile).toBe(true);556 expect(entry.isDirectory).toBe(false);557 expect(entry.name).toCanonicallyMatch(fileName);558 expect(entry.fullPath).toCanonicallyMatch(filePath);559 expect(entry.filesystem).toBeDefined();560 expect(entry.filesystem).toBe(root.filesystem);561 //clean up562 deleteEntry(entry.name, done);563 },564 getFile = function (file) {565 // create:false, exclusive:false, file exists566 root.getFile(fileName, {567 create : false568 }, win, failed.bind(null, done, 'root.getFile - Error getting file entry: ' + fileName));569 };570 // create file to kick off it571 root.getFile(fileName, {572 create : true573 }, getFile, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));574 });575 it("file.spec.22 DirectoryEntry.getFile: get FileEntry for invalid path", function (done) {576 if (isBrowser) {577 /*The plugin does not follow to ["8.3 Naming restrictions"]578 (http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions).*/579 pending();580 }581 var fileName = "de:invalid:path",582 fail = function (error) {583 expect(error).toBeDefined();584 expect(error).toBeFileError(FileError.ENCODING_ERR);585 done();586 };587 // create:false, exclusive:false, invalid path588 root.getFile(fileName, {589 create : false590 }, succeed.bind(null, done, 'root.getFile - Error unexpected callback, file should not exists: ' + fileName), fail);591 });592 it("file.spec.23 DirectoryEntry.getDirectory: get Entry for directory that does not exist", function (done) {593 var dirName = "de.no.dir",594 fail = function (error) {595 expect(error).toBeDefined();596 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);597 done();598 };599 // create:false, exclusive:false, directory does not exist600 root.getDirectory(dirName, {601 create : false602 }, succeed.bind(null, done, 'root.getDirectory - Error unexpected callback, directory should not exists: ' + dirName), fail);603 });604 it("file.spec.24 DirectoryEntry.getDirectory: create new dir with space then resolveLocalFileSystemURL", function (done) {605 var dirName = "de create dir";606 function win(directory) {607 expect(directory).toBeDefined();608 expect(directory.isFile).toBe(false);609 expect(directory.isDirectory).toBe(true);610 expect(directory.name).toCanonicallyMatch(dirName);611 expect(directory.fullPath).toCanonicallyMatch(joinURL(root.fullPath, dirName));612 // cleanup613 deleteEntry(directory.name, done);614 }615 function getDir(dirEntry) {616 expect(dirEntry.filesystem).toBeDefined();617 expect(dirEntry.filesystem).toBe(root.filesystem);618 var dirURI = dirEntry.toURL();619 // now encode URI and try to resolve620 window.resolveLocalFileSystemURL(dirURI, win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - getDir function - Error resolving directory: ' + dirURI));621 }622 // create:true, exclusive:false, directory does not exist623 root.getDirectory(dirName, {624 create : true625 }, getDir, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));626 });627 // This test is excluded, and should probably be removed. Filesystem628 // should always be properly encoded URLs, and *not* raw paths, and it629 // doesn't make sense to double-encode the URLs and expect that to be630 // handled by the implementation.631 // If a particular platform uses paths internally rather than URLs, // then that platform should careful to pass them correctly to its632 // backend.633 xit("file.spec.25 DirectoryEntry.getDirectory: create new dir with space resolveLocalFileSystemURL with encoded URI", function (done) {634 var dirName = "de create dir2",635 dirPath = joinURL(root.fullPath, dirName);636 function win(directory) {637 expect(directory).toBeDefined();638 expect(directory.isFile).toBe(false);639 expect(directory.isDirectory).toBe(true);640 expect(directory.name).toCanonicallyMatch(dirName);641 expect(directory.fullPath).toCanonicallyMatch(dirPath);642 // cleanup643 deleteEntry(directory.name, done);644 }645 function getDir(dirEntry) {646 var dirURI = dirEntry.toURL();647 // now encode URI and try to resolve648 window.resolveLocalFileSystemURL(encodeURI(dirURI), win, failed.bind(null, done, 'window.resolveLocalFileSystemURL - getDir function - Error resolving directory: ' + dirURI));649 }650 // create:true, exclusive:false, directory does not exist651 root.getDirectory(dirName, {652 create : true653 }, getDir, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));654 });655 it("file.spec.26 DirectoryEntry.getDirectory: create new directory", function (done) {656 var dirName = "de.create.dir",657 dirPath = joinURL(root.fullPath, dirName),658 win = function (directory) {659 expect(directory).toBeDefined();660 expect(directory.isFile).toBe(false);661 expect(directory.isDirectory).toBe(true);662 expect(directory.name).toCanonicallyMatch(dirName);663 expect(directory.fullPath).toCanonicallyMatch(dirPath);664 expect(directory.filesystem).toBeDefined();665 expect(directory.filesystem).toBe(root.filesystem);666 // cleanup667 deleteEntry(directory.name, done);668 };669 // create:true, exclusive:false, directory does not exist670 root.getDirectory(dirName, {671 create : true672 }, win, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));673 });674 it("file.spec.27 DirectoryEntry.getDirectory: create new directory (exclusive)", function (done) {675 var dirName = "de.create.exclusive.dir",676 dirPath = joinURL(root.fullPath, dirName),677 win = function (directory) {678 expect(directory).toBeDefined();679 expect(directory.isFile).toBe(false);680 expect(directory.isDirectory).toBe(true);681 expect(directory.name).toCanonicallyMatch(dirName);682 expect(directory.fullPath).toCanonicallyMatch(dirPath);683 expect(directory.filesystem).toBeDefined();684 expect(directory.filesystem).toBe(root.filesystem);685 // cleanup686 deleteEntry(directory.name, done);687 };688 // create:true, exclusive:true, directory does not exist689 root.getDirectory(dirName, {690 create : true,691 exclusive : true692 }, win, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));693 });694 it("file.spec.28 DirectoryEntry.getDirectory: create directory that already exists", function (done) {695 var dirName = "de.create.existing.dir",696 dirPath = joinURL(root.fullPath, dirName),697 win = function (directory) {698 expect(directory).toBeDefined();699 expect(directory.isFile).toBe(false);700 expect(directory.isDirectory).toBe(true);701 expect(directory.name).toCanonicallyMatch(dirName);702 expect(directory.fullPath).toCanonicallyMatch(dirPath);703 // cleanup704 deleteEntry(directory.name, done);705 };706 // create directory to kick off it707 root.getDirectory(dirName, {708 create : true709 }, function () {710 root.getDirectory(dirName, {711 create : true712 }, win, failed.bind(null, done, 'root.getDirectory - Error creating existent second directory : ' + dirName));713 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));714 });715 it("file.spec.29 DirectoryEntry.getDirectory: create directory that already exists (exclusive)", function (done) {716 var dirName = "de.create.exclusive.existing.dir",717 existingDir,718 fail = function (error) {719 expect(error).toBeDefined();720 if (isChrome) {721 /*INVALID_MODIFICATION_ERR (code: 9) is thrown instead of PATH_EXISTS_ERR(code: 12)722 on trying to exclusively create a file or directory, which already exists (Chrome).*/723 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);724 } else {725 expect(error).toBeFileError(FileError.PATH_EXISTS_ERR);726 }727 // cleanup728 deleteEntry(existingDir.name, done);729 };730 // create directory to kick off it731 root.getDirectory(dirName, {732 create : true733 }, function (directory) {734 existingDir = directory;735 // create:true, exclusive:true, directory exists736 root.getDirectory(dirName, {737 create : true,738 exclusive : true739 }, failed.bind(null, done, 'root.getDirectory - Unexpected success callback, second directory should not be created : ' + dirName), fail);740 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));741 });742 it("file.spec.30 DirectoryEntry.getDirectory: get Entry for existing directory", function (done) {743 var dirName = "de.get.dir",744 dirPath = joinURL(root.fullPath, dirName),745 win = function (directory) {746 expect(directory).toBeDefined();747 expect(directory.isFile).toBe(false);748 expect(directory.isDirectory).toBe(true);749 expect(directory.name).toCanonicallyMatch(dirName);750 expect(directory.fullPath).toCanonicallyMatch(dirPath);751 // cleanup752 deleteEntry(directory.name, done);753 };754 // create directory to kick it off755 root.getDirectory(dirName, {756 create : true757 }, function () {758 root.getDirectory(dirName, {759 create : false760 }, win, failed.bind(null, done, 'root.getDirectory - Error getting directory entry : ' + dirName));761 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));762 });763 it("file.spec.31 DirectoryEntry.getDirectory: get DirectoryEntry for invalid path", function (done) {764 if (isBrowser) {765 /*The plugin does not follow to ["8.3 Naming restrictions"]766 (http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions).*/767 pending();768 }769 var dirName = "de:invalid:path",770 fail = function (error) {771 expect(error).toBeDefined();772 expect(error).toBeFileError(FileError.ENCODING_ERR);773 done();774 };775 // create:false, exclusive:false, invalid path776 root.getDirectory(dirName, {777 create : false778 }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, directory should not exists: ' + dirName), fail);779 });780 it("file.spec.32 DirectoryEntry.getDirectory: get DirectoryEntry for existing file", function (done) {781 var fileName = "de.existing.file",782 existingFile,783 fail = function (error) {784 expect(error).toBeDefined();785 expect(error).toBeFileError(FileError.TYPE_MISMATCH_ERR);786 // cleanup787 deleteEntry(existingFile.name, done);788 };789 // create file to kick off it790 root.getFile(fileName, {791 create : true792 }, function (file) {793 existingFile = file;794 root.getDirectory(fileName, {795 create : false796 }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, directory should not exists: ' + fileName), fail);797 }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));798 });799 it("file.spec.33 DirectoryEntry.getFile: get FileEntry for existing directory", function (done) {800 var dirName = "de.existing.dir",801 existingDir,802 fail = function (error) {803 expect(error).toBeDefined();804 expect(error).toBeFileError(FileError.TYPE_MISMATCH_ERR);805 // cleanup806 deleteEntry(existingDir.name, done);807 };808 // create directory to kick off it809 root.getDirectory(dirName, {810 create : true811 }, function (directory) {812 existingDir = directory;813 root.getFile(dirName, {814 create : false815 }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, file should not exists: ' + dirName), fail);816 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));817 });818 it("file.spec.34 DirectoryEntry.removeRecursively on directory", function (done) {819 var dirName = "de.removeRecursively",820 subDirName = "dir",821 dirExists = function (error) {822 expect(error).toBeDefined();823 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);824 done();825 };826 // create a new directory entry to kick off it827 root.getDirectory(dirName, {828 create : true829 }, function (entry) {830 entry.getDirectory(subDirName, {831 create : true832 }, function (dir) {833 entry.removeRecursively(function () {834 root.getDirectory(dirName, {835 create : false836 }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, directory should not exists: ' + dirName), dirExists);837 }, failed.bind(null, done, 'entry.removeRecursively - Error removing directory recursively : ' + dirName));838 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + subDirName));839 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));840 });841 it("file.spec.35 createReader: create reader on existing directory", function () {842 // create reader for root directory843 var reader = root.createReader();844 expect(reader).toBeDefined();845 expect(typeof reader.readEntries).toBe('function');846 });847 it("file.spec.36 removeRecursively on root file system", function (done) {848 var remove = function (error) {849 expect(error).toBeDefined();850 if (isChrome) {851 /*INVALID_MODIFICATION_ERR (code: 9) is thrown instead of852 NO_MODIFICATION_ALLOWED_ERR(code: 6) on trying to call removeRecursively853 on the root file system (Chrome).*/854 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);855 } else {856 expect(error).toBeFileError(FileError.NO_MODIFICATION_ALLOWED_ERR);857 }858 done();859 };860 // remove root file system861 root.removeRecursively(succeed.bind(null, done, 'root.removeRecursively - Unexpected success callback, root cannot be removed'), remove);862 });863 });864 describe('DirectoryReader interface', function () {865 describe("readEntries", function () {866 it("file.spec.37 should read contents of existing directory", function (done) {867 var reader,868 win = function (entries) {869 expect(entries).toBeDefined();870 expect(entries instanceof Array).toBe(true);871 done();872 };873 // create reader for root directory874 reader = root.createReader();875 // read entries876 reader.readEntries(win, failed.bind(null, done, 'reader.readEntries - Error reading entries'));877 });878 it("file.spec.37.1 should read contents of existing directory", function (done) {879 var dirName = 'readEntries.dir',880 fileName = 'readeEntries.file';881 root.getDirectory(dirName, {882 create : true883 }, function (directory) {884 directory.getFile(fileName, {885 create : true886 }, function (fileEntry) {887 var reader = directory.createReader();888 reader.readEntries(function (entries) {889 expect(entries).toBeDefined();890 expect(entries instanceof Array).toBe(true);891 expect(entries.length).toBe(1);892 expect(entries[0].fullPath).toCanonicallyMatch(fileEntry.fullPath);893 expect(entries[0].filesystem).not.toBe(null);894 if (isChrome) {895 // Slicing '[object {type}]' -> '{type}'896 expect(entries[0].filesystem.toString().slice(8, -1)).toEqual("DOMFileSystem");897 }898 else {899 expect(entries[0].filesystem instanceof FileSystem).toBe(true);900 }901 // cleanup902 deleteEntry(directory.name, done);903 }, failed.bind(null, done, 'reader.readEntries - Error reading entries from directory: ' + dirName));904 }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + fileName));905 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));906 });907 it("file.spec.109 should return an empty entry list on the second call", function (done) {908 var reader,909 fileName = 'test109.txt';910 // Add a file to ensure the root directory is non-empty and then read the contents of the directory.911 root.getFile(fileName, {912 create : true913 }, function (entry) {914 reader = root.createReader();915 //First read916 reader.readEntries(function (entries) {917 expect(entries).toBeDefined();918 expect(entries instanceof Array).toBe(true);919 expect(entries.length).not.toBe(0);920 //Second read921 reader.readEntries(function (entries_) {922 expect(entries_).toBeDefined();923 expect(entries_ instanceof Array).toBe(true);924 expect(entries_.length).toBe(0);925 //Clean up926 deleteEntry(entry.name, done);927 }, failed.bind(null, done, 'reader.readEntries - Error during SECOND reading of entries from [root] directory'));928 }, failed.bind(null, done, 'reader.readEntries - Error during FIRST reading of entries from [root] directory'));929 }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));930 });931 });932 it("file.spec.38 should read contents of directory that has been removed", function (done) {933 var dirName = "de.createReader.notfound";934 // create a new directory entry to kick off it935 root.getDirectory(dirName, {936 create : true937 }, function (directory) {938 directory.removeRecursively(function () {939 var reader = directory.createReader();940 reader.readEntries(succeed.bind(null, done, 'reader.readEntries - Unexpected success callback, it should not read entries from deleted dir: ' + dirName), function (error) {941 expect(error).toBeDefined();942 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);943 root.getDirectory(dirName, {944 create : false945 }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, it should not get deleted directory: ' + dirName), function (err) {946 expect(err).toBeDefined();947 expect(err).toBeFileError(FileError.NOT_FOUND_ERR);948 done();949 });950 });951 }, failed.bind(null, done, 'directory.removeRecursively - Error removing directory recursively : ' + dirName));952 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dirName));953 });954 });955 //DirectoryReader interface956 describe('File', function () {957 it("file.spec.39 constructor should be defined", function () {958 expect(File).toBeDefined();959 expect(typeof File).toBe('function');960 });961 it("file.spec.40 should be define File attributes", function () {962 var file = new File();963 expect(file.name).toBeDefined();964 expect(file.type).toBeDefined();965 expect(file.lastModifiedDate).toBeDefined();966 expect(file.size).toBeDefined();967 });968 });969 //File970 describe('FileEntry', function () {971 it("file.spec.41 should be define FileEntry methods", function (done) {972 var fileName = "fe.methods",973 testFileEntry = function (fileEntry) {974 expect(fileEntry).toBeDefined();975 expect(typeof fileEntry.createWriter).toBe('function');976 expect(typeof fileEntry.file).toBe('function');977 // cleanup978 deleteEntry(fileEntry.name, done);979 };980 // create a new file entry to kick off it981 root.getFile(fileName, {982 create : true983 }, testFileEntry, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));984 });985 it("file.spec.42 createWriter should return a FileWriter object", function (done) {986 var fileName = "fe.createWriter",987 testFile,988 testWriter = function (writer) {989 expect(writer).toBeDefined();990 if (isChrome) {991 // Slicing '[object {type}]' -> '{type}'992 expect(writer.toString().slice(8, -1)).toEqual("FileWriter");993 }994 else {995 expect(writer instanceof FileWriter).toBe(true);996 }997 // cleanup998 deleteEntry(testFile.name, done);999 };1000 // create a new file entry to kick off it1001 root.getFile(fileName, {1002 create : true1003 }, function (fileEntry) {1004 testFile = fileEntry;1005 fileEntry.createWriter(testWriter, failed.bind(null, done, 'fileEntry.createWriter - Error creating Writer from entry'));1006 }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));1007 });1008 it("file.spec.43 file should return a File object", function (done) {1009 var fileName = "fe.file",1010 newFile,1011 testFile = function (file) {1012 expect(file).toBeDefined();1013 if (isChrome) {1014 // Slicing '[object {type}]' -> '{type}'1015 expect(file.toString().slice(8, -1)).toEqual("File");1016 }1017 else {1018 expect(file instanceof File).toBe(true);1019 }1020 // cleanup1021 deleteEntry(newFile.name, done);1022 };1023 // create a new file entry to kick off it1024 root.getFile(fileName, {1025 create : true1026 }, function (fileEntry) {1027 newFile = fileEntry;1028 fileEntry.file(testFile, failed.bind(null, done, 'fileEntry.file - Error reading file using fileEntry: ' + fileEntry.name));1029 }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));1030 });1031 it("file.spec.44 file: on File that has been removed", function (done) {1032 var fileName = "fe.no.file";1033 // create a new file entry to kick off it1034 root.getFile(fileName, {1035 create : true1036 }, function (fileEntry) {1037 fileEntry.remove(function () {1038 fileEntry.file(succeed.bind(null, done, 'fileEntry.file - Unexpected success callback, file it should not be created from removed entry'), function (error) {1039 expect(error).toBeDefined();1040 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1041 done();1042 });1043 }, failed.bind(null, done, 'fileEntry.remove - Error removing entry : ' + fileName));1044 }, failed.bind(null, done, 'root.getFile - Error creating file : ' + fileName));1045 });1046 });1047 //FileEntry1048 describe('Entry', function () {1049 it("file.spec.45 Entry object", function (done) {1050 var fileName = "entry",1051 fullPath = joinURL(root.fullPath, fileName),1052 winEntry = function (entry) {1053 expect(entry).toBeDefined();1054 expect(entry.isFile).toBe(true);1055 expect(entry.isDirectory).toBe(false);1056 expect(entry.name).toCanonicallyMatch(fileName);1057 expect(entry.fullPath).toCanonicallyMatch(fullPath);1058 expect(typeof entry.getMetadata).toBe('function');1059 expect(typeof entry.setMetadata).toBe('function');1060 expect(typeof entry.moveTo).toBe('function');1061 expect(typeof entry.copyTo).toBe('function');1062 expect(typeof entry.toURL).toBe('function');1063 expect(typeof entry.remove).toBe('function');1064 expect(typeof entry.getParent).toBe('function');1065 expect(typeof entry.createWriter).toBe('function');1066 expect(typeof entry.file).toBe('function');1067 // Clean up1068 deleteEntry(fileName, done);1069 };1070 // create a new file entry1071 createFile(fileName, winEntry, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));1072 });1073 it("file.spec.46 Entry.getMetadata on file", function (done) {1074 var fileName = "entry.metadata.file";1075 // create a new file entry1076 createFile(fileName, function (entry) {1077 entry.getMetadata(function (metadata) {1078 expect(metadata).toBeDefined();1079 expect(metadata.modificationTime instanceof Date).toBe(true);1080 expect(typeof metadata.size).toBe("number");1081 // cleanup1082 deleteEntry(fileName, done);1083 }, failed.bind(null, done, 'entry.getMetadata - Error getting metadata from entry : ' + fileName));1084 }, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));1085 });1086 it("file.spec.47 Entry.getMetadata on directory", function (done) {1087 if (isIndexedDBShim) {1088 /* Does not support metadata for directories (Firefox, IE) */1089 pending();1090 }1091 var dirName = "entry.metadata.dir";1092 // create a new directory entry1093 createDirectory(dirName, function (entry) {1094 entry.getMetadata(function (metadata) {1095 expect(metadata).toBeDefined();1096 expect(metadata.modificationTime instanceof Date).toBe(true);1097 expect(typeof metadata.size).toBe("number");1098 expect(metadata.size).toBe(0);1099 // cleanup1100 deleteEntry(dirName, done);1101 }, failed.bind(null, done, 'entry.getMetadata - Error getting metadata from entry : ' + dirName));1102 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));1103 });1104 it("file.spec.48 Entry.getParent on file in root file system", function (done) {1105 var fileName = "entry.parent.file",1106 rootPath = root.fullPath;1107 // create a new file entry1108 createFile(fileName, function (entry) {1109 entry.getParent(function (parent) {1110 expect(parent).toBeDefined();1111 expect(parent.fullPath).toCanonicallyMatch(rootPath);1112 // cleanup1113 deleteEntry(fileName, done);1114 }, failed.bind(null, done, 'entry.getParent - Error getting parent directory of file : ' + fileName));1115 }, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));1116 });1117 it("file.spec.49 Entry.getParent on directory in root file system", function (done) {1118 var dirName = "entry.parent.dir",1119 rootPath = root.fullPath;1120 // create a new directory entry1121 createDirectory(dirName, function (entry) {1122 entry.getParent(function (parent) {1123 expect(parent).toBeDefined();1124 expect(parent.fullPath).toCanonicallyMatch(rootPath);1125 // cleanup1126 deleteEntry(dirName, done);1127 }, failed.bind(null, done, 'entry.getParent - Error getting parent directory of directory : ' + dirName));1128 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));1129 });1130 it("file.spec.50 Entry.getParent on root file system", function (done) {1131 var rootPath = root.fullPath,1132 winParent = function (parent) {1133 expect(parent).toBeDefined();1134 expect(parent.fullPath).toCanonicallyMatch(rootPath);1135 done();1136 };1137 // create a new directory entry1138 root.getParent(winParent, failed.bind(null, done, 'root.getParent - Error getting parent directory of root'));1139 });1140 it("file.spec.51 Entry.toURL on file", function (done) {1141 var fileName = "entry.uri.file",1142 rootPath = root.fullPath,1143 winURI = function (entry) {1144 var uri = entry.toURL();1145 expect(uri).toBeDefined();1146 expect(uri.indexOf(rootPath)).not.toBe(-1);1147 // cleanup1148 deleteEntry(fileName, done);1149 };1150 // create a new file entry1151 createFile(fileName, winURI, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));1152 });1153 it("file.spec.52 Entry.toURL on directory", function (done) {1154 var dirName_1 = "num 1",1155 dirName_2 = "num 2",1156 rootPath = root.fullPath;1157 createDirectory(dirName_1, function (entry) {1158 entry.getDirectory(dirName_2, {1159 create : true1160 }, function (entryFile) {1161 var uri = entryFile.toURL();1162 expect(uri).toBeDefined();1163 expect(uri).toContain('/num%201/num%202/');1164 expect(uri.indexOf(rootPath)).not.toBe(-1);1165 // cleanup1166 deleteEntry(dirName_1, done);1167 }, failed.bind(null, done, 'entry.getDirectory - Error creating directory : ' + dirName_2));1168 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName_1));1169 });1170 it("file.spec.53 Entry.remove on file", function (done) {1171 var fileName = "entr .rm.file";1172 // create a new file entry1173 createFile(fileName, function (entry) {1174 expect(entry).toBeDefined();1175 entry.remove(function () {1176 root.getFile(fileName, null, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get deleted file : ' + fileName), function (error) {1177 expect(error).toBeDefined();1178 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1179 // cleanup1180 deleteEntry(fileName, done);1181 });1182 }, failed.bind(null, done, 'entry.remove - Error removing entry : ' + fileName));1183 }, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));1184 });1185 it("file.spec.53.1 Entry.remove on filename with #s", function (done) {1186 var fileName = "entry.#rm#.file";1187 // create a new file entry1188 createFile(fileName, function (entry) {1189 expect(entry).toBeDefined();1190 entry.remove(function () {1191 root.getFile(fileName, null, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get deleted file : ' + fileName), function (error) {1192 expect(error).toBeDefined();1193 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1194 // cleanup1195 deleteEntry(fileName, done);1196 });1197 }, failed.bind(null, done, 'entry.remove - Error removing entry : ' + fileName));1198 }, failed.bind(null, done, 'createFile - Error creating file : ' + fileName));1199 });1200 it("file.spec.54 remove on empty directory", function (done) {1201 var dirName = "entry.rm.dir";1202 // create a new directory entry1203 createDirectory(dirName, function (entry) {1204 expect(entry).toBeDefined();1205 entry.remove(function () {1206 root.getDirectory(dirName, null, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, it should not get deleted directory : ' + dirName), function (error) {1207 expect(error).toBeDefined();1208 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1209 // cleanup1210 deleteEntry(dirName, done);1211 });1212 }, failed.bind(null, done, 'entry.remove - Error removing entry : ' + dirName));1213 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));1214 });1215 it("file.spec.55 remove on non-empty directory", function (done) {1216 if (isIndexedDBShim) {1217 /* Both Entry.remove and directoryEntry.removeRecursively don't fail when removing1218 non-empty directories - directories being removed are cleaned1219 along with contents instead (Firefox, IE)*/1220 pending();1221 }1222 var dirName = "ent y.rm.dir.not.empty",1223 fileName = "re ove.txt",1224 fullPath = joinURL(root.fullPath, dirName);1225 // create a new directory entry1226 createDirectory(dirName, function (entry) {1227 entry.getFile(fileName, {1228 create : true1229 }, function (fileEntry) {1230 entry.remove(succeed.bind(null, done, 'entry.remove - Unexpected success callback, it should not remove a directory that contains files : ' + dirName), function (error) {1231 expect(error).toBeDefined();1232 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1233 root.getDirectory(dirName, null, function (entry) {1234 expect(entry).toBeDefined();1235 expect(entry.fullPath).toCanonicallyMatch(fullPath);1236 // cleanup1237 deleteEntry(dirName, done);1238 }, failed.bind(null, done, 'root.getDirectory - Error getting directory : ' + dirName));1239 });1240 }, failed.bind(null, done, 'entry.getFile - Error creating file : ' + fileName + ' inside of ' + dirName));1241 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));1242 });1243 it("file.spec.56 remove on root file system", function (done) {1244 // remove entry that doesn't exist1245 root.remove(succeed.bind(null, done, 'entry.remove - Unexpected success callback, it should not remove entry that it does not exists'), function (error) {1246 expect(error).toBeDefined();1247 if (isChrome) {1248 /*INVALID_MODIFICATION_ERR (code: 9) is thrown instead of1249 NO_MODIFICATION_ALLOWED_ERR(code: 6) on trying to call removeRecursively1250 on the root file system.*/1251 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1252 } else {1253 expect(error).toBeFileError(FileError.NO_MODIFICATION_ALLOWED_ERR);1254 }1255 done();1256 });1257 });1258 it("file.spec.57 copyTo: file", function (done) {1259 var file1 = "entry copy.file1",1260 file2 = "entry copy.file2",1261 fullPath = joinURL(root.fullPath, file2);1262 // create a new file entry to kick off it1263 deleteEntry(file2, function () {1264 createFile(file1, function (fileEntry) {1265 // copy file1 to file21266 fileEntry.copyTo(root, file2, function (entry) {1267 expect(entry).toBeDefined();1268 expect(entry.isFile).toBe(true);1269 expect(entry.isDirectory).toBe(false);1270 expect(entry.fullPath).toCanonicallyMatch(fullPath);1271 expect(entry.name).toCanonicallyMatch(file2);1272 root.getFile(file2, {1273 create : false1274 }, function (entry2) {1275 expect(entry2).toBeDefined();1276 expect(entry2.isFile).toBe(true);1277 expect(entry2.isDirectory).toBe(false);1278 expect(entry2.fullPath).toCanonicallyMatch(fullPath);1279 expect(entry2.name).toCanonicallyMatch(file2);1280 // cleanup1281 deleteEntry(file1, function () {1282 deleteEntry(file2, done);1283 });1284 }, failed.bind(null, done, 'root.getFile - Error getting copied file : ' + file2));1285 }, failed.bind(null, done, 'fileEntry.copyTo - Error copying file : ' + file2));1286 }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));1287 }, failed.bind(null, done, 'deleteEntry - Error removing file : ' + file2));1288 });1289 it("file.spec.58 copyTo: file onto itself", function (done) {1290 var file1 = "entry.copy.fos.file1";1291 // create a new file entry to kick off it1292 createFile(file1, function (entry) {1293 // copy file1 onto itself1294 entry.copyTo(root, null, succeed.bind(null, done, 'entry.copyTo - Unexpected success callback, it should not copy a null file'), function (error) {1295 expect(error).toBeDefined();1296 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1297 // cleanup1298 deleteEntry(file1, done);1299 });1300 }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));1301 });1302 it("file.spec.59 copyTo: directory", function (done) {1303 if (isIndexedDBShim) {1304 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1305 pending();1306 }1307 var file1 = "file1",1308 srcDir = "entry.copy.srcDir",1309 dstDir = "entry.copy.dstDir",1310 dstPath = joinURL(root.fullPath, dstDir),1311 filePath = joinURL(dstPath, file1);1312 // create a new directory entry to kick off it1313 deleteEntry(dstDir, function () {1314 createDirectory(srcDir, function (directory) {1315 // create a file within new directory1316 directory.getFile(file1, {1317 create : true1318 }, function () {1319 directory.copyTo(root, dstDir, function (directory) {1320 expect(directory).toBeDefined();1321 expect(directory.isFile).toBe(false);1322 expect(directory.isDirectory).toBe(true);1323 expect(directory.fullPath).toCanonicallyMatch(dstPath);1324 expect(directory.name).toCanonicallyMatch(dstDir);1325 root.getDirectory(dstDir, {1326 create : false1327 }, function (dirEntry) {1328 expect(dirEntry).toBeDefined();1329 expect(dirEntry.isFile).toBe(false);1330 expect(dirEntry.isDirectory).toBe(true);1331 expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);1332 expect(dirEntry.name).toCanonicallyMatch(dstDir);1333 dirEntry.getFile(file1, {1334 create : false1335 }, function (fileEntry) {1336 expect(fileEntry).toBeDefined();1337 expect(fileEntry.isFile).toBe(true);1338 expect(fileEntry.isDirectory).toBe(false);1339 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1340 expect(fileEntry.name).toCanonicallyMatch(file1);1341 // cleanup1342 deleteEntry(srcDir, function () {1343 deleteEntry(dstDir, done);1344 });1345 }, failed.bind(null, done, 'dirEntry.getFile - Error getting file : ' + file1));1346 }, failed.bind(null, done, 'root.getDirectory - Error getting copied directory : ' + dstDir));1347 }, failed.bind(null, done, 'directory.copyTo - Error copying directory : ' + srcDir + ' to :' + dstDir));1348 }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));1349 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1350 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));1351 });1352 it("file.spec.60 copyTo: directory to backup at same root directory", function (done) {1353 if (isIndexedDBShim) {1354 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1355 pending();1356 }1357 var file1 = "file1",1358 srcDir = "entry.copy srcDirSame",1359 dstDir = "entry.copy srcDirSame-backup",1360 dstPath = joinURL(root.fullPath, dstDir),1361 filePath = joinURL(dstPath, file1);1362 // create a new directory entry to kick off it1363 deleteEntry(dstDir, function () {1364 createDirectory(srcDir, function (directory) {1365 directory.getFile(file1, {1366 create : true1367 }, function () {1368 directory.copyTo(root, dstDir, function (directory) {1369 expect(directory).toBeDefined();1370 expect(directory.isFile).toBe(false);1371 expect(directory.isDirectory).toBe(true);1372 expect(directory.fullPath).toCanonicallyMatch(dstPath);1373 expect(directory.name).toCanonicallyMatch(dstDir);1374 root.getDirectory(dstDir, {1375 create : false1376 }, function (dirEntry) {1377 expect(dirEntry).toBeDefined();1378 expect(dirEntry.isFile).toBe(false);1379 expect(dirEntry.isDirectory).toBe(true);1380 expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);1381 expect(dirEntry.name).toCanonicallyMatch(dstDir);1382 dirEntry.getFile(file1, {1383 create : false1384 }, function (fileEntry) {1385 expect(fileEntry).toBeDefined();1386 expect(fileEntry.isFile).toBe(true);1387 expect(fileEntry.isDirectory).toBe(false);1388 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1389 expect(fileEntry.name).toCanonicallyMatch(file1);1390 // cleanup1391 deleteEntry(srcDir, function () {1392 deleteEntry(dstDir, done);1393 });1394 }, failed.bind(null, done, 'dirEntry.getFile - Error getting file : ' + file1));1395 }, failed.bind(null, done, 'root.getDirectory - Error getting copied directory : ' + dstDir));1396 }, failed.bind(null, done, 'directory.copyTo - Error copying directory : ' + srcDir + ' to :' + dstDir));1397 }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));1398 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1399 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));1400 });1401 it("file.spec.61 copyTo: directory onto itself", function (done) {1402 if (isIndexedDBShim) {1403 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1404 pending();1405 }1406 var file1 = "file1",1407 srcDir = "entry.copy.dos.srcDir",1408 srcPath = joinURL(root.fullPath, srcDir),1409 filePath = joinURL(srcPath, file1);1410 // create a new directory entry to kick off it1411 createDirectory(srcDir, function (directory) {1412 // create a file within new directory1413 directory.getFile(file1, {1414 create : true1415 }, function (fileEntry) {1416 // copy srcDir onto itself1417 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) {1418 expect(error).toBeDefined();1419 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1420 root.getDirectory(srcDir, {1421 create : false1422 }, function (dirEntry) {1423 expect(dirEntry).toBeDefined();1424 expect(dirEntry.fullPath).toCanonicallyMatch(srcPath);1425 dirEntry.getFile(file1, {1426 create : false1427 }, function (fileEntry) {1428 expect(fileEntry).toBeDefined();1429 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1430 // cleanup1431 deleteEntry(srcDir, done);1432 }, failed.bind(null, done, 'dirEntry.getFile - Error getting file : ' + file1));1433 }, failed.bind(null, done, 'root.getDirectory - Error getting directory : ' + srcDir));1434 });1435 }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));1436 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1437 });1438 it("file.spec.62 copyTo: directory into itself", function (done) {1439 if (isIndexedDBShim) {1440 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1441 pending();1442 }1443 var srcDir = "entry.copy.dis.srcDir",1444 dstDir = "entry.copy.dis.dstDir",1445 srcPath = joinURL(root.fullPath, srcDir);1446 // create a new directory entry to kick off it1447 createDirectory(srcDir, function (directory) {1448 // copy source directory into itself1449 directory.copyTo(directory, dstDir, succeed.bind(null, done, 'directory.copyTo - Unexpected success callback, it should not copy a directory ' + srcDir + ' into itself'), function (error) {1450 expect(error).toBeDefined();1451 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1452 root.getDirectory(srcDir, {1453 create : false1454 }, function (dirEntry) {1455 // returning confirms existence so just check fullPath entry1456 expect(dirEntry).toBeDefined();1457 expect(dirEntry.fullPath).toCanonicallyMatch(srcPath);1458 // cleanup1459 deleteEntry(srcDir, done);1460 }, failed.bind(null, done, 'root.getDirectory - Error getting directory : ' + srcDir));1461 });1462 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1463 });1464 it("file.spec.63 copyTo: directory that does not exist", function (done) {1465 var file1 = "entry.copy.dnf.file1",1466 dirName = 'dir-foo';1467 createFile(file1, function (fileEntry) {1468 createDirectory(dirName, function (dirEntry) {1469 dirEntry.remove(function () {1470 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) {1471 expect(error).toBeDefined();1472 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1473 done();1474 });1475 }, failed.bind(null, done, 'dirEntry.remove - Error removing directory : ' + dirName));1476 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dirName));1477 }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));1478 });1479 it("file.spec.64 copyTo: invalid target name", function (done) {1480 if (isBrowser) {1481 /*The plugin does not follow ["8.3 Naming restrictions"]1482 (http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions*/1483 pending();1484 }1485 var file1 = "entry.copy.itn.file1",1486 file2 = "bad:file:name";1487 // create a new file entry1488 createFile(file1, function (entry) {1489 // copy file1 to file21490 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) {1491 expect(error).toBeDefined();1492 expect(error).toBeFileError(FileError.ENCODING_ERR);1493 // cleanup1494 deleteEntry(file1, done);1495 });1496 }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));1497 });1498 it("file.spec.65 moveTo: file to same parent", function (done) {1499 var file1 = "entry.move.fsp.file1",1500 file2 = "entry.move.fsp.file2",1501 dstPath = joinURL(root.fullPath, file2);1502 // create a new file entry to kick off it1503 createFile(file1, function (entry) {1504 // move file1 to file21505 entry.moveTo(root, file2, function (entry) {1506 expect(entry).toBeDefined();1507 expect(entry.isFile).toBe(true);1508 expect(entry.isDirectory).toBe(false);1509 expect(entry.fullPath).toCanonicallyMatch(dstPath);1510 expect(entry.name).toCanonicallyMatch(file2);1511 root.getFile(file2, {1512 create : false1513 }, function (fileEntry) {1514 expect(fileEntry).toBeDefined();1515 expect(fileEntry.fullPath).toCanonicallyMatch(dstPath);1516 root.getFile(file1, {1517 create : false1518 }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {1519 //expect(navigator.fileMgr.testFileExists(srcPath) === false, "original file should not exist.");1520 expect(error).toBeDefined();1521 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1522 // cleanup1523 deleteEntry(file1, function () {1524 deleteEntry(file2, done);1525 });1526 });1527 }, failed.bind(null, done, 'root.getFile - Error getting file : ' + file2));1528 }, failed.bind(null, done, 'entry.moveTo - Error moving file : ' + file1 + ' to root as: ' + file2));1529 }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));1530 });1531 it("file.spec.66 moveTo: file to new parent", function (done) {1532 var file1 = "entry.move.fnp.file1",1533 dir = "entry.move.fnp.dir",1534 dstPath = joinURL(joinURL(root.fullPath, dir), file1);1535 // ensure destination directory is cleaned up first1536 deleteEntry(dir, function () {1537 // create a new file entry to kick off it1538 createFile(file1, function (entry) {1539 // create a parent directory to move file to1540 root.getDirectory(dir, {1541 create : true1542 }, function (directory) {1543 // move file1 to new directory1544 // move the file1545 entry.moveTo(directory, null, function (entry) {1546 expect(entry).toBeDefined();1547 expect(entry.isFile).toBe(true);1548 expect(entry.isDirectory).toBe(false);1549 expect(entry.fullPath).toCanonicallyMatch(dstPath);1550 expect(entry.name).toCanonicallyMatch(file1);1551 // test the moved file exists1552 directory.getFile(file1, {1553 create : false1554 }, function (fileEntry) {1555 expect(fileEntry).toBeDefined();1556 expect(fileEntry.fullPath).toCanonicallyMatch(dstPath);1557 root.getFile(file1, {1558 create : false1559 }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {1560 expect(error).toBeDefined();1561 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1562 // cleanup1563 deleteEntry(file1, function () {1564 deleteEntry(dir, done);1565 });1566 });1567 }, failed.bind(null, done, 'directory.getFile - Error getting file : ' + file1 + ' from: ' + dir));1568 }, failed.bind(null, done, 'entry.moveTo - Error moving file : ' + file1 + ' to: ' + dir + ' with the same name'));1569 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dir));1570 }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));1571 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dir));1572 });1573 it("file.spec.67 moveTo: directory to same parent", function (done) {1574 if (isIndexedDBShim) {1575 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1576 pending();1577 }1578 var file1 = "file1",1579 srcDir = "entry.move.dsp.srcDir",1580 dstDir = "entry.move.dsp.dstDir",1581 dstPath = joinURL(root.fullPath, dstDir),1582 filePath = joinURL(dstPath, file1);1583 // ensure destination directory is cleaned up before it1584 deleteEntry(dstDir, function () {1585 // create a new directory entry to kick off it1586 createDirectory(srcDir, function (directory) {1587 // create a file within directory1588 directory.getFile(file1, {1589 create : true1590 }, function () {1591 // move srcDir to dstDir1592 directory.moveTo(root, dstDir, function (directory) {1593 expect(directory).toBeDefined();1594 expect(directory.isFile).toBe(false);1595 expect(directory.isDirectory).toBe(true);1596 expect(directory.fullPath).toCanonicallyMatch(dstPath);1597 expect(directory.name).toCanonicallyMatch(dstDir);1598 // test that moved file exists in destination dir1599 directory.getFile(file1, {1600 create : false1601 }, function (fileEntry) {1602 expect(fileEntry).toBeDefined();1603 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1604 // check that the moved file no longer exists in original dir1605 root.getFile(file1, {1606 create : false1607 }, succeed.bind(null, done, 'directory.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {1608 expect(error).toBeDefined();1609 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1610 // cleanup1611 deleteEntry(srcDir, function() {1612 deleteEntry(dstDir, done);1613 });1614 });1615 }, failed.bind(null, done, 'directory.getFile - Error getting file : ' + file1 + ' from: ' + srcDir));1616 }, failed.bind(null, done, 'entry.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));1617 }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));1618 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1619 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));1620 });1621 it("file.spec.68 moveTo: directory to same parent with same name", function (done) {1622 if (isIndexedDBShim) {1623 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1624 pending();1625 }1626 var file1 = "file1",1627 srcDir = "entry.move.dsp.srcDir",1628 dstDir = "entry.move.dsp.srcDir-backup",1629 dstPath = joinURL(root.fullPath, dstDir),1630 filePath = joinURL(dstPath, file1);1631 // ensure destination directory is cleaned up before it1632 deleteEntry(dstDir, function () {1633 // create a new directory entry to kick off it1634 createDirectory(srcDir, function (directory) {1635 // create a file within directory1636 directory.getFile(file1, {1637 create : true1638 }, function () {1639 // move srcDir to dstDir1640 directory.moveTo(root, dstDir, function (directory) {1641 expect(directory).toBeDefined();1642 expect(directory.isFile).toBe(false);1643 expect(directory.isDirectory).toBe(true);1644 expect(directory.fullPath).toCanonicallyMatch(dstPath);1645 expect(directory.name).toCanonicallyMatch(dstDir);1646 // check that moved file exists in destination dir1647 directory.getFile(file1, {1648 create : false1649 }, function (fileEntry) {1650 expect(fileEntry).toBeDefined();1651 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1652 // check that the moved file no longer exists in original dir1653 root.getFile(file1, {1654 create : false1655 }, succeed.bind(null, done, 'directory.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {1656 expect(error).toBeDefined();1657 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1658 // cleanup1659 deleteEntry(srcDir, function() {1660 deleteEntry(dstDir, done);1661 });1662 });1663 }, failed.bind(null, done, 'directory.getFile - Error getting file : ' + file1 + ' from: ' + srcDir));1664 }, failed.bind(null, done, 'entry.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));1665 }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));1666 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1667 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));1668 });1669 it("file.spec.69 moveTo: directory to new parent", function (done) {1670 if (isIndexedDBShim) {1671 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1672 pending();1673 }1674 var file1 = "file1",1675 srcDir = "entry.move.dnp.srcDir",1676 dstDir = "entry.move.dnp.dstDir",1677 dstPath = joinURL(root.fullPath, dstDir),1678 filePath = joinURL(dstPath, file1);1679 // ensure destination directory is cleaned up before it1680 deleteEntry(dstDir, function () {1681 // create a new directory entry to kick off it1682 createDirectory(srcDir, function (directory) {1683 // create a file within directory1684 directory.getFile(file1, {1685 create : true1686 }, function () {1687 // move srcDir to dstDir1688 directory.moveTo(root, dstDir, function (dirEntry) {1689 expect(dirEntry).toBeDefined();1690 expect(dirEntry.isFile).toBe(false);1691 expect(dirEntry.isDirectory).toBe(true);1692 expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);1693 expect(dirEntry.name).toCanonicallyMatch(dstDir);1694 // test that moved file exists in destination dir1695 dirEntry.getFile(file1, {1696 create : false1697 }, function (fileEntry) {1698 expect(fileEntry).toBeDefined();1699 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1700 // test that the moved file no longer exists in original dir1701 root.getFile(file1, {1702 create : false1703 }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not get invalid or moved file: ' + file1), function (error) {1704 expect(error).toBeDefined();1705 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);1706 // cleanup1707 deleteEntry(srcDir, function() {1708 deleteEntry(dstDir, done);1709 });1710 });1711 }, failed.bind(null, done, 'directory.getFile - Error getting file : ' + file1 + ' from: ' + dstDir));1712 }, failed.bind(null, done, 'directory.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));1713 }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));1714 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1715 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));1716 });1717 it("file.spec.131 moveTo: directories tree to new parent", function (done) {1718 if (isIndexedDBShim) {1719 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1720 pending();1721 }1722 var srcDir = "entry.move.dnp.srcDir";1723 var srcDirNestedFirst = "entry.move.dnp.srcDir.Nested1";1724 var srcDirNestedSecond = "entry.move.dnp.srcDir.Nested2";1725 var dstDir = "entry.move.dnp.dstDir";1726 createDirectory(dstDir, function (dstDirectory) {1727 createDirectory(srcDir, function (srcDirectory) {1728 srcDirectory.getDirectory(srcDirNestedFirst, { create: true }, function () {1729 srcDirectory.getDirectory(srcDirNestedSecond, { create: true }, function () {1730 srcDirectory.moveTo(dstDirectory, srcDir, function successMove(transferredDirectory) {1731 var directoryReader = transferredDirectory.createReader();1732 directoryReader.readEntries(function successRead(entries) {1733 expect(entries.length).toBe(2);1734 expect(entries[0].name).toBe(srcDirNestedFirst);1735 expect(entries[1].name).toBe(srcDirNestedSecond);1736 deleteEntry(dstDir, done);1737 }, failed.bind(null, done, 'Error getting entries from: ' + transferredDirectory));1738 }, failed.bind(null, done, 'directory.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));1739 }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + srcDirNestedSecond));1740 }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + srcDirNestedFirst));1741 }, failed.bind(null, done, 'createDirectory - Error creating source directory : ' + srcDir));1742 }, failed.bind(null, done, 'createDirectory - Error creating dest directory : ' + dstDir));1743 });1744 it("file.spec.70 moveTo: directory onto itself", function (done) {1745 if (isIndexedDBShim) {1746 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1747 pending();1748 }1749 var file1 = "file1",1750 srcDir = "entry.move.dos.srcDir",1751 srcPath = joinURL(root.fullPath, srcDir),1752 filePath = joinURL(srcPath, file1);1753 // create a new directory entry to kick off it1754 createDirectory(srcDir, function (directory) {1755 // create a file within new directory1756 directory.getFile(file1, {1757 create : true1758 }, function () {1759 // move srcDir onto itself1760 directory.moveTo(root, null, succeed.bind(null, done, 'directory.moveTo - Unexpected success callback, it should not move directory to invalid path'), function (error) {1761 expect(error).toBeDefined();1762 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1763 // test that original dir still exists1764 root.getDirectory(srcDir, {1765 create : false1766 }, function (dirEntry) {1767 // returning confirms existence so just check fullPath entry1768 expect(dirEntry).toBeDefined();1769 expect(dirEntry.fullPath).toCanonicallyMatch(srcPath);1770 dirEntry.getFile(file1, {1771 create : false1772 }, function (fileEntry) {1773 expect(fileEntry).toBeDefined();1774 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1775 // cleanup1776 deleteEntry(srcDir, done);1777 }, failed.bind(null, done, 'dirEntry.getFile - Error getting file : ' + file1 + ' from: ' + srcDir));1778 }, failed.bind(null, done, 'root.getDirectory - Error getting directory : ' + srcDir));1779 });1780 }, failed.bind(null, done, 'directory.getFile - Error creating file : ' + file1));1781 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1782 });1783 it("file.spec.71 moveTo: directory into itself", function (done) {1784 if (isIndexedDBShim) {1785 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1786 pending();1787 }1788 var srcDir = "entry.move.dis.srcDir",1789 dstDir = "entry.move.dis.dstDir",1790 srcPath = joinURL(root.fullPath, srcDir);1791 // create a new directory entry to kick off it1792 createDirectory(srcDir, function (directory) {1793 // move source directory into itself1794 directory.moveTo(directory, dstDir, succeed.bind(null, done, 'directory.moveTo - Unexpected success callback, it should not move a directory into itself: ' + srcDir), function (error) {1795 expect(error).toBeDefined();1796 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1797 // make sure original directory still exists1798 root.getDirectory(srcDir, {1799 create : false1800 }, function (entry) {1801 expect(entry).toBeDefined();1802 expect(entry.fullPath).toCanonicallyMatch(srcPath);1803 // cleanup1804 deleteEntry(srcDir, done);1805 }, failed.bind(null, done, 'root.getDirectory - Error getting directory, making sure that original directory still exists: ' + srcDir));1806 });1807 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1808 });1809 it("file.spec.130 moveTo: directory into similar directory", function (done) {1810 if (isIndexedDBShim) {1811 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1812 pending();1813 }1814 var srcDir = "entry.move.dis.srcDir",1815 dstDir = "entry.move.dis.srcDir-backup";1816 // create a new directory entry to kick off it1817 createDirectory(srcDir, function (srcDirEntry) {1818 deleteEntry(dstDir, function () {1819 createDirectory(dstDir, function (dstDirEntry) {1820 // move source directory into itself1821 srcDirEntry.moveTo(dstDirEntry, 'file', function (newDirEntry) {1822 expect(newDirEntry).toBeDefined();1823 deleteEntry(dstDir, done);1824 }, failed.bind(null, done, 'directory.moveTo - Error moving a directory into a similarly-named directory: ' + srcDir));1825 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dstDir));1826 }, failed.bind(null, done, 'deleteEntry - Error deleting directory : ' + dstDir));1827 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1828 });1829 it("file.spec.72 moveTo: file onto itself", function (done) {1830 var file1 = "entry.move.fos.file1",1831 filePath = joinURL(root.fullPath, file1);1832 // create a new file entry to kick off it1833 createFile(file1, function (entry) {1834 // move file1 onto itself1835 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) {1836 expect(error).toBeDefined();1837 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1838 //test that original file still exists1839 root.getFile(file1, {1840 create : false1841 }, function (fileEntry) {1842 expect(fileEntry).toBeDefined();1843 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1844 // cleanup1845 deleteEntry(file1, done);1846 }, failed.bind(null, done, 'root.getFile - Error getting file, making sure that original file still exists: ' + file1));1847 });1848 }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));1849 });1850 it("file.spec.73 moveTo: file onto existing directory", function (done) {1851 var file1 = "entry.move.fod.file1",1852 dstDir = "entry.move.fod.dstDir",1853 subDir = "subDir",1854 dirPath = joinURL(joinURL(root.fullPath, dstDir), subDir),1855 filePath = joinURL(root.fullPath, file1);1856 // ensure destination directory is cleaned up before it1857 deleteEntry(dstDir, function () {1858 // create a new file entry to kick off it1859 createFile(file1, function (entry) {1860 // create top level directory1861 root.getDirectory(dstDir, {1862 create : true1863 }, function (directory) {1864 // create sub-directory1865 directory.getDirectory(subDir, {1866 create : true1867 }, function (subDirectory) {1868 // move file1 onto sub-directory1869 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) {1870 expect(error).toBeDefined();1871 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1872 // check that original dir still exists1873 directory.getDirectory(subDir, {1874 create : false1875 }, function (dirEntry) {1876 expect(dirEntry).toBeDefined();1877 expect(dirEntry.fullPath).toCanonicallyMatch(dirPath);1878 // check that original file still exists1879 root.getFile(file1, {1880 create : false1881 }, function (fileEntry) {1882 expect(fileEntry).toBeDefined();1883 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1884 // cleanup1885 deleteEntry(file1, function () {1886 deleteEntry(dstDir, done);1887 });1888 }, failed.bind(null, done, 'root.getFile - Error getting file, making sure that original file still exists: ' + file1));1889 }, failed.bind(null, done, 'directory.getDirectory - Error getting directory, making sure that original directory still exists: ' + subDir));1890 });1891 }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + subDir));1892 }, failed.bind(null, done, 'root.getDirectory - Error creating directory : ' + dstDir));1893 }, failed.bind(null, done, 'createFile - Error creating file : ' + file1));1894 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));1895 });1896 it("file.spec.74 moveTo: directory onto existing file", function (done) {1897 if (isIndexedDBShim) {1898 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1899 pending();1900 }1901 var file1 = "entry.move.dof.file1",1902 srcDir = "entry.move.dof.srcDir",1903 dirPath = joinURL(root.fullPath, srcDir),1904 filePath = joinURL(root.fullPath, file1);1905 // create a new directory entry to kick off it1906 createDirectory(srcDir, function (entry) {1907 // create file1908 root.getFile(file1, {1909 create : true1910 }, function (fileEntry) {1911 // move directory onto file1912 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) {1913 expect(error).toBeDefined();1914 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1915 // test that original directory exists1916 root.getDirectory(srcDir, {1917 create : false1918 }, function (dirEntry) {1919 // returning confirms existence so just check fullPath entry1920 expect(dirEntry).toBeDefined();1921 expect(dirEntry.fullPath).toCanonicallyMatch(dirPath);1922 // test that original file exists1923 root.getFile(file1, {1924 create : false1925 }, function (fileEntry) {1926 expect(fileEntry).toBeDefined();1927 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1928 // cleanup1929 deleteEntry(file1, function () {1930 deleteEntry(srcDir, done);1931 });1932 }, failed.bind(null, done, 'root.getFile - Error getting file, making sure that original file still exists: ' + file1));1933 }, failed.bind(null, done, 'directory.getDirectory - Error getting directory, making sure that original directory still exists: ' + srcDir));1934 });1935 }, failed.bind(null, done, 'root.getFile - Error creating file : ' + file1));1936 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1937 });1938 it("file.spec.75 copyTo: directory onto existing file", function (done) {1939 if (isIndexedDBShim) {1940 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1941 pending();1942 }1943 var file1 = "entry.copy.dof.file1",1944 srcDir = "entry.copy.dof.srcDir",1945 dirPath = joinURL(root.fullPath, srcDir),1946 filePath = joinURL(root.fullPath, file1);1947 // create a new directory entry to kick off it1948 createDirectory(srcDir, function (entry) {1949 // create file1950 root.getFile(file1, {1951 create : true1952 }, function () {1953 // copy directory onto file1954 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) {1955 expect(error).toBeDefined();1956 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);1957 //check that original dir still exists1958 root.getDirectory(srcDir, {1959 create : false1960 }, function (dirEntry) {1961 // returning confirms existence so just check fullPath entry1962 expect(dirEntry).toBeDefined();1963 expect(dirEntry.fullPath).toCanonicallyMatch(dirPath);1964 // test that original file still exists1965 root.getFile(file1, {1966 create : false1967 }, function (fileEntry) {1968 expect(fileEntry).toBeDefined();1969 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);1970 // cleanup1971 deleteEntry(file1, function () {1972 deleteEntry(srcDir, done);1973 });1974 }, failed.bind(null, done, 'root.getFile - Error getting file, making sure that original file still exists: ' + file1));1975 }, failed.bind(null, done, 'root.getDirectory - Error getting directory, making sure that original directory still exists: ' + srcDir));1976 });1977 }, failed.bind(null, done, 'root.getFile - Error creating file : ' + file1));1978 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));1979 });1980 it("file.spec.76 moveTo: directory onto directory that is not empty", function (done) {1981 if (isIndexedDBShim) {1982 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */1983 pending();1984 }1985 var srcDir = "entry.move.dod.srcDir",1986 dstDir = "entry.move.dod.dstDir",1987 subDir = "subDir",1988 srcPath = joinURL(root.fullPath, srcDir),1989 dstPath = joinURL(joinURL(root.fullPath, dstDir), subDir);1990 // ensure destination directory is cleaned up before it1991 deleteEntry(dstDir, function () {1992 // create a new file entry to kick off it1993 createDirectory(srcDir, function (entry) {1994 // create top level directory1995 root.getDirectory(dstDir, {1996 create : true1997 }, function (directory) {1998 // create sub-directory1999 directory.getDirectory(subDir, {2000 create : true2001 }, function () {2002 // move srcDir onto dstDir (not empty)2003 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) {2004 expect(error).toBeDefined();2005 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);2006 // making sure destination directory still exists2007 directory.getDirectory(subDir, {2008 create : false2009 }, function (dirEntry) {2010 // returning confirms existence so just check fullPath entry2011 expect(dirEntry).toBeDefined();2012 expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);2013 // making sure source directory exists2014 root.getDirectory(srcDir, {2015 create : false2016 }, function (srcEntry) {2017 expect(srcEntry).toBeDefined();2018 expect(srcEntry.fullPath).toCanonicallyMatch(srcPath);2019 // cleanup2020 deleteEntry(srcDir, function () {2021 deleteEntry(dstDir, done);2022 });2023 }, failed.bind(null, done, 'root.getDirectory - Error getting directory, making sure that original directory still exists: ' + srcDir));2024 }, failed.bind(null, done, 'directory.getDirectory - Error getting directory, making sure that original directory still exists: ' + subDir));2025 });2026 }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + subDir));2027 }, failed.bind(null, done, 'directory.getDirectory - Error creating directory : ' + subDir));2028 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));2029 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));2030 });2031 it("file.spec.77 moveTo: file replace existing file", function (done) {2032 var file1 = "entry.move.frf.file1",2033 file2 = "entry.move.frf.file2",2034 file2Path = joinURL(root.fullPath, file2);2035 // create a new directory entry to kick off it2036 createFile(file1, function (entry) {2037 // create file2038 root.getFile(file2, {2039 create : true2040 }, function () {2041 // replace file2 with file12042 entry.moveTo(root, file2, function (entry2) {2043 expect(entry2).toBeDefined();2044 expect(entry2.isFile).toBe(true);2045 expect(entry2.isDirectory).toBe(false);2046 expect(entry2.fullPath).toCanonicallyMatch(file2Path);2047 expect(entry2.name).toCanonicallyMatch(file2);2048 // old file should not exists2049 root.getFile(file1, {2050 create : false2051 }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, file: ' + file1 + ' should not exists'), function (error) {2052 expect(error).toBeDefined();2053 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);2054 // test that new file exists2055 root.getFile(file2, {2056 create : false2057 }, function (fileEntry) {2058 expect(fileEntry).toBeDefined();2059 expect(fileEntry.fullPath).toCanonicallyMatch(file2Path);2060 // cleanup2061 deleteEntry(file1, function () {2062 deleteEntry(file2, done);2063 });2064 }, failed.bind(null, done, 'root.getFile - Error getting moved file: ' + file2));2065 });2066 }, failed.bind(null, done, 'entry.moveTo - Error moving file : ' + file1 + ' to root as: ' + file2));2067 }, failed.bind(null, done, 'root.getFile - Error creating file: ' + file2));2068 }, failed.bind(null, done, 'createFile - Error creating file: ' + file1));2069 });2070 it("file.spec.78 moveTo: directory replace empty directory", function (done) {2071 if (isIndexedDBShim) {2072 /* `copyTo` and `moveTo` functions do not support directories (Firefox, IE) */2073 pending();2074 }2075 var file1 = "file1",2076 srcDir = "entry.move.drd.srcDir",2077 dstDir = "entry.move.drd.dstDir",2078 dstPath = joinURL(root.fullPath, dstDir),2079 filePath = dstPath + '/' + file1;2080 // ensure destination directory is cleaned up before it2081 deleteEntry(dstDir, function () {2082 // create a new directory entry to kick off it2083 createDirectory(srcDir, function (directory) {2084 // create a file within source directory2085 directory.getFile(file1, {2086 create : true2087 }, function () {2088 // create destination directory2089 root.getDirectory(dstDir, {2090 create : true2091 }, function () {2092 // move srcDir to dstDir2093 directory.moveTo(root, dstDir, function (dirEntry) {2094 expect(dirEntry).toBeDefined();2095 expect(dirEntry.isFile).toBe(false);2096 expect(dirEntry.isDirectory).toBe(true);2097 expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);2098 expect(dirEntry.name).toCanonicallyMatch(dstDir);2099 // check that old directory contents have been moved2100 dirEntry.getFile(file1, {2101 create : false2102 }, function (fileEntry) {2103 expect(fileEntry).toBeDefined();2104 expect(fileEntry.fullPath).toCanonicallyMatch(filePath);2105 // check that old directory no longer exists2106 root.getDirectory(srcDir, {2107 create : false2108 }, succeed.bind(null, done, 'root.getDirectory - Unexpected success callback, directory: ' + srcDir + ' should not exists'), function (error) {2109 expect(error).toBeDefined();2110 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);2111 // cleanup2112 deleteEntry(srcDir, function () {2113 deleteEntry(dstDir, done);2114 });2115 });2116 }, failed.bind(null, done, 'dirEntry.getFile - Error getting moved file: ' + file1));2117 }, failed.bind(null, done, 'entry.moveTo - Error moving directory : ' + srcDir + ' to root as: ' + dstDir));2118 }, failed.bind(null, done, 'root.getDirectory - Error creating directory: ' + dstDir));2119 }, failed.bind(null, done, 'root.getFile - Error creating file: ' + file1));2120 }, failed.bind(null, done, 'createDirectory - Error creating directory: ' + srcDir));2121 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));2122 });2123 it("file.spec.79 moveTo: directory that does not exist", function (done) {2124 var file1 = "entry.move.dnf.file1",2125 dstDir = "entry.move.dnf.dstDir",2126 dstPath = joinURL(root.fullPath, dstDir);2127 // create a new file entry to kick off it2128 createFile(file1, function (entry) {2129 // move file to directory that does not exist2130 var directory = new DirectoryEntry();2131 directory.filesystem = root.filesystem;2132 directory.fullPath = dstPath;2133 entry.moveTo(directory, null, succeed.bind(null, done, 'entry.moveTo - Unexpected success callback, parent directory: ' + dstPath + ' should not exists'), function (error) {2134 expect(error).toBeDefined();2135 if (isChrome) {2136 /*INVALID_MODIFICATION_ERR (code: 9) is thrown instead of NOT_FOUND_ERR(code: 1)2137 on trying to moveTo directory that does not exist.*/2138 expect(error).toBeFileError(FileError.INVALID_MODIFICATION_ERR);2139 } else {2140 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);2141 }2142 // cleanup2143 deleteEntry(file1, done);2144 });2145 }, failed.bind(null, done, 'createFile - Error creating file: ' + file1));2146 });2147 it("file.spec.80 moveTo: invalid target name", function (done) {2148 if (isBrowser) {2149 /*The plugin does not follow ["8.3 Naming restrictions"]2150 (http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions*/2151 pending();2152 }2153 var file1 = "entry.move.itn.file1",2154 file2 = "bad:file:name";2155 // create a new file entry to kick off it2156 createFile(file1, function (entry) {2157 // move file1 to file22158 entry.moveTo(root, file2, succeed.bind(null, done, 'entry.moveTo - Unexpected success callback, : ' + file1 + ' to root as: ' + file2), function (error) {2159 expect(error).toBeDefined();2160 expect(error).toBeFileError(FileError.ENCODING_ERR);2161 // cleanup2162 deleteEntry(file1, done);2163 });2164 }, failed.bind(null, done, 'createFile - Error creating file: ' + file1));2165 });2166 });2167 //Entry2168 describe('FileReader', function () {2169 it("file.spec.81 should have correct methods", function () {2170 var reader = new FileReader();2171 expect(reader).toBeDefined();2172 expect(typeof reader.readAsBinaryString).toBe('function');2173 expect(typeof reader.readAsDataURL).toBe('function');2174 expect(typeof reader.readAsText).toBe('function');2175 expect(typeof reader.readAsArrayBuffer).toBe('function');2176 expect(typeof reader.abort).toBe('function');2177 expect(reader.result).toBe(null);2178 });2179 });2180 //FileReader2181 describe('Read method', function () {2182 it("file.spec.82 should error out on non-existent file", function (done) {2183 var fileName = cordova.platformId === 'windowsphone' ? root.toURL() + "/" + "somefile.txt" : "somefile.txt",2184 verifier = function (evt) {2185 expect(evt).toBeDefined();2186 expect(evt.target.error).toBeFileError(FileError.NOT_FOUND_ERR);2187 done();2188 };2189 root.getFile(fileName, {2190 create : true2191 }, function (entry) {2192 entry.file(function (file) {2193 deleteEntry(fileName, function () {2194 //Create FileReader2195 var reader = new FileReader();2196 reader.onerror = verifier;2197 reader.onload = succeed.bind(null, done, 'reader.onload - Unexpected success callback, file: ' + fileName + ' it should not exists');2198 reader.readAsText(file);2199 }, failed.bind(null, done, 'deleteEntry - Error removing file: ' + fileName));2200 }, failed.bind(null, done, 'entry.file - Error reading file: ' + fileName));2201 }, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));2202 });2203 it("file.spec.83 should be able to read native blob objects", function (done) {2204 // Skip test if blobs are not supported (e.g.: Android 2.3).2205 if (typeof window.Blob == 'undefined' || typeof window.Uint8Array == 'undefined') {2206 expect(true).toFailWithMessage('Platform does not supported this feature');2207 done();2208 }2209 var contents = 'asdf';2210 var uint8Array = new Uint8Array(contents.length);2211 for (var i = 0; i < contents.length; ++i) {2212 uint8Array[i] = contents.charCodeAt(i);2213 }2214 var Builder = window.BlobBuilder || window.WebKitBlobBuilder;2215 var blob;2216 if (Builder) {2217 var builder = new Builder();2218 builder.append(uint8Array.buffer);2219 builder.append(contents);2220 blob = builder.getBlob("text/plain");2221 } else {2222 try {2223 // iOS 6 does not support Views, so pass in the buffer.2224 blob = new Blob([uint8Array.buffer, contents]);2225 } catch (e) {2226 // Skip the test if we can't create a blob (e.g.: iOS 5).2227 if (e instanceof TypeError) {2228 expect(true).toFailWithMessage('Platform does not supported this feature');2229 done();2230 }2231 throw e;2232 }2233 }2234 var verifier = function (evt) {2235 expect(evt).toBeDefined();2236 expect(evt.target.result).toBe('asdfasdf');2237 done();2238 };2239 var reader = new FileReader();2240 reader.onloadend = verifier;2241 reader.readAsText(blob);2242 });2243 function writeDummyFile(writeBinary, callback, done, fileContents) {2244 var fileName = "dummy.txt",2245 fileEntry = null,2246 // use default string if file data is not provided2247 fileData = fileContents !== undefined ? fileContents :2248 '\u20AC\xEB - There is an exception to every rule. Except this one.',2249 fileDataAsBinaryString = fileContents !== undefined ? fileContents :2250 '\xe2\x82\xac\xc3\xab - There is an exception to every rule. Except this one.';2251 function createWriter(fe) {2252 fileEntry = fe;2253 fileEntry.createWriter(writeFile, failed.bind(null, done, 'fileEntry.createWriter - Error reading file: ' + fileName));2254 }2255 // writes file and reads it back in2256 function writeFile(writer) {2257 writer.onwriteend = function () {2258 fileEntry.file(function (f) {2259 callback(fileEntry, f, fileData, fileDataAsBinaryString);2260 }, failed.bind(null, done, 'writer.onwriteend - Error writing data on file: ' + fileName));2261 };2262 writer.write(fileData);2263 }2264 fileData += writeBinary ? 'bin:\x01\x00' : '';2265 fileDataAsBinaryString += writeBinary ? 'bin:\x01\x00' : '';2266 // create a file, write to it, and read it in again2267 createFile(fileName, createWriter, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2268 }2269 function runReaderTest(funcName, writeBinary, done, progressFunc, verifierFunc, sliceStart, sliceEnd, fileContents) {2270 writeDummyFile(writeBinary, function (fileEntry, file, fileData, fileDataAsBinaryString) {2271 var verifier = function (evt) {2272 expect(evt).toBeDefined();2273 verifierFunc(evt, fileData, fileDataAsBinaryString);2274 };2275 var reader = new FileReader();2276 reader.onprogress = progressFunc;2277 reader.onload = verifier;2278 reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + file + ' using function: ' + funcName);2279 if (sliceEnd !== undefined) {2280 // 'type' is specified so that is will be preserved in the resulting file:2281 // http://www.w3.org/TR/FileAPI/#slice-method-algo -> "6.4.1. The slice method" -> 4. A), 6. c)2282 file = file.slice(sliceStart, sliceEnd, file.type);2283 } else if (sliceStart !== undefined) {2284 file = file.slice(sliceStart, file.size, file.type);2285 }2286 reader[funcName](file);2287 }, done, fileContents);2288 }2289 function arrayBufferEqualsString(ab, str) {2290 var buf = new Uint8Array(ab);2291 var match = buf.length == str.length;2292 for (var i = 0; match && i < buf.length; i++) {2293 match = buf[i] == str.charCodeAt(i);2294 }2295 return match;2296 }2297 it("file.spec.84 should read file properly, readAsText", function (done) {2298 runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {2299 expect(evt.target.result).toBe(fileData);2300 done();2301 });2302 });2303 it("file.spec.84.1 should read JSON file properly, readAsText", function (done) {2304 var testObject = {key1: "value1", key2: 2};2305 runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {2306 expect(evt.target.result).toEqual(JSON.stringify(testObject));2307 done();2308 }, undefined, undefined, JSON.stringify(testObject));2309 });2310 it("file.spec.85 should read file properly, Data URI", function (done) {2311 runReaderTest('readAsDataURL', true, done, null, function (evt, fileData, fileDataAsBinaryString) {2312 /* `readAsDataURL` function is supported, but the mediatype in Chrome depends on entry name extension,2313 mediatype in IE is always empty (which is the same as `text-plain` according the specification),2314 the mediatype in Firefox is always `application/octet-stream`.2315 For example, if the content is `abcdefg` then Firefox returns `data:application/octet-stream;base64,YWJjZGVmZw==`,2316 IE returns `data:;base64,YWJjZGVmZw==`, Chrome returns `data:<mediatype depending on extension of entry name>;base64,YWJjZGVmZw==`. */2317 expect(evt.target.result).toBeDataUrl();2318 //The atob function it is completely ignored during mobilespec execution, besides the returned object: evt2319 //it is encoded and the atob function is aimed to decode a string. Even with btoa (encode) the function it gets stucked2320 //because of the Unicode characters that contains the fileData object.2321 //Issue reported at JIRA with all the details: CB-70952322 //expect(evt.target.result.slice(23)).toBe(atob(fileData));2323 done();2324 });2325 });2326 it("file.spec.86 should read file properly, readAsBinaryString", function (done) {2327 if (isIE) {2328 /*`readAsBinaryString` function is not supported by IE and has not the stub.*/2329 pending();2330 }2331 runReaderTest('readAsBinaryString', true, done, null, function (evt, fileData, fileDataAsBinaryString) {2332 expect(evt.target.result).toBe(fileDataAsBinaryString);2333 done();2334 });2335 });2336 it("file.spec.87 should read file properly, readAsArrayBuffer", function (done) {2337 // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).2338 if (typeof window.ArrayBuffer == 'undefined') {2339 expect(true).toFailWithMessage('Platform does not supported this feature');2340 done();2341 }2342 runReaderTest('readAsArrayBuffer', true, done, null, function (evt, fileData, fileDataAsBinaryString) {2343 expect(arrayBufferEqualsString(evt.target.result, fileDataAsBinaryString)).toBe(true);2344 done();2345 });2346 });2347 it("file.spec.88 should read sliced file: readAsText", function (done) {2348 runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {2349 expect(evt.target.result).toBe(fileDataAsBinaryString.slice(10, 40));2350 done();2351 }, 10, 40);2352 });2353 it("file.spec.89 should read sliced file: slice past eof", function (done) {2354 runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {2355 expect(evt.target.result).toBe(fileData.slice(-5, 9999));2356 done();2357 }, -5, 9999);2358 });2359 it("file.spec.90 should read sliced file: slice to eof", function (done) {2360 runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {2361 expect(evt.target.result).toBe(fileData.slice(-5));2362 done();2363 }, -5);2364 });2365 it("file.spec.91 should read empty slice", function (done) {2366 runReaderTest('readAsText', false, done, null, function (evt, fileData, fileDataAsBinaryString) {2367 expect(evt.target.result).toBe('');2368 done();2369 }, 0, 0);2370 });2371 it("file.spec.92 should read sliced file properly, readAsDataURL", function (done) {2372 runReaderTest('readAsDataURL', true, done, null, function (evt, fileData, fileDataAsBinaryString) {2373 /* `readAsDataURL` function is supported, but the mediatype in Chrome depends on entry name extension,2374 mediatype in IE is always empty (which is the same as `text-plain` according the specification),2375 the mediatype in Firefox is always `application/octet-stream`.2376 For example, if the content is `abcdefg` then Firefox returns `data:application/octet-stream;base64,YWJjZGVmZw==`,2377 IE returns `data:;base64,YWJjZGVmZw==`, Chrome returns `data:<mediatype depending on extension of entry name>;base64,YWJjZGVmZw==`. */2378 expect(evt.target.result).toBeDataUrl();2379 //The atob function it is completely ignored during mobilespec execution, besides the returned object: evt2380 //it is encoded and the atob function is aimed to decode a string. Even with btoa (encode) the function it gets stucked2381 //because of the Unicode characters that contains the fileData object.2382 //Issue reported at JIRA with all the details: CB-70952383 //expect(evt.target.result.slice(23)).toBe(atob(fileDataAsBinaryString.slice(10, -3)));2384 done();2385 }, 10, -3);2386 });2387 it("file.spec.93 should read sliced file properly, readAsBinaryString", function (done) {2388 if (isIE) {2389 /*`readAsBinaryString` function is not supported by IE and has not the stub.*/2390 pending();2391 }2392 runReaderTest('readAsBinaryString', true, done, null, function (evt, fileData, fileDataAsBinaryString) {2393 expect(evt.target.result).toBe(fileDataAsBinaryString.slice(-10, -5));2394 done();2395 }, -10, -5);2396 });2397 it("file.spec.94 should read sliced file properly, readAsArrayBuffer", function (done) {2398 // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).2399 if (typeof window.ArrayBuffer == 'undefined') {2400 expect(true).toFailWithMessage('Platform does not supported this feature');2401 done();2402 }2403 runReaderTest('readAsArrayBuffer', true, done, null, function (evt, fileData, fileDataAsBinaryString) {2404 expect(arrayBufferEqualsString(evt.target.result, fileDataAsBinaryString.slice(0, -1))).toBe(true);2405 done();2406 }, 0, -1);2407 });2408 it("file.spec.94.5 should read large file in multiple chunks, readAsArrayBuffer", function (done) {2409 // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).2410 if (typeof window.ArrayBuffer == 'undefined') {2411 expect(true).toFailWithMessage('Platform does not supported this feature');2412 done();2413 }2414 var largeText = "";2415 for (var i = 0; i < 1000; i++) {2416 largeText += "Test " + i + "\n";2417 }2418 // Set the chunk size so that the read will take 5 chunks2419 FileReader.READ_CHUNK_SIZE = Math.floor(largeText.length / 4) + 1;2420 var chunkCount = 0;2421 var lastProgressValue = -1;2422 var progressFunc = function (evt) {2423 expect(evt.loaded).toBeDefined();2424 expect(evt.total).toBeDefined();2425 expect(evt.total >= largeText.length).toBe(true);2426 expect(evt.total <= largeText.length + 5).toBe(true);2427 expect(evt.loaded > lastProgressValue).toBe(true);2428 expect(evt.loaded <= evt.total).toBe(true);2429 lastProgressValue = evt.loaded;2430 chunkCount++;2431 };2432 runReaderTest(2433 'readAsArrayBuffer', true, done, progressFunc,2434 function (evt, fileData, fileDataAsBinaryString) {2435 expect(arrayBufferEqualsString(evt.target.result, fileDataAsBinaryString.slice(0, -1))).toBe(true);2436 expect(lastProgressValue >= largeText.length).toBe(true);2437 expect(lastProgressValue <= largeText.length + 5).toBe(true);2438 expect(chunkCount).toBe(5);2439 done();2440 },2441 0, -1, largeText);2442 });2443 it("file.spec.94.6 should read large file in multiple chunks, readAsDataURL", function (done) {2444 var largeText = "";2445 for (var i = 0; i < 10; i++) {2446 largeText += "Test " + i + "\n";2447 }2448 // Set the chunk size so that the read will take 5 chunks2449 FileReader.READ_CHUNK_SIZE = Math.floor(largeText.length / 4) + 1;2450 var lastProgressValue = 0;2451 var progressFunc = function (evt) {2452 expect(evt.total).toBeDefined();2453 expect(evt.total).toEqual(largeText.length);2454 expect(evt.loaded).toBeDefined();2455 expect(evt.loaded).toBeGreaterThan(lastProgressValue);2456 expect(evt.loaded).toBeLessThan(evt.total + 1);2457 lastProgressValue = evt.loaded;2458 };2459 runReaderTest('readAsDataURL', false, done, progressFunc,2460 function (evt, fileData, fileDataAsBinaryString) {2461 expect(function () {2462 // Cut off data uri prefix2463 var base64Data = evt.target.result.substring(evt.target.result.indexOf(',') + 1);2464 expect(window.atob(base64Data)).toEqual(fileData);2465 }).not.toThrow();2466 expect(lastProgressValue).toEqual(largeText.length);2467 done();2468 },2469 undefined, undefined, largeText);2470 });2471 });2472 //Read method2473 describe('FileWriter', function () {2474 it("file.spec.95 should have correct methods", function (done) {2475 // retrieve a FileWriter object2476 var fileName = "writer.methods";2477 // FileWriter2478 root.getFile(fileName, {2479 create : true2480 }, function (fileEntry) {2481 fileEntry.createWriter(function (writer) {2482 expect(writer).toBeDefined();2483 expect(typeof writer.write).toBe('function');2484 expect(typeof writer.seek).toBe('function');2485 expect(typeof writer.truncate).toBe('function');2486 expect(typeof writer.abort).toBe('function');2487 // cleanup2488 deleteFile(fileName, done);2489 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2490 }, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));2491 });2492 it("file.spec.96 should be able to write and append to file, createWriter", function (done) {2493 var fileName = "writer.append.createWriter", // file content2494 content = "There is an exception to every rule.", // for checkin file length2495 exception = " Except this one.",2496 length = content.length;2497 // create file, then write and append to it2498 createFile(fileName, function (fileEntry) {2499 // writes initial file content2500 fileEntry.createWriter(function (writer) {2501 //Verifiers declaration2502 function verifier(evt) {2503 expect(writer.length).toBe(length);2504 expect(writer.position).toBe(length);2505 // Append some more data2506 writer.onwriteend = secondVerifier;2507 length += exception.length;2508 writer.seek(writer.length);2509 writer.write(exception);2510 }2511 function secondVerifier(evt) {2512 expect(writer.length).toBe(length);2513 expect(writer.position).toBe(length);2514 var reader = new FileReader();2515 reader.onloadend = thirdVerifier;2516 reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);2517 fileEntry.file(function(f){reader.readAsText(f);});2518 }2519 function thirdVerifier(evt) {2520 expect(evt.target.result).toBe(content+exception);2521 // cleanup2522 deleteFile(fileName, done);2523 }2524 //Write process2525 writer.onwriteend = verifier;2526 writer.write(content);2527 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2528 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2529 });2530 it("file.spec.97 should be able to write and append to file, File object", function (done) {2531 var fileName = "writer.append.File", // file content2532 content = "There is an exception to every rule.", // for checkin file length2533 exception = " Except this one.",2534 length = content.length;2535 root.getFile(fileName, {2536 create : true2537 }, function (fileEntry) {2538 fileEntry.createWriter(function (writer) {2539 //Verifiers declaration2540 function verifier() {2541 expect(writer.length).toBe(length);2542 expect(writer.position).toBe(length);2543 // Append some more data2544 writer.onwriteend = secondVerifier;2545 length += exception.length;2546 writer.seek(writer.length);2547 writer.write(exception);2548 }2549 function secondVerifier() {2550 expect(writer.length).toBe(length);2551 expect(writer.position).toBe(length);2552 var reader = new FileReader();2553 reader.onloadend = thirdVerifier;2554 reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);2555 fileEntry.file(function(f){reader.readAsText(f);});2556 }2557 function thirdVerifier(evt) {2558 expect(evt.target.result).toBe(content+exception);2559 // cleanup2560 deleteFile(fileName, done);2561 }2562 //Write process2563 writer.onwriteend = verifier;2564 writer.write(content);2565 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2566 }, failed.bind(null, done, 'root.getFile - Error creating file: ' + fileName));2567 });2568 it("file.spec.98 should be able to seek to the middle of the file and write more data than file.length", function (done) {2569 var fileName = "writer.seek.write", // file content2570 content = "This is our sentence.", // for checking file length2571 exception = "newer sentence.",2572 length = content.length;2573 // create file, then write and append to it2574 createFile(fileName, function (fileEntry) {2575 fileEntry.createWriter(function (writer) {2576 //Verifiers declaration2577 function verifier(evt) {2578 expect(writer.length).toBe(length);2579 expect(writer.position).toBe(length);2580 // Append some more data2581 writer.onwriteend = secondVerifier;2582 length = 12 + exception.length;2583 writer.seek(12);2584 writer.write(exception);2585 }2586 function secondVerifier(evt) {2587 expect(writer.length).toBe(length);2588 expect(writer.position).toBe(length);2589 var reader = new FileReader();2590 reader.onloadend = thirdVerifier;2591 reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);2592 fileEntry.file(function(f){reader.readAsText(f);});2593 }2594 function thirdVerifier(evt) {2595 expect(evt.target.result).toBe(content.substr(0,12)+exception);2596 // cleanup2597 deleteFile(fileName, done);2598 }2599 //Write process2600 writer.onwriteend = verifier;2601 writer.write(content);2602 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2603 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2604 });2605 it("file.spec.99 should be able to seek to the middle of the file and write less data than file.length", function (done) {2606 if (isChrome) {2607 /* Chrome (re)writes as follows: "This is our sentence." -> "This is new.sentence.",2608 i.e. the length is not being changed from content.length and writer length will be equal 21 */2609 pending();2610 }2611 var fileName = "writer.seek.write2", // file content2612 content = "This is our sentence.", // for checking file length2613 exception = "new.",2614 length = content.length;2615 // create file, then write and append to it2616 createFile(fileName, function (fileEntry) {2617 fileEntry.createWriter(function (writer) {2618 // Verifiers declaration2619 function verifier(evt) {2620 expect(writer.length).toBe(length);2621 expect(writer.position).toBe(length);2622 // Append some more data2623 writer.onwriteend = secondVerifier;2624 length = 8 + exception.length;2625 writer.seek(8);2626 writer.write(exception);2627 }2628 function secondVerifier(evt) {2629 expect(writer.length).toBe(length);2630 expect(writer.position).toBe(length);2631 var reader = new FileReader();2632 reader.onloadend = thirdVerifier;2633 reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);2634 fileEntry.file(function(f){reader.readAsText(f);});2635 }2636 function thirdVerifier(evt) {2637 expect(evt.target.result).toBe(content.substr(0,8)+exception);2638 // cleanup2639 deleteFile(fileName, done);2640 }2641 //Write process2642 writer.onwriteend = verifier;2643 writer.write(content);2644 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2645 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2646 });2647 it("file.spec.100 should be able to write XML data", function (done) {2648 var fileName = "writer.xml", // file content2649 content = '<?xml version="1.0" encoding="UTF-8"?>\n<test prop="ack">\nData\n</test>\n', // for testing file length2650 length = content.length;2651 // creates file, then write XML data2652 createFile(fileName, function (fileEntry) {2653 fileEntry.createWriter(function (writer) {2654 //Verifier content2655 var verifier = function (evt) {2656 expect(writer.length).toBe(length);2657 expect(writer.position).toBe(length);2658 // cleanup2659 deleteFile(fileName, done);2660 };2661 //Write process2662 writer.onwriteend = verifier;2663 writer.write(content);2664 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2665 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2666 });2667 it("file.spec.101 should be able to write JSON data", function (done) {2668 var fileName = "writer.json", // file content2669 content = '{ "name": "Guy Incognito", "email": "here@there.com" }', // for testing file length2670 length = content.length;2671 // creates file, then write JSON content2672 createFile(fileName, function (fileEntry) {2673 fileEntry.createWriter(function (writer) {2674 //Verifier declaration2675 var verifier = function (evt) {2676 expect(writer.length).toBe(length);2677 expect(writer.position).toBe(length);2678 // cleanup2679 deleteFile(fileName, done);2680 };2681 //Write process2682 writer.onwriteend = verifier;2683 writer.write(content);2684 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2685 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2686 });2687 it("file.spec.102 should be able to seek", function (done) {2688 var fileName = "writer.seek", // file content2689 content = "There is an exception to every rule. Except this one.", // for testing file length2690 length = content.length;2691 // creates file, then write JSON content2692 createFile(fileName, function (fileEntry) {2693 // writes file content and tests writer.seek2694 fileEntry.createWriter(function (writer) {2695 //Verifier declaration2696 var verifier = function () {2697 expect(writer.position).toBe(length);2698 writer.seek(-5);2699 expect(writer.position).toBe(length - 5);2700 writer.seek(length + 100);2701 expect(writer.position).toBe(length);2702 writer.seek(10);2703 expect(writer.position).toBe(10);2704 // cleanup2705 deleteFile(fileName, done);2706 };2707 //Write process2708 writer.onwriteend = verifier;2709 writer.seek(-100);2710 expect(writer.position).toBe(0);2711 writer.write(content);2712 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2713 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2714 });2715 it("file.spec.103 should be able to truncate", function (done) {2716 if (isIndexedDBShim) {2717 /* `abort` and `truncate` functions are not supported (Firefox, IE) */2718 pending();2719 }2720 var fileName = "writer.truncate",2721 content = "There is an exception to every rule. Except this one.";2722 // creates file, writes to it, then truncates it2723 createFile(fileName, function (fileEntry) {2724 fileEntry.createWriter(function (writer) {2725 // Verifier declaration2726 var verifier = function () {2727 expect(writer.length).toBe(36);2728 expect(writer.position).toBe(36);2729 // cleanup2730 deleteFile(fileName, done);2731 };2732 //Write process2733 writer.onwriteend = function () {2734 //Truncate process after write2735 writer.onwriteend = verifier;2736 writer.truncate(36);2737 };2738 writer.write(content);2739 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2740 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2741 });2742 it("file.spec.104 should be able to write binary data from an ArrayBuffer", function (done) {2743 // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).2744 if (typeof window.ArrayBuffer == 'undefined') {2745 expect(true).toFailWithMessage('Platform does not supported this feature');2746 done();2747 return;2748 }2749 var fileName = "bufferwriter.bin", // file content2750 data = new ArrayBuffer(32),2751 dataView = new Int8Array(data), // for verifying file length2752 length = 32;2753 for (var i = 0; i < dataView.length; i++) {2754 dataView[i] = i;2755 }2756 // creates file, then write content2757 createFile(fileName, function (fileEntry) {2758 // writes file content2759 fileEntry.createWriter(function (writer) {2760 //Verifier declaration2761 var verifier = function () {2762 expect(writer.length).toBe(length);2763 expect(writer.position).toBe(length);2764 // cleanup2765 deleteFile(fileName, done);2766 };2767 //Write process2768 writer.onwriteend = verifier;2769 writer.write(data);2770 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2771 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2772 });2773 it("file.spec.105 should be able to write binary data from a Blob", function (done) {2774 // Skip test if Blobs are not supported (e.g.: Android 2.3).2775 if ((typeof window.Blob == 'undefined' && typeof window.WebKitBlobBuilder == 'undefined') || typeof window.ArrayBuffer == 'undefined') {2776 expect(true).toFailWithMessage('Platform does not supported this feature');2777 done();2778 return;2779 }2780 var fileName = "blobwriter.bin", // file content2781 data = new ArrayBuffer(32),2782 dataView = new Int8Array(data),2783 blob, // for verifying file length2784 length = 32;2785 for (var i = 0; i < dataView.length; i++) {2786 dataView[i] = i;2787 }2788 try {2789 // Mobile Safari: Use Blob constructor2790 blob = new Blob([data], {2791 "type" : "application/octet-stream"2792 });2793 } catch (e) {2794 if (window.WebKitBlobBuilder) {2795 // Android Browser: Use deprecated BlobBuilder2796 var builder = new WebKitBlobBuilder();2797 builder.append(data);2798 blob = builder.getBlob('application/octet-stream');2799 } else {2800 // We have no way defined to create a Blob, so fail2801 fail();2802 }2803 }2804 if (typeof blob !== 'undefined') {2805 // creates file, then write content2806 createFile(fileName, function (fileEntry) {2807 fileEntry.createWriter(function (writer) {2808 //Verifier declaration2809 var verifier = function () {2810 expect(writer.length).toBe(length);2811 expect(writer.position).toBe(length);2812 // cleanup2813 deleteFile(fileName, done);2814 };2815 //Write process2816 writer.onwriteend = verifier;2817 writer.write(blob);2818 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2819 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2820 }2821 });2822 it("file.spec.106 should be able to write a File to a FileWriter", function (done) {2823 var dummyFileName = 'dummy.txt',2824 outputFileName = 'verify.txt',2825 dummyFileText = 'This text should be written to two files',2826 verifier = function (outputFileWriter) {2827 expect(outputFileWriter.length).toBe(dummyFileText.length);2828 expect(outputFileWriter.position).toBe(dummyFileText.length);2829 deleteFile(outputFileName, done);2830 },2831 writeFile = function (fileName, fileData, win) {2832 var theWriter,2833 write_file = function (fileEntry) {2834 // writes file content to new file2835 fileEntry.createWriter(function (writer) {2836 theWriter = writer;2837 writer.onwriteend = function (ev) {2838 if (typeof fileData.length !== "undefined") {2839 expect(theWriter.length).toBe(fileData.length);2840 expect(theWriter.position).toBe(fileData.length);2841 }2842 win(theWriter);2843 };2844 writer.onerror = failed.bind(null, done, 'writer.onerror - Error writing content on file: ' + fileName);2845 writer.write(fileData);2846 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2847 };2848 createFile(fileName, write_file, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2849 },2850 openFile = function (fileName, callback) {2851 root.getFile(fileName, {2852 create : false2853 }, function (fileEntry) {2854 fileEntry.file(callback, failed.bind(null, done, 'fileEntry.file - Error reading file using fileEntry: ' + fileEntry.name));2855 }, failed.bind(null, done, 'root.getFile - Error getting file: ' + fileName));2856 };2857 writeFile(dummyFileName, dummyFileText, function (dummyFileWriter) {2858 openFile(dummyFileName, function (file) {2859 writeFile(outputFileName, file, verifier);2860 });2861 });2862 });2863 it("file.spec.107 should be able to write a sliced File to a FileWriter", function (done) {2864 var dummyFileName = 'dummy2.txt',2865 outputFileName = 'verify2.txt',2866 dummyFileText = 'This text should be written to two files',2867 verifier = function (outputFileWriter) {2868 expect(outputFileWriter.length).toBe(10);2869 expect(outputFileWriter.position).toBe(10);2870 deleteFile(outputFileName, done);2871 },2872 writeFile = function (fileName, fileData, win) {2873 var theWriter,2874 write_file = function (fileEntry) {2875 // writes file content to new file2876 fileEntry.createWriter(function (writer) {2877 theWriter = writer;2878 writer.onwriteend = function (ev) {2879 if (typeof fileData.length !== "undefined") {2880 expect(theWriter.length).toBe(fileData.length);2881 expect(theWriter.position).toBe(fileData.length);2882 }2883 win(theWriter);2884 };2885 writer.onerror = failed.bind(null, done, 'writer.onerror - Error writing content on file: ' + fileName);2886 writer.write(fileData);2887 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2888 };2889 createFile(fileName, write_file, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2890 },2891 openFile = function (fileName, callback) {2892 root.getFile(fileName, {2893 create : false2894 }, function (fileEntry) {2895 fileEntry.file(callback, failed.bind(null, done, 'fileEntry.file - Error reading file using fileEntry: ' + fileEntry.name));2896 }, failed.bind(null, done, 'root.getFile - Error getting file: ' + fileName));2897 };2898 writeFile(dummyFileName, dummyFileText, function (dummyFileWriter) {2899 openFile(dummyFileName, function (file) {2900 writeFile(outputFileName, file.slice(10, 20), verifier);2901 });2902 });2903 });2904 it("file.spec.108 should be able to write binary data from a File", function (done) {2905 // Skip test if Blobs are not supported (e.g.: Android 2.3).2906 if (typeof window.Blob == 'undefined' && typeof window.WebKitBlobBuilder == 'undefined') {2907 expect(true).toFailWithMessage('Platform does not supported this feature');2908 done();2909 }2910 var dummyFileName = "blobwriter.bin",2911 outputFileName = 'verify.bin', // file content2912 data = new ArrayBuffer(32),2913 dataView = new Int8Array(data),2914 blob, // for verifying file length2915 length = 32,2916 verifier = function (outputFileWriter) {2917 expect(outputFileWriter.length).toBe(length);2918 expect(outputFileWriter.position).toBe(length);2919 // cleanup2920 deleteFile(outputFileName);2921 done();2922 },2923 writeFile = function (fileName, fileData, win) {2924 var theWriter,2925 write_file = function (fileEntry) {2926 // writes file content to new file2927 fileEntry.createWriter(function (writer) {2928 theWriter = writer;2929 writer.onwriteend = function (ev) {2930 if (typeof fileData.length !== "undefined") {2931 expect(theWriter.length).toBe(fileData.length);2932 expect(theWriter.position).toBe(fileData.length);2933 }2934 win(theWriter);2935 };2936 writer.onerror = failed.bind(null, done, 'writer.onerror - Error writing content on file: ' + fileName);2937 writer.write(fileData);2938 }, failed.bind(null, done, 'fileEntry.createWriter - Error creating writer using fileEntry: ' + fileEntry.name));2939 };2940 createFile(fileName, write_file, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));2941 },2942 openFile = function (fileName, callback) {2943 root.getFile(fileName, {2944 create : false2945 }, function (fileEntry) {2946 fileEntry.file(callback, failed.bind(null, done, 'fileEntry.file - Error reading file using fileEntry: ' + fileEntry.name));2947 }, failed.bind(null, done, 'root.getFile - Error getting file: ' + fileName));2948 };2949 for (var i = 0; i < dataView.length; i++) {2950 dataView[i] = i;2951 }2952 try {2953 // Mobile Safari: Use Blob constructor2954 blob = new Blob([data], {2955 "type" : "application/octet-stream"2956 });2957 } catch (e) {2958 if (window.WebKitBlobBuilder) {2959 // Android Browser: Use deprecated BlobBuilder2960 var builder = new WebKitBlobBuilder();2961 builder.append(data);2962 blob = builder.getBlob('application/octet-stream');2963 } else {2964 // We have no way defined to create a Blob, so fail2965 fail();2966 }2967 }2968 if (typeof blob !== 'undefined') {2969 // creates file, then write content2970 writeFile(dummyFileName, blob, function (dummyFileWriter) {2971 openFile(dummyFileName, function (file) {2972 writeFile(outputFileName, file, verifier);2973 });2974 });2975 }2976 });2977 });2978 //FileWritter2979 describe('Backwards compatibility', function () {2980 /* These specs exist to test that the File plugin can still recognize file:///2981 * URLs, and can resolve them to FileEntry and DirectoryEntry objects.2982 * They rely on an undocumented interface to File which provides absolute file2983 * paths, which are not used internally anymore.2984 * If that interface is not present, then these tests will silently succeed.2985 */2986 it("file.spec.109 should be able to resolve a file:/// URL", function (done) {2987 var localFilename = 'file.txt';2988 var originalEntry;2989 root.getFile(localFilename, {2990 create : true2991 }, function (entry) {2992 originalEntry = entry;2993 /* This is an undocumented interface to File which exists only for testing2994 * backwards compatibilty. By obtaining the raw filesystem path of the download2995 * location, we can pass that to ft.download() to make sure that previously-stored2996 * paths are still valid.2997 */2998 cordova.exec(function (localPath) {2999 window.resolveLocalFileSystemURL("file://" + encodeURI(localPath), function (fileEntry) {3000 expect(fileEntry.toURL()).toEqual(originalEntry.toURL());3001 // cleanup3002 deleteFile(localFilename);3003 done();3004 }, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving URI: file://' + encodeURI(localPath)));3005 }, done, 'File', '_getLocalFilesystemPath', [entry.toURL()]);3006 }, failed.bind(null, done, 'root.getFile - Error creating file: ' + localFilename));3007 });3008 });3009 //Backwards Compatibility3010 describe('Parent References', function () {3011 /* These specs verify that paths with parent references i("..") in them3012 * work correctly, and do not cause the application to crash.3013 */3014 it("file.spec.110 should not throw exception resolving parent refefences", function (done) {3015 /* This is a direct copy of file.spec.9, with the filename changed, * as reported in CB-5721.3016 */3017 var fileName = "resolve.file.uri";3018 var dirName = "resolve.dir.uri";3019 // create a new file entry3020 createDirectory(dirName, function () {3021 createFile(dirName+"/../" + fileName, function (entry) {3022 // lookup file system entry3023 window.resolveLocalFileSystemURL(entry.toURL(), function (fileEntry) {3024 expect(fileEntry).toBeDefined();3025 expect(fileEntry.name).toCanonicallyMatch(fileName);3026 // cleanup3027 deleteEntry(fileName, done);3028 }, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving URI: ' + entry.toURL()));3029 }, failed.bind(null, done, 'createFile - Error creating file: ../' + fileName));3030 }, failed.bind(null, done, 'createDirectory - Error creating directory: ' + dirName));3031 });3032 it("file.spec.111 should not traverse above above the root directory", function (done) {3033 var fileName = "traverse.file.uri";3034 // create a new file entry3035 createFile(fileName, function (entry) {3036 // lookup file system entry3037 root.getFile('../' + fileName, {3038 create : false3039 }, function (fileEntry) {3040 // Note: we expect this to still resolve, as the correct behaviour is to ignore the ../, not to fail out.3041 expect(fileEntry).toBeDefined();3042 expect(fileEntry.name).toBe(fileName);3043 expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath +'/' + fileName);3044 // cleanup3045 deleteEntry(fileName, done);3046 }, failed.bind(null, done, 'root.getFile - Error getting file: ../' + fileName));3047 }, failed.bind(null, done, 'createFile - Error creating file: ../' + fileName));3048 });3049 it("file.spec.112 should traverse above above the current directory", function (done) {3050 var fileName = "traverse2.file.uri",3051 dirName = "traverse2.subdir";3052 // create a new directory and a file entry3053 createFile(fileName, function () {3054 createDirectory(dirName, function (entry) {3055 // lookup file system entry3056 entry.getFile('../' + fileName, {3057 create : false3058 }, function (fileEntry) {3059 expect(fileEntry).toBeDefined();3060 expect(fileEntry.name).toBe(fileName);3061 expect(fileEntry.fullPath).toCanonicallyMatch('/' + fileName);3062 // cleanup3063 deleteEntry(fileName, function () {3064 deleteEntry(dirName, done);3065 });3066 }, failed.bind(null, done, 'entry.getFile - Error getting file: ' + fileName + ' recently created above: ' + dirName));3067 }, failed.bind(null, done, 'createDirectory - Error creating directory: ' + dirName));3068 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));3069 });3070 it("file.spec.113 getFile: get Entry should error for missing file above root directory", function (done) {3071 var fileName = "../missing.file";3072 // create:false, exclusive:false, file does not exist3073 root.getFile(fileName, {3074 create : false3075 }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not locate nonexistent file: ' + fileName), function (error) {3076 expect(error).toBeDefined();3077 expect(error).toBeFileError(FileError.NOT_FOUND_ERR);3078 done();3079 });3080 });3081 });3082 //Parent References3083 describe('toNativeURL interface', function () {3084 /* These specs verify that FileEntries have a toNativeURL method3085 * which appears to be sane.3086 */3087 var pathExpect = cordova.platformId === 'windowsphone' ? "//nativ" : "file://";3088 if (isChrome) {3089 pathExpect = 'filesystem:file://';3090 }3091 it("file.spec.114 fileEntry should have a toNativeURL method", function (done) {3092 var fileName = "native.file.uri";3093 if (isWindows) {3094 var rootPath = root.fullPath;3095 pathExpect = rootPath.substr(0, rootPath.indexOf(":"));3096 }3097 // create a new file entry3098 createFile(fileName, function (entry) {3099 expect(entry.toNativeURL).toBeDefined();3100 expect(entry.name).toCanonicallyMatch(fileName);3101 expect(typeof entry.toNativeURL).toBe('function');3102 var nativeURL = entry.toNativeURL();3103 expect(typeof nativeURL).toBe("string");3104 expect(nativeURL.substring(0, pathExpect.length)).toEqual(pathExpect);3105 expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);3106 // cleanup3107 deleteEntry(fileName, done);3108 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));3109 });3110 it("file.spec.115 DirectoryReader should return entries with toNativeURL method", function (done) {3111 var dirName = 'nativeEntries.dir',3112 fileName = 'nativeEntries.file',3113 directory,3114 checkEntries = function (entries) {3115 expect(entries).toBeDefined();3116 expect(entries instanceof Array).toBe(true);3117 expect(entries.length).toBe(1);3118 expect(entries[0].toNativeURL).toBeDefined();3119 expect(typeof entries[0].toNativeURL).toBe('function');3120 var nativeURL = entries[0].toNativeURL();3121 expect(typeof nativeURL).toBe("string");3122 expect(nativeURL.substring(0, pathExpect.length)).toEqual(pathExpect);3123 expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);3124 // cleanup3125 directory.removeRecursively(null, null);3126 done();3127 };3128 // create a new file entry3129 root.getDirectory(dirName, {3130 create : true3131 }, function (dir) {3132 directory = dir;3133 directory.getFile(fileName, {3134 create : true3135 }, function (fileEntry) {3136 var reader = directory.createReader();3137 reader.readEntries(checkEntries, failed.bind(null, done, 'reader.readEntries - Error reading entries from directory: ' + dirName));3138 }, failed.bind(null, done, 'directory.getFile - Error creating file: ' + fileName));3139 }, failed.bind(null, done, 'root.getDirectory - Error creating directory: ' + dirName));3140 });3141 it("file.spec.116 resolveLocalFileSystemURL should return entries with toNativeURL method", function (done) {3142 var fileName = "native.resolve.uri";3143 // create a new file entry3144 createFile(fileName, function (entry) {3145 resolveLocalFileSystemURL(entry.toURL(), function (entry) {3146 expect(entry.toNativeURL).toBeDefined();3147 expect(entry.name).toCanonicallyMatch(fileName);3148 expect(typeof entry.toNativeURL).toBe('function');3149 var nativeURL = entry.toNativeURL();3150 expect(typeof nativeURL).toBe("string");3151 expect(nativeURL.substring(0, pathExpect.length)).toEqual(pathExpect);3152 expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);3153 // cleanup3154 deleteEntry(fileName, done);3155 }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + entry.toURL()));3156 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));3157 });3158 });3159 //toNativeURL interface3160 describe('resolveLocalFileSystemURL on file://', function () {3161 /* These specs verify that window.resolveLocalFileSystemURL works correctly on file:// URLs3162 */3163 it("file.spec.117 should not resolve native URLs outside of FS roots", function (done) {3164 // lookup file system entry3165 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) {3166 expect(error).toBeDefined();3167 done();3168 });3169 });3170 it("file.spec.118 should not resolve native URLs outside of FS roots", function (done) {3171 // lookup file system entry3172 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) {3173 expect(error).toBeDefined();3174 done();3175 });3176 });3177 it("file.spec.119 should not resolve invalid native URLs", function (done) {3178 // lookup file system entry3179 window.resolveLocalFileSystemURL("file://localhost", succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Unexpected success callback, it should not resolve invalid URL: file://localhost'), function (error) {3180 expect(error).toBeDefined();3181 done();3182 });3183 });3184 it("file.spec.120 should not resolve invalid native URLs with query strings", function (done) {3185 // lookup file system entry3186 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) {3187 expect(error).toBeDefined();3188 done();3189 });3190 });3191 it("file.spec.121 should resolve native URLs returned by API", function (done) {3192 var fileName = "native.resolve.uri1";3193 // create a new file entry3194 createFile(fileName, function (entry) {3195 resolveLocalFileSystemURL(entry.toNativeURL(), function (fileEntry) {3196 expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + "/" + fileName);3197 // cleanup3198 deleteEntry(fileName, done);3199 }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + entry.toNativeURL()));3200 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));3201 });3202 it("file.spec.122 should resolve native URLs returned by API with localhost", function (done) {3203 var fileName = "native.resolve.uri2";3204 // create a new file entry3205 createFile(fileName, function (entry) {3206 var url = entry.toNativeURL();3207 url = url.replace("///", "//localhost/");3208 resolveLocalFileSystemURL(url, function (fileEntry) {3209 expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + "/" + fileName);3210 // cleanup3211 deleteEntry(fileName, done);3212 }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + url));3213 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));3214 });3215 it("file.spec.123 should resolve native URLs returned by API with query string", function (done) {3216 var fileName = "native.resolve.uri3";3217 // create a new file entry3218 createFile(fileName, function (entry) {3219 var url = entry.toNativeURL();3220 url = url + "?test/test";3221 resolveLocalFileSystemURL(url, function (fileEntry) {3222 expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + "/" + fileName);3223 // cleanup3224 deleteEntry(fileName, done);3225 }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + url));3226 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));3227 });3228 it("file.spec.124 should resolve native URLs returned by API with localhost and query string", function (done) {3229 var fileName = "native.resolve.uri4";3230 // create a new file entry3231 createFile(fileName, function (entry) {3232 var url = entry.toNativeURL();3233 url = url.replace("///", "//localhost/") + "?test/test";3234 resolveLocalFileSystemURL(url, function (fileEntry) {3235 expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + "/" + fileName);3236 // cleanup3237 deleteEntry(fileName, done);3238 }, failed.bind(null, done, 'resolveLocalFileSystemURL - Error resolving file URL: ' + url));3239 }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName));3240 });3241 });3242 //resolveLocalFileSystemURL on file://3243 describe('cross-file-system copy and move', function () {3244 /* These specs verify that Entry.copyTo and Entry.moveTo work correctly3245 * when crossing filesystem boundaries.3246 */3247 it("file.spec.125 copyTo: temporary -> persistent", function (done) {3248 var file1 = "entry.copy.file1a",3249 file2 = "entry.copy.file2a",3250 sourceEntry,3251 fullPath = joinURL(root.fullPath, file2),3252 validateFile = function (entry) {3253 // a bit redundant since copy returned this entry already3254 expect(entry).toBeDefined();3255 expect(entry.isFile).toBe(true);3256 expect(entry.isDirectory).toBe(false);3257 expect(entry.name).toCanonicallyMatch(file2);3258 expect(entry.fullPath).toCanonicallyMatch(fullPath);3259 expect(entry.filesystem).toBeDefined();3260 if (isChrome) {3261 expect(entry.filesystem.name).toContain("Persistent");3262 } else {3263 expect(entry.filesystem.name).toEqual("persistent");3264 }3265 // cleanup3266 deleteEntry(entry.name);3267 deleteEntry(sourceEntry.name, done);3268 },3269 createSourceAndTransfer = function () {3270 temp_root.getFile(file1, {3271 create : true3272 }, function (entry) {3273 expect(entry.filesystem).toBeDefined();3274 if (isChrome) {3275 expect(entry.filesystem.name).toContain("Temporary");3276 } else {3277 expect(entry.filesystem.name).toEqual("temporary");3278 }3279 sourceEntry = entry;3280 // Save for later cleanup3281 entry.copyTo(persistent_root, file2, validateFile, failed.bind(null, done, 'entry.copyTo - Error copying file: ' + file1 + ' to PERSISTENT root as: ' + file2));3282 }, failed.bind(null, done, 'temp_root.getFile - Error creating file: ' + file1 + 'at TEMPORAL root'));3283 };3284 // Delete any existing file to start things off3285 persistent_root.getFile(file2, {}, function (entry) {3286 entry.remove(createSourceAndTransfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));3287 }, createSourceAndTransfer);3288 });3289 it("file.spec.126 copyTo: persistent -> temporary", function (done) {3290 var file1 = "entry.copy.file1b",3291 file2 = "entry.copy.file2b",3292 sourceEntry,3293 fullPath = joinURL(temp_root.fullPath, file2),3294 validateFile = function (entry) {3295 expect(entry).toBeDefined();3296 expect(entry.isFile).toBe(true);3297 expect(entry.isDirectory).toBe(false);3298 expect(entry.name).toCanonicallyMatch(file2);3299 expect(entry.fullPath).toCanonicallyMatch(fullPath);3300 if (isChrome) {3301 expect(entry.filesystem.name).toContain("Temporary");3302 } else {3303 expect(entry.filesystem.name).toEqual("temporary");3304 }3305 // cleanup3306 deleteEntry(entry.name);3307 deleteEntry(sourceEntry.name, done);3308 },3309 createSourceAndTransfer = function () {3310 persistent_root.getFile(file1, {3311 create : true3312 }, function (entry) {3313 expect(entry).toBeDefined();3314 expect(entry.filesystem).toBeDefined();3315 if (isChrome) {3316 expect(entry.filesystem.name).toContain("Persistent");3317 } else {3318 expect(entry.filesystem.name).toEqual("persistent");3319 }3320 sourceEntry = entry;3321 // Save for later cleanup3322 entry.copyTo(temp_root, file2, validateFile, failed.bind(null, done, 'entry.copyTo - Error copying file: ' + file1 + ' to TEMPORAL root as: ' + file2));3323 }, failed.bind(null, done, 'persistent_root.getFile - Error creating file: ' + file1 + 'at PERSISTENT root'));3324 };3325 // Delete any existing file to start things off3326 temp_root.getFile(file2, {}, function (entry) {3327 entry.remove(createSourceAndTransfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));3328 }, createSourceAndTransfer);3329 });3330 it("file.spec.127 moveTo: temporary -> persistent", function (done) {3331 var file1 = "entry.copy.file1a",3332 file2 = "entry.copy.file2a",3333 sourceEntry,3334 fullPath = joinURL(root.fullPath, file2),3335 validateFile = function (entry) {3336 // a bit redundant since copy returned this entry already3337 expect(entry).toBeDefined();3338 expect(entry.isFile).toBe(true);3339 expect(entry.isDirectory).toBe(false);3340 expect(entry.name).toCanonicallyMatch(file2);3341 expect(entry.fullPath).toCanonicallyMatch(fullPath);3342 expect(entry.filesystem).toBeDefined();3343 if (isChrome) {3344 expect(entry.filesystem.name).toContain("Persistent");3345 } else {3346 expect(entry.filesystem.name).toEqual("persistent");3347 }3348 // cleanup3349 deleteEntry(entry.name);3350 deleteEntry(sourceEntry.name, done);3351 },3352 createSourceAndTransfer = function () {3353 temp_root.getFile(file1, {3354 create : true3355 }, function (entry) {3356 expect(entry.filesystem).toBeDefined();3357 if (isChrome) {3358 expect(entry.filesystem.name).toContain("Temporary");3359 } else {3360 expect(entry.filesystem.name).toEqual("temporary");3361 }3362 sourceEntry = entry;3363 // Save for later cleanup3364 entry.moveTo(persistent_root, file2, validateFile, failed.bind(null, done, 'entry.moveTo - Error moving file: ' + file1 + ' to PERSISTENT root as: ' + file2));3365 }, failed.bind(null, done, 'temp_root.getFile - Error creating file: ' + file1 + 'at TEMPORAL root'));3366 };3367 // Delete any existing file to start things off3368 persistent_root.getFile(file2, {}, function (entry) {3369 entry.remove(createSourceAndTransfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));3370 }, createSourceAndTransfer);3371 });3372 it("file.spec.128 moveTo: persistent -> temporary", function (done) {3373 var file1 = "entry.copy.file1b",3374 file2 = "entry.copy.file2b",3375 sourceEntry,3376 fullPath = joinURL(temp_root.fullPath, file2),3377 validateFile = function (entry) {3378 expect(entry).toBeDefined();3379 expect(entry.isFile).toBe(true);3380 expect(entry.isDirectory).toBe(false);3381 expect(entry.name).toCanonicallyMatch(file2);3382 expect(entry.fullPath).toCanonicallyMatch(fullPath);3383 if(isChrome) {3384 expect(entry.filesystem.name).toContain("Temporary");3385 } else {3386 expect(entry.filesystem.name).toEqual("temporary");3387 }3388 // cleanup3389 deleteEntry(entry.name);3390 deleteEntry(sourceEntry.name, done);3391 },3392 createSourceAndTransfer = function () {3393 persistent_root.getFile(file1, {3394 create : true3395 }, function (entry) {3396 expect(entry).toBeDefined();3397 expect(entry.filesystem).toBeDefined();3398 if (isChrome) {3399 expect(entry.filesystem.name).toContain("Persistent");3400 } else {3401 expect(entry.filesystem.name).toEqual("persistent");3402 }3403 sourceEntry = entry;3404 // Save for later cleanup3405 entry.moveTo(temp_root, file2, validateFile, failed.bind(null, done, 'entry.moveTo - Error moving file: ' + file1 + ' to TEMPORAL root as: ' + file2));3406 }, failed.bind(null, done, 'persistent_root.getFile - Error creating file: ' + file1 + 'at PERSISTENT root'));3407 };3408 // Delete any existing file to start things off3409 temp_root.getFile(file2, {}, function (entry) {3410 entry.remove(createSourceAndTransfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));3411 }, createSourceAndTransfer);3412 });3413 it("file.spec.129 cordova.file.*Directory are set", function () {3414 var expectedPaths = ['applicationDirectory', 'applicationStorageDirectory', 'dataDirectory', 'cacheDirectory'];3415 if (cordova.platformId == 'android' || cordova.platformId == 'amazon-fireos') {3416 if (cordova.file.externalApplicationStorageDirectory !== null) {3417 // https://issues.apache.org/jira/browse/CB-104113418 // If external storage can't be mounted, the cordova.file.external* properties are null.3419 expectedPaths.push('externalApplicationStorageDirectory', 'externalRootDirectory', 'externalCacheDirectory', 'externalDataDirectory');3420 }3421 } else if (cordova.platformId == 'blackberry10') {3422 expectedPaths.push('externalRootDirectory', 'sharedDirectory');3423 } else if (cordova.platformId == 'ios') {3424 expectedPaths.push('syncedDataDirectory', 'documentsDirectory', 'tempDirectory');3425 } else if (cordova.platformId == 'osx') {3426 expectedPaths.push('documentsDirectory', 'tempDirectory', 'rootDirectory');3427 } else {3428 console.log('Skipping test due on unsupported platform.');3429 return;3430 }3431 for (var i = 0; i < expectedPaths.length; ++i) {3432 expect(typeof cordova.file[expectedPaths[i]]).toBe('string');3433 expect(cordova.file[expectedPaths[i]]).toMatch(/\/$/, 'Path should end with a slash');3434 }3435 });3436 });3437 describe('resolveLocalFileSystemURL on cdvfile://', function () {3438 it("file.spec.147 should be able to resolve cdvfile applicationDirectory fs root", function(done) {3439 var cdvfileApplicationDirectoryFsRootName;3440 if (cordova.platformId === 'android') {3441 cdvfileApplicationDirectoryFsRootName = 'assets';3442 } else if (cordova.platformId === 'ios') {3443 cdvfileApplicationDirectoryFsRootName = 'bundle';3444 } else {3445 pending();3446 }3447 resolveLocalFileSystemURL('cdvfile://localhost/' + cdvfileApplicationDirectoryFsRootName + '/', function(applicationDirectoryRoot) {3448 expect(applicationDirectoryRoot.isFile).toBe(false);3449 expect(applicationDirectoryRoot.isDirectory).toBe(true);3450 expect(applicationDirectoryRoot.name).toCanonicallyMatch('');3451 expect(applicationDirectoryRoot.fullPath).toCanonicallyMatch('/');3452 expect(applicationDirectoryRoot.filesystem.name).toEqual(cdvfileApplicationDirectoryFsRootName);3453 // Requires HelloCordova www assets, <allow-navigation href="cdvfile:*" /> in config.xml or3454 // cdvfile: in CSP and <access origin="cdvfile://*" /> in config.xml3455 resolveLocalFileSystemURL('cdvfile://localhost/' + cdvfileApplicationDirectoryFsRootName + '/www/img/logo.png', function(entry) {3456 expect(entry.isFile).toBe(true);3457 expect(entry.isDirectory).toBe(false);3458 expect(entry.name).toCanonicallyMatch('logo.png');3459 expect(entry.fullPath).toCanonicallyMatch('/www/img/logo.png');3460 expect(entry.filesystem.name).toEqual(cdvfileApplicationDirectoryFsRootName);3461 var img = new Image();3462 img.onerror = function(err) {3463 expect(err).not.toBeDefined();3464 done();3465 };3466 img.onload = function() {3467 done();3468 };3469 img.src = entry.toInternalURL();3470 }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for cdvfile applicationDirectory'));3471 }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for cdvfile applicationDirectory'));3472 });3473 });3474 //cross-file-system copy and move3475 describe('IndexedDB-based impl', function () {3476 it("file.spec.131 Nested file or nested directory should be removed when removing a parent directory", function (done) {3477 var parentDirName = 'deletedDir131',3478 nestedDirName = 'nestedDir131',3479 nestedFileName = 'nestedFile131.txt';3480 createDirectory(parentDirName, function (parent) {3481 parent.getDirectory(nestedDirName, { create: true}, function () {3482 parent.getFile(nestedFileName, { create: true}, function () {3483 parent.removeRecursively(function() {3484 root.getDirectory(parentDirName,{ create: false}, failed.bind(this, done, 'root.getDirectory - unexpected success callback : ' + parentDirName), function(){3485 parent.getFile(nestedFileName,{ create: false}, failed.bind(this, done, 'getFile - unexpected success callback : ' + nestedFileName), function(){3486 parent.getDirectory(nestedDirName, { create: false}, failed.bind(this, done, 'getDirectory - unexpected success callback : ' + nestedDirName), done);3487 });3488 });3489 }, failed.bind(this, done, 'removeRecursively - Error removing directory : ' + parentDirName));3490 }, failed.bind(this, done, 'getFile - Error creating file : ' + nestedFileName));3491 },failed.bind(this, done, 'getDirectory - Error creating directory : ' + nestedDirName));3492 }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + parentDirName));3493 });3494 it("file.spec.132 Entry should be created succesfully when using relative paths if its parent directory exists", function (done) {3495 /* Directory entries have to be created successively.3496 For example, the call `fs.root.getDirectory('dir1/dir2', {create:true}, successCallback, errorCallback)`3497 will fail if dir1 did not exist. */3498 var parentName = 'parentName132';3499 var nestedName = 'nestedName132';3500 var path = parentName + '/' + nestedName;3501 var win = function(directory){3502 expect(directory).toBeDefined();3503 expect(directory.isFile).toBe(false);3504 expect(directory.isDirectory).toBe(true);3505 expect(directory.name).toCanonicallyMatch(nestedName);3506 expect(directory.fullPath).toCanonicallyMatch('/' + path + '/');3507 deleteEntry(directory.name);3508 deleteEntry(parentName, done);3509 };3510 createDirectory(parentName, function() {3511 root.getDirectory(parentName + '/' + nestedName, {create:true}, win,3512 failed.bind(this, done, 'root.getDirectory - Error getting directory : ' + path));3513 }, failed.bind(this, done, 'root.getDirectory - Error getting directory : ' + parentName));3514 });3515 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) {3516 // Names include special symbols so that we check the IndexedDB range used3517 var deletedFileName = 'deletedFile.0',3518 secondFileName = 'deletedFile.0.1';3519 var win = function(fileEntry){3520 expect(fileEntry).toBeDefined();3521 expect(fileEntry.isFile).toBe(true);3522 expect(fileEntry.isDirectory).toBe(false);3523 expect(fileEntry.name).toCanonicallyMatch(secondFileName);3524 deleteEntry(fileEntry.name, done);3525 };3526 createFile(deletedFileName, function (deletedFile) {3527 createFile(secondFileName, function () {3528 deletedFile.remove(function() {3529 root.getFile(deletedFileName, {create: false}, failed.bind(this, done, 'getFile - unexpected success callback getting deleted file : ' + deletedFileName), function(){3530 root.getFile(secondFileName, {create: false}, win, failed.bind(this, done, 'getFile - Error getting file after deleting deletedFile : ' + secondFileName));3531 });3532 }, failed.bind(this, done, 'remove - Error removing file : ' + deletedFileName));3533 }, failed.bind(this, done, 'getFile - Error creating file : ' + secondFileName));3534 }, failed.bind(this, done, 'getFile - Error creating file : ' + deletedFileName));3535 });3536 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) {3537 // Names include special symbols so that we check the IndexedDB range used3538 var deletedDirName = 'deletedDir.0',3539 secondDirName = 'deletedDir.0.1';3540 var win = function(directory){3541 expect(directory).toBeDefined();3542 expect(directory.isFile).toBe(false);3543 expect(directory.isDirectory).toBe(true);3544 expect(directory.name).toCanonicallyMatch(secondDirName);3545 deleteEntry(directory.name, done);3546 };3547 createDirectory(deletedDirName, function (deletedDir) {3548 createDirectory(secondDirName, function () {3549 deletedDir.remove(function() {3550 root.getDirectory(deletedDirName, {create: false}, failed.bind(this, done, 'getDirectory - unexpected success callback getting deleted directory : ' + deletedDirName), function() {3551 root.getDirectory(secondDirName, {create: false}, win, failed.bind(this, done, 'getDirectory - Error getting directory after deleting deletedDirectory : ' + secondDirName));3552 });3553 }, failed.bind(this, done, 'remove - Error removing directory : ' + deletedDirName));3554 }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + secondDirName));3555 }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + deletedDirName));3556 });3557 it("file.spec.135 Deletion of a child directory should not affect the parent directory.", function (done) {3558 var parentName = 'parentName135';3559 var childName = 'childName135';3560 var win = function(directory){3561 expect(directory).toBeDefined();3562 expect(directory.isFile).toBe(false);3563 expect(directory.isDirectory).toBe(true);3564 expect(directory.name).toCanonicallyMatch(parentName);3565 deleteEntry(directory.name, done);3566 };3567 createDirectory(parentName, function(parent){3568 parent.getDirectory(childName, {create: true}, function(child){3569 child.removeRecursively(function(){3570 root.getDirectory(parentName, {create: false}, win, failed.bind(this, done, 'root.getDirectory - Error getting parent directory : ' + parentName));3571 },3572 failed.bind(this, done, 'getDirectory - Error removing directory : ' + childName));3573 }, failed.bind(this, done, 'getDirectory - Error creating directory : ' + childName));3574 }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + parentName));3575 });3576 it("file.spec.136 Paths should support Unicode symbols.", function (done) {3577 var dirName = '文件插件';3578 var win = function(directory){3579 expect(directory).toBeDefined();3580 expect(directory.isFile).toBe(false);3581 expect(directory.isDirectory).toBe(true);3582 expect(directory.name).toCanonicallyMatch(dirName);3583 deleteEntry(directory.name, done);3584 };3585 createDirectory(dirName, function(){3586 root.getDirectory(dirName, {create: false}, win,3587 failed.bind(this, done, 'root.getDirectory - Error getting directory : ' + dirName));3588 }, failed.bind(this, done, 'root.getDirectory - Error creating directory : ' + dirName));3589 });3590 });3591 // Content and Asset URLs3592 if (cordova.platformId == 'android') {3593 describe('content: URLs', function() {3594 // Warning: Default HelloWorld www directory structure is required for these tests (www/index.html at least)3595 function testContentCopy(src, done) {3596 var file2 = "entry.copy.file2b",3597 fullPath = joinURL(temp_root.fullPath, file2),3598 validateFile = function (entry) {3599 expect(entry.isFile).toBe(true);3600 expect(entry.isDirectory).toBe(false);3601 expect(entry.name).toCanonicallyMatch(file2);3602 expect(entry.fullPath).toCanonicallyMatch(fullPath);3603 expect(entry.filesystem.name).toEqual("temporary");3604 // cleanup3605 deleteEntry(entry.name, done);3606 },3607 transfer = function () {3608 resolveLocalFileSystemURL(src, function(entry) {3609 expect(entry).toBeDefined();3610 expect(entry.filesystem.name).toEqual("content");3611 entry.copyTo(temp_root, file2, validateFile, failed.bind(null, done, 'entry.copyTo - Error copying file: ' + entry.toURL() + ' to TEMPORAL root as: ' + file2));3612 }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for content provider'));3613 };3614 // Delete any existing file to start things off3615 temp_root.getFile(file2, {}, function (entry) {3616 entry.remove(transfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));3617 }, transfer);3618 }3619 it("file.spec.138 copyTo: content", function(done) {3620 testContentCopy('content://org.apache.cordova.file.testprovider/www/index.html', done);3621 });3622 it("file.spec.139 copyTo: content /w space and query", function(done) {3623 testContentCopy('content://org.apache.cordova.file.testprovider/?name=foo%20bar&realPath=%2Fwww%2Findex.html', done);3624 });3625 it("file.spec.140 delete: content should fail", function(done) {3626 resolveLocalFileSystemURL('content://org.apache.cordova.file.testprovider/www/index.html', function(entry) {3627 entry.remove(failed.bind(null, done, 'expected delete to fail'), done);3628 }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for content provider'));3629 });3630 });3631 // these tests ensure that you can read and copy from android_asset folder3632 // for details see https://issues.apache.org/jira/browse/CB-64283633 // and https://mail-archives.apache.org/mod_mbox/cordova-dev/201508.mbox/%3C782154441.8406572.1440182722528.JavaMail.yahoo%40mail.yahoo.com%3E3634 describe('asset: URLs', function() {3635 it("file.spec.141 filePaths.applicationStorage", function() {3636 expect(cordova.file.applicationDirectory).toEqual('file:///android_asset/');3637 }, MEDIUM_TIMEOUT);3638 it("file.spec.142 assets should be enumerable", function(done) {3639 resolveLocalFileSystemURL('file:///android_asset/www/fixtures/asset-test', function(entry) {3640 var reader = entry.createReader();3641 reader.readEntries(function (entries) {3642 expect(entries.length).not.toBe(0);3643 done();3644 }, failed.bind(null, done, 'reader.readEntries - Error during reading of entries from assets directory'));3645 }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for assets'));3646 }, MEDIUM_TIMEOUT);3647 it("file.spec.145 asset subdirectories should be obtainable", function(done) {3648 resolveLocalFileSystemURL('file:///android_asset/www/fixtures', function(entry) {3649 entry.getDirectory('asset-test', { create: false }, function (subDir) {3650 expect(subDir).toBeDefined();3651 expect(subDir.isFile).toBe(false);3652 expect(subDir.isDirectory).toBe(true);3653 expect(subDir.name).toCanonicallyMatch('asset-test');3654 done();3655 }, failed.bind(null, done, 'entry.getDirectory - Error getting asset subdirectory'));3656 }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for assets'));3657 }, MEDIUM_TIMEOUT);3658 it("file.spec.146 asset files should be readable", function(done) {3659 resolveLocalFileSystemURL('file:///android_asset/www/fixtures/asset-test/asset-test.txt', function(entry) {3660 expect(entry.isFile).toBe(true);3661 entry.file(function (file) {3662 expect(file).toBeDefined();3663 var reader = new FileReader();3664 reader.onerror = failed.bind(null, done, 'reader.readAsText - Error reading asset text file');3665 reader.onloadend = function () {3666 expect(this.result).toBeDefined();3667 expect(this.result.length).not.toBe(0);3668 done();3669 };3670 reader.readAsText(file);3671 }, failed.bind(null, done, 'entry.file - Error reading asset file'));3672 }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for assets'));3673 }, MEDIUM_TIMEOUT);3674 it("file.spec.143 copyTo: asset -> temporary", function(done) {3675 var file2 = "entry.copy.file2b",3676 fullPath = joinURL(temp_root.fullPath, file2),3677 validateFile = function (entry) {3678 expect(entry.isFile).toBe(true);3679 expect(entry.isDirectory).toBe(false);3680 expect(entry.name).toCanonicallyMatch(file2);3681 expect(entry.fullPath).toCanonicallyMatch(fullPath);3682 expect(entry.filesystem.name).toEqual("temporary");3683 // cleanup3684 deleteEntry(entry.name, done);3685 },3686 transfer = function () {3687 resolveLocalFileSystemURL('file:///android_asset/www/index.html', function(entry) {3688 expect(entry.filesystem.name).toEqual('assets');3689 entry.copyTo(temp_root, file2, validateFile, failed.bind(null, done, 'entry.copyTo - Error copying file: ' + entry.toURL() + ' to TEMPORAL root as: ' + file2));3690 }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for assets'));3691 };3692 // Delete any existing file to start things off3693 temp_root.getFile(file2, {}, function (entry) {3694 entry.remove(transfer, failed.bind(null, done, 'entry.remove - Error removing file: ' + file2));3695 }, transfer);3696 }, MEDIUM_TIMEOUT);3697 });3698 it("file.spec.144 copyTo: asset directory", function (done) {3699 var srcUrl = 'file:///android_asset/www/fixtures/asset-test';3700 var dstDir = "entry.copy.dstDir";3701 var dstPath = joinURL(root.fullPath, dstDir);3702 // create a new directory entry to kick off it3703 deleteEntry(dstDir, function () {3704 resolveLocalFileSystemURL(srcUrl, function(directory) {3705 directory.copyTo(root, dstDir, function (directory) {3706 expect(directory).toBeDefined();3707 expect(directory.isFile).toBe(false);3708 expect(directory.isDirectory).toBe(true);3709 expect(directory.fullPath).toCanonicallyMatch(dstPath);3710 expect(directory.name).toCanonicallyMatch(dstDir);3711 root.getDirectory(dstDir, {3712 create : false3713 }, function (dirEntry) {3714 expect(dirEntry).toBeDefined();3715 expect(dirEntry.isFile).toBe(false);3716 expect(dirEntry.isDirectory).toBe(true);3717 expect(dirEntry.fullPath).toCanonicallyMatch(dstPath);3718 expect(dirEntry.name).toCanonicallyMatch(dstDir);3719 dirEntry.getFile('asset-test.txt', {3720 create : false3721 }, function (fileEntry) {3722 expect(fileEntry).toBeDefined();3723 expect(fileEntry.isFile).toBe(true);3724 // cleanup3725 deleteEntry(dstDir, done);3726 }, failed.bind(null, done, 'dirEntry.getFile - Error getting subfile'));3727 }, failed.bind(null, done, 'root.getDirectory - Error getting copied directory'));3728 }, failed.bind(null, done, 'directory.copyTo - Error copying directory'));3729 }, failed.bind(null, done, 'resolving src dir'));3730 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));3731 }, MEDIUM_TIMEOUT);3732 }3733 });3734};3735//******************************************************************************************3736//***************************************Manual Tests***************************************3737//******************************************************************************************3738exports.defineManualTests = function (contentEl, createActionButton) {3739 function resolveFs(fsname) {...

Full Screen

Full Screen

DeleteEntry.test.js

Source:DeleteEntry.test.js Github

copy

Full Screen

...19 // repositoryStub defines the mocked ropository DeleteEntry method behavior20 Sinon.stub(clientRepositoryMock, "DeleteEntry").returns("ok")21 const deleteEntry = DeleteEntry(clientRepositoryMock)22 23 await deleteEntry(req, res)24 expect(sendStatusSpy.calledOnce).to.be.true25 expect(sendStatusSpy.firstCall.args[0]).to.be.equal(200)26 })27 it('should respond status 400 when request missing id', async function() {28 const req = {29 params: {}30 }31 const sendStatusSpy = Sinon.spy()32 const res = {33 sendStatus: sendStatusSpy34 }35 const clientRepositoryMock = new ClientRepositoryMock36 const deleteEntry = DeleteEntry(clientRepositoryMock)37 38 await deleteEntry(req, res)39 expect(sendStatusSpy.calledOnce).to.be.true40 expect(sendStatusSpy.firstCall.args[0]).to.be.equal(400)41 })42 it('should respond status 404 when id does not exist', async function() {43 const testId = new mongoose.Types.ObjectId().toString()44 45 const req = {46 params: {47 id: testId48 }49 }50 const sendStatusSpy = Sinon.spy()51 const res = {52 sendStatus: sendStatusSpy53 }54 const clientRepositoryMock = new ClientRepositoryMock55 Sinon.stub(clientRepositoryMock, "DeleteEntry").returns(null)56 const deleteEntry = DeleteEntry(clientRepositoryMock)57 58 await deleteEntry(req, res)59 expect(sendStatusSpy.calledOnce).to.be.true60 expect(sendStatusSpy.firstCall.args[0]).to.be.equal(404)61 })62 it('should respond status 500 due to repository error', async function() {63 const testId = new mongoose.Types.ObjectId().toString()64 65 const req = {66 params: {67 id: testId68 }69 }70 const sendStatusSpy = Sinon.spy()71 const res = {72 sendStatus: sendStatusSpy73 }74 const clientRepositoryMock = new ClientRepositoryMock75 Sinon.stub(clientRepositoryMock, "DeleteEntry").rejects()76 const deleteEntry = DeleteEntry(clientRepositoryMock)77 78 await deleteEntry(req, res)79 expect(sendStatusSpy.calledOnce).to.be.true80 expect(sendStatusSpy.firstCall.args[0]).to.be.equal(500)81 })...

Full Screen

Full Screen

ViewEntry.js

Source:ViewEntry.js Github

copy

Full Screen

...29 checkNotice();30 this.props.ShowEntry(this.props.match.params.id);31 document.querySelector('body').insertAdjacentHTML('afterbegin', `<img src="http://res.cloudinary.com/ddfepbdqg/image/upload/v1543597369/Rolling.svg" id="loading"></img>`);32 }33 deleteEntry(e) {34 e.preventDefault();35 this.props.DeleteEntry(this.state.entry.id);36 }37 /**38 * @description - This method runs whenever redux state changes39 * @returns {object} state40 * @param {object} props41 * @param {object} state42 * @memberof ViewTag43 */44 static getDerivedStateFromProps(props, state) {45 return {46 entry: props.entry,47 message: props.message,...

Full Screen

Full Screen

delete.test.js

Source:delete.test.js Github

copy

Full Screen

...27 const commit = () => Promise.resolve(null);28 const push = () => Promise.resolve(null);29 create.withArgs(repositoryPath).returns(Promise.resolve({ add, commit, push }));30 existsSync.withArgs(dataPath).returns(true);31 t.deepEqual(await deleteEntry.deleteEntry(type, { _id_: id }), {32 _id_: id,33 message: `${type} ${id} was successfully deleted`34 });35});36test.serial('deleteEntry should call remove if the folder exists', async t => {37 const type = 'type';38 const id = 'id';39 const repositoryPath = path.resolve(workingDirectory, 'master');40 const dataPath = path.resolve(repositoryPath, type, id);41 const add = () => Promise.resolve(null);42 const commit = () => Promise.resolve(null);43 const push = () => Promise.resolve(null);44 create.withArgs(repositoryPath).returns(Promise.resolve({ add, commit, push }));45 existsSync.withArgs(dataPath).returns(true);46 await deleteEntry.deleteEntry(type, { _id_: id });47 t.true(remove.called);48});49test.serial('deleteEntry should not call remove if the folder does not exist', async t => {50 const type = 'type';51 const id = 'id';52 const repositoryPath = path.resolve(workingDirectory, 'master');53 const dataPath = path.resolve(repositoryPath, type, id);54 create.withArgs(repositoryPath).returns(Promise.resolve([]));55 existsSync.withArgs(dataPath).returns(false);56 await deleteEntry.deleteEntry(type, { _id_: id });57 t.false(remove.called);58});59test('deleteEntry should throw error if repository is not found', async t => {60 const type = 'type';61 const id = 'id';62 const repositoryPath = path.resolve(workingDirectory, 'master');63 const dataPath = path.resolve(repositoryPath, type, id);64 create.withArgs(repositoryPath).returns(Promise.resolve([]));65 existsSync.withArgs(dataPath).returns(true);66 await t.throws(deleteEntry.deleteEntry(type, { _id_: id }));...

Full Screen

Full Screen

Entry.spec.js

Source:Entry.spec.js Github

copy

Full Screen

1import React from 'react'2import { shallow, mount } from 'enzyme'3import toJson from 'enzyme-to-json'4import { Entry } from '../Entry'5import { Dropdown } from 'semantic-ui-react'6jest.mock('universal-cookie')7const openEntryModal = jest.fn()8const deleteEntry = jest.fn()9describe('entry component', () => {10 beforeEach(() => {11 jest.resetAllMocks()12 })13 it('should render a basic entry correctly', () => {14 var dash = shallow(15 <Entry16 id={1}17 rating={5}18 date='2017-01-01'19 notes='Foo bar baz'20 openEntryModal={openEntryModal}21 deleteEntry={deleteEntry}22 />23 )24 expect(toJson(dash)).toMatchSnapshot()25 })26 it('should render without notes', () => {27 var dash = shallow(28 <Entry29 id={1}30 rating={5}31 date='2017-01-01'32 openEntryModal={openEntryModal}33 deleteEntry={deleteEntry}34 />35 )36 expect(toJson(dash)).toMatchSnapshot()37 })38 it('should render without a rating', () => {39 var dash = shallow(40 <Entry41 id={1}42 date='2017-01-01'43 notes='Foo bar baz'44 openEntryModal={openEntryModal}45 deleteEntry={deleteEntry}46 />47 )48 expect(toJson(dash)).toMatchSnapshot()49 })50 it('should call openEntryModel on edit click', () => {51 var dash = mount(52 <Entry53 id={1}54 date='2017-01-01'55 notes='Foo bar baz'56 openEntryModal={openEntryModal}57 deleteEntry={deleteEntry}58 />59 )60 dash.find(Dropdown.Item).findWhere((n) => n.props().icon === 'delete').simulate('click')61 expect(deleteEntry).toBeCalled()62 })63 it('should call deleteEntry on delete click', () => {64 var dash = mount(65 <Entry66 id={1}67 date='2017-01-01'68 notes='Foo bar baz'69 openEntryModal={openEntryModal}70 deleteEntry={deleteEntry}71 />72 )73 dash.find(Dropdown.Item).findWhere((n) => n.props().icon === 'edit').simulate('click')74 expect(openEntryModal).toBeCalled()75 })...

Full Screen

Full Screen

deleteentry.js

Source:deleteentry.js Github

copy

Full Screen

1const LenoxCommand = require('../LenoxCommand.js');2module.exports = class deleteentryCommand extends LenoxCommand {3 constructor(client) {4 super(client, {5 name: 'deleteentry',6 group: 'application',7 memberName: 'deleteentry',8 description: 'Deletes an entry from the template',9 format: 'deleteentry {entry}',10 aliases: [],11 examples: ['deleteentry How old are you?'],12 clientpermissions: ['SEND_MESSAGES'],13 userpermissions: ['ADMINISTRATOR'],14 shortDescription: 'Entries',15 dashboardsettings: true16 });17 }18 async run(msg) {19 const langSet = msg.client.provider.getGuild(msg.guild.id, 'language');20 const lang = require(`../../languages/${langSet}.json`);21 const args = msg.content.split(' ').slice(1);22 const input = args.slice().join(' ');23 if (input.length < 1) return msg.reply(lang.deleteentry_noinput);24 if (isNaN(input)) {25 for (let i = 0; i < msg.client.provider.getGuild(msg.guild.id, 'application').template.length; i++) {26 if (input.toLowerCase() === msg.client.provider.getGuild(msg.guild.id, 'application').template[i].toLowerCase()) {27 const currentApplication = msg.client.provider.getGuild(msg.guild.id, 'application');28 currentApplication.template.splice(i, 1);29 await msg.client.provider.getGuild(msg.guild.id, 'application', currentApplication);30 const removed = lang.deleteentry_removed.replace('%entry', `\`${input}\``);31 return msg.channel.send(removed);32 }33 }34 } else {35 const currentApplication = msg.client.provider.getGuild(msg.guild.id, 'application');36 currentApplication.template.splice(parseInt(input, 10) - 1, 1);37 await msg.client.provider.getGuild(msg.guild.id, 'application', currentApplication);38 const removed = lang.deleteentry_removed.replace('%entry', `\`${input}\``);39 return msg.channel.send(removed);40 }41 return msg.channel.send(lang.deleteentry_notexists);42 }...

Full Screen

Full Screen

Entry.js

Source:Entry.js Github

copy

Full Screen

...16 async function updateEntry() {17 UpdateEntry(state)18 .then(() => onUpdate());19 }20 async function deleteEntry() {21 DeleteEntry(state.id)22 .then(() => onUpdate());23 }24 return (25 <StyledEntry completed={state.completed}>26 <div className='entryBlock'>27 <div className='header'>28 <span className='pointer' onClick={() => dispatch({type: Actions.TOGGLE_COMPLETED})}>29 <div className={'entryText'}>{state.title}</div>30 </span>31 <div className='controls hidden'>32 <CustomButton buttonType={ButtonTypes.Edit} onClick={() => onSelect(state)}/>&nbsp;33 <CustomButton buttonType={ButtonTypes.Delete} onClick={() => deleteEntry()}/>34 </div>35 </div>36 <small className={`description hidden entryText`}>{state.description}</small>37 </div>38 </StyledEntry>39 );40};41Entry.propType = {42 entry: PropTypes.object,43 onSelect: PropTypes.func,44 onDelete: PropTypes.func...

Full Screen

Full Screen

PhonebookEntries.js

Source:PhonebookEntries.js Github

copy

Full Screen

...12 {filteredEntries.map(person => (13 <Entry14 key={person.name}15 person={person}16 deleteEntry={() => deleteEntry(person.id)}17 />18 ))}19 </ul>20 )21}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.deleteEntry('playwright');7 await page.deleteEntry('playwright', 'password');8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 await page.clear('playwright');16 await page.clear('playwright', 'password');17 await browser.close();18})();19const { chromium } = require('playwright');20(async () => {21 const browser = await chromium.launch();22 const context = await browser.newContext();23 const page = await context.newPage();24 await page.setViewportSize({width: 1000, height: 1000});25 await browser.close();26})();27const { chromium } = require('playwright');28(async () => {29 const browser = await chromium.launch();30 const context = await browser.newContext();31 const page = await context.newPage();32 await page.setViewportSize({width: 1000, height: 1000});33 await browser.close();34})();35const { chromium } = require('playwright');36(async () => {37 const browser = await chromium.launch();38 const context = await browser.newContext();39 const page = await context.newPage();40 await page.setViewportSize({width: 1000, height: 1000});41 await browser.close();42})();43const { chromium } = require('playwright');44(async () => {45 const browser = await chromium.launch();46 const context = await browser.newContext();47 const page = await context.newPage();48 await page.setViewportSize({width: 1000, height

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 await context.addCookies([7 {8 },9 ]);10 await deleteEntry(context, 'foo');11 const cookies = await context.cookies();12 console.log(cookies);13 await browser.close();14})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2deleteEntry('entryId');3const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');4deleteEntry('entryId');5const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');6deleteEntry('entryId');7const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');8deleteEntry('entryId');9const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');10deleteEntry('entryId');11const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');12deleteEntry('entryId');13const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');14deleteEntry('entryId');15const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');16deleteEntry('entryId');17const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');18deleteEntry('entryId');19const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');20deleteEntry('entryId');21const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');22deleteEntry('entryId');23const { deleteEntry } = require('playwright/lib/server/supplements/recorder/recorderSupplement');24deleteEntry('entryId');25const { deleteEntry }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { internal } = require('playwright');2import { internal } from 'playwright';3import { internal } from 'playwright';4const { internal } = require('playwright');5const { internal } = require('playwright');6const { internal } = require('playwright');7const { internal } = require('playwright');8const { internal } = require('playwright');9const { internal } = require('playwright');10const { internal } = require('playwright');11const { internal } = require('playwright');12const { internal } = require('playwright');13const { internal } = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const context = await browser.newContext();12 const page = await context.newPage();13 await browser.close();14})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { deleteEntry } = require('@playwright/test/lib/server/networkCache');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.reload();8 await browser.close();9})();10const { deleteAllEntries } = require('@playwright/test/lib/server/networkCache');11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 await deleteAllEntries(page);17 await page.reload();18 await browser.close();19})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { deleteEntry } = require('playwright/lib/utils/registry');2deleteEntry('chromium');3const { downloadBrowserWithProgressBar } = require('playwright/lib/utils/registry');4downloadBrowserWithProgressBar('chromium');5const { downloadBrowserWithProgressBar } = require('playwright/lib/utils/registry');6downloadBrowserWithProgressBar('chromium');7const { downloadBrowserWithProgressBar } = require('playwright/lib/utils/registry');8downloadBrowserWithProgressBar('chromium');9const { downloadBrowserWithProgressBar } = require('playwright/lib/utils/registry');10downloadBrowserWithProgressBar('chromium');11const { downloadBrowserWithProgressBar } = require('playwright/lib/utils/registry');12downloadBrowserWithProgressBar('chromium');

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const {deleteEntry} = require(path.join(__dirname, 'node_modules/playwright/lib/server/playwright.js'));3deleteEntry('playwright.db', 'browserContexts', 'id', 'f0e90c9b-8b5f-4e0b-9b2c-0a8c2d2d9b9c');4deleteEntry('playwright.db', 'pages', 'id', 'f0e90c9b-8b5f-4e0b-9b2c-0a8c2d2d9b9c');5deleteEntry('playwright.db', 'contexts', 'id', 'f0e90c9b-8b5f-4e0b-9b2c-0a8c2d2d9b9c');6deleteEntry('playwright.db', 'browserContexts', 'id', 'f0e90c9b-8b5f-4e0b-9b2c-0a8c2d2d9b9c');7deleteEntry('playwright.db', 'devices', 'id', 'f0e90c9b-8b5f-4e0b-9b2c-0a8c2d2d9b9c');8deleteEntry('playwright.db', '

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful