// 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 =
""
""
" "
" "
" "
"";
const char *valid_xml_with_hash =
""
""
" "
" "
" "
"";
static const char* kMissingAppId =
""
""
" "
" "
" "
"";
static const char* kInvalidCodebase =
""
""
" "
" "
" "
"";
static const char* kMissingVersion =
""
""
" "
" "
" "
"";
static const char* kInvalidVersion =
""
""
" "
" "
" "
"";
static const char* kUsesNamespacePrefix =
""
""
" "
" "
" "
"";
// Includes unrelated tags from other xml namespaces - this should
// not cause problems.
static const char* kSimilarTagnames =
""
""
" "
" "
" "
" "
" "
"";
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);
}