File.lastModifiedDate must return null if the modified time info is not available
authorkinuko@chromium.org <kinuko@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 May 2012 13:57:32 +0000 (13:57 +0000)
committerkinuko@chromium.org <kinuko@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 May 2012 13:57:32 +0000 (13:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=87709

Reviewed by Kentaro Hara.

Source/WebCore:

Per File API spec, File.lastModifiedDate must return null if the
modified time info is not available.
http://dev.w3.org/2006/webapi/FileAPI/#dfn-lastModifiedDate

Test: http/tests/local/fileapi/file-last-modified-after-delete.html

* fileapi/File.cpp:
(WebCore::File::lastModifiedDateForBinding): Added.
(WebCore):
* fileapi/File.h:
(File):
* fileapi/File.idl: Added ImplementedAs=lastModifiedDateForBinding.

LayoutTests:

* http/tests/local/fileapi/file-last-modified-after-delete-expected.txt: Added.
* http/tests/local/fileapi/file-last-modified-after-delete.html: Added.
* http/tests/local/fileapi/resources/temp-file-utils.js: Added.
* http/tests/local/fileapi/script-tests/file-last-modified-after-delete.js: Added.
* http/tests/local/fileapi/script-tests/send-sliced-dragged-file.js: Factored out common temp-file related functions into temp-file-utils.js.
* http/tests/local/fileapi/send-sliced-dragged-file.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@118920 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/local/fileapi/file-last-modified-after-delete-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/local/fileapi/file-last-modified-after-delete.html [new file with mode: 0644]
LayoutTests/http/tests/local/fileapi/resources/temp-file-utils.js [new file with mode: 0644]
LayoutTests/http/tests/local/fileapi/script-tests/file-last-modified-after-delete.js [new file with mode: 0644]
LayoutTests/http/tests/local/fileapi/script-tests/send-sliced-dragged-file.js
LayoutTests/http/tests/local/fileapi/send-sliced-dragged-file.html
Source/WebCore/ChangeLog
Source/WebCore/fileapi/File.cpp
Source/WebCore/fileapi/File.h
Source/WebCore/fileapi/File.idl

index 894677d..d31301b 100644 (file)
@@ -1,3 +1,17 @@
+2012-05-30  Kinuko Yasuda  <kinuko@chromium.org>
+
+        File.lastModifiedDate must return null if the modified time info is not available
+        https://bugs.webkit.org/show_bug.cgi?id=87709
+
+        Reviewed by Kentaro Hara.
+
+        * http/tests/local/fileapi/file-last-modified-after-delete-expected.txt: Added.
+        * http/tests/local/fileapi/file-last-modified-after-delete.html: Added.
+        * http/tests/local/fileapi/resources/temp-file-utils.js: Added.
+        * http/tests/local/fileapi/script-tests/file-last-modified-after-delete.js: Added.
+        * http/tests/local/fileapi/script-tests/send-sliced-dragged-file.js: Factored out common temp-file related functions into temp-file-utils.js.
+        * http/tests/local/fileapi/send-sliced-dragged-file.html:
+
 2012-05-30  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
 
         [EFL][DRT] EFL's DRT needs "postProgressFinishedNotification" message
diff --git a/LayoutTests/http/tests/local/fileapi/file-last-modified-after-delete-expected.txt b/LayoutTests/http/tests/local/fileapi/file-last-modified-after-delete-expected.txt
new file mode 100644 (file)
index 0000000..5ceef9a
--- /dev/null
@@ -0,0 +1,11 @@
+Test File.lastModifiedDate returns null if the information is not available.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.dataTransfer contains a File object on drop.
+PASS lastModifiedDate is null
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/local/fileapi/file-last-modified-after-delete.html b/LayoutTests/http/tests/local/fileapi/file-last-modified-after-delete.html
new file mode 100644 (file)
index 0000000..ad2195d
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/setup-file-input-element-for-drag.js"></script>
+<script src="resources/temp-file-utils.js"></script>
+<script src="script-tests/file-last-modified-after-delete.js"></script>
+<script src="../../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/local/fileapi/resources/temp-file-utils.js b/LayoutTests/http/tests/local/fileapi/resources/temp-file-utils.js
new file mode 100644 (file)
index 0000000..b5ce2cf
--- /dev/null
@@ -0,0 +1,32 @@
+function createTempFile(fileName, fileData)
+{
+    var xhr = new XMLHttpRequest();
+    xhr.open("POST", "http://127.0.0.1:8000/resources/write-temp-file.php?filename=" + fileName + "&data=" + fileData, false);
+    xhr.send();
+    if (xhr.status != 200) {
+        testFailed("Unexpected response status received: " + xhr.status);
+        return;
+    }
+
+    var values = xhr.responseText.split('\n');
+    if (xhr.responseText.indexOf("FAIL") == 0) {
+        testFailed("Unexpected response text received: " + xhr.responseText);
+        return;
+    }
+
+    return xhr.responseText;
+}
+
+function touchTempFile(fileName)
+{
+    var xhr = new XMLHttpRequest();
+    xhr.open("POST", "http://127.0.0.1:8000/resources/touch-temp-file.php?filename=" + fileName, false);
+    xhr.send();
+}
+
+function removeTempFile(fileName)
+{
+    var xhr = new XMLHttpRequest();
+    xhr.open("POST", "http://127.0.0.1:8000/resources/reset-temp-file.php?filename=" + fileName, false);
+    xhr.send();
+}
diff --git a/LayoutTests/http/tests/local/fileapi/script-tests/file-last-modified-after-delete.js b/LayoutTests/http/tests/local/fileapi/script-tests/file-last-modified-after-delete.js
new file mode 100644 (file)
index 0000000..7c0794a
--- /dev/null
@@ -0,0 +1,37 @@
+description("Test File.lastModifiedDate returns null if the information is not available.");
+
+var tempFileContent = "1234567890";
+var tempFileName = "file-last-modified-after-delete.tmp";
+var lastModifiedDate;
+
+function onFileDrop(file)
+{
+    // Remove the temp file.
+    removeTempFile(tempFileName);
+
+    // This synchronosly queries the file's lastModifiedDate (which should fail) until/unless we start capturing the file metadata at File construction time.
+    lastModifiedDate = file.lastModifiedDate;
+    shouldBe('lastModifiedDate', 'null');
+}
+
+function runTest()
+{
+    var tempFilePath = createTempFile(tempFileName, tempFileContent);
+    if (tempFilePath.length == 0)
+        return;
+
+    setFileInputDropCallback(onFileDrop);
+    eventSender.beginDragWithFiles([tempFilePath]);
+    moveMouseToCenterOfElement(fileInput);
+    eventSender.mouseUp();
+}
+
+if (window.eventSender) {
+    runTest();
+    // Clean up after ourselves
+    removeFileInputElement();
+} else {
+    testFailed("This test is not interactive, please run using DumpRenderTree");
+}
+
+var successfullyParsed = true;
index d8e5b9b..1390d2d 100644 (file)
@@ -41,39 +41,6 @@ function uploadFile(file, filePath, start, length, expectedException)
         testFailed(message);
 }
 
-function createTempFile(fileData)
-{
-    var xhr = new XMLHttpRequest();
-    xhr.open("POST", "http://127.0.0.1:8000/resources/write-temp-file.php?filename=" + tempFileName + "&data=" + fileData, false);
-    xhr.send();
-    if (xhr.status != 200) {
-        testFailed("Unexpected response status received: " + xhr.status);
-        return;
-    }
-
-    var values = xhr.responseText.split('\n');
-    if (xhr.responseText.indexOf("FAIL") == 0) {
-        testFailed("Unexpected response text received: " + xhr.responseText);
-        return;
-    }
-
-    return xhr.responseText;
-}
-
-function touchTempFile()
-{
-    var xhr = new XMLHttpRequest();
-    xhr.open("POST", "http://127.0.0.1:8000/resources/touch-temp-file.php?filename=" + tempFileName, false);
-    xhr.send();
-}
-
-function removeTempFile()
-{
-    var xhr = new XMLHttpRequest();
-    xhr.open("POST", "http://127.0.0.1:8000/resources/reset-temp-file.php?filename=" + tempFileName, false);
-    xhr.send();
-}
-
 function computeExpectedLength(fileLength, start, length)
 {
     var expectedLength = length;
@@ -116,18 +83,18 @@ function onUnstableFileDrop(file, filePath, fileLength, start, length, contentTy
     uploadFile(subfile, filePath, start, length, false);
 
     // Touch the underlying temp file.
-    touchTempFile();
+    touchTempFile(tempFileName);
     
     // Upload the sliced file. We should receive an exception since the file has been changed.
     uploadFile(subfile, filePath, start, length, true);
 
     // Remove the temp file.
-    removeTempFile();
+    removeTempFile(tempFileName);
 }
 
 function dragAndSliceUnstableFile(start, length, contentType)
 {
-    var tempFilePath = createTempFile(tempFileContent);
+    var tempFilePath = createTempFile(tempFileName, tempFileContent);
     if (tempFilePath.length == 0)
         return;
 
index 1268db7..aee8378 100644 (file)
@@ -7,6 +7,7 @@
 <p id="description"></p>
 <div id="console"></div>
 <script src="resources/setup-file-input-element-for-drag.js"></script>
+<script src="resources/temp-file-utils.js"></script>
 <script src="script-tests/send-sliced-dragged-file.js"></script>
 <script src="../../../../fast/js/resources/js-test-post.js"></script>
 </body>
index 2bf19a1..0401ba9 100644 (file)
@@ -1,3 +1,23 @@
+2012-05-30  Kinuko Yasuda  <kinuko@chromium.org>
+
+        File.lastModifiedDate must return null if the modified time info is not available
+        https://bugs.webkit.org/show_bug.cgi?id=87709
+
+        Reviewed by Kentaro Hara.
+
+        Per File API spec, File.lastModifiedDate must return null if the
+        modified time info is not available.
+        http://dev.w3.org/2006/webapi/FileAPI/#dfn-lastModifiedDate
+
+        Test: http/tests/local/fileapi/file-last-modified-after-delete.html
+
+        * fileapi/File.cpp:
+        (WebCore::File::lastModifiedDateForBinding): Added.
+        (WebCore):
+        * fileapi/File.h:
+        (File):
+        * fileapi/File.idl: Added ImplementedAs=lastModifiedDateForBinding.
+
 2012-05-30  Jochen Eisinger  <jochen@chromium.org>
 
         Match Firefox restrictions to window.blur and window.focus
index 54aec51..86d5989 100644 (file)
@@ -142,6 +142,12 @@ double File::lastModifiedDate() const
     return modificationTime * 1000.0;
 }
 
+double File::lastModifiedDateForBinding() const
+{
+    double value = lastModifiedDate();
+    return (!value) ? std::numeric_limits<double>::quiet_NaN() : value;
+}
+
 unsigned long long File::size() const
 {
 #if ENABLE(FILE_SYSTEM)
index 8bc480d..67f31f6 100644 (file)
@@ -80,6 +80,9 @@ public:
     // This may return zero if getFileModificationTime() platform call has failed or zero snapshot lastModifiedTime is given at construction time.
     double lastModifiedDate() const;
 
+    // For binding. We want to return null Date if we get the value 0 Date (which is used to indicate the information is unavailable).
+    double lastModifiedDateForBinding() const;
+
 #if ENABLE(DIRECTORY_UPLOAD)
     // Returns the relative path of this file in the context of a directory selection.
     const String& webkitRelativePath() const { return m_relativePath; }
index e88b9bf..00bdde6 100644 (file)
@@ -32,8 +32,7 @@ module html {
     ] File : Blob {
         readonly attribute DOMString name;
 #if !defined(LANGUAGE_GOBJECT) || !LANGUAGE_GOBJECT
-        // FIXME: this should return null Date if the value is 0.
-        readonly attribute Date lastModifiedDate;
+        readonly attribute [ImplementedAs=lastModifiedDateForBinding] Date lastModifiedDate;
 #endif
 #if defined(ENABLE_DIRECTORY_UPLOAD) && ENABLE_DIRECTORY_UPLOAD
         readonly attribute DOMString webkitRelativePath;