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 3// found in the LICENSE file. 4 5#include "config.h" 6#include "core/clipboard/DataObject.h" 7 8#include "core/clipboard/DataObjectItem.h" 9#include "public/platform/Platform.h" 10#include "public/platform/WebUnitTestSupport.h" 11#include <gtest/gtest.h> 12 13namespace blink { 14 15class DataObjectTest : public ::testing::Test { 16public: 17 DataObjectTest() 18 : m_dataObject(DataObject::create()) 19 { 20 } 21 22protected: 23 RefPtrWillBePersistent<DataObject> m_dataObject; 24}; 25 26TEST_F(DataObjectTest, addItemWithFilenameAndNoTitle) 27{ 28 String filePath = Platform::current()->unitTestSupport()->webKitRootDir(); 29 filePath.append("/Source/core/clipboard/DataObjectTest.cpp"); 30 31 m_dataObject->addFilename(filePath, String()); 32 EXPECT_EQ(1U, m_dataObject->length()); 33 34 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->item(0); 35 EXPECT_EQ(DataObjectItem::FileKind, item->kind()); 36 37 RefPtrWillBeRawPtr<Blob> blob = item->getAsFile(); 38 ASSERT_TRUE(blob->isFile()); 39 RefPtrWillBeRawPtr<File> file = toFile(blob.get()); 40 EXPECT_TRUE(file->hasBackingFile()); 41 EXPECT_EQ(File::IsUserVisible, file->userVisibility()); 42 EXPECT_EQ(filePath, file->path()); 43} 44 45TEST_F(DataObjectTest, addItemWithFilenameAndTitle) 46{ 47 String filePath = Platform::current()->unitTestSupport()->webKitRootDir(); 48 filePath.append("/Source/core/clipboard/DataObjectTest.cpp"); 49 50 m_dataObject->addFilename(filePath, "name.cpp"); 51 EXPECT_EQ(1U, m_dataObject->length()); 52 53 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->item(0); 54 EXPECT_EQ(DataObjectItem::FileKind, item->kind()); 55 56 RefPtrWillBeRawPtr<Blob> blob = item->getAsFile(); 57 ASSERT_TRUE(blob->isFile()); 58 RefPtrWillBeRawPtr<File> file = toFile(blob.get()); 59 EXPECT_TRUE(file->hasBackingFile()); 60 EXPECT_EQ(File::IsUserVisible, file->userVisibility()); 61 EXPECT_EQ(filePath, file->path()); 62 EXPECT_EQ("name.cpp", file->name()); 63} 64 65} // namespace blink 66