OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "FileInputType.h" | 6 #include "FileInputType.h" |
7 | 7 |
8 #include "core/clipboard/DataObject.h" | 8 #include "core/clipboard/DataObject.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/fileapi/FileList.h" | 10 #include "core/fileapi/FileList.h" |
11 #include "core/html/HTMLInputElement.h" | 11 #include "core/html/HTMLInputElement.h" |
12 #include "core/page/DragData.h" | 12 #include "core/page/DragData.h" |
13 #include "wtf/DateMath.h" | |
14 | |
15 #include <gtest/gtest.h> | 13 #include <gtest/gtest.h> |
16 | 14 |
17 namespace blink { | 15 namespace blink { |
18 | 16 |
19 TEST(FileInputTypeTest, createFileList) | 17 TEST(FileInputTypeTest, createFileList) |
20 { | 18 { |
21 Vector<FileChooserFileInfo> files; | 19 Vector<FileChooserFileInfo> files; |
22 | 20 |
23 // Native file. | 21 // Natvie file. |
24 files.append(FileChooserFileInfo("/native/path/native-file", "display-name")
); | 22 files.append(FileChooserFileInfo( |
| 23 "/native/path/native-file", |
| 24 "display-name")); |
25 | 25 |
26 // Non-native file. | 26 // Non-native file. |
27 KURL url(ParsedURLStringTag(), "filesystem:http://example.com/isolated/hash/
non-native-file"); | 27 KURL url(ParsedURLStringTag(), "filesystem:http://example.com/isolated/hash/
non-native-file"); |
28 FileMetadata metadata; | 28 FileMetadata metadata; |
29 metadata.length = 64; | 29 metadata.length = 64; |
30 metadata.modificationTimeMS = 1.0 * msPerDay + 3; | 30 metadata.modificationTime = 24 * 60 * 60 /* sec */; |
31 files.append(FileChooserFileInfo(url, metadata)); | 31 files.append(FileChooserFileInfo(url, metadata)); |
32 | 32 |
33 | 33 |
34 FileList* list = FileInputType::createFileList(files, false); | 34 FileList* list = FileInputType::createFileList(files, false); |
35 ASSERT_TRUE(list); | 35 ASSERT_TRUE(list); |
36 ASSERT_EQ(2u, list->length()); | 36 ASSERT_EQ(2u, list->length()); |
37 | 37 |
38 EXPECT_EQ("/native/path/native-file", list->item(0)->path()); | 38 EXPECT_EQ("/native/path/native-file", list->item(0)->path()); |
39 EXPECT_EQ("display-name", list->item(0)->name()); | 39 EXPECT_EQ("display-name", list->item(0)->name()); |
40 EXPECT_TRUE(list->item(0)->fileSystemURL().isEmpty()); | 40 EXPECT_TRUE(list->item(0)->fileSystemURL().isEmpty()); |
41 | 41 |
42 EXPECT_TRUE(list->item(1)->path().isEmpty()); | 42 EXPECT_TRUE(list->item(1)->path().isEmpty()); |
43 EXPECT_EQ("non-native-file", list->item(1)->name()); | 43 EXPECT_EQ("non-native-file", list->item(1)->name()); |
44 EXPECT_EQ(url, list->item(1)->fileSystemURL()); | 44 EXPECT_EQ(url, list->item(1)->fileSystemURL()); |
45 EXPECT_EQ(64u, list->item(1)->size()); | 45 EXPECT_EQ(64u, list->item(1)->size()); |
46 EXPECT_EQ(1.0 * msPerDay + 3, list->item(1)->lastModified()); | 46 EXPECT_EQ(24 * 60 * 60 * 1000 /* ms */, list->item(1)->lastModified()); |
47 } | 47 } |
48 | 48 |
49 TEST(FileInputTypeTest, ignoreDroppedNonNativeFiles) | 49 TEST(FileInputTypeTest, ignoreDroppedNonNativeFiles) |
50 { | 50 { |
51 const RefPtrWillBeRawPtr<Document> document = Document::create(); | 51 const RefPtrWillBeRawPtr<Document> document = Document::create(); |
52 const RefPtrWillBeRawPtr<HTMLInputElement> input = | 52 const RefPtrWillBeRawPtr<HTMLInputElement> input = |
53 HTMLInputElement::create(*document, nullptr, false); | 53 HTMLInputElement::create(*document, nullptr, false); |
54 const RefPtrWillBeRawPtr<InputType> fileInput = FileInputType::create(*input
); | 54 const RefPtrWillBeRawPtr<InputType> fileInput = FileInputType::create(*input
); |
55 | 55 |
56 const RefPtrWillBeRawPtr<DataObject> nativeFileRawDragData = DataObject::cre
ate(); | 56 const RefPtrWillBeRawPtr<DataObject> nativeFileRawDragData = DataObject::cre
ate(); |
(...skipping 13 matching lines...) Expand all Loading... |
70 nonNativeFileDragData.platformData()->add(File::createForFileSystemFile(url,
metadata, File::IsUserVisible)); | 70 nonNativeFileDragData.platformData()->add(File::createForFileSystemFile(url,
metadata, File::IsUserVisible)); |
71 nonNativeFileDragData.platformData()->setFilesystemId("fileSystemId"); | 71 nonNativeFileDragData.platformData()->setFilesystemId("fileSystemId"); |
72 fileInput->receiveDroppedFiles(&nonNativeFileDragData); | 72 fileInput->receiveDroppedFiles(&nonNativeFileDragData); |
73 // Dropping non-native files should not change the existing files. | 73 // Dropping non-native files should not change the existing files. |
74 EXPECT_EQ("fileSystemId", fileInput->droppedFileSystemId()); | 74 EXPECT_EQ("fileSystemId", fileInput->droppedFileSystemId()); |
75 ASSERT_EQ(1u, fileInput->files()->length()); | 75 ASSERT_EQ(1u, fileInput->files()->length()); |
76 EXPECT_EQ(String("/native/path"), fileInput->files()->item(0)->path()); | 76 EXPECT_EQ(String("/native/path"), fileInput->files()->item(0)->path()); |
77 } | 77 } |
78 | 78 |
79 } // namespace blink | 79 } // namespace blink |
OLD | NEW |