Commit e02de703 authored by jianli@chromium.org's avatar jianli@chromium.org

File.type support.

https://bugs.webkit.org/show_bug.cgi?id=35361

Reviewed by Dmitry Titov.

WebCore:

Test: LayoutTests/editing/pasteboard/file-input-files-access.html

* html/File.cpp:
(WebCore::File::File):
* html/File.h:
(WebCore::File::type):
* html/File.idl:

LayoutTests:

Update the layout test to test File.type.

* editing/pasteboard/file-input-files-access-expected.txt:
* editing/pasteboard/script-tests/file-input-files-access.js:
(fileListShouldBe):
(runTest):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55257 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 43b309bf
2010-02-25 Jian Li <jianli@chromium.org>
Reviewed by Dmitry Titov.
File.type support.
https://bugs.webkit.org/show_bug.cgi?id=35361
Update the layout test to test File.type.
* editing/pasteboard/file-input-files-access-expected.txt:
* editing/pasteboard/script-tests/file-input-files-access.js:
(fileListShouldBe):
(runTest):
2010-02-25 Oliver Hunt <oliver@apple.com>
Reviewed by Maciej Stachowiak.
......
......@@ -10,6 +10,7 @@ Dragging a single (non-existant) file to a file input control:
PASS fileInput.value is "DRTFakeFile"
PASS fileInput.files.length is 1
PASS fileInput.files[0].name is "DRTFakeFile"
PASS fileInput.files[0].type is ""
PASS fileInput.files[0].size is 0
PASS fileInput.files[0].fileName is "DRTFakeFile"
PASS fileInput.files[0].fileSize is 0
......@@ -17,6 +18,7 @@ Dragging a real file to a file input control:
PASS fileInput.value is "apple.gif"
PASS fileInput.files.length is 1
PASS fileInput.files[0].name is "apple.gif"
PASS fileInput.files[0].type is "image/gif"
PASS fileInput.files[0].size is 1476
PASS fileInput.files[0].fileName is "apple.gif"
PASS fileInput.files[0].fileSize is 1476
......@@ -38,10 +40,12 @@ Dragging two files to a multi-file input control:
PASS fileInput.value is "apple.gif"
PASS fileInput.files.length is 2
PASS fileInput.files[0].name is "apple.gif"
PASS fileInput.files[0].type is "image/gif"
PASS fileInput.files[0].size is 1476
PASS fileInput.files[0].fileName is "apple.gif"
PASS fileInput.files[0].fileSize is 1476
PASS fileInput.files[1].name is "mozilla.gif"
PASS fileInput.files[1].type is "image/gif"
PASS fileInput.files[1].size is 2593
PASS fileInput.files[1].fileName is "mozilla.gif"
PASS fileInput.files[1].fileSize is 2593
......
......@@ -27,6 +27,7 @@ function fileListShouldBe(fileListString, filesArray)
for (var x = 0; x < filesArray.length; x++) {
var fileValueString = fileListString + "[" + x + "]";
shouldBeEqualToString(fileValueString + ".name", filesArray[x]['name']);
shouldBeEqualToString(fileValueString + ".type", filesArray[x]['type']);
shouldBe(fileValueString + ".size", "" + filesArray[x]['size']);
// FIXME: to be removed after legacy attributes are removed.
......@@ -80,12 +81,12 @@ function runTest()
debug("Dragging a single (non-existant) file to a file input control:");
testDraggingFiles([
{ 'path': 'DRTFakeFile', 'name' : 'DRTFakeFile', 'size' : 0 }
{ 'path': 'DRTFakeFile', 'name' : 'DRTFakeFile', 'size' : 0, 'type' : '' }
]);
debug("Dragging a real file to a file input control:");
testDraggingFiles([
{ 'path': 'resources/apple.gif', 'name' : 'apple.gif', 'size' : 1476 }
{ 'path': 'resources/apple.gif', 'name' : 'apple.gif', 'size' : 1476, 'type' : 'image/gif' }
]);
// Directory dragging behavior is covered by
......@@ -105,8 +106,8 @@ function runTest()
debug("Dragging two files to a multi-file input control:");
testDraggingFiles([
{ 'path': 'resources/apple.gif', 'name' : 'apple.gif', 'size' : 1476 },
{ 'path': 'resources/mozilla.gif', 'name' : 'mozilla.gif', 'size' : 2593 }
{ 'path': 'resources/apple.gif', 'name' : 'apple.gif', 'size' : 1476, 'type' : 'image/gif' },
{ 'path': 'resources/mozilla.gif', 'name' : 'mozilla.gif', 'size' : 2593, 'type' : 'image/gif' }
]);
testOrderedDraggingWithDirectory();
......
2010-02-25 Jian Li <jianli@chromium.org>
Reviewed by Dmitry Titov.
File.type support.
https://bugs.webkit.org/show_bug.cgi?id=35361
Test: LayoutTests/editing/pasteboard/file-input-files-access.html
* html/File.cpp:
(WebCore::File::File):
* html/File.h:
(WebCore::File::type):
* html/File.idl:
2010-02-25 Alexander Pavlov <apavlov@chromium.org>
Reviewed by Pavel Feldman.
......
......@@ -27,6 +27,7 @@
#include "File.h"
#include "FileSystem.h"
#include "MIMETypeRegistry.h"
namespace WebCore {
......@@ -34,6 +35,10 @@ File::File(const String& path)
: Blob(path)
, m_name(pathGetFileName(path))
{
// We don't use MIMETypeRegistry::getMIMETypeForPath() because it returns "application/octet-stream" upon failure.
int index = m_name.reverseFind('.');
if (index != -1)
m_type = MIMETypeRegistry::getMIMETypeForExtension(m_name.substring(index + 1));
}
} // namespace WebCore
......@@ -40,6 +40,7 @@ public:
}
const String& name() const { return m_name; }
const String& type() const { return m_type; }
// FIXME: obsolete attributes. To be removed.
const String& fileName() const { return m_name; }
......@@ -49,6 +50,7 @@ private:
File(const String& path);
String m_name;
String m_type;
};
} // namespace WebCore
......
......@@ -30,6 +30,7 @@ module html {
GenerateToJS
] File : Blob {
readonly attribute DOMString name;
readonly attribute DOMString type;
// FIXME: obsolete attributes. To be removed.
readonly attribute DOMString fileName;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment