Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / extensions / common / update_manifest_unittest.cc
blob02beb677450407c7bc5c923be881d93f2721a129
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.
5 #include "extensions/common/update_manifest.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 static const char kValidXml[] =
10 "<?xml version='1.0' encoding='UTF-8'?>"
11 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
12 " <app appid='12345'>"
13 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
14 " version='1.2.3.4' prodversionmin='2.0.143.0' />"
15 " </app>"
16 "</gupdate>";
18 static const char valid_xml_with_hash[] =
19 "<?xml version='1.0' encoding='UTF-8'?>"
20 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
21 " <app appid='12345'>"
22 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
23 " version='1.2.3.4' prodversionmin='2.0.143.0' "
24 " hash_sha256='1234'/>"
25 " </app>"
26 "</gupdate>";
28 static const char kMissingAppId[] =
29 "<?xml version='1.0'?>"
30 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
31 " <app>"
32 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
33 " version='1.2.3.4' />"
34 " </app>"
35 "</gupdate>";
37 static const char kInvalidCodebase[] =
38 "<?xml version='1.0'?>"
39 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
40 " <app appid='12345' status='ok'>"
41 " <updatecheck codebase='example.com/extension_1.2.3.4.crx'"
42 " version='1.2.3.4' />"
43 " </app>"
44 "</gupdate>";
46 static const char kMissingVersion[] =
47 "<?xml version='1.0'?>"
48 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
49 " <app appid='12345' status='ok'>"
50 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' />"
51 " </app>"
52 "</gupdate>";
54 static const char kInvalidVersion[] =
55 "<?xml version='1.0'?>"
56 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
57 " <app appid='12345' status='ok'>"
58 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' "
59 " version='1.2.3.a'/>"
60 " </app>"
61 "</gupdate>";
63 static const char kUsesNamespacePrefix[] =
64 "<?xml version='1.0' encoding='UTF-8'?>"
65 "<g:gupdate xmlns:g='http://www.google.com/update2/response' protocol='2.0'>"
66 " <g:app appid='12345'>"
67 " <g:updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
68 " version='1.2.3.4' prodversionmin='2.0.143.0' />"
69 " </g:app>"
70 "</g:gupdate>";
72 // Includes unrelated <app> tags from other xml namespaces - this should
73 // not cause problems.
74 static const char kSimilarTagnames[] =
75 "<?xml version='1.0' encoding='UTF-8'?>"
76 "<gupdate xmlns='http://www.google.com/update2/response'"
77 " xmlns:a='http://a' protocol='2.0'>"
78 " <a:app/>"
79 " <b:app xmlns:b='http://b' />"
80 " <app appid='12345'>"
81 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
82 " version='1.2.3.4' prodversionmin='2.0.143.0' />"
83 " </app>"
84 "</gupdate>";
86 // Includes a <daystart> tag.
87 static const char kWithDaystart[] =
88 "<?xml version='1.0' encoding='UTF-8'?>"
89 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
90 " <daystart elapsed_seconds='456' />"
91 " <app appid='12345'>"
92 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
93 " version='1.2.3.4' prodversionmin='2.0.143.0' />"
94 " </app>"
95 "</gupdate>";
97 // Indicates no updates available - this should not be a parse error.
98 static const char kNoUpdate[] =
99 "<?xml version='1.0' encoding='UTF-8'?>"
100 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
101 " <app appid='12345'>"
102 " <updatecheck status='noupdate' />"
103 " </app>"
104 "</gupdate>";
106 // Includes two <app> tags, one with an error.
107 static const char kTwoAppsOneError[] =
108 "<?xml version='1.0' encoding='UTF-8'?>"
109 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
110 " <app appid='aaaaaaaa' status='error-unknownApplication'>"
111 " <updatecheck status='error-unknownapplication'/>"
112 " </app>"
113 " <app appid='bbbbbbbb'>"
114 " <updatecheck codebase='http://example.com/b_3.1.crx' version='3.1'/>"
115 " </app>"
116 "</gupdate>";
118 TEST(ExtensionUpdateManifestTest, TestUpdateManifest) {
119 UpdateManifest parser;
121 // Test parsing of a number of invalid xml cases
122 EXPECT_FALSE(parser.Parse(std::string()));
123 EXPECT_FALSE(parser.errors().empty());
125 EXPECT_TRUE(parser.Parse(kMissingAppId));
126 EXPECT_TRUE(parser.results().list.empty());
127 EXPECT_FALSE(parser.errors().empty());
129 EXPECT_TRUE(parser.Parse(kInvalidCodebase));
130 EXPECT_TRUE(parser.results().list.empty());
131 EXPECT_FALSE(parser.errors().empty());
133 EXPECT_TRUE(parser.Parse(kMissingVersion));
134 EXPECT_TRUE(parser.results().list.empty());
135 EXPECT_FALSE(parser.errors().empty());
137 EXPECT_TRUE(parser.Parse(kInvalidVersion));
138 EXPECT_TRUE(parser.results().list.empty());
139 EXPECT_FALSE(parser.errors().empty());
141 // Parse some valid XML, and check that all params came out as expected
142 EXPECT_TRUE(parser.Parse(kValidXml));
143 EXPECT_TRUE(parser.errors().empty());
144 EXPECT_FALSE(parser.results().list.empty());
145 const UpdateManifest::Result* firstResult = &parser.results().list.at(0);
146 EXPECT_EQ(GURL("http://example.com/extension_1.2.3.4.crx"),
147 firstResult->crx_url);
149 EXPECT_EQ("1.2.3.4", firstResult->version);
150 EXPECT_EQ("2.0.143.0", firstResult->browser_min_version);
152 // Parse some xml that uses namespace prefixes.
153 EXPECT_TRUE(parser.Parse(kUsesNamespacePrefix));
154 EXPECT_TRUE(parser.errors().empty());
155 EXPECT_TRUE(parser.Parse(kSimilarTagnames));
156 EXPECT_TRUE(parser.errors().empty());
158 // Parse xml with hash value
159 EXPECT_TRUE(parser.Parse(valid_xml_with_hash));
160 EXPECT_TRUE(parser.errors().empty());
161 EXPECT_FALSE(parser.results().list.empty());
162 firstResult = &parser.results().list.at(0);
163 EXPECT_EQ("1234", firstResult->package_hash);
165 // Parse xml with a <daystart> element.
166 EXPECT_TRUE(parser.Parse(kWithDaystart));
167 EXPECT_TRUE(parser.errors().empty());
168 EXPECT_FALSE(parser.results().list.empty());
169 EXPECT_EQ(parser.results().daystart_elapsed_seconds, 456);
171 // Parse a no-update response.
172 EXPECT_TRUE(parser.Parse(kNoUpdate));
173 EXPECT_TRUE(parser.errors().empty());
174 EXPECT_FALSE(parser.results().list.empty());
175 firstResult = &parser.results().list.at(0);
176 EXPECT_EQ(firstResult->extension_id, "12345");
177 EXPECT_EQ(firstResult->version, "");
179 // Parse xml with one error and one success <app> tag.
180 EXPECT_TRUE(parser.Parse(kTwoAppsOneError));
181 EXPECT_FALSE(parser.errors().empty());
182 EXPECT_EQ(1u, parser.results().list.size());
183 firstResult = &parser.results().list.at(0);
184 EXPECT_EQ(firstResult->extension_id, "bbbbbbbb");