OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "base/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
6 #include "chrome/common/extensions/update_manifest.h" | 6 #include "chrome/browser/component_updater/update_manifest.h" |
7 #include "libxml/globals.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "libxml/globals.h" | |
9 | 9 |
10 static const char* kValidXml = | 10 namespace component_updater { |
11 | |
12 const char* kValidXml = | |
11 "<?xml version='1.0' encoding='UTF-8'?>" | 13 "<?xml version='1.0' encoding='UTF-8'?>" |
12 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" | 14 "<response protocol='3.0'>" |
13 " <app appid='12345'>" | 15 " <app appid='12345'>" |
14 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 16 " <updatecheck status='ok'>" |
15 " version='1.2.3.4' prodversionmin='2.0.143.0' />" | 17 " <urls>" |
18 " <url codebase='http://example.com/'/>" | |
19 " </urls>" | |
20 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" | |
21 " <packages>" | |
22 " <package name='extension_1_2_3_4.crx'/>" | |
23 " </packages>" | |
24 " </manifest>" | |
25 " </updatecheck>" | |
16 " </app>" | 26 " </app>" |
17 "</gupdate>"; | 27 "</response>"; |
18 | 28 |
19 const char *valid_xml_with_hash = | 29 const char *valid_xml_with_hash = |
20 "<?xml version='1.0' encoding='UTF-8'?>" | 30 "<?xml version='1.0' encoding='UTF-8'?>" |
21 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" | 31 "<response protocol='3.0'>" |
22 " <app appid='12345'>" | 32 " <app appid='12345'>" |
23 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 33 " <updatecheck status='ok'>" |
24 " version='1.2.3.4' prodversionmin='2.0.143.0' " | 34 " <urls>" |
25 " hash='1234'/>" | 35 " <url codebase='http://example.com/'/>" |
36 " </urls>" | |
37 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" | |
38 " <packages>" | |
39 " <package name='extension_1_2_3_4.crx' hash_sha256='1234'/>" | |
40 " </packages>" | |
41 " </manifest>" | |
42 " </updatecheck>" | |
26 " </app>" | 43 " </app>" |
27 "</gupdate>"; | 44 "</response>"; |
28 | 45 |
29 static const char* kMissingAppId = | 46 const char* kMissingAppId = |
30 "<?xml version='1.0'?>" | 47 "<?xml version='1.0'?>" |
31 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" | 48 "<response protocol='3.0'>" |
32 " <app>" | 49 " <app>" |
33 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 50 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
34 " version='1.2.3.4' />" | 51 " version='1.2.3.4' />" |
35 " </app>" | 52 " </app>" |
36 "</gupdate>"; | 53 "</response>"; |
37 | 54 |
38 static const char* kInvalidCodebase = | 55 const char* kInvalidCodebase = |
39 "<?xml version='1.0'?>" | 56 "<?xml version='1.0'?>" |
40 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" | 57 "<response protocol='3.0'>" |
41 " <app appid='12345' status='ok'>" | 58 " <app appid='12345' status='ok'>" |
42 " <updatecheck codebase='example.com/extension_1.2.3.4.crx'" | 59 " <updatecheck codebase='example.com/extension_1.2.3.4.crx'" |
43 " version='1.2.3.4' />" | 60 " version='1.2.3.4' />" |
44 " </app>" | 61 " </app>" |
45 "</gupdate>"; | 62 "</response>"; |
46 | 63 |
47 static const char* kMissingVersion = | 64 const char* kMissingVersion = |
48 "<?xml version='1.0'?>" | 65 "<?xml version='1.0'?>" |
49 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" | 66 "<response protocol='3.0'>" |
50 " <app appid='12345' status='ok'>" | 67 " <app appid='12345' status='ok'>" |
51 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' />" | 68 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' />" |
52 " </app>" | 69 " </app>" |
53 "</gupdate>"; | 70 "</response>"; |
54 | 71 |
55 static const char* kInvalidVersion = | 72 const char* kInvalidVersion = |
56 "<?xml version='1.0'?>" | 73 "<?xml version='1.0'?>" |
57 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" | 74 "<response protocol='3.0'>" |
58 " <app appid='12345' status='ok'>" | 75 " <app appid='12345' status='ok'>" |
59 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' " | 76 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' " |
60 " version='1.2.3.a'/>" | 77 " version='1.2.3.a'/>" |
61 " </app>" | 78 " </app>" |
62 "</gupdate>"; | 79 "</response>"; |
63 | 80 |
64 static const char* kUsesNamespacePrefix = | 81 // The v3 version of the protocol is not using namespaces. However, the parser |
82 // must be able to parse responses that include namespaces. | |
83 const char* kUsesNamespacePrefix = | |
65 "<?xml version='1.0' encoding='UTF-8'?>" | 84 "<?xml version='1.0' encoding='UTF-8'?>" |
66 "<g:gupdate xmlns:g='http://www.google.com/update2/response' protocol='2.0'>" | 85 "<g:response xmlns='http://www.google.com/update2/response' protocol='3.0'>" |
67 " <g:app appid='12345'>" | 86 " <g:app appid='12345'>" |
68 " <g:updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 87 " <g:updatecheck status='ok'>" |
69 " version='1.2.3.4' prodversionmin='2.0.143.0' />" | 88 " <g:urls>" |
89 " <g:url codebase='http://example.com/'/>" | |
90 " </g:urls>" | |
91 " <g:manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" | |
92 " <g:packages>" | |
93 " <g:package name='extension_1_2_3_4.crx'/>" | |
94 " </g:packages>" | |
95 " </g:manifest>" | |
96 " </g:updatecheck>" | |
70 " </g:app>" | 97 " </g:app>" |
71 "</g:gupdate>"; | 98 "</g:response>"; |
72 | 99 |
73 // Includes unrelated <app> tags from other xml namespaces - this should | 100 // Includes unrelated <app> tags from other xml namespaces - this should |
74 // not cause problems. | 101 // not cause problems. |
75 static const char* kSimilarTagnames = | 102 const char* kSimilarTagnames = |
76 "<?xml version='1.0' encoding='UTF-8'?>" | 103 "<?xml version='1.0' encoding='UTF-8'?>" |
77 "<gupdate xmlns='http://www.google.com/update2/response'" | 104 "<response xmlns:a='http://a' protocol='3.0'>" |
78 " xmlns:a='http://a' protocol='2.0'>" | 105 " <a:app appid='12345'>" |
79 " <a:app/>" | 106 " <updatecheck status='ok'>" |
80 " <b:app xmlns:b='http://b' />" | 107 " <urls>" |
81 " <app appid='12345'>" | 108 " <url codebase='http://example.com/'/>" |
82 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 109 " </urls>" |
83 " version='1.2.3.4' prodversionmin='2.0.143.0' />" | 110 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
84 " </app>" | 111 " <packages>" |
85 "</gupdate>"; | 112 " <package name='extension_1_2_3_4.crx'/>" |
113 " </packages>" | |
114 " </manifest>" | |
115 " </updatecheck>" | |
116 " </a:app>" | |
117 " <b:app appid='xyz' xmlns:b='http://b'>" | |
118 " <updatecheck status='noupdate'/>" | |
119 " </b:app>" | |
120 "</response>"; | |
86 | 121 |
87 // Includes a <daystart> tag. | 122 // Includes a <daystart> tag. |
88 static const char* kWithDaystart = | 123 const char* kWithDaystart = |
89 "<?xml version='1.0' encoding='UTF-8'?>" | 124 "<?xml version='1.0' encoding='UTF-8'?>" |
90 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" | 125 "<response protocol='3.0'>" |
91 " <daystart elapsed_seconds='456' />" | 126 " <daystart elapsed_seconds='456' />" |
92 " <app appid='12345'>" | 127 " <app appid='12345'>" |
93 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" | 128 " <updatecheck status='ok'>" |
94 " version='1.2.3.4' prodversionmin='2.0.143.0' />" | 129 " <urls>" |
130 " <url codebase='http://example.com/'/>" | |
131 " </urls>" | |
132 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" | |
133 " <packages>" | |
134 " <package name='extension_1_2_3_4.crx'/>" | |
135 " </packages>" | |
136 " </manifest>" | |
137 " </updatecheck>" | |
95 " </app>" | 138 " </app>" |
96 "</gupdate>"; | 139 "</response>"; |
97 | 140 |
98 // Indicates no updates available - this should not be a parse error. | 141 // Indicates no updates available - this should not be a parse error. |
99 static const char* kNoUpdate = | 142 const char* kNoUpdate = |
100 "<?xml version='1.0' encoding='UTF-8'?>" | 143 "<?xml version='1.0' encoding='UTF-8'?>" |
101 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" | 144 "<response protocol='3.0'>" |
102 " <app appid='12345'>" | 145 " <app appid='12345'>" |
103 " <updatecheck status='noupdate' />" | 146 " <updatecheck status='noupdate' />" |
104 " </app>" | 147 " </app>" |
105 "</gupdate>"; | 148 "</response>"; |
106 | 149 |
107 // Includes two <app> tags, one with an error. | 150 // Includes two <app> tags, one with an error. |
108 static const char* kTwoAppsOneError = | 151 const char* kTwoAppsOneError = |
109 "<?xml version='1.0' encoding='UTF-8'?>" | 152 "<?xml version='1.0' encoding='UTF-8'?>" |
110 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" | 153 "<response protocol='3.0'>" |
111 " <app appid='aaaaaaaa' status='error-unknownApplication'>" | 154 " <app appid='aaaaaaaa' status='error-unknownApplication'>" |
112 " <updatecheck status='error-unknownapplication'/>" | 155 " <updatecheck status='error-unknownapplication'/>" |
113 " </app>" | 156 " </app>" |
114 " <app appid='bbbbbbbb'>" | 157 " <app appid='bbbbbbbb'>" |
115 " <updatecheck codebase='http://example.com/b_3.1.crx' version='3.1'/>" | 158 " <updatecheck status='ok'>" |
159 " <urls>" | |
160 " <url codebase='http://example.com/'/>" | |
161 " </urls>" | |
162 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" | |
163 " <packages>" | |
164 " <package name='extension_1_2_3_4.crx'/>" | |
165 " </packages>" | |
166 " </manifest>" | |
167 " </updatecheck>" | |
116 " </app>" | 168 " </app>" |
117 "</gupdate>"; | 169 "</response>"; |
118 | 170 |
waffles
2013/11/18 22:15:59
Should we add a test for a response with diffs?
Sorin Jianu
2013/11/19 04:25:45
I've added a quick test.
| |
119 TEST(ExtensionUpdateManifestTest, TestUpdateManifest) { | 171 TEST(ComponentUpdaterManifestTest, TestUpdateManifest) { |
120 UpdateManifest parser; | 172 UpdateManifest parser; |
121 | 173 |
122 // Test parsing of a number of invalid xml cases | 174 // Test parsing of a number of invalid xml cases |
123 EXPECT_FALSE(parser.Parse(std::string())); | 175 EXPECT_FALSE(parser.Parse(std::string())); |
124 EXPECT_FALSE(parser.errors().empty()); | 176 EXPECT_FALSE(parser.errors().empty()); |
125 | 177 |
126 EXPECT_TRUE(parser.Parse(kMissingAppId)); | 178 EXPECT_TRUE(parser.Parse(kMissingAppId)); |
127 EXPECT_TRUE(parser.results().list.empty()); | 179 EXPECT_TRUE(parser.results().list.empty()); |
128 EXPECT_FALSE(parser.errors().empty()); | 180 EXPECT_FALSE(parser.errors().empty()); |
129 | 181 |
130 EXPECT_TRUE(parser.Parse(kInvalidCodebase)); | 182 EXPECT_TRUE(parser.Parse(kInvalidCodebase)); |
131 EXPECT_TRUE(parser.results().list.empty()); | 183 EXPECT_TRUE(parser.results().list.empty()); |
132 EXPECT_FALSE(parser.errors().empty()); | 184 EXPECT_FALSE(parser.errors().empty()); |
133 | 185 |
134 EXPECT_TRUE(parser.Parse(kMissingVersion)); | 186 EXPECT_TRUE(parser.Parse(kMissingVersion)); |
135 EXPECT_TRUE(parser.results().list.empty()); | 187 EXPECT_TRUE(parser.results().list.empty()); |
136 EXPECT_FALSE(parser.errors().empty()); | 188 EXPECT_FALSE(parser.errors().empty()); |
137 | 189 |
138 EXPECT_TRUE(parser.Parse(kInvalidVersion)); | 190 EXPECT_TRUE(parser.Parse(kInvalidVersion)); |
139 EXPECT_TRUE(parser.results().list.empty()); | 191 EXPECT_TRUE(parser.results().list.empty()); |
140 EXPECT_FALSE(parser.errors().empty()); | 192 EXPECT_FALSE(parser.errors().empty()); |
141 | 193 |
142 // Parse some valid XML, and check that all params came out as expected | 194 // Parse some valid XML, and check that all params came out as expected |
143 EXPECT_TRUE(parser.Parse(kValidXml)); | 195 EXPECT_TRUE(parser.Parse(kValidXml)); |
144 EXPECT_TRUE(parser.errors().empty()); | 196 EXPECT_TRUE(parser.errors().empty()); |
145 EXPECT_FALSE(parser.results().list.empty()); | 197 EXPECT_EQ(1u, parser.results().list.size()); |
146 const UpdateManifest::Result* firstResult = &parser.results().list.at(0); | 198 const UpdateManifest::Result* firstResult = &parser.results().list[0]; |
147 EXPECT_EQ(GURL("http://example.com/extension_1.2.3.4.crx"), | 199 EXPECT_EQ(1u, firstResult->crx_urls.size()); |
148 firstResult->crx_url); | 200 EXPECT_EQ(GURL("http://example.com/"), firstResult->crx_urls[0]); |
149 | 201 EXPECT_EQ("1.2.3.4", firstResult->manifest.version); |
150 EXPECT_EQ("1.2.3.4", firstResult->version); | 202 EXPECT_EQ("2.0.143.0", firstResult->manifest.browser_min_version); |
151 EXPECT_EQ("2.0.143.0", firstResult->browser_min_version); | 203 EXPECT_EQ(1u, firstResult->manifest.packages.size()); |
204 EXPECT_EQ("extension_1_2_3_4.crx", firstResult->manifest.packages[0].name); | |
152 | 205 |
153 // Parse some xml that uses namespace prefixes. | 206 // Parse some xml that uses namespace prefixes. |
154 EXPECT_TRUE(parser.Parse(kUsesNamespacePrefix)); | 207 EXPECT_TRUE(parser.Parse(kUsesNamespacePrefix)); |
155 EXPECT_TRUE(parser.errors().empty()); | 208 EXPECT_TRUE(parser.errors().empty()); |
156 EXPECT_TRUE(parser.Parse(kSimilarTagnames)); | 209 EXPECT_TRUE(parser.Parse(kSimilarTagnames)); |
157 EXPECT_TRUE(parser.errors().empty()); | 210 EXPECT_TRUE(parser.errors().empty()); |
158 xmlCleanupGlobals(); | 211 xmlCleanupGlobals(); |
159 | 212 |
160 // Parse xml with hash value | 213 // Parse xml with hash value |
161 EXPECT_TRUE(parser.Parse(valid_xml_with_hash)); | 214 EXPECT_TRUE(parser.Parse(valid_xml_with_hash)); |
162 EXPECT_TRUE(parser.errors().empty()); | 215 EXPECT_TRUE(parser.errors().empty()); |
163 EXPECT_FALSE(parser.results().list.empty()); | 216 EXPECT_FALSE(parser.results().list.empty()); |
164 firstResult = &parser.results().list.at(0); | 217 firstResult = &parser.results().list[0]; |
165 EXPECT_EQ("1234", firstResult->package_hash); | 218 EXPECT_FALSE(firstResult->manifest.packages.empty()); |
219 EXPECT_EQ("1234", firstResult->manifest.packages[0].hash_sha256); | |
166 | 220 |
167 // Parse xml with a <daystart> element. | 221 // Parse xml with a <daystart> element. |
168 EXPECT_TRUE(parser.Parse(kWithDaystart)); | 222 EXPECT_TRUE(parser.Parse(kWithDaystart)); |
169 EXPECT_TRUE(parser.errors().empty()); | 223 EXPECT_TRUE(parser.errors().empty()); |
170 EXPECT_FALSE(parser.results().list.empty()); | 224 EXPECT_FALSE(parser.results().list.empty()); |
171 EXPECT_EQ(parser.results().daystart_elapsed_seconds, 456); | 225 EXPECT_EQ(parser.results().daystart_elapsed_seconds, 456); |
172 | 226 |
173 // Parse a no-update response. | 227 // Parse a no-update response. |
174 EXPECT_TRUE(parser.Parse(kNoUpdate)); | 228 EXPECT_TRUE(parser.Parse(kNoUpdate)); |
175 EXPECT_TRUE(parser.errors().empty()); | 229 EXPECT_TRUE(parser.errors().empty()); |
176 EXPECT_FALSE(parser.results().list.empty()); | 230 EXPECT_FALSE(parser.results().list.empty()); |
177 firstResult = &parser.results().list.at(0); | 231 firstResult = &parser.results().list[0]; |
178 EXPECT_EQ(firstResult->extension_id, "12345"); | 232 EXPECT_EQ(firstResult->extension_id, "12345"); |
179 EXPECT_EQ(firstResult->version, ""); | 233 EXPECT_EQ(firstResult->manifest.version, ""); |
180 | 234 |
181 // Parse xml with one error and one success <app> tag. | 235 // Parse xml with one error and one success <app> tag. |
182 EXPECT_TRUE(parser.Parse(kTwoAppsOneError)); | 236 EXPECT_TRUE(parser.Parse(kTwoAppsOneError)); |
183 EXPECT_FALSE(parser.errors().empty()); | 237 EXPECT_FALSE(parser.errors().empty()); |
184 EXPECT_EQ(1u, parser.results().list.size()); | 238 EXPECT_EQ(1u, parser.results().list.size()); |
185 firstResult = &parser.results().list.at(0); | 239 firstResult = &parser.results().list[0]; |
186 EXPECT_EQ(firstResult->extension_id, "bbbbbbbb"); | 240 EXPECT_EQ(firstResult->extension_id, "bbbbbbbb"); |
187 } | 241 } |
242 | |
243 } // namespace component_updater | |
244 | |
OLD | NEW |