| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/platform_file.h" |
| 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/string16.h" |
| 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/version.h" |
| 13 #include "chrome/installer/setup/install.h" |
| 14 #include "chrome/installer/setup/setup_constants.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 class CreateVisualElementsManifestTest : public testing::Test { |
| 20 protected: |
| 21 virtual void SetUp() OVERRIDE { |
| 22 // Create a temp directory for testing. |
| 23 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
| 24 |
| 25 version_ = Version("0.0.0.0"); |
| 26 |
| 27 version_dir_ = test_dir_.path().AppendASCII(version_.GetString()); |
| 28 ASSERT_TRUE(file_util::CreateDirectory(version_dir_)); |
| 29 |
| 30 manifest_path_ = |
| 31 test_dir_.path().Append(installer::kVisualElementsManifest); |
| 32 } |
| 33 |
| 34 virtual void TearDown() OVERRIDE { |
| 35 // Clean up test directory manually so we can fail if it leaks. |
| 36 ASSERT_TRUE(test_dir_.Delete()); |
| 37 } |
| 38 |
| 39 // The temporary directory used to contain the test operations. |
| 40 ScopedTempDir test_dir_; |
| 41 |
| 42 // A dummy version number used to create the version directory. |
| 43 Version version_; |
| 44 |
| 45 // The path to |test_dir_|\|version_|. |
| 46 FilePath version_dir_; |
| 47 |
| 48 // The path to VisualElementsManifest.xml. |
| 49 FilePath manifest_path_; |
| 50 }; |
| 51 |
| 52 } // namespace |
| 53 |
| 54 // Test that VisualElementsManifest.xml is not created when VisualElements are |
| 55 // not present. |
| 56 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { |
| 57 ASSERT_TRUE( |
| 58 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); |
| 59 ASSERT_FALSE(file_util::PathExists(manifest_path_)); |
| 60 } |
| 61 |
| 62 // Test that VisualElementsManifest.xml is created with the correct content when |
| 63 // VisualElements are present. |
| 64 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestCreated) { |
| 65 ASSERT_TRUE(file_util::CreateDirectory( |
| 66 version_dir_.Append(installer::kVisualElements))); |
| 67 ASSERT_TRUE( |
| 68 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); |
| 69 ASSERT_TRUE(file_util::PathExists(manifest_path_)); |
| 70 |
| 71 std::string read_manifest; |
| 72 ASSERT_TRUE(file_util::ReadFileToString(manifest_path_, &read_manifest)); |
| 73 |
| 74 static const char kExpectedManifest[] = |
| 75 "<Application>\r\n" |
| 76 " <VisualElements\r\n" |
| 77 " DisplayName='Google Chrome'\r\n" |
| 78 " Logo='0.0.0.0\\VisualElements\\Logo.png'\r\n" |
| 79 " SmallLogo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" |
| 80 " ForegroundText='light'\r\n" |
| 81 " BackgroundColor='white'>\r\n" |
| 82 " <DefaultTile ShowName='allLogos'/>\r\n" |
| 83 " <SplashScreen Image='0.0.0.0\\VisualElements\\splash-620x300.png'/>" |
| 84 "\r\n" |
| 85 " </VisualElements>\r\n" |
| 86 "</Application>"; |
| 87 |
| 88 ASSERT_STREQ(kExpectedManifest, read_manifest.c_str()); |
| 89 } |
| 90 |
| 91 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { |
| 92 string16 val(L"This has 'crazy' \"chars\" && < and > signs."); |
| 93 static const wchar_t kExpectedEscapedVal[] = |
| 94 L"This has 'crazy' \"chars\" && < and > signs."; |
| 95 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 96 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 97 } |
| 98 |
| 99 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
| 100 string16 val(L"Google Chrome"); |
| 101 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; |
| 102 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 103 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 104 } |
| OLD | NEW |