1- /*
1+ /*
22 *
33 * Licensed to the Apache Software Foundation (ASF) under one
44 * or more contributor license agreements. See the NOTICE file
1818 *
1919 */
2020exports . defineAutoTests = function ( ) {
21+ var isWindows = ( cordova . platformId == "windows" ) || ( navigator . appVersion . indexOf ( "MSAppHost/1.0" ) !== - 1 ) ;
22+
2123 describe ( 'File API' , function ( ) {
2224 // Adding a Jasmine helper matcher, to report errors when comparing to FileError better.
2325 var fileErrorMap = {
@@ -2674,7 +2676,7 @@ exports.defineAutoTests = function () {
26742676 } , function ( fileEntry ) {
26752677 expect ( fileEntry ) . toBeDefined ( ) ;
26762678 expect ( fileEntry . name ) . toBe ( fileName ) ;
2677- expect ( fileEntry . fullPath ) . toCanonicallyMatch ( '/' + fileName ) ;
2679+ expect ( fileEntry . fullPath ) . toCanonicallyMatch ( root . fullPath + '/' + fileName ) ;
26782680 // cleanup
26792681 deleteEntry ( fileName ) ;
26802682 done ( ) ;
@@ -2722,14 +2724,19 @@ exports.defineAutoTests = function () {
27222724 var pathExpect = cordova . platformId === 'windowsphone' ? "//nativ" : "file://" ;
27232725 it ( "file.spec.114 fileEntry should have a toNativeURL method" , function ( done ) {
27242726 var fileName = "native.file.uri" ;
2727+ if ( isWindows ) {
2728+ var rootPath = root . fullPath ;
2729+ pathExpect = rootPath . substr ( 0 , rootPath . indexOf ( ":" ) ) ;
2730+ }
27252731 // create a new file entry
27262732 createFile ( fileName , function ( entry ) {
27272733 expect ( entry . toNativeURL ) . toBeDefined ( ) ;
27282734 expect ( entry . name ) . toCanonicallyMatch ( fileName ) ;
27292735 expect ( typeof entry . toNativeURL ) . toBe ( 'function' ) ;
27302736 var nativeURL = entry . toNativeURL ( ) ;
2737+ var indexOfRoot = isWindows ? rootPath . indexOf ( ":" ) : 7 ;
27312738 expect ( typeof nativeURL ) . toBe ( "string" ) ;
2732- expect ( nativeURL . substring ( 0 , 7 ) ) . toEqual ( pathExpect ) ;
2739+ expect ( nativeURL . substring ( 0 , indexOfRoot ) ) . toEqual ( pathExpect ) ;
27332740 expect ( nativeURL . substring ( nativeURL . length - fileName . length ) ) . toEqual ( fileName ) ;
27342741 // cleanup
27352742 deleteEntry ( fileName ) ;
@@ -2746,8 +2753,9 @@ exports.defineAutoTests = function () {
27462753 expect ( entries [ 0 ] . toNativeURL ) . toBeDefined ( ) ;
27472754 expect ( typeof entries [ 0 ] . toNativeURL ) . toBe ( 'function' ) ;
27482755 var nativeURL = entries [ 0 ] . toNativeURL ( ) ;
2756+ var indexOfRoot = ( isWindows ) ? nativeURL . indexOf ( ":" ) : 7 ;
27492757 expect ( typeof nativeURL ) . toBe ( "string" ) ;
2750- expect ( nativeURL . substring ( 0 , 7 ) ) . toEqual ( pathExpect ) ;
2758+ expect ( nativeURL . substring ( 0 , indexOfRoot ) ) . toEqual ( pathExpect ) ;
27512759 expect ( nativeURL . substring ( nativeURL . length - fileName . length ) ) . toEqual ( fileName ) ;
27522760 // cleanup
27532761 directory . removeRecursively ( null , null ) ;
@@ -2774,8 +2782,9 @@ exports.defineAutoTests = function () {
27742782 expect ( entry . name ) . toCanonicallyMatch ( fileName ) ;
27752783 expect ( typeof entry . toNativeURL ) . toBe ( 'function' ) ;
27762784 var nativeURL = entry . toNativeURL ( ) ;
2785+ var indexOfRoot = ( isWindows ) ? nativeURL . indexOf ( ":" ) : 7 ;
27772786 expect ( typeof nativeURL ) . toBe ( "string" ) ;
2778- expect ( nativeURL . substring ( 0 , 7 ) ) . toEqual ( pathExpect ) ;
2787+ expect ( nativeURL . substring ( 0 , indexOfRoot ) ) . toEqual ( pathExpect ) ;
27792788 expect ( nativeURL . substring ( nativeURL . length - fileName . length ) ) . toEqual ( fileName ) ;
27802789 // cleanup
27812790 deleteEntry ( fileName ) ;
@@ -2821,7 +2830,7 @@ exports.defineAutoTests = function () {
28212830 // create a new file entry
28222831 createFile ( fileName , function ( entry ) {
28232832 resolveLocalFileSystemURL ( entry . toNativeURL ( ) , function ( fileEntry ) {
2824- expect ( fileEntry . fullPath ) . toCanonicallyMatch ( "/" + fileName ) ;
2833+ expect ( fileEntry . fullPath ) . toCanonicallyMatch ( root . fullPath + "/" + fileName ) ;
28252834 // cleanup
28262835 deleteEntry ( fileName ) ;
28272836 done ( ) ;
@@ -2835,7 +2844,7 @@ exports.defineAutoTests = function () {
28352844 var url = entry . toNativeURL ( ) ;
28362845 url = url . replace ( "///" , "//localhost/" ) ;
28372846 resolveLocalFileSystemURL ( url , function ( fileEntry ) {
2838- expect ( fileEntry . fullPath ) . toCanonicallyMatch ( "/" + fileName ) ;
2847+ expect ( fileEntry . fullPath ) . toCanonicallyMatch ( root . fullPath + "/" + fileName ) ;
28392848 // cleanup
28402849 deleteEntry ( fileName ) ;
28412850 done ( ) ;
@@ -2849,7 +2858,7 @@ exports.defineAutoTests = function () {
28492858 var url = entry . toNativeURL ( ) ;
28502859 url = url + "?test/test" ;
28512860 resolveLocalFileSystemURL ( url , function ( fileEntry ) {
2852- expect ( fileEntry . fullPath ) . toCanonicallyMatch ( "/" + fileName ) ;
2861+ expect ( fileEntry . fullPath ) . toCanonicallyMatch ( root . fullPath + "/" + fileName ) ;
28532862 // cleanup
28542863 deleteEntry ( fileName ) ;
28552864 done ( ) ;
@@ -2863,7 +2872,7 @@ exports.defineAutoTests = function () {
28632872 var url = entry . toNativeURL ( ) ;
28642873 url = url . replace ( "///" , "//localhost/" ) + "?test/test" ;
28652874 resolveLocalFileSystemURL ( url , function ( fileEntry ) {
2866- expect ( fileEntry . fullPath ) . toCanonicallyMatch ( "/" + fileName ) ;
2875+ expect ( fileEntry . fullPath ) . toCanonicallyMatch ( root . fullPath + "/" + fileName ) ;
28672876 // cleanup
28682877 deleteEntry ( fileName ) ;
28692878 done ( ) ;
0 commit comments