Index: chrome/browser/component_updater/test/update_manifest_unittest.cc |
diff --git a/chrome/common/extensions/update_manifest_unittest.cc b/chrome/browser/component_updater/test/update_manifest_unittest.cc |
similarity index 50% |
copy from chrome/common/extensions/update_manifest_unittest.cc |
copy to chrome/browser/component_updater/test/update_manifest_unittest.cc |
index 2a16b9c8a340df2dab039254999cc0264fee8976..8312181e7941f6a6964d2452cd07bf3c54d459ec 100644 |
--- a/chrome/common/extensions/update_manifest_unittest.cc |
+++ b/chrome/browser/component_updater/test/update_manifest_unittest.cc |
@@ -3,120 +3,172 @@ |
// found in the LICENSE file. |
#include "base/memory/scoped_vector.h" |
-#include "chrome/common/extensions/update_manifest.h" |
-#include "testing/gtest/include/gtest/gtest.h" |
+#include "chrome/browser/component_updater/update_manifest.h" |
#include "libxml/globals.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
-static const char* kValidXml = |
+namespace component_updater { |
+ |
+const char* kValidXml = |
"<?xml version='1.0' encoding='UTF-8'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" |
+"<response protocol='3.0'>" |
" <app appid='12345'>" |
-" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
-" version='1.2.3.4' prodversionmin='2.0.143.0' />" |
+" <updatecheck status='ok'>" |
+" <urls>" |
+" <url codebase='http://example.com/'/>" |
+" </urls>" |
+" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
+" <packages>" |
+" <package name='extension_1_2_3_4.crx'/>" |
+" </packages>" |
+" </manifest>" |
+" </updatecheck>" |
" </app>" |
-"</gupdate>"; |
+"</response>"; |
const char *valid_xml_with_hash = |
"<?xml version='1.0' encoding='UTF-8'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" |
+"<response protocol='3.0'>" |
" <app appid='12345'>" |
-" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
-" version='1.2.3.4' prodversionmin='2.0.143.0' " |
-" hash='1234'/>" |
+" <updatecheck status='ok'>" |
+" <urls>" |
+" <url codebase='http://example.com/'/>" |
+" </urls>" |
+" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
+" <packages>" |
+" <package name='extension_1_2_3_4.crx' hash_sha256='1234'/>" |
+" </packages>" |
+" </manifest>" |
+" </updatecheck>" |
" </app>" |
-"</gupdate>"; |
+"</response>"; |
-static const char* kMissingAppId = |
+const char* kMissingAppId = |
"<?xml version='1.0'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" |
+"<response protocol='3.0'>" |
" <app>" |
" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
" version='1.2.3.4' />" |
" </app>" |
-"</gupdate>"; |
+"</response>"; |
-static const char* kInvalidCodebase = |
+const char* kInvalidCodebase = |
"<?xml version='1.0'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" |
+"<response protocol='3.0'>" |
" <app appid='12345' status='ok'>" |
" <updatecheck codebase='example.com/extension_1.2.3.4.crx'" |
" version='1.2.3.4' />" |
" </app>" |
-"</gupdate>"; |
+"</response>"; |
-static const char* kMissingVersion = |
+const char* kMissingVersion = |
"<?xml version='1.0'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" |
+"<response protocol='3.0'>" |
" <app appid='12345' status='ok'>" |
" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' />" |
" </app>" |
-"</gupdate>"; |
+"</response>"; |
-static const char* kInvalidVersion = |
+const char* kInvalidVersion = |
"<?xml version='1.0'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" |
+"<response protocol='3.0'>" |
" <app appid='12345' status='ok'>" |
" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' " |
" version='1.2.3.a'/>" |
" </app>" |
-"</gupdate>"; |
+"</response>"; |
-static const char* kUsesNamespacePrefix = |
+// The v3 version of the protocol is not using namespaces. However, the parser |
+// must be able to parse responses that include namespaces. |
+const char* kUsesNamespacePrefix = |
"<?xml version='1.0' encoding='UTF-8'?>" |
-"<g:gupdate xmlns:g='http://www.google.com/update2/response' protocol='2.0'>" |
+"<g:response xmlns='http://www.google.com/update2/response' protocol='3.0'>" |
" <g:app appid='12345'>" |
-" <g:updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
-" version='1.2.3.4' prodversionmin='2.0.143.0' />" |
+" <g:updatecheck status='ok'>" |
+" <g:urls>" |
+" <g:url codebase='http://example.com/'/>" |
+" </g:urls>" |
+" <g:manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
+" <g:packages>" |
+" <g:package name='extension_1_2_3_4.crx'/>" |
+" </g:packages>" |
+" </g:manifest>" |
+" </g:updatecheck>" |
" </g:app>" |
-"</g:gupdate>"; |
+"</g:response>"; |
// Includes unrelated <app> tags from other xml namespaces - this should |
// not cause problems. |
-static const char* kSimilarTagnames = |
+const char* kSimilarTagnames = |
"<?xml version='1.0' encoding='UTF-8'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response'" |
-" xmlns:a='http://a' protocol='2.0'>" |
-" <a:app/>" |
-" <b:app xmlns:b='http://b' />" |
-" <app appid='12345'>" |
-" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
-" version='1.2.3.4' prodversionmin='2.0.143.0' />" |
-" </app>" |
-"</gupdate>"; |
+"<response xmlns:a='http://a' protocol='3.0'>" |
+" <a:app appid='12345'>" |
+" <updatecheck status='ok'>" |
+" <urls>" |
+" <url codebase='http://example.com/'/>" |
+" </urls>" |
+" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
+" <packages>" |
+" <package name='extension_1_2_3_4.crx'/>" |
+" </packages>" |
+" </manifest>" |
+" </updatecheck>" |
+" </a:app>" |
+" <b:app appid='xyz' xmlns:b='http://b'>" |
+" <updatecheck status='noupdate'/>" |
+" </b:app>" |
+"</response>"; |
// Includes a <daystart> tag. |
-static const char* kWithDaystart = |
+const char* kWithDaystart = |
"<?xml version='1.0' encoding='UTF-8'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" |
+"<response protocol='3.0'>" |
" <daystart elapsed_seconds='456' />" |
" <app appid='12345'>" |
-" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" |
-" version='1.2.3.4' prodversionmin='2.0.143.0' />" |
+" <updatecheck status='ok'>" |
+" <urls>" |
+" <url codebase='http://example.com/'/>" |
+" </urls>" |
+" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
+" <packages>" |
+" <package name='extension_1_2_3_4.crx'/>" |
+" </packages>" |
+" </manifest>" |
+" </updatecheck>" |
" </app>" |
-"</gupdate>"; |
+"</response>"; |
// Indicates no updates available - this should not be a parse error. |
-static const char* kNoUpdate = |
+const char* kNoUpdate = |
"<?xml version='1.0' encoding='UTF-8'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" |
+"<response protocol='3.0'>" |
" <app appid='12345'>" |
" <updatecheck status='noupdate' />" |
" </app>" |
-"</gupdate>"; |
+"</response>"; |
// Includes two <app> tags, one with an error. |
-static const char* kTwoAppsOneError = |
+const char* kTwoAppsOneError = |
"<?xml version='1.0' encoding='UTF-8'?>" |
-"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>" |
+"<response protocol='3.0'>" |
" <app appid='aaaaaaaa' status='error-unknownApplication'>" |
" <updatecheck status='error-unknownapplication'/>" |
" </app>" |
" <app appid='bbbbbbbb'>" |
-" <updatecheck codebase='http://example.com/b_3.1.crx' version='3.1'/>" |
+" <updatecheck status='ok'>" |
+" <urls>" |
+" <url codebase='http://example.com/'/>" |
+" </urls>" |
+" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
+" <packages>" |
+" <package name='extension_1_2_3_4.crx'/>" |
+" </packages>" |
+" </manifest>" |
+" </updatecheck>" |
" </app>" |
-"</gupdate>"; |
+"</response>"; |
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.
|
-TEST(ExtensionUpdateManifestTest, TestUpdateManifest) { |
+TEST(ComponentUpdaterManifestTest, TestUpdateManifest) { |
UpdateManifest parser; |
// Test parsing of a number of invalid xml cases |
@@ -142,13 +194,14 @@ TEST(ExtensionUpdateManifestTest, TestUpdateManifest) { |
// Parse some valid XML, and check that all params came out as expected |
EXPECT_TRUE(parser.Parse(kValidXml)); |
EXPECT_TRUE(parser.errors().empty()); |
- EXPECT_FALSE(parser.results().list.empty()); |
- const UpdateManifest::Result* firstResult = &parser.results().list.at(0); |
- EXPECT_EQ(GURL("http://example.com/extension_1.2.3.4.crx"), |
- firstResult->crx_url); |
- |
- EXPECT_EQ("1.2.3.4", firstResult->version); |
- EXPECT_EQ("2.0.143.0", firstResult->browser_min_version); |
+ EXPECT_EQ(1u, parser.results().list.size()); |
+ const UpdateManifest::Result* firstResult = &parser.results().list[0]; |
+ EXPECT_EQ(1u, firstResult->crx_urls.size()); |
+ EXPECT_EQ(GURL("http://example.com/"), firstResult->crx_urls[0]); |
+ EXPECT_EQ("1.2.3.4", firstResult->manifest.version); |
+ EXPECT_EQ("2.0.143.0", firstResult->manifest.browser_min_version); |
+ EXPECT_EQ(1u, firstResult->manifest.packages.size()); |
+ EXPECT_EQ("extension_1_2_3_4.crx", firstResult->manifest.packages[0].name); |
// Parse some xml that uses namespace prefixes. |
EXPECT_TRUE(parser.Parse(kUsesNamespacePrefix)); |
@@ -161,8 +214,9 @@ TEST(ExtensionUpdateManifestTest, TestUpdateManifest) { |
EXPECT_TRUE(parser.Parse(valid_xml_with_hash)); |
EXPECT_TRUE(parser.errors().empty()); |
EXPECT_FALSE(parser.results().list.empty()); |
- firstResult = &parser.results().list.at(0); |
- EXPECT_EQ("1234", firstResult->package_hash); |
+ firstResult = &parser.results().list[0]; |
+ EXPECT_FALSE(firstResult->manifest.packages.empty()); |
+ EXPECT_EQ("1234", firstResult->manifest.packages[0].hash_sha256); |
// Parse xml with a <daystart> element. |
EXPECT_TRUE(parser.Parse(kWithDaystart)); |
@@ -174,14 +228,17 @@ TEST(ExtensionUpdateManifestTest, TestUpdateManifest) { |
EXPECT_TRUE(parser.Parse(kNoUpdate)); |
EXPECT_TRUE(parser.errors().empty()); |
EXPECT_FALSE(parser.results().list.empty()); |
- firstResult = &parser.results().list.at(0); |
+ firstResult = &parser.results().list[0]; |
EXPECT_EQ(firstResult->extension_id, "12345"); |
- EXPECT_EQ(firstResult->version, ""); |
+ EXPECT_EQ(firstResult->manifest.version, ""); |
// Parse xml with one error and one success <app> tag. |
EXPECT_TRUE(parser.Parse(kTwoAppsOneError)); |
EXPECT_FALSE(parser.errors().empty()); |
EXPECT_EQ(1u, parser.results().list.size()); |
- firstResult = &parser.results().list.at(0); |
+ firstResult = &parser.results().list[0]; |
EXPECT_EQ(firstResult->extension_id, "bbbbbbbb"); |
} |
+ |
+} // namespace component_updater |
+ |