Merge branch 'CB-5175'
diff --git a/doc/index.md b/doc/index.md
index 41e23a8..a464e4f 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -40,6 +40,15 @@
 For an overview of other storage options, refer to Cordova's
 [storage guide](http://cordova.apache.org/docs/en/edge/cordova_storage_storage.md.html).
 
+This plugin defines global `cordova.file` object.
+
+Although in the global scope, it is not available until after the `deviceready` event.
+
+    document.addEventListener("deviceready", onDeviceReady, false);
+    function onDeviceReady() {
+        console.log(cordova.file);
+    }
+
 ## Installation
 
     cordova plugin add org.apache.cordova.file
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 05cda35..9bbd7f8 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -305,11 +305,7 @@
         // This weird test is to determine if we are copying or moving a directory into itself.
         // Copy /sdcard/myDir to /sdcard/myDir-backup is okay but
         // Copy /sdcard/myDir to /sdcard/myDir/backup should throw an INVALID_MODIFICATION_ERR
-        if (dest.startsWith(src) && dest.indexOf(File.separator, src.length() - 1) != -1) {
-            return true;
-        }
-
-        return false;
+        return dest.equals(src) || dest.startsWith(src + File.separator);
     }
 
     /**
diff --git a/tests/tests.js b/tests/tests.js
index 6d625b9..6c85e06 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -18,6 +18,8 @@
  *
  */
 exports.defineAutoTests = function () {
+    var isWindows = (cordova.platformId == "windows") || (navigator.appVersion.indexOf("MSAppHost/1.0") !== -1);
+
     describe('File API', function () {
         // Adding a Jasmine helper matcher, to report errors when comparing to FileError better.
         var fileErrorMap = {
@@ -1599,6 +1601,24 @@
                     });
                 }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
             });
+            it("file.spec.130 moveTo: directory into similar directory", function (done) {
+                var srcDir = "entry.move.dis.srcDir",
+                dstDir = "entry.move.dis.srcDir-backup",
+                srcPath = joinURL(root.fullPath, srcDir);
+                // create a new directory entry to kick off it
+                createDirectory(srcDir, function (srcDirEntry) {
+                deleteEntry(dstDir, function () {
+                createDirectory(dstDir, function (dstDirEntry) {
+                    // move source directory into itself
+                    srcDirEntry.moveTo(dstDirEntry, 'file', function (newDirEntry) {
+                        expect(newDirEntry).toBeDefined();
+                        deleteEntry(dstDir);
+                        done();
+                    }, failed.bind(null, done, 'directory.moveTo - Error moving a directory into a similarly-named directory: ' + srcDir));
+                }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + dstDir));
+                }, failed.bind(null, done, 'deleteEntry - Error deleting directory : ' + dstDir));
+                }, failed.bind(null, done, 'createDirectory - Error creating directory : ' + srcDir));
+            });
             it("file.spec.72 moveTo: file onto itself", function (done) {
                 var file1 = "entry.move.fos.file1",
                 filePath = joinURL(root.fullPath, file1);
@@ -2674,7 +2694,7 @@
                     }, function (fileEntry) {
                         expect(fileEntry).toBeDefined();
                         expect(fileEntry.name).toBe(fileName);
-                        expect(fileEntry.fullPath).toCanonicallyMatch('/' + fileName);
+                        expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath +'/' + fileName);
                         // cleanup
                         deleteEntry(fileName);
                         done();
@@ -2722,14 +2742,19 @@
             var pathExpect = cordova.platformId === 'windowsphone' ? "//nativ" : "file://";
             it("file.spec.114 fileEntry should have a toNativeURL method", function (done) {
                 var fileName = "native.file.uri";
+                if (isWindows) {
+                    var rootPath = root.fullPath;
+                    pathExpect = rootPath.substr(0, rootPath.indexOf(":"));
+                }
                 // create a new file entry
                 createFile(fileName, function (entry) {
                     expect(entry.toNativeURL).toBeDefined();
                     expect(entry.name).toCanonicallyMatch(fileName);
                     expect(typeof entry.toNativeURL).toBe('function');
                     var nativeURL = entry.toNativeURL();
+                    var indexOfRoot = isWindows ? rootPath.indexOf(":") : 7;
                     expect(typeof nativeURL).toBe("string");
-                    expect(nativeURL.substring(0, 7)).toEqual(pathExpect);
+                    expect(nativeURL.substring(0, indexOfRoot)).toEqual(pathExpect);
                     expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
                     // cleanup
                     deleteEntry(fileName);
@@ -2746,8 +2771,9 @@
                     expect(entries[0].toNativeURL).toBeDefined();
                     expect(typeof entries[0].toNativeURL).toBe('function');
                     var nativeURL = entries[0].toNativeURL();
+                    var indexOfRoot = (isWindows) ? nativeURL.indexOf(":") : 7;
                     expect(typeof nativeURL).toBe("string");
-                    expect(nativeURL.substring(0, 7)).toEqual(pathExpect);
+                    expect(nativeURL.substring(0, indexOfRoot)).toEqual(pathExpect);
                     expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
                     // cleanup
                     directory.removeRecursively(null, null);
@@ -2774,8 +2800,9 @@
                         expect(entry.name).toCanonicallyMatch(fileName);
                         expect(typeof entry.toNativeURL).toBe('function');
                         var nativeURL = entry.toNativeURL();
+                        var indexOfRoot = (isWindows) ? nativeURL.indexOf(":") : 7;
                         expect(typeof nativeURL).toBe("string");
-                        expect(nativeURL.substring(0, 7)).toEqual(pathExpect);
+                        expect(nativeURL.substring(0, indexOfRoot)).toEqual(pathExpect);
                         expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
                         // cleanup
                         deleteEntry(fileName);
@@ -2821,7 +2848,7 @@
                 // create a new file entry
                 createFile(fileName, function (entry) {
                     resolveLocalFileSystemURL(entry.toNativeURL(), function (fileEntry) {
-                        expect(fileEntry.fullPath).toCanonicallyMatch("/" + fileName);
+                        expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + "/" + fileName);
                         // cleanup
                         deleteEntry(fileName);
                         done();
@@ -2835,7 +2862,7 @@
                     var url = entry.toNativeURL();
                     url = url.replace("///", "//localhost/");
                     resolveLocalFileSystemURL(url, function (fileEntry) {
-                        expect(fileEntry.fullPath).toCanonicallyMatch("/" + fileName);
+                        expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + "/" + fileName);
                         // cleanup
                         deleteEntry(fileName);
                         done();
@@ -2849,7 +2876,7 @@
                     var url = entry.toNativeURL();
                     url = url + "?test/test";
                     resolveLocalFileSystemURL(url, function (fileEntry) {
-                        expect(fileEntry.fullPath).toCanonicallyMatch("/" + fileName);
+                        expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + "/" + fileName);
                         // cleanup
                         deleteEntry(fileName);
                         done();
@@ -2863,7 +2890,7 @@
                     var url = entry.toNativeURL();
                     url = url.replace("///", "//localhost/") + "?test/test";
                     resolveLocalFileSystemURL(url, function (fileEntry) {
-                        expect(fileEntry.fullPath).toCanonicallyMatch("/" + fileName);
+                        expect(fileEntry.fullPath).toCanonicallyMatch(root.fullPath + "/" + fileName);
                         // cleanup
                         deleteEntry(fileName);
                         done();