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

Side by Side Diff: Source/platform/network/FormDataTest.cpp

Issue 594473002: [Thread-safe] Take deep copy of String/KURL in FormData::deepCopy() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add unit tests. Created 6 years, 2 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 | « Source/platform/network/FormData.cpp ('k') | 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
(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 #ifndef FormDataTest_h
6 #define FormDataTest_h
7
8 #include "config.h"
9 #include "platform/network/FormData.h"
10
11 #include <gmock/gmock.h>
abarth-chromium 2014/10/16 16:13:18 Why do we need gmock?
hiroshige 2014/10/20 05:16:00 Removed.
12 #include <gtest/gtest.h>
13
14 namespace blink {
15
16 namespace {
17
18 class FormDataTest : public ::testing::Test {
19 public:
20 void checkDeepCopied(const String& a, const String& b)
21 {
22 EXPECT_EQ(a, b);
23 if (b.impl())
24 EXPECT_NE(a.impl(), b.impl());
25 }
26
27 void checkDeepCopied(const KURL& a, const KURL& b)
28 {
29 EXPECT_EQ(a, b);
30 checkDeepCopied(a.string(), b.string());
31 if (a.innerURL() && b.innerURL())
32 checkDeepCopied(*a.innerURL(), *b.innerURL());
33 }
34
35 void checkDeepCopied(const FormDataElement& a, const FormDataElement& b)
36 {
37 EXPECT_EQ(a, b);
38 checkDeepCopied(a.m_filename, b.m_filename);
39 checkDeepCopied(a.m_blobUUID, b.m_blobUUID);
40 checkDeepCopied(a.m_fileSystemURL, b.m_fileSystemURL);
41 }
42 };
43
44 TEST_F(FormDataTest, DeepCopy)
45 {
46 RefPtr<FormData> original(FormData::create());
47 original->appendData("Foo", 3);
48 original->appendFileRange("example.txt", 12345, 56789, 9999.0);
49 original->appendBlob("originalUUID", nullptr);
50 original->appendFileSystemURLRange(KURL(KURL(), "ws://localhost/"), 23456, 3 4567, 1111.0);
51
52 RefPtr<FormData> copy = original->deepCopy();
53
54 // Check that contents are copied (compare the copy with expected values).
55 const Vector<FormDataElement>& originalElements = original->elements();
56 const Vector<FormDataElement>& copyElements = copy->elements();
57 ASSERT_EQ(4ul, copyElements.size());
58
59 Vector<char> fooVector;
60 fooVector.append("Foo", 3);
61
62 EXPECT_EQ(FormDataElement::data, copyElements[0].m_type);
63 EXPECT_EQ(fooVector, copyElements[0].m_data);
64
65 EXPECT_EQ(FormDataElement::encodedFile, copyElements[1].m_type);
66 EXPECT_EQ(String("example.txt"), copyElements[1].m_filename);
67 EXPECT_EQ(12345ll, copyElements[1].m_fileStart);
68 EXPECT_EQ(56789ll, copyElements[1].m_fileLength);
69 EXPECT_EQ(9999.0, copyElements[1].m_expectedFileModificationTime);
70
71 EXPECT_EQ(FormDataElement::encodedBlob, copyElements[2].m_type);
72 EXPECT_EQ(String("originalUUID"), copyElements[2].m_blobUUID);
73
74 EXPECT_EQ(FormDataElement::encodedFileSystemURL, copyElements[3].m_type);
75 EXPECT_EQ(KURL(KURL(), String("ws://localhost/")), copyElements[3].m_fileSys temURL);
76 EXPECT_EQ(23456ll, copyElements[3].m_fileStart);
77 EXPECT_EQ(34567ll, copyElements[3].m_fileLength);
78 EXPECT_EQ(1111.0, copyElements[3].m_expectedFileModificationTime);
79
80 // Check that contents are copied (compare the copy with the original).
81 EXPECT_EQ(*original, *copy);
82
83 // Check pointers are different, i.e. deep-copied.
84 ASSERT_NE(original.get(), copy.get());
85
86 for (size_t i = 0; i < 4; ++i) {
87 if (copyElements[i].m_filename.impl()) {
88 EXPECT_NE(originalElements[i].m_filename.impl(), copyElements[i].m_f ilename.impl());
89 EXPECT_TRUE(copyElements[i].m_filename.impl()->hasOneRef());
90 }
91
92 if (copyElements[i].m_blobUUID.impl()) {
93 EXPECT_NE(originalElements[i].m_blobUUID.impl(), copyElements[i].m_b lobUUID.impl());
94 EXPECT_TRUE(copyElements[i].m_blobUUID.impl()->hasOneRef());
95 }
96
97 if (copyElements[i].m_fileSystemURL.string().impl()) {
98 EXPECT_NE(originalElements[i].m_fileSystemURL.string().impl(), copyE lements[i].m_fileSystemURL.string().impl());
99 EXPECT_TRUE(copyElements[i].m_fileSystemURL.string().impl()->hasOneR ef());
100 }
101
102 EXPECT_EQ(nullptr, copyElements[i].m_fileSystemURL.innerURL());
103
104 // m_optionalBlobDataHandle is not checked, because BlobDataHandle is Th readSafeRefCounted.
105 }
106 }
107
108 } // namespace
109
110 } // namespace blink
111
112 #endif
OLDNEW
« no previous file with comments | « Source/platform/network/FormData.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698