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

Side by Side Diff: ui/base/clipboard/custom_data_helper_unittest.cc

Issue 117983002: Prefix string16 with base:: in ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/clipboard/custom_data_helper.cc ('k') | ui/base/cocoa/find_pasteboard.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace ui { 13 namespace ui {
14 14
15 namespace { 15 namespace {
16 16
17 void PrepareEmptyTestData(Pickle* pickle) { 17 void PrepareEmptyTestData(Pickle* pickle) {
18 std::map<string16, string16> data; 18 std::map<base::string16, base::string16> data;
19 WriteCustomDataToPickle(data, pickle); 19 WriteCustomDataToPickle(data, pickle);
20 } 20 }
21 21
22 void PrepareTestData(Pickle* pickle) { 22 void PrepareTestData(Pickle* pickle) {
23 std::map<string16, string16> data; 23 std::map<base::string16, base::string16> data;
24 data.insert(std::make_pair(ASCIIToUTF16("abc"), string16())); 24 data.insert(std::make_pair(ASCIIToUTF16("abc"), base::string16()));
25 data.insert(std::make_pair(ASCIIToUTF16("de"), ASCIIToUTF16("1"))); 25 data.insert(std::make_pair(ASCIIToUTF16("de"), ASCIIToUTF16("1")));
26 data.insert(std::make_pair(ASCIIToUTF16("f"), ASCIIToUTF16("23"))); 26 data.insert(std::make_pair(ASCIIToUTF16("f"), ASCIIToUTF16("23")));
27 WriteCustomDataToPickle(data, pickle); 27 WriteCustomDataToPickle(data, pickle);
28 } 28 }
29 29
30 TEST(CustomDataHelperTest, EmptyReadTypes) { 30 TEST(CustomDataHelperTest, EmptyReadTypes) {
31 Pickle pickle; 31 Pickle pickle;
32 PrepareEmptyTestData(&pickle); 32 PrepareEmptyTestData(&pickle);
33 33
34 std::vector<string16> types; 34 std::vector<base::string16> types;
35 ReadCustomDataTypes(pickle.data(), pickle.size(), &types); 35 ReadCustomDataTypes(pickle.data(), pickle.size(), &types);
36 EXPECT_EQ(0u, types.size()); 36 EXPECT_EQ(0u, types.size());
37 } 37 }
38 38
39 TEST(CustomDataHelperTest, EmptyReadSingleType) { 39 TEST(CustomDataHelperTest, EmptyReadSingleType) {
40 Pickle pickle; 40 Pickle pickle;
41 PrepareEmptyTestData(&pickle); 41 PrepareEmptyTestData(&pickle);
42 42
43 string16 result; 43 base::string16 result;
44 ReadCustomDataForType(pickle.data(), 44 ReadCustomDataForType(pickle.data(),
45 pickle.size(), 45 pickle.size(),
46 ASCIIToUTF16("f"), 46 ASCIIToUTF16("f"),
47 &result); 47 &result);
48 EXPECT_EQ(string16(), result); 48 EXPECT_EQ(base::string16(), result);
49 } 49 }
50 50
51 TEST(CustomDataHelperTest, EmptyReadMap) { 51 TEST(CustomDataHelperTest, EmptyReadMap) {
52 Pickle pickle; 52 Pickle pickle;
53 PrepareEmptyTestData(&pickle); 53 PrepareEmptyTestData(&pickle);
54 54
55 std::map<string16, string16> result; 55 std::map<base::string16, base::string16> result;
56 ReadCustomDataIntoMap(pickle.data(), pickle.size(), &result); 56 ReadCustomDataIntoMap(pickle.data(), pickle.size(), &result);
57 EXPECT_EQ(0u, result.size()); 57 EXPECT_EQ(0u, result.size());
58 } 58 }
59 59
60 TEST(CustomDataHelperTest, ReadTypes) { 60 TEST(CustomDataHelperTest, ReadTypes) {
61 Pickle pickle; 61 Pickle pickle;
62 PrepareTestData(&pickle); 62 PrepareTestData(&pickle);
63 63
64 std::vector<string16> types; 64 std::vector<base::string16> types;
65 ReadCustomDataTypes(pickle.data(), pickle.size(), &types); 65 ReadCustomDataTypes(pickle.data(), pickle.size(), &types);
66 66
67 std::vector<string16> expected; 67 std::vector<base::string16> expected;
68 expected.push_back(ASCIIToUTF16("abc")); 68 expected.push_back(ASCIIToUTF16("abc"));
69 expected.push_back(ASCIIToUTF16("de")); 69 expected.push_back(ASCIIToUTF16("de"));
70 expected.push_back(ASCIIToUTF16("f")); 70 expected.push_back(ASCIIToUTF16("f"));
71 EXPECT_EQ(expected, types); 71 EXPECT_EQ(expected, types);
72 } 72 }
73 73
74 TEST(CustomDataHelperTest, ReadSingleType) { 74 TEST(CustomDataHelperTest, ReadSingleType) {
75 Pickle pickle; 75 Pickle pickle;
76 PrepareTestData(&pickle); 76 PrepareTestData(&pickle);
77 77
78 string16 result; 78 base::string16 result;
79 ReadCustomDataForType(pickle.data(), 79 ReadCustomDataForType(pickle.data(),
80 pickle.size(), 80 pickle.size(),
81 ASCIIToUTF16("abc"), 81 ASCIIToUTF16("abc"),
82 &result); 82 &result);
83 EXPECT_EQ(string16(), result); 83 EXPECT_EQ(base::string16(), result);
84 84
85 ReadCustomDataForType(pickle.data(), 85 ReadCustomDataForType(pickle.data(),
86 pickle.size(), 86 pickle.size(),
87 ASCIIToUTF16("de"), 87 ASCIIToUTF16("de"),
88 &result); 88 &result);
89 EXPECT_EQ(ASCIIToUTF16("1"), result); 89 EXPECT_EQ(ASCIIToUTF16("1"), result);
90 90
91 ReadCustomDataForType(pickle.data(), 91 ReadCustomDataForType(pickle.data(),
92 pickle.size(), 92 pickle.size(),
93 ASCIIToUTF16("f"), 93 ASCIIToUTF16("f"),
94 &result); 94 &result);
95 EXPECT_EQ(ASCIIToUTF16("23"), result); 95 EXPECT_EQ(ASCIIToUTF16("23"), result);
96 } 96 }
97 97
98 TEST(CustomDataHelperTest, ReadMap) { 98 TEST(CustomDataHelperTest, ReadMap) {
99 Pickle pickle; 99 Pickle pickle;
100 PrepareTestData(&pickle); 100 PrepareTestData(&pickle);
101 101
102 std::map<string16, string16> result; 102 std::map<base::string16, base::string16> result;
103 ReadCustomDataIntoMap(pickle.data(), pickle.size(), &result); 103 ReadCustomDataIntoMap(pickle.data(), pickle.size(), &result);
104 104
105 std::map<string16, string16> expected; 105 std::map<base::string16, base::string16> expected;
106 expected.insert(std::make_pair(ASCIIToUTF16("abc"), string16())); 106 expected.insert(std::make_pair(ASCIIToUTF16("abc"), base::string16()));
107 expected.insert(std::make_pair(ASCIIToUTF16("de"), ASCIIToUTF16("1"))); 107 expected.insert(std::make_pair(ASCIIToUTF16("de"), ASCIIToUTF16("1")));
108 expected.insert(std::make_pair(ASCIIToUTF16("f"), ASCIIToUTF16("23"))); 108 expected.insert(std::make_pair(ASCIIToUTF16("f"), ASCIIToUTF16("23")));
109 EXPECT_EQ(expected, result); 109 EXPECT_EQ(expected, result);
110 } 110 }
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<base::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.WriteUInt64(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<base::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.WriteUInt64(1); 129 malformed2.WriteUInt64(1);
130 malformed2.WriteString16(ASCIIToUTF16("hello")); 130 malformed2.WriteString16(ASCIIToUTF16("hello"));
131 std::vector<string16> actual2(expected); 131 std::vector<base::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 base::string16 result_data;
138 std::map<string16, string16> result_map; 138 std::map<base::string16, base::string16> result_map;
139 139
140 Pickle malformed; 140 Pickle malformed;
141 malformed.WriteUInt64(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);
(...skipping 10 matching lines...) Expand all
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
OLDNEW
« no previous file with comments | « ui/base/clipboard/custom_data_helper.cc ('k') | ui/base/cocoa/find_pasteboard.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698