// Copyright (c) 2012 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 #include "base/file_util.h" #include "base/platform_file.h" #include "base/scoped_temp_dir.h" #include "base/string16.h" #include "base/utf_string_conversions.h" #include "base/version.h" #include "chrome/installer/setup/install.h" #include "chrome/installer/setup/setup_constants.h" #include "testing/gtest/include/gtest/gtest.h" namespace { class CreateVisualElementsManifestTest : public testing::Test { protected: virtual void SetUp() OVERRIDE { // Create a temp directory for testing. ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); version_ = Version("0.0.0.0"); version_dir_ = test_dir_.path().AppendASCII(version_.GetString()); ASSERT_TRUE(file_util::CreateDirectory(version_dir_)); manifest_path_ = test_dir_.path().Append(installer::kVisualElementsManifest); } virtual void TearDown() OVERRIDE { // Clean up test directory manually so we can fail if it leaks. ASSERT_TRUE(test_dir_.Delete()); } // The temporary directory used to contain the test operations. ScopedTempDir test_dir_; // A dummy version number used to create the version directory. Version version_; // The path to |test_dir_|\|version_|. FilePath version_dir_; // The path to VisualElementsManifest.xml. FilePath manifest_path_; }; } // namespace // Test that VisualElementsManifest.xml is not created when VisualElements are // not present. TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { ASSERT_TRUE( installer::CreateVisualElementsManifest(test_dir_.path(), version_)); ASSERT_FALSE(file_util::PathExists(manifest_path_)); } // Test that VisualElementsManifest.xml is created with the correct content when // VisualElements are present. TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestCreated) { ASSERT_TRUE(file_util::CreateDirectory( version_dir_.Append(installer::kVisualElements))); ASSERT_TRUE( installer::CreateVisualElementsManifest(test_dir_.path(), version_)); ASSERT_TRUE(file_util::PathExists(manifest_path_)); std::string read_manifest; ASSERT_TRUE(file_util::ReadFileToString(manifest_path_, &read_manifest)); static const char kExpectedManifest[] = "\r\n" " \r\n" " \r\n" " " "\r\n" " \r\n" ""; ASSERT_STREQ(kExpectedManifest, read_manifest.c_str()); } TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { string16 val(L"This has 'crazy' \"chars\" && < and > signs."); static const wchar_t kExpectedEscapedVal[] = L"This has 'crazy' \"chars\" && < and > signs."; installer::EscapeXmlAttributeValueInSingleQuotes(&val); ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); } TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { string16 val(L"Google Chrome"); static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; installer::EscapeXmlAttributeValueInSingleQuotes(&val); ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); }