blob: f472f0d1791067ce950d572ca164f103f0b38a31 [file] [log] [blame]
<!DOCTYPE html>
<head>
<title>Test webkitRelativePath IDL attribute</title>
</head>
<body>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/choosers/file_chooser.mojom.js"></script>
<script src="../resources/mock-file-chooser.js"></script>
<script src="../resources/common.js"></script>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<input type="file" webkitdirectory>
<script>
// This is an automated-version of external/wpt/entries-api/file-webkitRelativePath-manual.html
const t = async_test('webkitRelativePath is relative from the parent of the chosen directory');
t.step(() => {
assert_own_property(window, 'eventSender');
const file = document.querySelector('input');
file.addEventListener('change', t.step_func_done(() => {
const files = Array.from(file.files).sort((a, b) => a.name < b.name ? -1 : b.name < a.name ? 1 : 0);
assert_equals(files.length, 3);
assert_equals(files[0].webkitRelativePath, 'a/b/c/d/1.txt');
assert_equals(files[1].webkitRelativePath, 'a/b/c/d/2.txt');
assert_equals(files[2].webkitRelativePath, 'a/b/c/3.txt');
// mockFileChooserFactory doesn't support concurrent multiple sessions.
setTimeout(runTest2Later, 0);
}));
const chosenDir = '/tmp/web_tests/external/wpt/entries-api/support/a';
mockFileChooserFactory.setPathsToBeChosen([chosenDir + '/b/c/d/1.txt',
chosenDir + '/b/c/d/2.txt',
chosenDir + '/b/c/3.txt'], chosenDir)
clickElement(file);
});
const t2 = async_test('webkitRelativePath is relative from the selected root directory');
function runTest2Later() {
t2.step(() => {
assert_own_property(window, 'eventSender');
const file = document.querySelector('input');
file.addEventListener('change', t2.step_func_done(() => {
const files = Array.from(file.files).sort((a, b) => a.name < b.name ? -1 : b.name < a.name ? 1 : 0);
assert_equals(files.length, 2);
assert_equals(files[0].webkitRelativePath, '/Users/tkent/1.txt');
assert_equals(files[1].webkitRelativePath, '/Users/tkent/tmp/2.txt');
}));
mockFileChooserFactory.setPathsToBeChosen(['/Users/tkent/1.txt',
'/Users/tkent/tmp/2.txt'], '/')
clickElement(file);
});
}
</script>
</body>