[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 5 | #include "components/update_client/protocol_parser_xml.h" |
| 6 | |
| 7 | #include <memory> |
| 8 | |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
| 10 | |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 11 | namespace update_client { |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 12 | |
| 13 | const char* kValidXml = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 14 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 15 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 16 | " <app appid='12345'>" |
| 17 | " <updatecheck status='ok'>" |
| 18 | " <urls>" |
| 19 | " <url codebase='http://example.com/'/>" |
| 20 | " <url codebasediff='http://diff.example.com/'/>" |
| 21 | " </urls>" |
| 22 | " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 23 | " <packages>" |
| 24 | " <package name='extension_1_2_3_4.crx'/>" |
| 25 | " </packages>" |
| 26 | " </manifest>" |
| 27 | " </updatecheck>" |
| 28 | " </app>" |
| 29 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 30 | |
| 31 | const char* valid_xml_with_hash = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 32 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 33 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 34 | " <app appid='12345'>" |
| 35 | " <updatecheck status='ok'>" |
| 36 | " <urls>" |
| 37 | " <url codebase='http://example.com/'/>" |
| 38 | " </urls>" |
| 39 | " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 40 | " <packages>" |
sorin | 74e7067 | 2016-02-03 03:13:10 | [diff] [blame] | 41 | " <package name='extension_1_2_3_4.crx' hash_sha256='1234'" |
| 42 | " hashdiff_sha256='5678'/>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 43 | " </packages>" |
| 44 | " </manifest>" |
| 45 | " </updatecheck>" |
| 46 | " </app>" |
| 47 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 48 | |
| 49 | const char* valid_xml_with_invalid_sizes = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 50 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 51 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 52 | " <app appid='12345'>" |
| 53 | " <updatecheck status='ok'>" |
| 54 | " <urls>" |
| 55 | " <url codebase='http://example.com/'/>" |
| 56 | " </urls>" |
| 57 | " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 58 | " <packages>" |
| 59 | " <package name='1' size='1234'/>" |
| 60 | " <package name='2' size='-1234'/>" |
| 61 | " <package name='3' />" |
| 62 | " <package name='4' size='-a'/>" |
| 63 | " <package name='5' size='-123467890123456789'/>" |
| 64 | " <package name='6' size='123467890123456789'/>" |
| 65 | " </packages>" |
| 66 | " </manifest>" |
| 67 | " </updatecheck>" |
| 68 | " </app>" |
| 69 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 70 | |
[email protected] | da37c1d | 2013-12-19 01:04:38 | [diff] [blame] | 71 | const char* kInvalidValidXmlMissingCodebase = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 72 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 73 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 74 | " <app appid='12345'>" |
| 75 | " <updatecheck status='ok'>" |
| 76 | " <urls>" |
| 77 | " <url codebasediff='http://diff.example.com/'/>" |
| 78 | " </urls>" |
| 79 | " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 80 | " <packages>" |
| 81 | " <package namediff='extension_1_2_3_4.crx'/>" |
| 82 | " </packages>" |
| 83 | " </manifest>" |
| 84 | " </updatecheck>" |
| 85 | " </app>" |
| 86 | "</response>"; |
[email protected] | da37c1d | 2013-12-19 01:04:38 | [diff] [blame] | 87 | |
sorin | 7af7f8ef | 2015-05-28 23:49:03 | [diff] [blame] | 88 | const char* kInvalidValidXmlMissingManifest = |
| 89 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 90 | "<response protocol='3.1'>" |
sorin | 7af7f8ef | 2015-05-28 23:49:03 | [diff] [blame] | 91 | " <app appid='12345'>" |
| 92 | " <updatecheck status='ok'>" |
| 93 | " <urls>" |
| 94 | " <url codebase='http://example.com/'/>" |
| 95 | " </urls>" |
| 96 | " </updatecheck>" |
| 97 | " </app>" |
| 98 | "</response>"; |
| 99 | |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 100 | const char* kMissingAppId = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 101 | "<?xml version='1.0'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 102 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 103 | " <app>" |
| 104 | " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
sorin | 46bdd0b3 | 2016-08-30 22:42:26 | [diff] [blame] | 105 | " version='1.2.3.4'/>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 106 | " </app>" |
| 107 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 108 | |
| 109 | const char* kInvalidCodebase = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 110 | "<?xml version='1.0'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 111 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 112 | " <app appid='12345' status='ok'>" |
| 113 | " <updatecheck codebase='example.com/extension_1.2.3.4.crx'" |
sorin | 46bdd0b3 | 2016-08-30 22:42:26 | [diff] [blame] | 114 | " version='1.2.3.4'/>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 115 | " </app>" |
| 116 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 117 | |
| 118 | const char* kMissingVersion = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 119 | "<?xml version='1.0'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 120 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 121 | " <app appid='12345' status='ok'>" |
sorin | 46bdd0b3 | 2016-08-30 22:42:26 | [diff] [blame] | 122 | " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'/>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 123 | " </app>" |
| 124 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 125 | |
| 126 | const char* kInvalidVersion = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 127 | "<?xml version='1.0'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 128 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 129 | " <app appid='12345' status='ok'>" |
| 130 | " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' " |
| 131 | " version='1.2.3.a'/>" |
| 132 | " </app>" |
| 133 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 134 | |
| 135 | // The v3 version of the protocol is not using namespaces. However, the parser |
| 136 | // must be able to parse responses that include namespaces. |
| 137 | const char* kUsesNamespacePrefix = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 138 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 139 | "<g:response xmlns:g='http://www.google.com/update2/response' " |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 140 | "protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 141 | " <g:app appid='12345'>" |
| 142 | " <g:updatecheck status='ok'>" |
| 143 | " <g:urls>" |
| 144 | " <g:url codebase='http://example.com/'/>" |
| 145 | " </g:urls>" |
| 146 | " <g:manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 147 | " <g:packages>" |
| 148 | " <g:package name='extension_1_2_3_4.crx'/>" |
| 149 | " </g:packages>" |
| 150 | " </g:manifest>" |
| 151 | " </g:updatecheck>" |
| 152 | " </g:app>" |
| 153 | "</g:response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 154 | |
| 155 | // Includes unrelated <app> tags from other xml namespaces - this should |
| 156 | // not cause problems. |
| 157 | const char* kSimilarTagnames = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 158 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 159 | "<response xmlns:a='http://a' protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 160 | " <a:app appid='12345'>" |
| 161 | " <updatecheck status='ok'>" |
| 162 | " <urls>" |
| 163 | " <url codebase='http://example.com/'/>" |
| 164 | " </urls>" |
| 165 | " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 166 | " <packages>" |
| 167 | " <package name='extension_1_2_3_4.crx'/>" |
| 168 | " </packages>" |
| 169 | " </manifest>" |
| 170 | " </updatecheck>" |
| 171 | " </a:app>" |
| 172 | " <b:app appid='xyz' xmlns:b='http://b'>" |
| 173 | " <updatecheck status='noupdate'/>" |
| 174 | " </b:app>" |
| 175 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 176 | |
| 177 | // Includes a <daystart> tag. |
| 178 | const char* kWithDaystart = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 179 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 180 | "<response protocol='3.1'>" |
sorin | 46bdd0b3 | 2016-08-30 22:42:26 | [diff] [blame] | 181 | " <daystart elapsed_seconds='456'/>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 182 | " <app appid='12345'>" |
| 183 | " <updatecheck status='ok'>" |
| 184 | " <urls>" |
| 185 | " <url codebase='http://example.com/'/>" |
| 186 | " </urls>" |
| 187 | " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 188 | " <packages>" |
| 189 | " <package name='extension_1_2_3_4.crx'/>" |
| 190 | " </packages>" |
| 191 | " </manifest>" |
| 192 | " </updatecheck>" |
| 193 | " </app>" |
| 194 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 195 | |
| 196 | // Indicates no updates available - this should not be a parse error. |
| 197 | const char* kNoUpdate = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 198 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 199 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 200 | " <app appid='12345'>" |
sorin | 46bdd0b3 | 2016-08-30 22:42:26 | [diff] [blame] | 201 | " <updatecheck status='noupdate'/>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 202 | " </app>" |
| 203 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 204 | |
| 205 | // Includes two <app> tags, one with an error. |
| 206 | const char* kTwoAppsOneError = |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 207 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 208 | "<response protocol='3.1'>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 209 | " <app appid='aaaaaaaa' status='error-unknownApplication'>" |
sorin | 9ef301c | 2017-02-16 20:29:17 | [diff] [blame] | 210 | " <updatecheck status='error-internal'/>" |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 211 | " </app>" |
| 212 | " <app appid='bbbbbbbb'>" |
| 213 | " <updatecheck status='ok'>" |
| 214 | " <urls>" |
| 215 | " <url codebase='http://example.com/'/>" |
| 216 | " </urls>" |
| 217 | " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 218 | " <packages>" |
| 219 | " <package name='extension_1_2_3_4.crx'/>" |
| 220 | " </packages>" |
| 221 | " </manifest>" |
| 222 | " </updatecheck>" |
| 223 | " </app>" |
| 224 | "</response>"; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 225 | |
waffles | f43eb2fd3 | 2016-08-23 19:15:29 | [diff] [blame] | 226 | // Includes two <app> tags, both of which set the cohort. |
| 227 | const char* kTwoAppsSetCohort = |
| 228 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 229 | "<response protocol='3.1'>" |
waffles | f43eb2fd3 | 2016-08-23 19:15:29 | [diff] [blame] | 230 | " <app appid='aaaaaaaa' cohort='1:2q3/'>" |
| 231 | " <updatecheck status='noupdate'/>" |
| 232 | " </app>" |
| 233 | " <app appid='bbbbbbbb' cohort='1:[email protected]' cohortname='cname'>" |
| 234 | " <updatecheck status='ok'>" |
| 235 | " <urls>" |
| 236 | " <url codebase='http://example.com/'/>" |
| 237 | " </urls>" |
| 238 | " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 239 | " <packages>" |
| 240 | " <package name='extension_1_2_3_4.crx'/>" |
| 241 | " </packages>" |
| 242 | " </manifest>" |
| 243 | " </updatecheck>" |
| 244 | " </app>" |
| 245 | "</response>"; |
| 246 | |
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 247 | // Includes a run action for an update check with status='ok'. |
| 248 | const char* kUpdateCheckStatusOkWithRunAction = |
| 249 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 250 | "<response protocol='3.1'>" |
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 251 | " <app appid='12345'>" |
| 252 | " <updatecheck status='ok'>" |
| 253 | " <urls>" |
| 254 | " <url codebase='http://example.com/'/>" |
| 255 | " <url codebasediff='http://diff.example.com/'/>" |
| 256 | " </urls>" |
| 257 | " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 258 | " <packages>" |
| 259 | " <package name='extension_1_2_3_4.crx'/>" |
| 260 | " </packages>" |
| 261 | " </manifest>" |
| 262 | " <actions>" |
| 263 | " <action run='this'/>" |
| 264 | " </actions>" |
| 265 | " </updatecheck>" |
| 266 | " </app>" |
| 267 | "</response>"; |
| 268 | |
| 269 | // Includes a run action for an update check with status='noupdate'. |
| 270 | const char* kUpdateCheckStatusNoUpdateWithRunAction = |
| 271 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 272 | "<response protocol='3.1'>" |
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 273 | " <app appid='12345'>" |
| 274 | " <updatecheck status='noupdate'>" |
| 275 | " <actions>" |
| 276 | " <action run='this'/>" |
| 277 | " </actions>" |
| 278 | " </updatecheck>" |
| 279 | " </app>" |
| 280 | "</response>"; |
| 281 | |
| 282 | // Includes a run action for an update check with status='error'. |
| 283 | const char* kUpdateCheckStatusErrorWithRunAction = |
| 284 | "<?xml version='1.0' encoding='UTF-8'?>" |
sorin | 3985280 | 2017-05-01 22:46:28 | [diff] [blame] | 285 | "<response protocol='3.1'>" |
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 286 | " <app appid='12345' status='ok'>" |
| 287 | " <updatecheck status='error-osnotsupported'>" |
| 288 | " <actions>" |
| 289 | " <action run='this'/>" |
| 290 | " </actions>" |
| 291 | " </updatecheck>" |
| 292 | " </app>" |
| 293 | "</response>"; |
| 294 | |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 295 | // Includes four <app> tags with status different than "ok". |
| 296 | const char* kAppsStatusError = |
| 297 | "<?xml version='1.0' encoding='UTF-8'?>" |
| 298 | "<response protocol='3.1'>" |
| 299 | " <app appid='aaaaaaaa' status='error-unknownApplication'>" |
| 300 | " <updatecheck status='error-internal'/>" |
| 301 | " </app>" |
| 302 | " <app appid='bbbbbbbb' status='restricted'>" |
| 303 | " <updatecheck status='error-internal'/>" |
| 304 | " </app>" |
| 305 | " <app appid='cccccccc' status='error-invalidAppId'>" |
| 306 | " <updatecheck status='error-internal'/>" |
| 307 | " </app>" |
| 308 | " <app appid='dddddddd' status='foobar'>" |
| 309 | " <updatecheck status='error-internal'/>" |
| 310 | " </app>" |
| 311 | "</response>"; |
| 312 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 313 | TEST(UpdateClientProtocolParserXmlTest, Parse) { |
| 314 | const auto parser = std::make_unique<ProtocolParserXml>(); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 315 | |
| 316 | // Test parsing of a number of invalid xml cases |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 317 | EXPECT_FALSE(parser->Parse(std::string())); |
| 318 | EXPECT_FALSE(parser->errors().empty()); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 319 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 320 | EXPECT_TRUE(parser->Parse(kMissingAppId)); |
| 321 | EXPECT_TRUE(parser->results().list.empty()); |
| 322 | EXPECT_FALSE(parser->errors().empty()); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 323 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 324 | EXPECT_TRUE(parser->Parse(kInvalidCodebase)); |
| 325 | EXPECT_TRUE(parser->results().list.empty()); |
| 326 | EXPECT_FALSE(parser->errors().empty()); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 327 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 328 | EXPECT_TRUE(parser->Parse(kMissingVersion)); |
| 329 | EXPECT_TRUE(parser->results().list.empty()); |
| 330 | EXPECT_FALSE(parser->errors().empty()); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 331 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 332 | EXPECT_TRUE(parser->Parse(kInvalidVersion)); |
| 333 | EXPECT_TRUE(parser->results().list.empty()); |
| 334 | EXPECT_FALSE(parser->errors().empty()); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 335 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 336 | EXPECT_TRUE(parser->Parse(kInvalidValidXmlMissingCodebase)); |
| 337 | EXPECT_TRUE(parser->results().list.empty()); |
| 338 | EXPECT_FALSE(parser->errors().empty()); |
[email protected] | da37c1d | 2013-12-19 01:04:38 | [diff] [blame] | 339 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 340 | EXPECT_TRUE(parser->Parse(kInvalidValidXmlMissingManifest)); |
| 341 | EXPECT_TRUE(parser->results().list.empty()); |
| 342 | EXPECT_FALSE(parser->errors().empty()); |
sorin | 7af7f8ef | 2015-05-28 23:49:03 | [diff] [blame] | 343 | |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 344 | // Parse some valid XML, and check that all params came out as expected |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 345 | EXPECT_TRUE(parser->Parse(kValidXml)); |
| 346 | EXPECT_TRUE(parser->errors().empty()); |
| 347 | EXPECT_EQ(1u, parser->results().list.size()); |
| 348 | const ProtocolParser::Result* first_result = &parser->results().list[0]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 349 | EXPECT_STREQ("ok", first_result->status.c_str()); |
| 350 | EXPECT_EQ(1u, first_result->crx_urls.size()); |
| 351 | EXPECT_EQ(GURL("http://example.com/"), first_result->crx_urls[0]); |
| 352 | EXPECT_EQ(GURL("http://diff.example.com/"), first_result->crx_diffurls[0]); |
| 353 | EXPECT_EQ("1.2.3.4", first_result->manifest.version); |
| 354 | EXPECT_EQ("2.0.143.0", first_result->manifest.browser_min_version); |
| 355 | EXPECT_EQ(1u, first_result->manifest.packages.size()); |
| 356 | EXPECT_EQ("extension_1_2_3_4.crx", first_result->manifest.packages[0].name); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 357 | |
| 358 | // Parse some xml that uses namespace prefixes. |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 359 | EXPECT_TRUE(parser->Parse(kUsesNamespacePrefix)); |
| 360 | EXPECT_TRUE(parser->errors().empty()); |
| 361 | EXPECT_TRUE(parser->Parse(kSimilarTagnames)); |
| 362 | EXPECT_TRUE(parser->errors().empty()); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 363 | |
| 364 | // Parse xml with hash value |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 365 | EXPECT_TRUE(parser->Parse(valid_xml_with_hash)); |
| 366 | EXPECT_TRUE(parser->errors().empty()); |
| 367 | EXPECT_FALSE(parser->results().list.empty()); |
| 368 | first_result = &parser->results().list[0]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 369 | EXPECT_FALSE(first_result->manifest.packages.empty()); |
| 370 | EXPECT_EQ("1234", first_result->manifest.packages[0].hash_sha256); |
| 371 | EXPECT_EQ("5678", first_result->manifest.packages[0].hashdiff_sha256); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 372 | |
| 373 | // Parse xml with package size value |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 374 | EXPECT_TRUE(parser->Parse(valid_xml_with_invalid_sizes)); |
| 375 | EXPECT_TRUE(parser->errors().empty()); |
| 376 | EXPECT_FALSE(parser->results().list.empty()); |
| 377 | first_result = &parser->results().list[0]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 378 | EXPECT_FALSE(first_result->manifest.packages.empty()); |
| 379 | EXPECT_EQ(1234, first_result->manifest.packages[0].size); |
| 380 | EXPECT_EQ(-1234, first_result->manifest.packages[1].size); |
| 381 | EXPECT_EQ(0, first_result->manifest.packages[2].size); |
| 382 | EXPECT_EQ(0, first_result->manifest.packages[3].size); |
| 383 | EXPECT_EQ(0, first_result->manifest.packages[4].size); |
| 384 | EXPECT_EQ(0, first_result->manifest.packages[5].size); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 385 | |
| 386 | // Parse xml with a <daystart> element. |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 387 | EXPECT_TRUE(parser->Parse(kWithDaystart)); |
| 388 | EXPECT_TRUE(parser->errors().empty()); |
| 389 | EXPECT_FALSE(parser->results().list.empty()); |
| 390 | EXPECT_EQ(parser->results().daystart_elapsed_seconds, 456); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 391 | |
| 392 | // Parse a no-update response. |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 393 | EXPECT_TRUE(parser->Parse(kNoUpdate)); |
| 394 | EXPECT_TRUE(parser->errors().empty()); |
| 395 | EXPECT_FALSE(parser->results().list.empty()); |
| 396 | first_result = &parser->results().list[0]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 397 | EXPECT_STREQ("noupdate", first_result->status.c_str()); |
| 398 | EXPECT_EQ(first_result->extension_id, "12345"); |
| 399 | EXPECT_EQ(first_result->manifest.version, ""); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 400 | |
| 401 | // Parse xml with one error and one success <app> tag. |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 402 | EXPECT_TRUE(parser->Parse(kTwoAppsOneError)); |
| 403 | EXPECT_TRUE(parser->errors().empty()); |
| 404 | EXPECT_EQ(2u, parser->results().list.size()); |
| 405 | first_result = &parser->results().list[0]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 406 | EXPECT_EQ(first_result->extension_id, "aaaaaaaa"); |
| 407 | EXPECT_STREQ("error-unknownApplication", first_result->status.c_str()); |
| 408 | EXPECT_TRUE(first_result->manifest.version.empty()); |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 409 | const ProtocolParser::Result* second_result = &parser->results().list[1]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 410 | EXPECT_EQ(second_result->extension_id, "bbbbbbbb"); |
| 411 | EXPECT_STREQ("ok", second_result->status.c_str()); |
| 412 | EXPECT_EQ("1.2.3.4", second_result->manifest.version); |
waffles | f43eb2fd3 | 2016-08-23 19:15:29 | [diff] [blame] | 413 | |
| 414 | // Parse xml with two apps setting the cohort info. |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 415 | EXPECT_TRUE(parser->Parse(kTwoAppsSetCohort)); |
| 416 | EXPECT_TRUE(parser->errors().empty()); |
| 417 | EXPECT_EQ(2u, parser->results().list.size()); |
| 418 | first_result = &parser->results().list[0]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 419 | EXPECT_EQ(first_result->extension_id, "aaaaaaaa"); |
| 420 | EXPECT_NE(first_result->cohort_attrs.find("cohort"), |
| 421 | first_result->cohort_attrs.end()); |
| 422 | EXPECT_EQ(first_result->cohort_attrs.find("cohort")->second, "1:2q3/"); |
| 423 | EXPECT_EQ(first_result->cohort_attrs.find("cohortname"), |
| 424 | first_result->cohort_attrs.end()); |
| 425 | EXPECT_EQ(first_result->cohort_attrs.find("cohorthint"), |
| 426 | first_result->cohort_attrs.end()); |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 427 | second_result = &parser->results().list[1]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 428 | EXPECT_EQ(second_result->extension_id, "bbbbbbbb"); |
| 429 | EXPECT_NE(second_result->cohort_attrs.find("cohort"), |
| 430 | second_result->cohort_attrs.end()); |
| 431 | EXPECT_EQ(second_result->cohort_attrs.find("cohort")->second, "1:[email protected]"); |
| 432 | EXPECT_NE(second_result->cohort_attrs.find("cohortname"), |
| 433 | second_result->cohort_attrs.end()); |
| 434 | EXPECT_EQ(second_result->cohort_attrs.find("cohortname")->second, "cname"); |
| 435 | EXPECT_EQ(second_result->cohort_attrs.find("cohorthint"), |
| 436 | second_result->cohort_attrs.end()); |
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 437 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 438 | EXPECT_TRUE(parser->Parse(kUpdateCheckStatusOkWithRunAction)); |
| 439 | EXPECT_TRUE(parser->errors().empty()); |
| 440 | EXPECT_FALSE(parser->results().list.empty()); |
| 441 | first_result = &parser->results().list[0]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 442 | EXPECT_STREQ("ok", first_result->status.c_str()); |
| 443 | EXPECT_EQ(first_result->extension_id, "12345"); |
| 444 | EXPECT_STREQ("this", first_result->action_run.c_str()); |
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 445 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 446 | EXPECT_TRUE(parser->Parse(kUpdateCheckStatusNoUpdateWithRunAction)); |
| 447 | EXPECT_TRUE(parser->errors().empty()); |
| 448 | EXPECT_FALSE(parser->results().list.empty()); |
| 449 | first_result = &parser->results().list[0]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 450 | EXPECT_STREQ("noupdate", first_result->status.c_str()); |
| 451 | EXPECT_EQ(first_result->extension_id, "12345"); |
| 452 | EXPECT_STREQ("this", first_result->action_run.c_str()); |
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 453 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 454 | EXPECT_TRUE(parser->Parse(kUpdateCheckStatusErrorWithRunAction)); |
| 455 | EXPECT_FALSE(parser->errors().empty()); |
| 456 | EXPECT_TRUE(parser->results().list.empty()); |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 457 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 458 | EXPECT_TRUE(parser->Parse(kAppsStatusError)); |
| 459 | EXPECT_STREQ("Unknown app status", parser->errors().c_str()); |
| 460 | EXPECT_EQ(3u, parser->results().list.size()); |
| 461 | first_result = &parser->results().list[0]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 462 | EXPECT_EQ(first_result->extension_id, "aaaaaaaa"); |
| 463 | EXPECT_STREQ("error-unknownApplication", first_result->status.c_str()); |
| 464 | EXPECT_TRUE(first_result->manifest.version.empty()); |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 465 | second_result = &parser->results().list[1]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 466 | EXPECT_EQ(second_result->extension_id, "bbbbbbbb"); |
| 467 | EXPECT_STREQ("restricted", second_result->status.c_str()); |
| 468 | EXPECT_TRUE(second_result->manifest.version.empty()); |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 469 | const ProtocolParser::Result* third_result = &parser->results().list[2]; |
Sorin Jianu | aa416553 | 2018-06-08 19:46:46 | [diff] [blame] | 470 | EXPECT_EQ(third_result->extension_id, "cccccccc"); |
| 471 | EXPECT_STREQ("error-invalidAppId", third_result->status.c_str()); |
| 472 | EXPECT_TRUE(third_result->manifest.version.empty()); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 473 | } |
| 474 | |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 475 | } // namespace update_client |