summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/update_manifest_unittest.cc
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 16:18:21 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 16:18:21 +0000
commitdbb92e0d55eede17bf2ada8370650d39834e6060 (patch)
tree941532e52eceab1115b60556960abde35f786368 /chrome/common/extensions/update_manifest_unittest.cc
parente667f718463a78b7d1de5a51e71982211f00f875 (diff)
downloadchromium_src-dbb92e0d55eede17bf2ada8370650d39834e6060.zip
chromium_src-dbb92e0d55eede17bf2ada8370650d39834e6060.tar.gz
chromium_src-dbb92e0d55eede17bf2ada8370650d39834e6060.tar.bz2
Do extensions update manifest XML parsing in a sandboxed process.
This involves moving the xml parsing code from static functions in extension_updater.cc to a UpdateManifest class, and switching from logging any errors directly to collecting them up and passing them across the IPC channel. BUG=http://crbug.com/12677 TEST=extensions auto-update should still work correctly Review URL: http://codereview.chromium.org/164541 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23822 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/update_manifest_unittest.cc')
-rw-r--r--chrome/common/extensions/update_manifest_unittest.cc119
1 files changed, 119 insertions, 0 deletions
diff --git a/chrome/common/extensions/update_manifest_unittest.cc b/chrome/common/extensions/update_manifest_unittest.cc
new file mode 100644
index 0000000..7adc17f
--- /dev/null
+++ b/chrome/common/extensions/update_manifest_unittest.cc
@@ -0,0 +1,119 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/scoped_vector.h"
+#include "base/version.h"
+#include "chrome/common/extensions/update_manifest.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "libxml/globals.h"
+
+static const char* kValidXml =
+"<?xml version='1.0' encoding='UTF-8'?>"
+"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.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' />"
+" </app>"
+"</gupdate>";
+
+const char *valid_xml_with_hash =
+"<?xml version='1.0' encoding='UTF-8'?>"
+"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.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'/>"
+" </app>"
+"</gupdate>";
+
+static const char* kMissingAppId =
+"<?xml version='1.0'?>"
+"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
+" <app>"
+" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
+" version='1.2.3.4' />"
+" </app>"
+"</gupdate>";
+
+static const char* kInvalidCodebase =
+"<?xml version='1.0'?>"
+"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
+" <app appid='12345' status='ok'>"
+" <updatecheck codebase='example.com/extension_1.2.3.4.crx'"
+" version='1.2.3.4' />"
+" </app>"
+"</gupdate>";
+
+static const char* kMissingVersion =
+"<?xml version='1.0'?>"
+"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
+" <app appid='12345' status='ok'>"
+" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' />"
+" </app>"
+"</gupdate>";
+
+static const char* kInvalidVersion =
+"<?xml version='1.0'?>"
+"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
+" <app appid='12345' status='ok'>"
+" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' "
+" version='1.2.3.a'/>"
+" </app>"
+"</gupdate>";
+
+static const char* kUsesNamespacePrefix =
+"<?xml version='1.0' encoding='UTF-8'?>"
+"<g:gupdate xmlns:g='http://www.google.com/update2/response' protocol='2.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:app>"
+"</g:gupdate>";
+
+// Includes unrelated <app> tags from other xml namespaces - this should
+// not cause problems.
+static 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>";
+
+
+TEST(ExtensionUpdateManifestTest, TestUpdateManifest) {
+ UpdateManifest parser;
+
+ // Test parsing of a number of invalid xml cases
+ EXPECT_FALSE(parser.Parse(""));
+ EXPECT_FALSE(parser.Parse(kMissingAppId));
+ EXPECT_FALSE(parser.Parse(kInvalidCodebase));
+ EXPECT_FALSE(parser.Parse(kMissingVersion));
+ EXPECT_FALSE(parser.Parse(kInvalidVersion));
+
+ // Parse some valid XML, and check that all params came out as expected
+ EXPECT_TRUE(parser.Parse(kValidXml));
+ EXPECT_FALSE(parser.results().empty());
+ const UpdateManifest::Result* firstResult = &parser.results().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);
+
+ // Parse some xml that uses namespace prefixes.
+ EXPECT_TRUE(parser.Parse(kUsesNamespacePrefix));
+ EXPECT_TRUE(parser.Parse(kSimilarTagnames));
+ xmlCleanupGlobals();
+
+ // Parse xml with hash value
+ EXPECT_TRUE(parser.Parse(valid_xml_with_hash));
+ EXPECT_FALSE(parser.results().empty());
+ firstResult = &parser.results().at(0);
+ EXPECT_EQ("1234", firstResult->package_hash);
+}