Chromium Code Reviews| Index: Source/web/WebDragDataTest.cpp |
| diff --git a/Source/web/WebDragDataTest.cpp b/Source/web/WebDragDataTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dc2219a9889151dab7f82d3f1260d796b6a2cb56 |
| --- /dev/null |
| +++ b/Source/web/WebDragDataTest.cpp |
| @@ -0,0 +1,169 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
tkent
2014/07/30 23:56:01
We should not put a test not for Source/web/ to So
pwnall-personal
2014/07/31 01:31:26
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "public/platform/WebDragData.h" |
| + |
| +#include "core/clipboard/DataObject.h" |
| +#include "core/clipboard/DataObjectItem.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebBlobRegistry.h" |
| +#include "public/platform/WebFileUtilities.h" |
| +#include "public/platform/WebMimeRegistry.h" |
| +#include "public/platform/WebUnitTestSupport.h" |
| +#include <gtest/gtest.h> |
| + |
| +using namespace blink; |
| + |
| +namespace { |
|
tkent
2014/07/30 23:56:02
We should use |namespace blink| for a test for bli
pwnall-personal
2014/07/31 01:31:26
Done. Thank you for teaching me!
|
| + |
| +class MockMimeRegistry : public WebMimeRegistry { |
| +public: |
| + virtual SupportsType supportsMIMEType(const WebString& mimeType) OVERRIDE |
| + { |
| + return SupportsType::MayBeSupported; |
| + } |
| + |
| + virtual SupportsType supportsImageMIMEType(const WebString& mimeType) OVERRIDE |
| + { |
| + return SupportsType::MayBeSupported; |
| + } |
| + |
| + virtual SupportsType supportsJavaScriptMIMEType(const WebString& mimeType) OVERRIDE |
| + { |
| + return SupportsType::MayBeSupported; |
| + } |
| + |
| + virtual SupportsType supportsMediaMIMEType(const WebString& mimeType, const WebString& codecs, const WebString& keySystem) OVERRIDE |
| + { |
| + return SupportsType::MayBeSupported; |
| + } |
| + |
| + virtual bool supportsMediaSourceMIMEType(const WebString& mimeType, const WebString& codecs) OVERRIDE |
| + { |
| + return false; |
| + } |
| + |
| + virtual bool supportsEncryptedMediaMIMEType(const WebString& keySystem, const WebString& mimeType, const WebString& codecs) OVERRIDE |
| + { |
| + return false; |
| + } |
| + |
| + virtual SupportsType supportsNonImageMIMEType(const WebString& mimeType) OVERRIDE |
| + { |
| + return SupportsType::MayBeSupported; |
| + } |
| + |
| + virtual WebString mimeTypeForExtension(const WebString& fileExtension) OVERRIDE |
| + { |
| + return WebString(); |
| + } |
| + |
| + virtual WebString wellKnownMimeTypeForExtension(const WebString& fileExtension) OVERRIDE |
| + { |
| + return WebString(); |
| + } |
| + |
| + virtual WebString mimeTypeFromFile(const WebString& filePath) OVERRIDE |
| + { |
| + return WebString(); |
| + } |
| +}; |
| + |
| +class MockFileUtilities : public WebFileUtilities { |
| +public: |
| + ~MockFileUtilities() { } |
| +}; |
| + |
| +class RegistryMockPlatform : public Platform { |
| +public: |
| + RegistryMockPlatform(Platform* oldPlatform) |
| + : m_oldPlatform(oldPlatform) |
| + { |
| + } |
| + |
| + virtual ~RegistryMockPlatform() { } |
| + |
| + virtual WebBlobRegistry* blobRegistry() OVERRIDE |
| + { |
| + return &mockBlobRegistry; |
| + } |
| + |
| + virtual WebMimeRegistry* mimeRegistry() OVERRIDE |
| + { |
| + return &mockMimeRegistry; |
| + } |
| + |
| + virtual WebFileUtilities* fileUtilities() OVERRIDE |
| + { |
| + return &mockFileUtilities; |
| + } |
| + |
| + virtual WebUnitTestSupport* unitTestSupport() OVERRIDE |
| + { |
| + return m_oldPlatform->unitTestSupport(); |
| + } |
| + |
| + virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t length) OVERRIDE |
| + { |
| + m_oldPlatform->cryptographicallyRandomValues(buffer, length); |
| + } |
| + |
| +protected: |
| + WebBlobRegistry mockBlobRegistry; |
|
tkent
2014/07/30 23:56:01
mockBlobRegistry -> m_mockBlobRegistry
pwnall-personal
2014/07/31 01:31:26
Done! Thank you, and sorry!
|
| + MockMimeRegistry mockMimeRegistry; |
|
tkent
2014/07/30 23:56:02
mockMimeRegistry -> m_mockMimeRegistry
pwnall-personal
2014/07/31 01:31:26
Done.
|
| + MockFileUtilities mockFileUtilities; |
|
tkent
2014/07/30 23:56:01
mockFileUtilities -> m_mockFileUtilities
pwnall-personal
2014/07/31 01:31:26
Done.
|
| + Platform* m_oldPlatform; |
| +}; |
| + |
| +class WebDragDataTest : public testing::Test { |
| +public: |
| + WebDragDataTest() : m_dragData() { } |
|
tkent
2014/07/30 23:56:01
|m_dragData()| is unnecessary.
pwnall-personal
2014/07/31 01:31:26
Done.
|
| + |
| +protected: |
| + virtual void SetUp() |
| + { |
| + m_dragData = adoptPtr(new WebDragData()); |
| + m_dragData->initialize(); |
| + m_oldPlatform = Platform::current(); |
| + m_mockPlatform = adoptPtr(new RegistryMockPlatform(m_oldPlatform)); |
| + Platform::initialize(m_mockPlatform.get()); |
| + } |
| + virtual void TearDown() |
| + { |
| + // reset() invokes the File destructor, which uses WebBlobRegistry, so |
| + // reset() must be called before restoring the original Platform |
| + m_dragData->reset(); |
| + Platform::initialize(m_oldPlatform); |
| + } |
| + |
| + OwnPtrWillBeRawPtr<WebDragData> m_dragData; |
|
tkent
2014/07/30 23:56:01
OwnPtrWillBeRawPtr -> OwnPtr
pwnall-personal
2014/07/31 01:31:26
Done. Thank you!
|
| + OwnPtrWillBeRawPtr<RegistryMockPlatform> m_mockPlatform; |
|
tkent
2014/07/30 23:56:01
OwnPtrWillBeRawPtr -> OwnPtr
pwnall-personal
2014/07/31 01:31:26
Done.
|
| + Platform* m_oldPlatform; |
| +}; |
| + |
| +TEST_F(WebDragDataTest, addItemWithFilename) |
| +{ |
| + WTF::String filePath = Platform::current()->unitTestSupport()->webKitRootDir(); |
| + filePath.append("/Source/web/tests/data/dragdata/file.txt"); |
| + WebDragData::Item webDragDataItem; |
| + webDragDataItem.storageType = WebDragData::Item::StorageTypeFilename; |
| + webDragDataItem.filenameData = filePath; |
| + m_dragData->addItem(webDragDataItem); |
| + |
| + DataObject* dataObject = m_dragData->getValue(); |
| + EXPECT_EQ(1U, dataObject->length()); |
| + |
| + RefPtrWillBeRawPtr<DataObjectItem> item = dataObject->item(0); |
| + EXPECT_EQ(DataObjectItem::FileKind, item->kind()); |
| + |
| + RefPtrWillBeRawPtr<Blob> blob = item->getAsFile(); |
| + ASSERT_TRUE(blob->isFile()); |
| + RefPtrWillBeRawPtr<File> file = toFile(blob.get()); |
| + EXPECT_TRUE(file->hasBackingFile()); |
| + EXPECT_EQ(File::IsUserVisible, file->userVisibility()); |
| + EXPECT_EQ(filePath, file->path()); |
| +} |
| + |
| +} // namespace |