Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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/WebBlobRegistry.h" | |
| 11 #include "public/platform/WebFileUtilities.h" | |
| 12 #include "public/platform/WebMimeRegistry.h" | |
| 13 #include "public/platform/WebUnitTestSupport.h" | |
| 14 #include <gtest/gtest.h> | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 class MockMimeRegistry : public WebMimeRegistry { | |
| 19 public: | |
| 20 virtual SupportsType supportsMIMEType(const WebString& mimeType) OVERRIDE | |
| 21 { | |
| 22 return SupportsType::MayBeSupported; | |
| 23 } | |
| 24 | |
| 25 virtual SupportsType supportsImageMIMEType(const WebString& mimeType) OVERRI DE | |
| 26 { | |
| 27 return SupportsType::MayBeSupported; | |
| 28 } | |
| 29 | |
| 30 virtual SupportsType supportsJavaScriptMIMEType(const WebString& mimeType) O VERRIDE | |
| 31 { | |
| 32 return SupportsType::MayBeSupported; | |
| 33 } | |
| 34 | |
| 35 virtual SupportsType supportsMediaMIMEType(const WebString& mimeType, const WebString& codecs, const WebString& keySystem) OVERRIDE | |
| 36 { | |
| 37 return SupportsType::MayBeSupported; | |
| 38 } | |
| 39 | |
| 40 virtual bool supportsMediaSourceMIMEType(const WebString& mimeType, const We bString& codecs) OVERRIDE | |
| 41 { | |
| 42 return false; | |
| 43 } | |
| 44 | |
| 45 virtual bool supportsEncryptedMediaMIMEType(const WebString& keySystem, cons t WebString& mimeType, const WebString& codecs) OVERRIDE | |
| 46 { | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 virtual SupportsType supportsNonImageMIMEType(const WebString& mimeType) OVE RRIDE | |
| 51 { | |
| 52 return SupportsType::MayBeSupported; | |
| 53 } | |
| 54 | |
| 55 virtual WebString mimeTypeForExtension(const WebString& fileExtension) OVERR IDE | |
| 56 { | |
| 57 return WebString(); | |
| 58 } | |
| 59 | |
| 60 virtual WebString wellKnownMimeTypeForExtension(const WebString& fileExtensi on) OVERRIDE | |
| 61 { | |
| 62 return WebString(); | |
| 63 } | |
| 64 | |
| 65 virtual WebString mimeTypeFromFile(const WebString& filePath) OVERRIDE | |
| 66 { | |
| 67 return WebString(); | |
| 68 } | |
| 69 }; | |
| 70 | |
| 71 class MockFileUtilities : public WebFileUtilities { | |
| 72 public: | |
| 73 ~MockFileUtilities() { } | |
| 74 }; | |
| 75 | |
| 76 class RegistryMockPlatform : public Platform { | |
| 77 public: | |
| 78 RegistryMockPlatform(Platform* oldPlatform) | |
| 79 : m_oldPlatform(oldPlatform) | |
| 80 { | |
| 81 } | |
| 82 | |
| 83 virtual ~RegistryMockPlatform() { } | |
| 84 | |
| 85 virtual WebBlobRegistry* blobRegistry() OVERRIDE | |
| 86 { | |
| 87 return &m_mockBlobRegistry; | |
| 88 } | |
| 89 | |
| 90 virtual WebMimeRegistry* mimeRegistry() OVERRIDE | |
| 91 { | |
| 92 return &m_mockMimeRegistry; | |
| 93 } | |
| 94 | |
| 95 virtual WebFileUtilities* fileUtilities() OVERRIDE | |
| 96 { | |
| 97 return &m_mockFileUtilities; | |
| 98 } | |
| 99 | |
| 100 virtual WebUnitTestSupport* unitTestSupport() OVERRIDE | |
| 101 { | |
| 102 return m_oldPlatform->unitTestSupport(); | |
| 103 } | |
| 104 | |
| 105 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t len gth) OVERRIDE | |
| 106 { | |
| 107 m_oldPlatform->cryptographicallyRandomValues(buffer, length); | |
| 108 } | |
| 109 | |
| 110 protected: | |
| 111 WebBlobRegistry m_mockBlobRegistry; | |
| 112 MockMimeRegistry m_mockMimeRegistry; | |
| 113 MockFileUtilities m_mockFileUtilities; | |
| 114 Platform* m_oldPlatform; | |
| 115 }; | |
| 116 | |
| 117 class DataObjectTest : public ::testing::Test { | |
| 118 public: | |
| 119 DataObjectTest() { } | |
| 120 | |
| 121 protected: | |
| 122 virtual void SetUp() | |
|
tkent
2014/07/31 01:41:15
add OVERRIDE
pwnall-personal
2014/07/31 02:04:33
Done. Thank you!
| |
| 123 { | |
| 124 m_oldPlatform = Platform::current(); | |
| 125 m_mockPlatform = adoptPtr(new RegistryMockPlatform(m_oldPlatform)); | |
| 126 Platform::initialize(m_mockPlatform.get()); | |
| 127 | |
| 128 m_dataObject = DataObject::create(); | |
| 129 } | |
| 130 virtual void TearDown() | |
|
tkent
2014/07/31 01:41:15
Ditto.
pwnall-personal
2014/07/31 02:04:33
Done.
| |
| 131 { | |
| 132 // clear() invokes the File destructor, which uses WebBlobRegistry, so | |
| 133 // clear() must be called before restoring the original Platform | |
| 134 m_dataObject.clear(); | |
| 135 Platform::initialize(m_oldPlatform); | |
| 136 } | |
| 137 | |
| 138 RefPtr<DataObject> m_dataObject; | |
|
tkent
2014/07/31 01:41:15
RefPtr -> RefPtrWillBePersistent
pwnall-personal
2014/07/31 02:04:33
Done. Thank you!
| |
| 139 OwnPtr<RegistryMockPlatform> m_mockPlatform; | |
| 140 Platform* m_oldPlatform; | |
| 141 }; | |
| 142 | |
| 143 TEST_F(DataObjectTest, addItemWithFilename) | |
| 144 { | |
| 145 WTF::String filePath = Platform::current()->unitTestSupport()->webKitRootDir (); | |
|
tkent
2014/07/31 01:41:14
WTF:: prefix is unnecessary.
pwnall-personal
2014/07/31 02:04:33
Done.
| |
| 146 filePath.append("/Source/web/tests/data/dragdata/file.txt"); | |
|
tkent
2014/07/31 01:41:15
Dependency to Source/web/ from Source/core is a la
pwnall-personal
2014/07/31 02:04:33
Done. Thank you!
| |
| 147 | |
| 148 m_dataObject->addFilename(filePath, WTF::String()); | |
|
tkent
2014/07/31 01:41:15
WTF:: prefix is unnecessary.
pwnall-personal
2014/07/31 02:04:33
Done.
| |
| 149 EXPECT_EQ(1U, m_dataObject->length()); | |
| 150 | |
| 151 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->item(0); | |
| 152 EXPECT_EQ(DataObjectItem::FileKind, item->kind()); | |
| 153 | |
| 154 RefPtrWillBeRawPtr<Blob> blob = item->getAsFile(); | |
| 155 ASSERT_TRUE(blob->isFile()); | |
| 156 RefPtrWillBeRawPtr<File> file = toFile(blob.get()); | |
| 157 EXPECT_TRUE(file->hasBackingFile()); | |
| 158 EXPECT_EQ(File::IsUserVisible, file->userVisibility()); | |
| 159 EXPECT_EQ(filePath, file->path()); | |
| 160 } | |
| 161 | |
| 162 } // namespace blink | |
| OLD | NEW |