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

Side by Side Diff: Source/web/WebDragDataTest.cpp

Issue 423283003: Fix userVisibility() for files dragged into the renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added test. 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
OLDNEW
(Empty)
1 // 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.
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 "public/platform/WebDragData.h"
7
8 #include "core/clipboard/DataObject.h"
9 #include "core/clipboard/DataObjectItem.h"
10 #include "public/platform/Platform.h"
11 #include "public/platform/WebBlobRegistry.h"
12 #include "public/platform/WebFileUtilities.h"
13 #include "public/platform/WebMimeRegistry.h"
14 #include "public/platform/WebUnitTestSupport.h"
15 #include <gtest/gtest.h>
16
17 using namespace blink;
18
19 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!
20
21 class MockMimeRegistry : public WebMimeRegistry {
22 public:
23 virtual SupportsType supportsMIMEType(const WebString& mimeType) OVERRIDE
24 {
25 return SupportsType::MayBeSupported;
26 }
27
28 virtual SupportsType supportsImageMIMEType(const WebString& mimeType) OVERRI DE
29 {
30 return SupportsType::MayBeSupported;
31 }
32
33 virtual SupportsType supportsJavaScriptMIMEType(const WebString& mimeType) O VERRIDE
34 {
35 return SupportsType::MayBeSupported;
36 }
37
38 virtual SupportsType supportsMediaMIMEType(const WebString& mimeType, const WebString& codecs, const WebString& keySystem) OVERRIDE
39 {
40 return SupportsType::MayBeSupported;
41 }
42
43 virtual bool supportsMediaSourceMIMEType(const WebString& mimeType, const We bString& codecs) OVERRIDE
44 {
45 return false;
46 }
47
48 virtual bool supportsEncryptedMediaMIMEType(const WebString& keySystem, cons t WebString& mimeType, const WebString& codecs) OVERRIDE
49 {
50 return false;
51 }
52
53 virtual SupportsType supportsNonImageMIMEType(const WebString& mimeType) OVE RRIDE
54 {
55 return SupportsType::MayBeSupported;
56 }
57
58 virtual WebString mimeTypeForExtension(const WebString& fileExtension) OVERR IDE
59 {
60 return WebString();
61 }
62
63 virtual WebString wellKnownMimeTypeForExtension(const WebString& fileExtensi on) OVERRIDE
64 {
65 return WebString();
66 }
67
68 virtual WebString mimeTypeFromFile(const WebString& filePath) OVERRIDE
69 {
70 return WebString();
71 }
72 };
73
74 class MockFileUtilities : public WebFileUtilities {
75 public:
76 ~MockFileUtilities() { }
77 };
78
79 class RegistryMockPlatform : public Platform {
80 public:
81 RegistryMockPlatform(Platform* oldPlatform)
82 : m_oldPlatform(oldPlatform)
83 {
84 }
85
86 virtual ~RegistryMockPlatform() { }
87
88 virtual WebBlobRegistry* blobRegistry() OVERRIDE
89 {
90 return &mockBlobRegistry;
91 }
92
93 virtual WebMimeRegistry* mimeRegistry() OVERRIDE
94 {
95 return &mockMimeRegistry;
96 }
97
98 virtual WebFileUtilities* fileUtilities() OVERRIDE
99 {
100 return &mockFileUtilities;
101 }
102
103 virtual WebUnitTestSupport* unitTestSupport() OVERRIDE
104 {
105 return m_oldPlatform->unitTestSupport();
106 }
107
108 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t len gth) OVERRIDE
109 {
110 m_oldPlatform->cryptographicallyRandomValues(buffer, length);
111 }
112
113 protected:
114 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!
115 MockMimeRegistry mockMimeRegistry;
tkent 2014/07/30 23:56:02 mockMimeRegistry -> m_mockMimeRegistry
pwnall-personal 2014/07/31 01:31:26 Done.
116 MockFileUtilities mockFileUtilities;
tkent 2014/07/30 23:56:01 mockFileUtilities -> m_mockFileUtilities
pwnall-personal 2014/07/31 01:31:26 Done.
117 Platform* m_oldPlatform;
118 };
119
120 class WebDragDataTest : public testing::Test {
121 public:
122 WebDragDataTest() : m_dragData() { }
tkent 2014/07/30 23:56:01 |m_dragData()| is unnecessary.
pwnall-personal 2014/07/31 01:31:26 Done.
123
124 protected:
125 virtual void SetUp()
126 {
127 m_dragData = adoptPtr(new WebDragData());
128 m_dragData->initialize();
129 m_oldPlatform = Platform::current();
130 m_mockPlatform = adoptPtr(new RegistryMockPlatform(m_oldPlatform));
131 Platform::initialize(m_mockPlatform.get());
132 }
133 virtual void TearDown()
134 {
135 // reset() invokes the File destructor, which uses WebBlobRegistry, so
136 // reset() must be called before restoring the original Platform
137 m_dragData->reset();
138 Platform::initialize(m_oldPlatform);
139 }
140
141 OwnPtrWillBeRawPtr<WebDragData> m_dragData;
tkent 2014/07/30 23:56:01 OwnPtrWillBeRawPtr -> OwnPtr
pwnall-personal 2014/07/31 01:31:26 Done. Thank you!
142 OwnPtrWillBeRawPtr<RegistryMockPlatform> m_mockPlatform;
tkent 2014/07/30 23:56:01 OwnPtrWillBeRawPtr -> OwnPtr
pwnall-personal 2014/07/31 01:31:26 Done.
143 Platform* m_oldPlatform;
144 };
145
146 TEST_F(WebDragDataTest, addItemWithFilename)
147 {
148 WTF::String filePath = Platform::current()->unitTestSupport()->webKitRootDir ();
149 filePath.append("/Source/web/tests/data/dragdata/file.txt");
150 WebDragData::Item webDragDataItem;
151 webDragDataItem.storageType = WebDragData::Item::StorageTypeFilename;
152 webDragDataItem.filenameData = filePath;
153 m_dragData->addItem(webDragDataItem);
154
155 DataObject* dataObject = m_dragData->getValue();
156 EXPECT_EQ(1U, dataObject->length());
157
158 RefPtrWillBeRawPtr<DataObjectItem> item = dataObject->item(0);
159 EXPECT_EQ(DataObjectItem::FileKind, item->kind());
160
161 RefPtrWillBeRawPtr<Blob> blob = item->getAsFile();
162 ASSERT_TRUE(blob->isFile());
163 RefPtrWillBeRawPtr<File> file = toFile(blob.get());
164 EXPECT_TRUE(file->hasBackingFile());
165 EXPECT_EQ(File::IsUserVisible, file->userVisibility());
166 EXPECT_EQ(filePath, file->path());
167 }
168
169 } // namespace
OLDNEW
« no previous file with comments | « Source/modules/filesystem/FileSystemCallbacks.cpp ('k') | Source/web/tests/data/dragdata/file.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698