OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/html/DOMFormData.h" | 6 #include "core/html/FormData.h" |
7 | 7 |
8 #include "core/html/FormDataList.h" | |
9 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> |
10 | 9 |
11 namespace blink { | 10 namespace blink { |
12 | 11 |
13 TEST(DOMFormDataTest, opacityGet) | 12 TEST(FormDataTest, opacityGet) |
14 { | 13 { |
15 DOMFormData* fd = DOMFormData::create(UTF8Encoding()); | 14 FormData* fd = FormData::create(UTF8Encoding()); |
16 fd->append("name1", "value1"); | 15 fd->append("name1", "value1"); |
17 | 16 |
18 FileOrUSVString result; | 17 FileOrUSVString result; |
19 fd->get("name1", result); | 18 fd->get("name1", result); |
20 EXPECT_TRUE(result.isUSVString()); | 19 EXPECT_TRUE(result.isUSVString()); |
21 EXPECT_EQ("value1", result.getAsUSVString()); | 20 EXPECT_EQ("value1", result.getAsUSVString()); |
22 | 21 |
23 const FormDataList::Item& entry = fd->items()[0]; | 22 const FormDataList::Item& entry = fd->items()[0]; |
24 EXPECT_STREQ("name1", entry.key().data()); | 23 EXPECT_STREQ("name1", entry.key().data()); |
25 EXPECT_STREQ("value1", entry.data().data()); | 24 EXPECT_STREQ("value1", entry.data().data()); |
26 | 25 |
27 fd->makeOpaque(); | 26 fd->makeOpaque(); |
28 | 27 |
29 // Web-exposed interface should be opaque. | 28 // Web-exposed interface should be opaque. |
30 FileOrUSVString opaqueResult; | 29 FileOrUSVString opaqueResult; |
31 fd->get("name1", opaqueResult); | 30 fd->get("name1", opaqueResult); |
32 EXPECT_TRUE(opaqueResult.isNull()); | 31 EXPECT_TRUE(opaqueResult.isNull()); |
33 | 32 |
34 // Internal interface should be uneffected. | 33 // Internal interface should be uneffected. |
35 const FormDataList::Item& entry2 = fd->items()[0]; | 34 const FormDataList::Item& entry2 = fd->items()[0]; |
36 EXPECT_STREQ("name1", entry2.key().data()); | 35 EXPECT_STREQ("name1", entry2.key().data()); |
37 EXPECT_STREQ("value1", entry2.data().data()); | 36 EXPECT_STREQ("value1", entry2.data().data()); |
38 } | 37 } |
39 | 38 |
40 TEST(DOMFormDataTest, opacityGetAll) | 39 TEST(FormDataTest, opacityGetAll) |
41 { | 40 { |
42 DOMFormData* fd = DOMFormData::create(UTF8Encoding()); | 41 FormData* fd = FormData::create(UTF8Encoding()); |
43 fd->append("name1", "value1"); | 42 fd->append("name1", "value1"); |
44 | 43 |
45 HeapVector<FormDataEntryValue> results = fd->getAll("name1"); | 44 HeapVector<FormDataEntryValue> results = fd->getAll("name1"); |
46 EXPECT_EQ(1u, results.size()); | 45 EXPECT_EQ(1u, results.size()); |
47 EXPECT_TRUE(results[0].isUSVString()); | 46 EXPECT_TRUE(results[0].isUSVString()); |
48 EXPECT_EQ("value1", results[0].getAsUSVString()); | 47 EXPECT_EQ("value1", results[0].getAsUSVString()); |
49 | 48 |
50 EXPECT_EQ(1u, fd->size()); | 49 EXPECT_EQ(1u, fd->size()); |
51 | 50 |
52 fd->makeOpaque(); | 51 fd->makeOpaque(); |
53 | 52 |
54 // Web-exposed interface should be opaque. | 53 // Web-exposed interface should be opaque. |
55 results = fd->getAll("name1"); | 54 results = fd->getAll("name1"); |
56 EXPECT_EQ(0u, results.size()); | 55 EXPECT_EQ(0u, results.size()); |
57 | 56 |
58 // Internal interface should be uneffected. | 57 // Internal interface should be uneffected. |
59 EXPECT_EQ(1u, fd->size()); | 58 EXPECT_EQ(1u, fd->size()); |
60 } | 59 } |
61 | 60 |
62 TEST(DOMFormDataTest, opacityHas) | 61 TEST(FormDataTest, opacityHas) |
63 { | 62 { |
64 DOMFormData* fd = DOMFormData::create(UTF8Encoding()); | 63 FormData* fd = FormData::create(UTF8Encoding()); |
65 fd->append("name1", "value1"); | 64 fd->append("name1", "value1"); |
66 | 65 |
67 EXPECT_TRUE(fd->has("name1")); | 66 EXPECT_TRUE(fd->has("name1")); |
68 EXPECT_EQ(1u, fd->size()); | 67 EXPECT_EQ(1u, fd->size()); |
69 | 68 |
70 fd->makeOpaque(); | 69 fd->makeOpaque(); |
71 | 70 |
72 // Web-exposed interface should be opaque. | 71 // Web-exposed interface should be opaque. |
73 EXPECT_FALSE(fd->has("name1")); | 72 EXPECT_FALSE(fd->has("name1")); |
74 | 73 |
75 // Internal collection should be uneffected. | 74 // Internal collection should be uneffected. |
76 EXPECT_EQ(1u, fd->size()); | 75 EXPECT_EQ(1u, fd->size()); |
77 } | 76 } |
78 | 77 |
79 } // namespace blink | 78 } // namespace blink |
OLD | NEW |