| 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 "core/clipboard/DataObject.h" | 5 #include "core/clipboard/DataObject.h" |
| 6 | 6 |
| 7 #include "core/clipboard/DataObjectItem.h" | 7 #include "core/clipboard/DataObjectItem.h" |
| 8 #include "platform/testing/UnitTestHelpers.h" | 8 #include "platform/testing/UnitTestHelpers.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class DataObjectTest : public ::testing::Test { | 13 class DataObjectTest : public ::testing::Test { |
| 14 public: | 14 public: |
| 15 DataObjectTest() : m_dataObject(DataObject::create()) {} | 15 DataObjectTest() : m_dataObject(DataObject::create()) {} |
| 16 | 16 |
| 17 protected: | 17 protected: |
| 18 Persistent<DataObject> m_dataObject; | 18 Persistent<DataObject> m_dataObject; |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 TEST_F(DataObjectTest, addItemWithFilenameAndNoTitle) { | 21 TEST_F(DataObjectTest, addItemWithFilenameAndNoTitle) { |
| 22 String filePath = testing::blinkRootDir(); | 22 String filePath = testing::blinkRootDir(); |
| 23 filePath.append("/Source/core/clipboard/DataObjectTest.cpp"); | 23 filePath.append("/Source/core/clipboard/DataObjectTest.cpp"); |
| 24 | 24 |
| 25 m_dataObject->addFilename(filePath, String()); | 25 m_dataObject->addFilename(filePath, String(), String()); |
| 26 EXPECT_EQ(1U, m_dataObject->length()); | 26 EXPECT_EQ(1U, m_dataObject->length()); |
| 27 | 27 |
| 28 DataObjectItem* item = m_dataObject->item(0); | 28 DataObjectItem* item = m_dataObject->item(0); |
| 29 EXPECT_EQ(DataObjectItem::FileKind, item->kind()); | 29 EXPECT_EQ(DataObjectItem::FileKind, item->kind()); |
| 30 | 30 |
| 31 Blob* blob = item->getAsFile(); | 31 Blob* blob = item->getAsFile(); |
| 32 ASSERT_TRUE(blob->isFile()); | 32 ASSERT_TRUE(blob->isFile()); |
| 33 File* file = toFile(blob); | 33 File* file = toFile(blob); |
| 34 EXPECT_TRUE(file->hasBackingFile()); | 34 EXPECT_TRUE(file->hasBackingFile()); |
| 35 EXPECT_EQ(File::IsUserVisible, file->getUserVisibility()); | 35 EXPECT_EQ(File::IsUserVisible, file->getUserVisibility()); |
| 36 EXPECT_EQ(filePath, file->path()); | 36 EXPECT_EQ(filePath, file->path()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 TEST_F(DataObjectTest, addItemWithFilenameAndTitle) { | 39 TEST_F(DataObjectTest, addItemWithFilenameAndTitle) { |
| 40 String filePath = testing::blinkRootDir(); | 40 String filePath = testing::blinkRootDir(); |
| 41 filePath.append("/Source/core/clipboard/DataObjectTest.cpp"); | 41 filePath.append("/Source/core/clipboard/DataObjectTest.cpp"); |
| 42 | 42 |
| 43 m_dataObject->addFilename(filePath, "name.cpp"); | 43 m_dataObject->addFilename(filePath, "name.cpp", String()); |
| 44 EXPECT_EQ(1U, m_dataObject->length()); | 44 EXPECT_EQ(1U, m_dataObject->length()); |
| 45 | 45 |
| 46 DataObjectItem* item = m_dataObject->item(0); | 46 DataObjectItem* item = m_dataObject->item(0); |
| 47 EXPECT_EQ(DataObjectItem::FileKind, item->kind()); | 47 EXPECT_EQ(DataObjectItem::FileKind, item->kind()); |
| 48 | 48 |
| 49 Blob* blob = item->getAsFile(); | 49 Blob* blob = item->getAsFile(); |
| 50 ASSERT_TRUE(blob->isFile()); | 50 ASSERT_TRUE(blob->isFile()); |
| 51 File* file = toFile(blob); | 51 File* file = toFile(blob); |
| 52 EXPECT_TRUE(file->hasBackingFile()); | 52 EXPECT_TRUE(file->hasBackingFile()); |
| 53 EXPECT_EQ(File::IsUserVisible, file->getUserVisibility()); | 53 EXPECT_EQ(File::IsUserVisible, file->getUserVisibility()); |
| 54 EXPECT_EQ(filePath, file->path()); | 54 EXPECT_EQ(filePath, file->path()); |
| 55 EXPECT_EQ("name.cpp", file->name()); | 55 EXPECT_EQ("name.cpp", file->name()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 TEST_F(DataObjectTest, fileSystemId) { |
| 59 String filePath = testing::blinkRootDir(); |
| 60 filePath.append("/Source/core/clipboard/DataObjectTest.cpp"); |
| 61 KURL url; |
| 62 |
| 63 m_dataObject->addFilename(filePath, String(), String()); |
| 64 m_dataObject->addFilename(filePath, String(), "fileSystemIdForFilename"); |
| 65 m_dataObject->add( |
| 66 File::createForFileSystemFile(url, FileMetadata(), File::IsUserVisible), |
| 67 "fileSystemIdForFileSystemFile"); |
| 68 |
| 69 ASSERT_EQ(3U, m_dataObject->length()); |
| 70 |
| 71 { |
| 72 DataObjectItem* item = m_dataObject->item(0); |
| 73 EXPECT_FALSE(item->hasFileSystemId()); |
| 74 } |
| 75 |
| 76 { |
| 77 DataObjectItem* item = m_dataObject->item(1); |
| 78 EXPECT_TRUE(item->hasFileSystemId()); |
| 79 EXPECT_EQ("fileSystemIdForFilename", item->fileSystemId()); |
| 80 } |
| 81 |
| 82 { |
| 83 DataObjectItem* item = m_dataObject->item(2); |
| 84 EXPECT_TRUE(item->hasFileSystemId()); |
| 85 EXPECT_EQ("fileSystemIdForFileSystemFile", item->fileSystemId()); |
| 86 } |
| 87 } |
| 88 |
| 58 } // namespace blink | 89 } // namespace blink |
| OLD | NEW |