| 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 "platform/network/FormData.h" | |
| 7 | |
| 8 #include <gtest/gtest.h> | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 class FormDataTest : public ::testing::Test { | |
| 15 public: | |
| 16 void checkDeepCopied(const String& a, const String& b) | |
| 17 { | |
| 18 EXPECT_EQ(a, b); | |
| 19 if (b.impl()) | |
| 20 EXPECT_NE(a.impl(), b.impl()); | |
| 21 } | |
| 22 | |
| 23 void checkDeepCopied(const KURL& a, const KURL& b) | |
| 24 { | |
| 25 EXPECT_EQ(a, b); | |
| 26 checkDeepCopied(a.string(), b.string()); | |
| 27 if (a.innerURL() && b.innerURL()) | |
| 28 checkDeepCopied(*a.innerURL(), *b.innerURL()); | |
| 29 } | |
| 30 | |
| 31 void checkDeepCopied(const FormDataElement& a, const FormDataElement& b) | |
| 32 { | |
| 33 EXPECT_EQ(a, b); | |
| 34 checkDeepCopied(a.m_filename, b.m_filename); | |
| 35 checkDeepCopied(a.m_blobUUID, b.m_blobUUID); | |
| 36 checkDeepCopied(a.m_fileSystemURL, b.m_fileSystemURL); | |
| 37 } | |
| 38 }; | |
| 39 | |
| 40 TEST_F(FormDataTest, DeepCopy) | |
| 41 { | |
| 42 RefPtr<FormData> original(FormData::create()); | |
| 43 original->appendData("Foo", 3); | |
| 44 original->appendFileRange("example.txt", 12345, 56789, 9999.0); | |
| 45 original->appendBlob("originalUUID", nullptr); | |
| 46 original->appendFileSystemURLRange(KURL(KURL(), "ws://localhost/"), 23456, 3
4567, 1111.0); | |
| 47 | |
| 48 Vector<char> boundaryVector; | |
| 49 boundaryVector.append("----boundaryForTest", 19); | |
| 50 original->setIdentifier(45678); | |
| 51 original->setBoundary(boundaryVector); | |
| 52 original->setContainsPasswordData(true); | |
| 53 | |
| 54 RefPtr<FormData> copy = original->deepCopy(); | |
| 55 | |
| 56 // Check that contents are copied (compare the copy with expected values). | |
| 57 const Vector<FormDataElement>& originalElements = original->elements(); | |
| 58 const Vector<FormDataElement>& copyElements = copy->elements(); | |
| 59 ASSERT_EQ(4ul, copyElements.size()); | |
| 60 | |
| 61 Vector<char> fooVector; | |
| 62 fooVector.append("Foo", 3); | |
| 63 | |
| 64 EXPECT_EQ(FormDataElement::data, copyElements[0].m_type); | |
| 65 EXPECT_EQ(fooVector, copyElements[0].m_data); | |
| 66 | |
| 67 EXPECT_EQ(FormDataElement::encodedFile, copyElements[1].m_type); | |
| 68 EXPECT_EQ(String("example.txt"), copyElements[1].m_filename); | |
| 69 EXPECT_EQ(12345ll, copyElements[1].m_fileStart); | |
| 70 EXPECT_EQ(56789ll, copyElements[1].m_fileLength); | |
| 71 EXPECT_EQ(9999.0, copyElements[1].m_expectedFileModificationTime); | |
| 72 | |
| 73 EXPECT_EQ(FormDataElement::encodedBlob, copyElements[2].m_type); | |
| 74 EXPECT_EQ(String("originalUUID"), copyElements[2].m_blobUUID); | |
| 75 | |
| 76 EXPECT_EQ(FormDataElement::encodedFileSystemURL, copyElements[3].m_type); | |
| 77 EXPECT_EQ(KURL(KURL(), String("ws://localhost/")), copyElements[3].m_fileSys
temURL); | |
| 78 EXPECT_EQ(23456ll, copyElements[3].m_fileStart); | |
| 79 EXPECT_EQ(34567ll, copyElements[3].m_fileLength); | |
| 80 EXPECT_EQ(1111.0, copyElements[3].m_expectedFileModificationTime); | |
| 81 | |
| 82 EXPECT_EQ(45678, copy->identifier()); | |
| 83 EXPECT_EQ(boundaryVector, copy->boundary()); | |
| 84 EXPECT_EQ(true, copy->containsPasswordData()); | |
| 85 | |
| 86 // Check that contents are copied (compare the copy with the original). | |
| 87 EXPECT_EQ(*original, *copy); | |
| 88 | |
| 89 // Check pointers are different, i.e. deep-copied. | |
| 90 ASSERT_NE(original.get(), copy.get()); | |
| 91 | |
| 92 for (size_t i = 0; i < 4; ++i) { | |
| 93 if (copyElements[i].m_filename.impl()) { | |
| 94 EXPECT_NE(originalElements[i].m_filename.impl(), copyElements[i].m_f
ilename.impl()); | |
| 95 EXPECT_TRUE(copyElements[i].m_filename.impl()->hasOneRef()); | |
| 96 } | |
| 97 | |
| 98 if (copyElements[i].m_blobUUID.impl()) { | |
| 99 EXPECT_NE(originalElements[i].m_blobUUID.impl(), copyElements[i].m_b
lobUUID.impl()); | |
| 100 EXPECT_TRUE(copyElements[i].m_blobUUID.impl()->hasOneRef()); | |
| 101 } | |
| 102 | |
| 103 if (copyElements[i].m_fileSystemURL.string().impl()) { | |
| 104 EXPECT_NE(originalElements[i].m_fileSystemURL.string().impl(), copyE
lements[i].m_fileSystemURL.string().impl()); | |
| 105 EXPECT_TRUE(copyElements[i].m_fileSystemURL.string().impl()->hasOneR
ef()); | |
| 106 } | |
| 107 | |
| 108 EXPECT_EQ(nullptr, copyElements[i].m_fileSystemURL.innerURL()); | |
| 109 | |
| 110 // m_optionalBlobDataHandle is not checked, because BlobDataHandle is Th
readSafeRefCounted. | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 } // namespace | |
| 115 | |
| 116 } // namespace blink | |
| OLD | NEW |