Chromium Code Reviews| Index: chrome/installer/setup/install_unittest.cc |
| diff --git a/chrome/installer/setup/install_unittest.cc b/chrome/installer/setup/install_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7add766bd83becf03832a5c90066239e40e62806 |
| --- /dev/null |
| +++ b/chrome/installer/setup/install_unittest.cc |
| @@ -0,0 +1,108 @@ |
| +// 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 <string> |
| + |
| +#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[] = |
| + "<Application>\r\n" |
| + " <VisualElements\r\n" |
| + " DisplayName='Google Chrome'\r\n" |
| + " Logo='0.0.0.0\\VisualElements\\Logo.png'\r\n" |
| + " SmallLogo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" |
| + " ForegroundText='light'\r\n" |
| + " BackgroundColor='white'>\r\n" |
| + " <DefaultTile ShowName='allLogos'/>\r\n" |
| + " <SplashScreen " |
| + "Image='0.0.0.0\\VisualElements\\splash-620x300.png'/>\r\n" |
|
grt (UTC plus 2)
2012/05/04 21:22:42
maybe indent this four spaces?
gab
2012/05/04 23:02:09
Hmmm this is already 4 spaces... unless you mean w
grt (UTC plus 2)
2012/05/05 02:16:59
this is a tough one. aesthetically, i think the w
gab
2012/05/05 16:19:51
Me likee :).
Done.
|
| + " </VisualElements>\r\n" |
| + "</Application>"; |
| + |
| + ASSERT_STREQ(kExpectedManifest, read_manifest.c_str()); |
| +} |
| + |
| +void EscapeXmlAttributeValueTestHelper(const string16& expected_escaped_val, |
|
grt (UTC plus 2)
2012/05/04 21:22:42
i think this helper function makes it harder to re
gab
2012/05/04 23:02:09
Done.
|
| + string16& val) { |
| + installer::EscapeXmlAttributeValueInSingleQuotes(val); |
| + ASSERT_STREQ(expected_escaped_val.c_str(), val.c_str()); |
| +} |
| + |
| +TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { |
| + string16 val(L"This has 'crazy' \"chars\" && < and > signs."); |
| + static const char kExpectedEscapedVal[] = |
|
grt (UTC plus 2)
2012/05/04 21:22:42
you could use wchar_t here since binary size isn't
gab
2012/05/04 23:02:09
Done.
|
| + "This has 'crazy' \"chars\" && < and > signs."; |
|
grt (UTC plus 2)
2012/05/04 21:22:42
four-space indent
gab
2012/05/04 23:02:09
Done.
|
| + EscapeXmlAttributeValueTestHelper(UTF8ToUTF16(kExpectedEscapedVal), val); |
| +} |
| + |
| +TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
| + string16 val(L"Google Chrome"); |
| + static const char kExpectedEscapedVal[] = "Google Chrome"; |
| + EscapeXmlAttributeValueTestHelper(UTF8ToUTF16(kExpectedEscapedVal), val); |
| +} |