Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: Source/core/clipboard/DataObjectTest.cpp

Issue 434823002: Remove mocking from DataObjectTest.cpp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "core/clipboard/DataObject.h" 6 #include "core/clipboard/DataObject.h"
7 7
8 #include "core/clipboard/DataObjectItem.h" 8 #include "core/clipboard/DataObjectItem.h"
9 #include "public/platform/Platform.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" 10 #include "public/platform/WebUnitTestSupport.h"
14 #include <gtest/gtest.h> 11 #include <gtest/gtest.h>
15 12
16 namespace blink { 13 namespace blink {
17 14
18 class MockMimeRegistry : public WebMimeRegistry { 15 class DataObjectTest : public ::testing::Test {
19 public: 16 public:
20 virtual SupportsType supportsMIMEType(const WebString& mimeType) OVERRIDE 17 DataObjectTest()
21 { 18 : m_dataObject(DataObject::create())
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 { 19 {
81 } 20 }
82 21
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 virtual const unsigned char* getTraceCategoryEnabledFlag(const char* categor yName) OVERRIDE
111 {
112 return m_oldPlatform->getTraceCategoryEnabledFlag(categoryName);
113 }
114
115 protected: 22 protected:
116 WebBlobRegistry m_mockBlobRegistry; 23 RefPtrWillBePersistent<DataObject> m_dataObject;
117 MockMimeRegistry m_mockMimeRegistry;
118 MockFileUtilities m_mockFileUtilities;
119 Platform* m_oldPlatform;
120 }; 24 };
121 25
122 class DataObjectTest : public ::testing::Test { 26 TEST_F(DataObjectTest, addItemWithFilenameAndNoTitle)
123 public:
124 DataObjectTest() { }
125
126 protected:
127 virtual void SetUp() OVERRIDE
128 {
129 m_oldPlatform = Platform::current();
130 m_mockPlatform = adoptPtr(new RegistryMockPlatform(m_oldPlatform));
131 Platform::initialize(m_mockPlatform.get());
132
133 m_dataObject = DataObject::create();
134 }
135 virtual void TearDown() OVERRIDE
136 {
137 // clear() invokes the File destructor, which uses WebBlobRegistry, so
138 // clear() must be called before restoring the original Platform
139 m_dataObject.clear();
140 Heap::collectAllGarbage();
141 Platform::initialize(m_oldPlatform);
142 }
143
144 RefPtrWillBePersistent<DataObject> m_dataObject;
145 OwnPtr<RegistryMockPlatform> m_mockPlatform;
146 Platform* m_oldPlatform;
147 };
148
149 TEST_F(DataObjectTest, addItemWithFilename)
150 { 27 {
151 String filePath = Platform::current()->unitTestSupport()->webKitRootDir(); 28 String filePath = Platform::current()->unitTestSupport()->webKitRootDir();
152 filePath.append("/Source/core/clipboard/DataObjectTest.cpp"); 29 filePath.append("/Source/core/clipboard/DataObjectTest.cpp");
153 30
154 m_dataObject->addFilename(filePath, String()); 31 m_dataObject->addFilename(filePath, String());
155 EXPECT_EQ(1U, m_dataObject->length()); 32 EXPECT_EQ(1U, m_dataObject->length());
156 33
157 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->item(0); 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
45 TEST_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);
158 EXPECT_EQ(DataObjectItem::FileKind, item->kind()); 54 EXPECT_EQ(DataObjectItem::FileKind, item->kind());
159 55
160 RefPtrWillBeRawPtr<Blob> blob = item->getAsFile(); 56 RefPtrWillBeRawPtr<Blob> blob = item->getAsFile();
161 ASSERT_TRUE(blob->isFile()); 57 ASSERT_TRUE(blob->isFile());
162 RefPtrWillBeRawPtr<File> file = toFile(blob.get()); 58 RefPtrWillBeRawPtr<File> file = toFile(blob.get());
163 EXPECT_TRUE(file->hasBackingFile()); 59 EXPECT_TRUE(file->hasBackingFile());
164 EXPECT_EQ(File::IsUserVisible, file->userVisibility()); 60 EXPECT_EQ(File::IsUserVisible, file->userVisibility());
165 EXPECT_EQ(filePath, file->path()); 61 EXPECT_EQ(filePath, file->path());
62 EXPECT_EQ("name.cpp", file->name());
166 } 63 }
167 64
168 } // namespace blink 65 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698