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

Side by Side Diff: chrome/browser/component_updater/test/update_manifest_unittest.cc

Issue 74893002: Changed the update protocol for component updater from v2 to v3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed feedback from cdn@ Created 7 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/scoped_vector.h"
6 #include "chrome/browser/component_updater/update_manifest.h"
7 #include "libxml/globals.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace component_updater {
11
12 const char* kValidXml =
13 "<?xml version='1.0' encoding='UTF-8'?>"
14 "<response protocol='3.0'>"
15 " <app appid='12345'>"
16 " <updatecheck status='ok'>"
17 " <urls>"
18 " <url codebase='http://example.com/'/>"
19 " <url codebasediff='http://diff.example.com/'/>"
20 " </urls>"
21 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
22 " <packages>"
23 " <package name='extension_1_2_3_4.crx'/>"
24 " </packages>"
25 " </manifest>"
26 " </updatecheck>"
27 " </app>"
28 "</response>";
29
30 const char* valid_xml_with_hash =
31 "<?xml version='1.0' encoding='UTF-8'?>"
32 "<response protocol='3.0'>"
33 " <app appid='12345'>"
34 " <updatecheck status='ok'>"
35 " <urls>"
36 " <url codebase='http://example.com/'/>"
37 " </urls>"
38 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
39 " <packages>"
40 " <package name='extension_1_2_3_4.crx' hash_sha256='1234'/>"
41 " </packages>"
42 " </manifest>"
43 " </updatecheck>"
44 " </app>"
45 "</response>";
46
47 const char* valid_xml_with_invalid_sizes =
48 "<?xml version='1.0' encoding='UTF-8'?>"
49 "<response protocol='3.0'>"
50 " <app appid='12345'>"
51 " <updatecheck status='ok'>"
52 " <urls>"
53 " <url codebase='http://example.com/'/>"
54 " </urls>"
55 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
56 " <packages>"
57 " <package name='1' size='1234'/>"
58 " <package name='2' size='-1234'/>"
59 " <package name='3' />"
60 " <package name='4' size='-a'/>"
61 " <package name='5' size='-123467890123456789'/>"
62 " <package name='6' size='123467890123456789'/>"
63 " </packages>"
64 " </manifest>"
65 " </updatecheck>"
66 " </app>"
67 "</response>";
68
69 const char* kMissingAppId =
70 "<?xml version='1.0'?>"
71 "<response protocol='3.0'>"
72 " <app>"
73 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
74 " version='1.2.3.4' />"
75 " </app>"
76 "</response>";
77
78 const char* kInvalidCodebase =
79 "<?xml version='1.0'?>"
80 "<response protocol='3.0'>"
81 " <app appid='12345' status='ok'>"
82 " <updatecheck codebase='example.com/extension_1.2.3.4.crx'"
83 " version='1.2.3.4' />"
84 " </app>"
85 "</response>";
86
87 const char* kMissingVersion =
88 "<?xml version='1.0'?>"
89 "<response protocol='3.0'>"
90 " <app appid='12345' status='ok'>"
91 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' />"
92 " </app>"
93 "</response>";
94
95 const char* kInvalidVersion =
96 "<?xml version='1.0'?>"
97 "<response protocol='3.0'>"
98 " <app appid='12345' status='ok'>"
99 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' "
100 " version='1.2.3.a'/>"
101 " </app>"
102 "</response>";
103
104 // The v3 version of the protocol is not using namespaces. However, the parser
105 // must be able to parse responses that include namespaces.
106 const char* kUsesNamespacePrefix =
107 "<?xml version='1.0' encoding='UTF-8'?>"
108 "<g:response xmlns='http://www.google.com/update2/response' protocol='3.0'>"
109 " <g:app appid='12345'>"
110 " <g:updatecheck status='ok'>"
111 " <g:urls>"
112 " <g:url codebase='http://example.com/'/>"
113 " </g:urls>"
114 " <g:manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
115 " <g:packages>"
116 " <g:package name='extension_1_2_3_4.crx'/>"
117 " </g:packages>"
118 " </g:manifest>"
119 " </g:updatecheck>"
120 " </g:app>"
121 "</g:response>";
122
123 // Includes unrelated <app> tags from other xml namespaces - this should
124 // not cause problems.
125 const char* kSimilarTagnames =
126 "<?xml version='1.0' encoding='UTF-8'?>"
127 "<response xmlns:a='http://a' protocol='3.0'>"
128 " <a:app appid='12345'>"
129 " <updatecheck status='ok'>"
130 " <urls>"
131 " <url codebase='http://example.com/'/>"
132 " </urls>"
133 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
134 " <packages>"
135 " <package name='extension_1_2_3_4.crx'/>"
136 " </packages>"
137 " </manifest>"
138 " </updatecheck>"
139 " </a:app>"
140 " <b:app appid='xyz' xmlns:b='http://b'>"
141 " <updatecheck status='noupdate'/>"
142 " </b:app>"
143 "</response>";
144
145 // Includes a <daystart> tag.
146 const char* kWithDaystart =
147 "<?xml version='1.0' encoding='UTF-8'?>"
148 "<response protocol='3.0'>"
149 " <daystart elapsed_seconds='456' />"
150 " <app appid='12345'>"
151 " <updatecheck status='ok'>"
152 " <urls>"
153 " <url codebase='http://example.com/'/>"
154 " </urls>"
155 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
156 " <packages>"
157 " <package name='extension_1_2_3_4.crx'/>"
158 " </packages>"
159 " </manifest>"
160 " </updatecheck>"
161 " </app>"
162 "</response>";
163
164 // Indicates no updates available - this should not be a parse error.
165 const char* kNoUpdate =
166 "<?xml version='1.0' encoding='UTF-8'?>"
167 "<response protocol='3.0'>"
168 " <app appid='12345'>"
169 " <updatecheck status='noupdate' />"
170 " </app>"
171 "</response>";
172
173 // Includes two <app> tags, one with an error.
174 const char* kTwoAppsOneError =
175 "<?xml version='1.0' encoding='UTF-8'?>"
176 "<response protocol='3.0'>"
177 " <app appid='aaaaaaaa' status='error-unknownApplication'>"
178 " <updatecheck status='error-unknownapplication'/>"
179 " </app>"
180 " <app appid='bbbbbbbb'>"
181 " <updatecheck status='ok'>"
182 " <urls>"
183 " <url codebase='http://example.com/'/>"
184 " </urls>"
185 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
186 " <packages>"
187 " <package name='extension_1_2_3_4.crx'/>"
188 " </packages>"
189 " </manifest>"
190 " </updatecheck>"
191 " </app>"
192 "</response>";
193
194 TEST(ComponentUpdaterManifestTest, TestUpdateManifest) {
195 UpdateManifest parser;
196
197 // Test parsing of a number of invalid xml cases
198 EXPECT_FALSE(parser.Parse(std::string()));
199 EXPECT_FALSE(parser.errors().empty());
200
201 EXPECT_TRUE(parser.Parse(kMissingAppId));
202 EXPECT_TRUE(parser.results().list.empty());
203 EXPECT_FALSE(parser.errors().empty());
204
205 EXPECT_TRUE(parser.Parse(kInvalidCodebase));
206 EXPECT_TRUE(parser.results().list.empty());
207 EXPECT_FALSE(parser.errors().empty());
208
209 EXPECT_TRUE(parser.Parse(kMissingVersion));
210 EXPECT_TRUE(parser.results().list.empty());
211 EXPECT_FALSE(parser.errors().empty());
212
213 EXPECT_TRUE(parser.Parse(kInvalidVersion));
214 EXPECT_TRUE(parser.results().list.empty());
215 EXPECT_FALSE(parser.errors().empty());
216
217 // Parse some valid XML, and check that all params came out as expected
218 EXPECT_TRUE(parser.Parse(kValidXml));
219 EXPECT_TRUE(parser.errors().empty());
220 EXPECT_EQ(1u, parser.results().list.size());
221 const UpdateManifest::Result* firstResult = &parser.results().list[0];
222 EXPECT_EQ(1u, firstResult->crx_urls.size());
223 EXPECT_EQ(GURL("http://example.com/"), firstResult->crx_urls[0]);
224 EXPECT_EQ(GURL("http://diff.example.com/"), firstResult->crx_diffurls[0]);
225 EXPECT_EQ("1.2.3.4", firstResult->manifest.version);
226 EXPECT_EQ("2.0.143.0", firstResult->manifest.browser_min_version);
227 EXPECT_EQ(1u, firstResult->manifest.packages.size());
228 EXPECT_EQ("extension_1_2_3_4.crx", firstResult->manifest.packages[0].name);
229
230 // Parse some xml that uses namespace prefixes.
231 EXPECT_TRUE(parser.Parse(kUsesNamespacePrefix));
232 EXPECT_TRUE(parser.errors().empty());
233 EXPECT_TRUE(parser.Parse(kSimilarTagnames));
234 EXPECT_TRUE(parser.errors().empty());
235 xmlCleanupGlobals();
236
237 // Parse xml with hash value
238 EXPECT_TRUE(parser.Parse(valid_xml_with_hash));
239 EXPECT_TRUE(parser.errors().empty());
240 EXPECT_FALSE(parser.results().list.empty());
241 firstResult = &parser.results().list[0];
242 EXPECT_FALSE(firstResult->manifest.packages.empty());
243 EXPECT_EQ("1234", firstResult->manifest.packages[0].hash_sha256);
244
245 // Parse xml with package size value
246 EXPECT_TRUE(parser.Parse(valid_xml_with_invalid_sizes));
247 EXPECT_TRUE(parser.errors().empty());
248 EXPECT_FALSE(parser.results().list.empty());
249 firstResult = &parser.results().list[0];
250 EXPECT_FALSE(firstResult->manifest.packages.empty());
251 EXPECT_EQ(1234, firstResult->manifest.packages[0].size);
252 EXPECT_EQ(-1234, firstResult->manifest.packages[1].size);
253 EXPECT_EQ(0, firstResult->manifest.packages[2].size);
254 EXPECT_EQ(0, firstResult->manifest.packages[3].size);
255 EXPECT_EQ(0, firstResult->manifest.packages[4].size);
256 EXPECT_EQ(0, firstResult->manifest.packages[5].size);
257
258 // Parse xml with a <daystart> element.
259 EXPECT_TRUE(parser.Parse(kWithDaystart));
260 EXPECT_TRUE(parser.errors().empty());
261 EXPECT_FALSE(parser.results().list.empty());
262 EXPECT_EQ(parser.results().daystart_elapsed_seconds, 456);
263
264 // Parse a no-update response.
265 EXPECT_TRUE(parser.Parse(kNoUpdate));
266 EXPECT_TRUE(parser.errors().empty());
267 EXPECT_FALSE(parser.results().list.empty());
268 firstResult = &parser.results().list[0];
269 EXPECT_EQ(firstResult->extension_id, "12345");
270 EXPECT_EQ(firstResult->manifest.version, "");
271
272 // Parse xml with one error and one success <app> tag.
273 EXPECT_TRUE(parser.Parse(kTwoAppsOneError));
274 EXPECT_FALSE(parser.errors().empty());
275 EXPECT_EQ(1u, parser.results().list.size());
276 firstResult = &parser.results().list[0];
277 EXPECT_EQ(firstResult->extension_id, "bbbbbbbb");
278 }
279
280 } // namespace component_updater
281
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698