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

Side by Side Diff: components/update_client/update_response_unittest.cc

Issue 2856573003: Fix the broken XML parser due to version mismatch. (Closed)
Patch Set: Created 3 years, 7 months 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
« no previous file with comments | « components/update_client/update_response.cc ('k') | components/update_client/utils.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/update_client/update_response.h" 5 #include "components/update_client/update_response.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace update_client { 8 namespace update_client {
9 9
10 const char* kValidXml = 10 const char* kValidXml =
11 "<?xml version='1.0' encoding='UTF-8'?>" 11 "<?xml version='1.0' encoding='UTF-8'?>"
12 "<response protocol='3.0'>" 12 "<response protocol='3.1'>"
13 " <app appid='12345'>" 13 " <app appid='12345'>"
14 " <updatecheck status='ok'>" 14 " <updatecheck status='ok'>"
15 " <urls>" 15 " <urls>"
16 " <url codebase='http://example.com/'/>" 16 " <url codebase='http://example.com/'/>"
17 " <url codebasediff='http://diff.example.com/'/>" 17 " <url codebasediff='http://diff.example.com/'/>"
18 " </urls>" 18 " </urls>"
19 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 19 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
20 " <packages>" 20 " <packages>"
21 " <package name='extension_1_2_3_4.crx'/>" 21 " <package name='extension_1_2_3_4.crx'/>"
22 " </packages>" 22 " </packages>"
23 " </manifest>" 23 " </manifest>"
24 " </updatecheck>" 24 " </updatecheck>"
25 " </app>" 25 " </app>"
26 "</response>"; 26 "</response>";
27 27
28 const char* valid_xml_with_hash = 28 const char* valid_xml_with_hash =
29 "<?xml version='1.0' encoding='UTF-8'?>" 29 "<?xml version='1.0' encoding='UTF-8'?>"
30 "<response protocol='3.0'>" 30 "<response protocol='3.1'>"
31 " <app appid='12345'>" 31 " <app appid='12345'>"
32 " <updatecheck status='ok'>" 32 " <updatecheck status='ok'>"
33 " <urls>" 33 " <urls>"
34 " <url codebase='http://example.com/'/>" 34 " <url codebase='http://example.com/'/>"
35 " </urls>" 35 " </urls>"
36 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 36 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
37 " <packages>" 37 " <packages>"
38 " <package name='extension_1_2_3_4.crx' hash_sha256='1234'" 38 " <package name='extension_1_2_3_4.crx' hash_sha256='1234'"
39 " hashdiff_sha256='5678'/>" 39 " hashdiff_sha256='5678'/>"
40 " </packages>" 40 " </packages>"
41 " </manifest>" 41 " </manifest>"
42 " </updatecheck>" 42 " </updatecheck>"
43 " </app>" 43 " </app>"
44 "</response>"; 44 "</response>";
45 45
46 const char* valid_xml_with_invalid_sizes = 46 const char* valid_xml_with_invalid_sizes =
47 "<?xml version='1.0' encoding='UTF-8'?>" 47 "<?xml version='1.0' encoding='UTF-8'?>"
48 "<response protocol='3.0'>" 48 "<response protocol='3.1'>"
49 " <app appid='12345'>" 49 " <app appid='12345'>"
50 " <updatecheck status='ok'>" 50 " <updatecheck status='ok'>"
51 " <urls>" 51 " <urls>"
52 " <url codebase='http://example.com/'/>" 52 " <url codebase='http://example.com/'/>"
53 " </urls>" 53 " </urls>"
54 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 54 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
55 " <packages>" 55 " <packages>"
56 " <package name='1' size='1234'/>" 56 " <package name='1' size='1234'/>"
57 " <package name='2' size='-1234'/>" 57 " <package name='2' size='-1234'/>"
58 " <package name='3' />" 58 " <package name='3' />"
59 " <package name='4' size='-a'/>" 59 " <package name='4' size='-a'/>"
60 " <package name='5' size='-123467890123456789'/>" 60 " <package name='5' size='-123467890123456789'/>"
61 " <package name='6' size='123467890123456789'/>" 61 " <package name='6' size='123467890123456789'/>"
62 " </packages>" 62 " </packages>"
63 " </manifest>" 63 " </manifest>"
64 " </updatecheck>" 64 " </updatecheck>"
65 " </app>" 65 " </app>"
66 "</response>"; 66 "</response>";
67 67
68 const char* kInvalidValidXmlMissingCodebase = 68 const char* kInvalidValidXmlMissingCodebase =
69 "<?xml version='1.0' encoding='UTF-8'?>" 69 "<?xml version='1.0' encoding='UTF-8'?>"
70 "<response protocol='3.0'>" 70 "<response protocol='3.1'>"
71 " <app appid='12345'>" 71 " <app appid='12345'>"
72 " <updatecheck status='ok'>" 72 " <updatecheck status='ok'>"
73 " <urls>" 73 " <urls>"
74 " <url codebasediff='http://diff.example.com/'/>" 74 " <url codebasediff='http://diff.example.com/'/>"
75 " </urls>" 75 " </urls>"
76 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 76 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
77 " <packages>" 77 " <packages>"
78 " <package namediff='extension_1_2_3_4.crx'/>" 78 " <package namediff='extension_1_2_3_4.crx'/>"
79 " </packages>" 79 " </packages>"
80 " </manifest>" 80 " </manifest>"
81 " </updatecheck>" 81 " </updatecheck>"
82 " </app>" 82 " </app>"
83 "</response>"; 83 "</response>";
84 84
85 const char* kInvalidValidXmlMissingManifest = 85 const char* kInvalidValidXmlMissingManifest =
86 "<?xml version='1.0' encoding='UTF-8'?>" 86 "<?xml version='1.0' encoding='UTF-8'?>"
87 "<response protocol='3.0'>" 87 "<response protocol='3.1'>"
88 " <app appid='12345'>" 88 " <app appid='12345'>"
89 " <updatecheck status='ok'>" 89 " <updatecheck status='ok'>"
90 " <urls>" 90 " <urls>"
91 " <url codebase='http://example.com/'/>" 91 " <url codebase='http://example.com/'/>"
92 " </urls>" 92 " </urls>"
93 " </updatecheck>" 93 " </updatecheck>"
94 " </app>" 94 " </app>"
95 "</response>"; 95 "</response>";
96 96
97 const char* kMissingAppId = 97 const char* kMissingAppId =
98 "<?xml version='1.0'?>" 98 "<?xml version='1.0'?>"
99 "<response protocol='3.0'>" 99 "<response protocol='3.1'>"
100 " <app>" 100 " <app>"
101 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" 101 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
102 " version='1.2.3.4'/>" 102 " version='1.2.3.4'/>"
103 " </app>" 103 " </app>"
104 "</response>"; 104 "</response>";
105 105
106 const char* kInvalidCodebase = 106 const char* kInvalidCodebase =
107 "<?xml version='1.0'?>" 107 "<?xml version='1.0'?>"
108 "<response protocol='3.0'>" 108 "<response protocol='3.1'>"
109 " <app appid='12345' status='ok'>" 109 " <app appid='12345' status='ok'>"
110 " <updatecheck codebase='example.com/extension_1.2.3.4.crx'" 110 " <updatecheck codebase='example.com/extension_1.2.3.4.crx'"
111 " version='1.2.3.4'/>" 111 " version='1.2.3.4'/>"
112 " </app>" 112 " </app>"
113 "</response>"; 113 "</response>";
114 114
115 const char* kMissingVersion = 115 const char* kMissingVersion =
116 "<?xml version='1.0'?>" 116 "<?xml version='1.0'?>"
117 "<response protocol='3.0'>" 117 "<response protocol='3.1'>"
118 " <app appid='12345' status='ok'>" 118 " <app appid='12345' status='ok'>"
119 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'/>" 119 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'/>"
120 " </app>" 120 " </app>"
121 "</response>"; 121 "</response>";
122 122
123 const char* kInvalidVersion = 123 const char* kInvalidVersion =
124 "<?xml version='1.0'?>" 124 "<?xml version='1.0'?>"
125 "<response protocol='3.0'>" 125 "<response protocol='3.1'>"
126 " <app appid='12345' status='ok'>" 126 " <app appid='12345' status='ok'>"
127 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' " 127 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' "
128 " version='1.2.3.a'/>" 128 " version='1.2.3.a'/>"
129 " </app>" 129 " </app>"
130 "</response>"; 130 "</response>";
131 131
132 // The v3 version of the protocol is not using namespaces. However, the parser 132 // The v3 version of the protocol is not using namespaces. However, the parser
133 // must be able to parse responses that include namespaces. 133 // must be able to parse responses that include namespaces.
134 const char* kUsesNamespacePrefix = 134 const char* kUsesNamespacePrefix =
135 "<?xml version='1.0' encoding='UTF-8'?>" 135 "<?xml version='1.0' encoding='UTF-8'?>"
136 "<g:response xmlns:g='http://www.google.com/update2/response' " 136 "<g:response xmlns:g='http://www.google.com/update2/response' "
137 "protocol='3.0'>" 137 "protocol='3.1'>"
138 " <g:app appid='12345'>" 138 " <g:app appid='12345'>"
139 " <g:updatecheck status='ok'>" 139 " <g:updatecheck status='ok'>"
140 " <g:urls>" 140 " <g:urls>"
141 " <g:url codebase='http://example.com/'/>" 141 " <g:url codebase='http://example.com/'/>"
142 " </g:urls>" 142 " </g:urls>"
143 " <g:manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 143 " <g:manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
144 " <g:packages>" 144 " <g:packages>"
145 " <g:package name='extension_1_2_3_4.crx'/>" 145 " <g:package name='extension_1_2_3_4.crx'/>"
146 " </g:packages>" 146 " </g:packages>"
147 " </g:manifest>" 147 " </g:manifest>"
148 " </g:updatecheck>" 148 " </g:updatecheck>"
149 " </g:app>" 149 " </g:app>"
150 "</g:response>"; 150 "</g:response>";
151 151
152 // Includes unrelated <app> tags from other xml namespaces - this should 152 // Includes unrelated <app> tags from other xml namespaces - this should
153 // not cause problems. 153 // not cause problems.
154 const char* kSimilarTagnames = 154 const char* kSimilarTagnames =
155 "<?xml version='1.0' encoding='UTF-8'?>" 155 "<?xml version='1.0' encoding='UTF-8'?>"
156 "<response xmlns:a='http://a' protocol='3.0'>" 156 "<response xmlns:a='http://a' protocol='3.1'>"
157 " <a:app appid='12345'>" 157 " <a:app appid='12345'>"
158 " <updatecheck status='ok'>" 158 " <updatecheck status='ok'>"
159 " <urls>" 159 " <urls>"
160 " <url codebase='http://example.com/'/>" 160 " <url codebase='http://example.com/'/>"
161 " </urls>" 161 " </urls>"
162 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 162 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
163 " <packages>" 163 " <packages>"
164 " <package name='extension_1_2_3_4.crx'/>" 164 " <package name='extension_1_2_3_4.crx'/>"
165 " </packages>" 165 " </packages>"
166 " </manifest>" 166 " </manifest>"
167 " </updatecheck>" 167 " </updatecheck>"
168 " </a:app>" 168 " </a:app>"
169 " <b:app appid='xyz' xmlns:b='http://b'>" 169 " <b:app appid='xyz' xmlns:b='http://b'>"
170 " <updatecheck status='noupdate'/>" 170 " <updatecheck status='noupdate'/>"
171 " </b:app>" 171 " </b:app>"
172 "</response>"; 172 "</response>";
173 173
174 // Includes a <daystart> tag. 174 // Includes a <daystart> tag.
175 const char* kWithDaystart = 175 const char* kWithDaystart =
176 "<?xml version='1.0' encoding='UTF-8'?>" 176 "<?xml version='1.0' encoding='UTF-8'?>"
177 "<response protocol='3.0'>" 177 "<response protocol='3.1'>"
178 " <daystart elapsed_seconds='456'/>" 178 " <daystart elapsed_seconds='456'/>"
179 " <app appid='12345'>" 179 " <app appid='12345'>"
180 " <updatecheck status='ok'>" 180 " <updatecheck status='ok'>"
181 " <urls>" 181 " <urls>"
182 " <url codebase='http://example.com/'/>" 182 " <url codebase='http://example.com/'/>"
183 " </urls>" 183 " </urls>"
184 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 184 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
185 " <packages>" 185 " <packages>"
186 " <package name='extension_1_2_3_4.crx'/>" 186 " <package name='extension_1_2_3_4.crx'/>"
187 " </packages>" 187 " </packages>"
188 " </manifest>" 188 " </manifest>"
189 " </updatecheck>" 189 " </updatecheck>"
190 " </app>" 190 " </app>"
191 "</response>"; 191 "</response>";
192 192
193 // Indicates no updates available - this should not be a parse error. 193 // Indicates no updates available - this should not be a parse error.
194 const char* kNoUpdate = 194 const char* kNoUpdate =
195 "<?xml version='1.0' encoding='UTF-8'?>" 195 "<?xml version='1.0' encoding='UTF-8'?>"
196 "<response protocol='3.0'>" 196 "<response protocol='3.1'>"
197 " <app appid='12345'>" 197 " <app appid='12345'>"
198 " <updatecheck status='noupdate'/>" 198 " <updatecheck status='noupdate'/>"
199 " </app>" 199 " </app>"
200 "</response>"; 200 "</response>";
201 201
202 // Includes two <app> tags, one with an error. 202 // Includes two <app> tags, one with an error.
203 const char* kTwoAppsOneError = 203 const char* kTwoAppsOneError =
204 "<?xml version='1.0' encoding='UTF-8'?>" 204 "<?xml version='1.0' encoding='UTF-8'?>"
205 "<response protocol='3.0'>" 205 "<response protocol='3.1'>"
206 " <app appid='aaaaaaaa' status='error-unknownApplication'>" 206 " <app appid='aaaaaaaa' status='error-unknownApplication'>"
207 " <updatecheck status='error-internal'/>" 207 " <updatecheck status='error-internal'/>"
208 " </app>" 208 " </app>"
209 " <app appid='bbbbbbbb'>" 209 " <app appid='bbbbbbbb'>"
210 " <updatecheck status='ok'>" 210 " <updatecheck status='ok'>"
211 " <urls>" 211 " <urls>"
212 " <url codebase='http://example.com/'/>" 212 " <url codebase='http://example.com/'/>"
213 " </urls>" 213 " </urls>"
214 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 214 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
215 " <packages>" 215 " <packages>"
216 " <package name='extension_1_2_3_4.crx'/>" 216 " <package name='extension_1_2_3_4.crx'/>"
217 " </packages>" 217 " </packages>"
218 " </manifest>" 218 " </manifest>"
219 " </updatecheck>" 219 " </updatecheck>"
220 " </app>" 220 " </app>"
221 "</response>"; 221 "</response>";
222 222
223 // Includes two <app> tags, both of which set the cohort. 223 // Includes two <app> tags, both of which set the cohort.
224 const char* kTwoAppsSetCohort = 224 const char* kTwoAppsSetCohort =
225 "<?xml version='1.0' encoding='UTF-8'?>" 225 "<?xml version='1.0' encoding='UTF-8'?>"
226 "<response protocol='3.0'>" 226 "<response protocol='3.1'>"
227 " <app appid='aaaaaaaa' cohort='1:2q3/'>" 227 " <app appid='aaaaaaaa' cohort='1:2q3/'>"
228 " <updatecheck status='noupdate'/>" 228 " <updatecheck status='noupdate'/>"
229 " </app>" 229 " </app>"
230 " <app appid='bbbbbbbb' cohort='1:33z@0.33' cohortname='cname'>" 230 " <app appid='bbbbbbbb' cohort='1:33z@0.33' cohortname='cname'>"
231 " <updatecheck status='ok'>" 231 " <updatecheck status='ok'>"
232 " <urls>" 232 " <urls>"
233 " <url codebase='http://example.com/'/>" 233 " <url codebase='http://example.com/'/>"
234 " </urls>" 234 " </urls>"
235 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 235 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
236 " <packages>" 236 " <packages>"
237 " <package name='extension_1_2_3_4.crx'/>" 237 " <package name='extension_1_2_3_4.crx'/>"
238 " </packages>" 238 " </packages>"
239 " </manifest>" 239 " </manifest>"
240 " </updatecheck>" 240 " </updatecheck>"
241 " </app>" 241 " </app>"
242 "</response>"; 242 "</response>";
243 243
244 // Includes a run action for an update check with status='ok'. 244 // Includes a run action for an update check with status='ok'.
245 const char* kUpdateCheckStatusOkWithRunAction = 245 const char* kUpdateCheckStatusOkWithRunAction =
246 "<?xml version='1.0' encoding='UTF-8'?>" 246 "<?xml version='1.0' encoding='UTF-8'?>"
247 "<response protocol='3.0'>" 247 "<response protocol='3.1'>"
248 " <app appid='12345'>" 248 " <app appid='12345'>"
249 " <updatecheck status='ok'>" 249 " <updatecheck status='ok'>"
250 " <urls>" 250 " <urls>"
251 " <url codebase='http://example.com/'/>" 251 " <url codebase='http://example.com/'/>"
252 " <url codebasediff='http://diff.example.com/'/>" 252 " <url codebasediff='http://diff.example.com/'/>"
253 " </urls>" 253 " </urls>"
254 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" 254 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
255 " <packages>" 255 " <packages>"
256 " <package name='extension_1_2_3_4.crx'/>" 256 " <package name='extension_1_2_3_4.crx'/>"
257 " </packages>" 257 " </packages>"
258 " </manifest>" 258 " </manifest>"
259 " <actions>" 259 " <actions>"
260 " <action run='this'/>" 260 " <action run='this'/>"
261 " </actions>" 261 " </actions>"
262 " </updatecheck>" 262 " </updatecheck>"
263 " </app>" 263 " </app>"
264 "</response>"; 264 "</response>";
265 265
266 // Includes a run action for an update check with status='noupdate'. 266 // Includes a run action for an update check with status='noupdate'.
267 const char* kUpdateCheckStatusNoUpdateWithRunAction = 267 const char* kUpdateCheckStatusNoUpdateWithRunAction =
268 "<?xml version='1.0' encoding='UTF-8'?>" 268 "<?xml version='1.0' encoding='UTF-8'?>"
269 "<response protocol='3.0'>" 269 "<response protocol='3.1'>"
270 " <app appid='12345'>" 270 " <app appid='12345'>"
271 " <updatecheck status='noupdate'>" 271 " <updatecheck status='noupdate'>"
272 " <actions>" 272 " <actions>"
273 " <action run='this'/>" 273 " <action run='this'/>"
274 " </actions>" 274 " </actions>"
275 " </updatecheck>" 275 " </updatecheck>"
276 " </app>" 276 " </app>"
277 "</response>"; 277 "</response>";
278 278
279 // Includes a run action for an update check with status='error'. 279 // Includes a run action for an update check with status='error'.
280 const char* kUpdateCheckStatusErrorWithRunAction = 280 const char* kUpdateCheckStatusErrorWithRunAction =
281 "<?xml version='1.0' encoding='UTF-8'?>" 281 "<?xml version='1.0' encoding='UTF-8'?>"
282 "<response protocol='3.0'>" 282 "<response protocol='3.1'>"
283 " <app appid='12345' status='ok'>" 283 " <app appid='12345' status='ok'>"
284 " <updatecheck status='error-osnotsupported'>" 284 " <updatecheck status='error-osnotsupported'>"
285 " <actions>" 285 " <actions>"
286 " <action run='this'/>" 286 " <action run='this'/>"
287 " </actions>" 287 " </actions>"
288 " </updatecheck>" 288 " </updatecheck>"
289 " </app>" 289 " </app>"
290 "</response>"; 290 "</response>";
291 291
292 TEST(ComponentUpdaterUpdateResponseTest, TestParser) { 292 TEST(ComponentUpdaterUpdateResponseTest, TestParser) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 EXPECT_STREQ("noupdate", firstResult->status.c_str()); 425 EXPECT_STREQ("noupdate", firstResult->status.c_str());
426 EXPECT_EQ(firstResult->extension_id, "12345"); 426 EXPECT_EQ(firstResult->extension_id, "12345");
427 EXPECT_STREQ("this", firstResult->action_run.c_str()); 427 EXPECT_STREQ("this", firstResult->action_run.c_str());
428 428
429 EXPECT_TRUE(parser.Parse(kUpdateCheckStatusErrorWithRunAction)); 429 EXPECT_TRUE(parser.Parse(kUpdateCheckStatusErrorWithRunAction));
430 EXPECT_FALSE(parser.errors().empty()); 430 EXPECT_FALSE(parser.errors().empty());
431 EXPECT_TRUE(parser.results().list.empty()); 431 EXPECT_TRUE(parser.results().list.empty());
432 } 432 }
433 433
434 } // namespace update_client 434 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/update_response.cc ('k') | components/update_client/utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698