Skip to content

Commit

Permalink
File/Directory Entries API: Make tests Edge friendly (web-platform-te…
Browse files Browse the repository at this point in the history
…sts#7659)

* Reduce dependencies on APIs by tests
  • Loading branch information
inexorabletash authored Oct 11, 2017
1 parent 1f31c88 commit 2f76ef2
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 94 deletions.
10 changes: 5 additions & 5 deletions entries-api/filesystem-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
entry_test((t, entry) => {
const fs = entry.filesystem;

entry.getParent(t.step_func(parent => {
const pfs = parent.filesystem;
assert_not_equals(fs, pfs.filesystem, 'FileSystem objects do not have object identity');
assert_equals(fs.name, pfs.name, 'FileSystem names match');
getChildEntry(entry, 'file.txt', t.step_func(child => {
const cfs = child.filesystem;
assert_not_equals(fs, cfs.filesystem, 'FileSystem objects do not have object identity');
assert_equals(fs.name, cfs.name, 'FileSystem names match');

t.done();
}), t.unreached_func('getParent() should not fail'));
}), t.unreached_func('child entry file.txt should be present'));

}, 'FileSystem - name consistency and object identity');
</script>
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemDirectoryEntry manual test</title>
<title>Entries API: FileSystemDirectoryEntry attributes manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#api-directoryentry">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>
entry_test((t, entry) => {
// FileSystemEntry ----------

assert_idl_attribute(entry, 'isFile', 'FileSystemDirectoryEntry has isFile attribute');
assert_equals(typeof entry.isFile, 'boolean', 'isFile is boolean');

Expand All @@ -23,32 +21,17 @@
assert_equals(typeof entry.fullPath, 'string', 'fullPath is a string');

assert_idl_attribute(entry, 'filesystem', 'FileSystemDirectoryEntry has filesystem attribute');

assert_idl_attribute(entry, 'getParent', 'FileSystemDirectoryEntry has getParent');
assert_equals(typeof entry.getParent, 'function', 'getParent() is a method');

// FileSystemDirectoryEntry ----------

assert_idl_attribute(entry, 'getFile', 'FileSystemDirectoryEntry has getFile');
assert_equals(typeof entry.getFile, 'function',
'getFile() is a method');

assert_idl_attribute(entry, 'getDirectory', 'FileSystemDirectoryEntry has getDirectory');
assert_equals(typeof entry.getDirectory, 'function',
'getDirectory() is a method');

assert_idl_attribute(entry, 'createReader', 'FileSystemDirectoryEntry has createReader');
assert_equals(typeof entry.createReader, 'function',
'createReader() is a method');
assert_equals(typeof entry.filesystem, 'object', 'filesystem is an object');

t.done();
}, 'FileSystemDirectoryEntry - interface');
}, 'FileSystemDirectoryEntry - attribute types');

entry_test((t, entry) => {
assert_false(entry.isFile, 'isFile is false');
assert_true(entry.isDirectory, 'isDirectory is true');
assert_equals(entry.name, 'upload', 'expected directory was uploaded');
assert_equals(entry.fullPath, '/upload', 'directory is child of root directory');
t.done();
}, 'FileSystemDirectoryEntry - attributes');
}, 'FileSystemDirectoryEntry - attribute values');

</script>
23 changes: 23 additions & 0 deletions entries-api/filesystemdirectoryentry-createReader-manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemDirectoryEntry createReader() manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#api-directoryentry">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>
entry_test((t, entry) => {

assert_idl_attribute(entry, 'createReader', 'FileSystemDirectoryEntry has createReader');
assert_equals(typeof entry.createReader, 'function', 'createReader() is a method');

t.done();
}, 'FileSystemDirectoryEntry - createReader()');

entry_test((t, entry) => {
assert_not_equals(entry.createReader(), entry.createReader(),
'createReader() returns a new object each time');
t.done();
}, 'FileSystemDirectoryEntry - createReader() distinct objects');
</script>
7 changes: 7 additions & 0 deletions entries-api/filesystemdirectoryentry-getDirectory-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<script src="support.js"></script>

<script>
entry_test((t, entry) => {
assert_idl_attribute(entry, 'getDirectory', 'FileSystemDirectoryEntry has getDirectory');
assert_equals(typeof entry.getDirectory, 'function', 'getDirectory() is a method');

t.done();
}, 'FileSystemDirectoryEntry - getDirectory()');

INVALID_PATHS.forEach(path => {
entry_test((t, entry) => {
entry.getDirectory(
Expand Down
7 changes: 7 additions & 0 deletions entries-api/filesystemdirectoryentry-getFile-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<script src="support.js"></script>

<script>
entry_test((t, entry) => {
assert_idl_attribute(entry, 'getFile', 'FileSystemDirectoryEntry has getFile');
assert_equals(typeof entry.getFile, 'function', 'getFile() is a method');

t.done();
}, 'FileSystemDirectoryEntry - getFile()');

INVALID_PATHS.forEach(path => {
entry_test((t, entry) => {
entry.getFile(
Expand Down
17 changes: 17 additions & 0 deletions entries-api/filesystemdirectoryentry-getParent-manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemDirectoryEntry getParent() manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#api-directoryentry">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>
entry_test((t, entry) => {

assert_idl_attribute(entry, 'getParent', 'FileSystemDirectoryEntry has getParent');
assert_equals(typeof entry.getParent, 'function', 'getParent() is a method');

t.done();
}, 'FileSystemDirectoryEntry - getParent()');
</script>
4 changes: 2 additions & 2 deletions entries-api/filesystemdirectoryreader-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


entry_test((t, entry) => {
entry.getDirectory('subdir', {}, t.step_func(dir => {
getChildEntry(entry, 'subdir', t.step_func(dir => {
const reader = dir.createReader();
assert_equals(typeof reader.readEntries, 'function');

Expand All @@ -39,7 +39,7 @@
})));

do_chunk();
}), t.unreached_func('getDirectory should not fail'));
}), t.unreached_func('A child entry should be found'));
}, 'FileSystemDirectoryReader - basic enumeration');

entry_test((t, entry) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemEntry manual test</title>
<title>Entries API: FileSystemEntry attributes manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#api-entry">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand All @@ -21,25 +21,9 @@
assert_equals(typeof entry.fullPath, 'string', 'fullPath is a string');

assert_idl_attribute(entry, 'filesystem', 'FileSystemEntry has filesystem attribute');

assert_idl_attribute(entry, 'getParent', 'FileSystemEntry has filesystem attribute');
assert_equals(typeof entry.getParent, 'function', 'FileSystemEntry has a getParent() method');
assert_equals(typeof entry.filesystem, 'object', 'filesystem is an object');

t.done();
}, 'FileSystemEntry - interface');

entry_test((t, entry) => {
assert_equals(entry.getParent(), void 0, 'getParent() arguments are optional');

entry.getParent(t.step_func(parent => {
assert_true(parent.isDirectory, 'parent should be a directory');

assert_equals(parent.fullPath, '/', 'parent should be root');
assert_equals(parent.name, '', 'root name is empty string');

t.done();
}), t.unreached_func('getParent() should not fail'));
}, 'FileSystemEntry - getParent()');
}, 'FileSystemEntry - attribute types');

// TODO: Manual test for getParent() where containing directory is removed before getParent() is called.
</script>
27 changes: 27 additions & 0 deletions entries-api/filesystementry-getParent-manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemEntry getParent() manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#dom-filesystementry-getparentapi-entry">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>
entry_test((t, entry) => {
assert_idl_attribute(entry, 'getParent', 'FileSystemEntry has getParent method');
assert_equals(typeof entry.getParent, 'function', 'FileSystemEntry has a getParent() method');

assert_equals(entry.getParent(), void 0, 'getParent() arguments are optional');

entry.getParent(t.step_func(parent => {
assert_true(parent.isDirectory, 'parent should be a directory');

assert_equals(parent.fullPath, '/', 'parent should be root');
assert_equals(parent.name, '', 'root name is empty string');

t.done();
}), t.unreached_func('getParent() should not fail'));
}, 'FileSystemEntry - getParent()');

// TODO: Manual test for getParent() where containing directory is removed before getParent() is called.
</script>
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemFileEntry manual test</title>
<title>Entries API: FileSystemFileEntry attributes manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#api-entry">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>
file_entry_test('file.txt', (t, entry) => {
// FileSystemEntry ----------

assert_idl_attribute(entry, 'isFile', 'FileSystemEntry has isFile attribute');
assert_equals(typeof entry.isFile, 'boolean', 'isFile is boolean');
Expand All @@ -24,33 +23,15 @@

assert_idl_attribute(entry, 'filesystem', 'FileSystemEntry has filesystem attribute');

assert_idl_attribute(entry, 'getParent', 'FileSystemEntry has filesystem attribute');
assert_equals(typeof entry.getParent, 'function', 'FileSystemEntry has a getParent() method');

// FileSystemFileEntry ----------

assert_equals(typeof entry.file, 'function', 'FileSystemFileEntry has a file() method');
t.done();
}, 'FileSystemFileEntry - interface');
}, 'FileSystemFileEntry - attribute types');

file_entry_test('file.txt', (t, entry) => {
assert_true(entry.isFile);
assert_false(entry.isDirectory);
assert_equals(entry.name, 'file.txt');
assert_equals(entry.fullPath, '/upload/file.txt');
t.done();
}, 'FileSystemFileEntry - attributes');

file_entry_test('file.txt', (t, entry) => {
assert_throws(TypeError(), () => entry.file(), 'file() has a required argument');
entry.file(t.step_func(file => {

assert_class_string(file, 'File', 'file() should yield a File');
assert_equals(entry.name, file.name, 'entry and file names should match');
t.done();

}), t.unreached_func('file() should not fail'));
}, 'FileSystemFileEntry - file()');
}, 'FileSystemFileEntry - attribute values');

// TODO: Manual test where file is replaced with directory before file() called
</script>
26 changes: 26 additions & 0 deletions entries-api/filesystemfileentry-file-manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemFileEntry file() manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#api-entry">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>

file_entry_test('file.txt', (t, entry) => {
assert_idl_attribute(entry, 'file', 'FileSystemFileEntry has a file() method');
assert_equals(typeof entry.file, 'function', 'FileSystemFileEntry has a file() method');

assert_throws(TypeError(), () => entry.file(), 'file() has a required argument');
entry.file(t.step_func(file => {

assert_class_string(file, 'File', 'file() should yield a File');
assert_equals(entry.name, file.name, 'entry and file names should match');
t.done();

}), t.unreached_func('file() should not fail'));
}, 'FileSystemFileEntry - file()');

// TODO: Manual test where file is replaced with directory before file() called
</script>
17 changes: 17 additions & 0 deletions entries-api/filesystemfileentry-getParent-manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemFileEntry getParent() manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#api-entry">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>

file_entry_test('file.txt', (t, entry) => {
assert_idl_attribute(entry, 'getParent', 'FileSystemFileEntry has a getParent method');
assert_equals(typeof entry.getParent, 'function', 'FileSystemFileEntry has a getParent() method');
t.done();
}, 'FileSystemFileEntry - getParent() method');

</script>
22 changes: 5 additions & 17 deletions entries-api/interfaces-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,16 @@
<script>
'use strict';

function getFileAsPromise(dirEntry, path) {
return new Promise((resolve, reject) => {
dirEntry.getFile(path, {}, resolve, reject);
});
}

function getDirectoryAsPromise(dirEntry, path) {
return new Promise((resolve, reject) => {
dirEntry.getDirectory(path, {}, resolve, reject);
});
}

entry_test((t, entry, item) => {
assert_true(entry.isDirectory);
Promise.all([
getFileAsPromise(entry, FILE_PATHS[0]),
getDirectoryAsPromise(entry, DIR_PATHS[0]),
getEntriesAsPromise(entry),
fetch('interfaces.idl').then(r => r.text())
]).then(t.step_func(([fileEntry, dirEntry, idls]) => {
]).then(t.step_func(([entries, idls]) => {
window.samples = {
item: item,
dirEntry: dirEntry,
fileEntry: fileEntry,
dirEntry: entries.filter(entry => entry.isDirectory)[0],
fileEntry: entries.filter(entry => entry.isFile)[0],
fileSystem: entry.filesystem,
};

Expand Down
2 changes: 1 addition & 1 deletion entries-api/interfaces.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.then(r => r.text())
.then(idls => {

var idl_array = new IdlArray();
const idl_array = new IdlArray();

// https://w3c.github.io/FileAPI/#dfn-file
idl_array.add_untested_idls('[Exposed=(Window,Worker)] interface File {};');
Expand Down
Loading

0 comments on commit 2f76ef2

Please sign in to comment.