OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/clipboard/custom_data_helper.h" | 5 #include "ui/base/clipboard/custom_data_helper.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 TEST(CustomDataHelperTest, BadReadTypes) { | 112 TEST(CustomDataHelperTest, BadReadTypes) { |
113 // ReadCustomDataTypes makes the additional guarantee that the contents of the | 113 // ReadCustomDataTypes makes the additional guarantee that the contents of the |
114 // result vector will not change if the input is malformed. | 114 // result vector will not change if the input is malformed. |
115 std::vector<string16> expected; | 115 std::vector<string16> expected; |
116 expected.push_back(ASCIIToUTF16("abc")); | 116 expected.push_back(ASCIIToUTF16("abc")); |
117 expected.push_back(ASCIIToUTF16("de")); | 117 expected.push_back(ASCIIToUTF16("de")); |
118 expected.push_back(ASCIIToUTF16("f")); | 118 expected.push_back(ASCIIToUTF16("f")); |
119 | 119 |
120 Pickle malformed; | 120 Pickle malformed; |
121 malformed.WriteSize(1000); | 121 malformed.WriteUInt64(1000); |
122 malformed.WriteString16(ASCIIToUTF16("hello")); | 122 malformed.WriteString16(ASCIIToUTF16("hello")); |
123 malformed.WriteString16(ASCIIToUTF16("world")); | 123 malformed.WriteString16(ASCIIToUTF16("world")); |
124 std::vector<string16> actual(expected); | 124 std::vector<string16> actual(expected); |
125 ReadCustomDataTypes(malformed.data(), malformed.size(), &actual); | 125 ReadCustomDataTypes(malformed.data(), malformed.size(), &actual); |
126 EXPECT_EQ(expected, actual); | 126 EXPECT_EQ(expected, actual); |
127 | 127 |
128 Pickle malformed2; | 128 Pickle malformed2; |
129 malformed2.WriteSize(1); | 129 malformed2.WriteUInt64(1); |
130 malformed2.WriteString16(ASCIIToUTF16("hello")); | 130 malformed2.WriteString16(ASCIIToUTF16("hello")); |
131 std::vector<string16> actual2(expected); | 131 std::vector<string16> actual2(expected); |
132 ReadCustomDataTypes(malformed2.data(), malformed2.size(), &actual2); | 132 ReadCustomDataTypes(malformed2.data(), malformed2.size(), &actual2); |
133 EXPECT_EQ(expected, actual2); | 133 EXPECT_EQ(expected, actual2); |
134 } | 134 } |
135 | 135 |
136 TEST(CustomDataHelperTest, BadPickle) { | 136 TEST(CustomDataHelperTest, BadPickle) { |
137 string16 result_data; | 137 string16 result_data; |
138 std::map<string16, string16> result_map; | 138 std::map<string16, string16> result_map; |
139 | 139 |
140 Pickle malformed; | 140 Pickle malformed; |
141 malformed.WriteSize(1000); | 141 malformed.WriteUInt64(1000); |
142 malformed.WriteString16(ASCIIToUTF16("hello")); | 142 malformed.WriteString16(ASCIIToUTF16("hello")); |
143 malformed.WriteString16(ASCIIToUTF16("world")); | 143 malformed.WriteString16(ASCIIToUTF16("world")); |
144 | 144 |
145 ReadCustomDataForType(malformed.data(), | 145 ReadCustomDataForType(malformed.data(), |
146 malformed.size(), | 146 malformed.size(), |
147 ASCIIToUTF16("f"), | 147 ASCIIToUTF16("f"), |
148 &result_data); | 148 &result_data); |
149 ReadCustomDataIntoMap(malformed.data(), malformed.size(), &result_map); | 149 ReadCustomDataIntoMap(malformed.data(), malformed.size(), &result_map); |
150 EXPECT_EQ(0u, result_data.size()); | 150 EXPECT_EQ(0u, result_data.size()); |
151 EXPECT_EQ(0u, result_map.size()); | 151 EXPECT_EQ(0u, result_map.size()); |
152 | 152 |
153 Pickle malformed2; | 153 Pickle malformed2; |
154 malformed2.WriteSize(1); | 154 malformed2.WriteUInt64(1); |
155 malformed2.WriteString16(ASCIIToUTF16("hello")); | 155 malformed2.WriteString16(ASCIIToUTF16("hello")); |
156 | 156 |
157 ReadCustomDataForType(malformed2.data(), | 157 ReadCustomDataForType(malformed2.data(), |
158 malformed2.size(), | 158 malformed2.size(), |
159 ASCIIToUTF16("f"), | 159 ASCIIToUTF16("f"), |
160 &result_data); | 160 &result_data); |
161 ReadCustomDataIntoMap(malformed2.data(), malformed2.size(), &result_map); | 161 ReadCustomDataIntoMap(malformed2.data(), malformed2.size(), &result_map); |
162 EXPECT_EQ(0u, result_data.size()); | 162 EXPECT_EQ(0u, result_data.size()); |
163 EXPECT_EQ(0u, result_map.size()); | 163 EXPECT_EQ(0u, result_map.size()); |
164 } | 164 } |
165 | 165 |
166 } // namespace | 166 } // namespace |
167 | 167 |
168 } // namespace ui | 168 } // namespace ui |
OLD | NEW |