OLD | NEW |
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 "platform/network/FormData.h" | 6 #include "platform/network/EncodedFormData.h" |
7 | 7 |
8 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 class FormDataTest : public ::testing::Test { | 14 class EncodedFormDataTest : public ::testing::Test { |
15 public: | 15 public: |
16 void checkDeepCopied(const String& a, const String& b) | 16 void checkDeepCopied(const String& a, const String& b) |
17 { | 17 { |
18 EXPECT_EQ(a, b); | 18 EXPECT_EQ(a, b); |
19 if (b.impl()) | 19 if (b.impl()) |
20 EXPECT_NE(a.impl(), b.impl()); | 20 EXPECT_NE(a.impl(), b.impl()); |
21 } | 21 } |
22 | 22 |
23 void checkDeepCopied(const KURL& a, const KURL& b) | 23 void checkDeepCopied(const KURL& a, const KURL& b) |
24 { | 24 { |
25 EXPECT_EQ(a, b); | 25 EXPECT_EQ(a, b); |
26 checkDeepCopied(a.string(), b.string()); | 26 checkDeepCopied(a.string(), b.string()); |
27 if (a.innerURL() && b.innerURL()) | 27 if (a.innerURL() && b.innerURL()) |
28 checkDeepCopied(*a.innerURL(), *b.innerURL()); | 28 checkDeepCopied(*a.innerURL(), *b.innerURL()); |
29 } | 29 } |
30 | 30 |
31 void checkDeepCopied(const FormDataElement& a, const FormDataElement& b) | 31 void checkDeepCopied(const FormDataElement& a, const FormDataElement& b) |
32 { | 32 { |
33 EXPECT_EQ(a, b); | 33 EXPECT_EQ(a, b); |
34 checkDeepCopied(a.m_filename, b.m_filename); | 34 checkDeepCopied(a.m_filename, b.m_filename); |
35 checkDeepCopied(a.m_blobUUID, b.m_blobUUID); | 35 checkDeepCopied(a.m_blobUUID, b.m_blobUUID); |
36 checkDeepCopied(a.m_fileSystemURL, b.m_fileSystemURL); | 36 checkDeepCopied(a.m_fileSystemURL, b.m_fileSystemURL); |
37 } | 37 } |
38 }; | 38 }; |
39 | 39 |
40 TEST_F(FormDataTest, DeepCopy) | 40 TEST_F(EncodedFormDataTest, DeepCopy) |
41 { | 41 { |
42 RefPtr<FormData> original(FormData::create()); | 42 RefPtr<EncodedFormData> original(EncodedFormData::create()); |
43 original->appendData("Foo", 3); | 43 original->appendData("Foo", 3); |
44 original->appendFileRange("example.txt", 12345, 56789, 9999.0); | 44 original->appendFileRange("example.txt", 12345, 56789, 9999.0); |
45 original->appendBlob("originalUUID", nullptr); | 45 original->appendBlob("originalUUID", nullptr); |
46 original->appendFileSystemURLRange(KURL(KURL(), "ws://localhost/"), 23456, 3
4567, 1111.0); | 46 original->appendFileSystemURLRange(KURL(KURL(), "ws://localhost/"), 23456, 3
4567, 1111.0); |
47 | 47 |
48 Vector<char> boundaryVector; | 48 Vector<char> boundaryVector; |
49 boundaryVector.append("----boundaryForTest", 19); | 49 boundaryVector.append("----boundaryForTest", 19); |
50 original->setIdentifier(45678); | 50 original->setIdentifier(45678); |
51 original->setBoundary(boundaryVector); | 51 original->setBoundary(boundaryVector); |
52 original->setContainsPasswordData(true); | 52 original->setContainsPasswordData(true); |
53 | 53 |
54 RefPtr<FormData> copy = original->deepCopy(); | 54 RefPtr<EncodedFormData> copy = original->deepCopy(); |
55 | 55 |
56 // Check that contents are copied (compare the copy with expected values). | 56 // Check that contents are copied (compare the copy with expected values). |
57 const Vector<FormDataElement>& originalElements = original->elements(); | 57 const Vector<FormDataElement>& originalElements = original->elements(); |
58 const Vector<FormDataElement>& copyElements = copy->elements(); | 58 const Vector<FormDataElement>& copyElements = copy->elements(); |
59 ASSERT_EQ(4ul, copyElements.size()); | 59 ASSERT_EQ(4ul, copyElements.size()); |
60 | 60 |
61 Vector<char> fooVector; | 61 Vector<char> fooVector; |
62 fooVector.append("Foo", 3); | 62 fooVector.append("Foo", 3); |
63 | 63 |
64 EXPECT_EQ(FormDataElement::data, copyElements[0].m_type); | 64 EXPECT_EQ(FormDataElement::data, copyElements[0].m_type); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 EXPECT_EQ(nullptr, copyElements[i].m_fileSystemURL.innerURL()); | 108 EXPECT_EQ(nullptr, copyElements[i].m_fileSystemURL.innerURL()); |
109 | 109 |
110 // m_optionalBlobDataHandle is not checked, because BlobDataHandle is Th
readSafeRefCounted. | 110 // m_optionalBlobDataHandle is not checked, because BlobDataHandle is Th
readSafeRefCounted. |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 } // namespace | 114 } // namespace |
115 | 115 |
116 } // namespace blink | 116 } // namespace blink |
OLD | NEW |