/api/uploaded-file should return createdAt as a POSIX timestamp
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Mar 2017 00:27:01 +0000 (00:27 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Mar 2017 00:27:01 +0000 (00:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169980

Rubber-stamped by Antti Koivisto.

Call Database::to_js_time on createdAt to return it as a POSIX timestamp.

* public/include/uploaded-file-helpers.php:
(format_uploaded_file): Fixed the bug.
* server-tests/api-manifest-tests.js: Renamed from api-manifest.js.
* server-tests/api-uploaded-file-tests.js: Renamed from api-uploaded-file.js. Added a test case.

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

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/public/include/uploaded-file-helpers.php
Websites/perf.webkit.org/server-tests/api-manifest-tests.js [moved from Websites/perf.webkit.org/server-tests/api-manifest.js with 100% similarity]
Websites/perf.webkit.org/server-tests/api-uploaded-file-tests.js [moved from Websites/perf.webkit.org/server-tests/api-uploaded-file.js with 94% similarity]

index 9959e94..5d36862 100644 (file)
@@ -1,5 +1,19 @@
 2017-03-22  Ryosuke Niwa  <rniwa@webkit.org>
 
+        /api/uploaded-file should return createdAt as a POSIX timestamp
+        https://bugs.webkit.org/show_bug.cgi?id=169980
+
+        Rubber-stamped by Antti Koivisto.
+
+        Call Database::to_js_time on createdAt to return it as a POSIX timestamp.
+
+        * public/include/uploaded-file-helpers.php:
+        (format_uploaded_file): Fixed the bug.
+        * server-tests/api-manifest-tests.js: Renamed from api-manifest.js.
+        * server-tests/api-uploaded-file-tests.js: Renamed from api-uploaded-file.js. Added a test case.
+
+2017-03-22  Ryosuke Niwa  <rniwa@webkit.org>
+
         UploadedFile should support a callback for upload progress
         https://bugs.webkit.org/show_bug.cgi?id=169977
 
index 51b6c57..24f4ca5 100644 (file)
@@ -5,7 +5,7 @@ function format_uploaded_file($file_row)
     return array(
         'id' => $file_row['file_id'],
         'size' => $file_row['file_size'],
-        'createdAt' => $file_row['file_created_at'],
+        'createdAt' => Database::to_js_time($file_row['file_created_at']),
         'mime' => $file_row['file_mime'],
         'filename' => $file_row['file_filename'],
         'author' => $file_row['file_author'],
@@ -51,6 +51,21 @@ describe('/api/uploaded-file', function () {
         });
     });
 
+    it('should return the file content with createdAt using POSIX timestamp in UTC', () => {
+        let uploadedFile;
+        const startTime = +Date.now();
+        return TemporaryFile.makeTemporaryFile('some.dat', 'some content').then((stream) => {
+            return PrivilegedAPI.sendRequest('upload-file', {newFile: stream}, {useFormData: true});
+        }).then((response) => {
+            uploadedFile = response['uploadedFile'];
+            console.assert(typeof(uploadedFile.createdAt) == 'number')
+            const createdAt = +new Date(uploadedFile.createdAt);
+            const endTime = +Date.now();
+            assert(startTime <= createdAt, 'createdAt should be after the time POST request was made');
+            assert(createdAt <= endTime, 'createdAt should be before the uploadedFile response had finished');
+        });
+    });
+
     it('should return "NotFound" when the specified SHA256 is invalid', () => {
         return TestServer.remoteAPI().getJSON('/api/uploaded-file/?sha256=abc').then((content) => {
             assert.equal(content['status'], 'NotFound');