Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

<!-- include spec files here... -->
<script type="text/javascript" src="spec/SampleTest.js"></script>
<script type="text/javascript" src="spec/NativeFileSystem-test.js"></script>

<!-- include source files here... -->
<script type="text/javascript" src="../src/thirdparty/CodeMirror2/lib/CodeMirror.js"></script>
<script type="text/javascript" src="../src/thirdparty/CodeMirror2/mode/javascript/javascript.js"></script>
<script type="text/javascript" src="../src/thirdparty/jquery-1.7.min.js"></script>
<script type="text/javascript" src="../src/thirdparty/less-1.1.5.min.js"></script>
<script type="text/javascript" src="../src/NativeFileSystem.js"></script>

<script type="text/javascript">
(function() {
Expand Down
1 change: 1 addition & 0 deletions test/spec/NativeFileSystem-test-files/dir1/file2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is file2 in dir1
1 change: 1 addition & 0 deletions test/spec/NativeFileSystem-test-files/file1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Here is file1
57 changes: 57 additions & 0 deletions test/spec/NativeFileSystem-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
describe("NativeFileSystem", function(){

describe("Reading", function() {

beforeEach(function() {
this.addMatchers({
toContainDirectoryWithName: function(expected) {
for (var i = 0 ; i < this.actual.length; ++i) {
if (this.actual[i].isDirectory && this.actual[i].name === expected) {
return true;
}
}
return false;
}
, toContainFileWithName: function(expected) {
for (var i = 0 ; i < this.actual.length; ++i) {
if (this.actual[i].isFile && this.actual[i].name === expected) {
return true;
}
}
return false;
}
});
});

it("should read a directory from disk", function() {

//TODO: Make this relative -- right now, asking for "." gives "/"
//Want to be able to simply use:
// var path = "spec/NativeFileSystem-test-files";
var path = window.location.href;
path = path.substr("file://".length);
path = path.substr(0,path.lastIndexOf("/")+1);
path = path + "spec/NativeFileSystem-test-files";

var entries = null;
var readComplete = false;

var nfs = window.NativeFileSystem.requestNativeFileSystem(path);
var reader = nfs.createReader();

var successCallback = function(e) { entries = e; readComplete = true; }
// TODO: not sure what parameters error callback will take because it's not implemented yet
var errorCallback = function() { readComplete = true; }

reader.readEntries(successCallback, errorCallback);

waitsFor(function() { return readComplete; }, 1000);

runs(function() {
expect(entries).toContainDirectoryWithName("dir1");
expect(entries).toContainFileWithName("file1");
expect(entries).not.toContainFileWithName("file2");
});
});
});
});