[Native File System] getFile() returns a File sized correctly
The getFile() method on NativeFileSystemFileHandleImpl returned a File
that wasn't sized correctly. This caused issues when trying to use
methods on the File object that would use the bounds to do operations.
BUG=1011179
Change-Id: If900ac39be6b7bfc9d693680aa5d20b6b9c926d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1845998
Commit-Queue: Olivier Yiptong <oyiptong@chromium.org>
Reviewed-by: Marijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703764}
diff --git a/content/browser/native_file_system/native_file_system_file_handle_impl.cc b/content/browser/native_file_system/native_file_system_file_handle_impl.cc
index f4e0c98..6473a30 100644
--- a/content/browser/native_file_system/native_file_system_file_handle_impl.cc
+++ b/content/browser/native_file_system/native_file_system_file_handle_impl.cc
@@ -109,11 +109,16 @@
std::string uuid = base::GenerateGUID();
auto blob_builder = std::make_unique<storage::BlobDataBuilder>(uuid);
- // Use AppendFileSystemFile here, since we're streaming the file directly
- // from the file system backend, and the file thus might not actually be
- // backed by a file on disk.
- blob_builder->AppendFileSystemFile(url().ToGURL(), 0, -1, info.last_modified,
- file_system_context());
+
+ // Only append if the file has data.
+ if (info.size > 0) {
+ // Use AppendFileSystemFile here, since we're streaming the file directly
+ // from the file system backend, and the file thus might not actually be
+ // backed by a file on disk.
+ blob_builder->AppendFileSystemFile(url().ToGURL(), 0, info.size,
+ info.last_modified,
+ file_system_context());
+ }
base::FilePath::StringType extension = url().path().Extension();
if (!extension.empty()) {
diff --git a/third_party/blink/web_tests/TestExpectations b/third_party/blink/web_tests/TestExpectations
index 9ab2188..0368d96 100644
--- a/third_party/blink/web_tests/TestExpectations
+++ b/third_party/blink/web_tests/TestExpectations
@@ -6066,6 +6066,7 @@
crbug.com/998917 external/wpt/native-file-system/native_FileSystemDirectoryHandle-getEntries.tentative.https.manual.window.html [ Skip ]
crbug.com/998917 external/wpt/native-file-system/native_FileSystemDirectoryHandle-getFile.tentative.https.manual.window.html [ Skip ]
crbug.com/998917 external/wpt/native-file-system/native_FileSystemDirectoryHandle-removeEntry.tentative.https.manual.window.html [ Skip ]
+crbug.com/998917 external/wpt/native-file-system/native_FileSystemFileHandle-getFile.tentative.https.manual.window.html [ Skip ]
crbug.com/998917 external/wpt/native-file-system/native_FileSystemWriter.tentative.https.manual.window.html [ Skip ]
crbug.com/1000051 media/controls/volume-slider.html [ Failure Timeout Pass ]
diff --git a/third_party/blink/web_tests/external/wpt/native-file-system/native_FileSystemFileHandle-getFile.tentative.https.manual.window.js b/third_party/blink/web_tests/external/wpt/native-file-system/native_FileSystemFileHandle-getFile.tentative.https.manual.window.js
new file mode 100644
index 0000000..16c68c5
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/native-file-system/native_FileSystemFileHandle-getFile.tentative.https.manual.window.js
@@ -0,0 +1,4 @@
+// META: script=/resources/testdriver.js
+// META: script=resources/test-helpers.js
+// META: script=resources/native-fs-test-helpers.js
+// META: script=script-tests/FileSystemFileHandle-getFile.js
diff --git a/third_party/blink/web_tests/external/wpt/native-file-system/sandboxed_FileSystemFileHandle-getFile.tentative.https.any.js b/third_party/blink/web_tests/external/wpt/native-file-system/sandboxed_FileSystemFileHandle-getFile.tentative.https.any.js
new file mode 100644
index 0000000..fb93858
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/native-file-system/sandboxed_FileSystemFileHandle-getFile.tentative.https.any.js
@@ -0,0 +1,3 @@
+// META: script=resources/test-helpers.js
+// META: script=resources/sandboxed-fs-test-helpers.js
+// META: script=script-tests/FileSystemFileHandle-getFile.js
diff --git a/third_party/blink/web_tests/external/wpt/native-file-system/script-tests/FileSystemFileHandle-getFile.js b/third_party/blink/web_tests/external/wpt/native-file-system/script-tests/FileSystemFileHandle-getFile.js
new file mode 100644
index 0000000..88e5593
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/native-file-system/script-tests/FileSystemFileHandle-getFile.js
@@ -0,0 +1,8 @@
+directory_test(async (t, root) => {
+ const fileContents = 'awesome content';
+ let handle = await createFileWithContents(t, 'foo.txt', fileContents, /*parent=*/ root);
+ let file = await handle.getFile();
+ let slice = file.slice(1, file.size);
+ let actualContents = await slice.text();
+ assert_equals(actualContents, fileContents.slice(1, fileContents.length));
+}, 'getFile() provides a file that can be sliced');