OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include "base/base_paths.h" | |
8 #include "base/file_util.h" | 7 #include "base/file_util.h" |
9 #include "base/path_service.h" | 8 #include "base/path_service.h" |
10 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
11 #include "base/string_util.h" | 10 #include "base/time.h" |
12 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
13 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
14 #include "chrome/installer/setup/setup_util.h" | 13 #include "chrome/installer/setup/setup_util.h" |
15 #include "chrome/installer/util/master_preferences.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
17 | 15 |
18 namespace { | 16 namespace { |
19 class SetupUtilTest : public testing::Test { | 17 class SetupUtilTest : public testing::Test { |
20 protected: | 18 protected: |
21 virtual void SetUp() { | 19 virtual void SetUp() { |
22 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); | 20 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); |
23 data_dir_ = data_dir_.AppendASCII("installer"); | 21 data_dir_ = data_dir_.AppendASCII("installer"); |
24 ASSERT_TRUE(file_util::PathExists(data_dir_)); | 22 ASSERT_TRUE(file_util::PathExists(data_dir_)); |
25 | 23 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 file_util::CreateDirectory(chrome_dir); | 87 file_util::CreateDirectory(chrome_dir); |
90 ASSERT_TRUE(file_util::PathExists(chrome_dir)); | 88 ASSERT_TRUE(file_util::PathExists(chrome_dir)); |
91 chrome_dir = test_dir_.path().AppendASCII("1.1.1.1"); | 89 chrome_dir = test_dir_.path().AppendASCII("1.1.1.1"); |
92 file_util::CreateDirectory(chrome_dir); | 90 file_util::CreateDirectory(chrome_dir); |
93 ASSERT_TRUE(file_util::PathExists(chrome_dir)); | 91 ASSERT_TRUE(file_util::PathExists(chrome_dir)); |
94 | 92 |
95 version.reset(installer::GetMaxVersionFromArchiveDir(test_dir_.path())); | 93 version.reset(installer::GetMaxVersionFromArchiveDir(test_dir_.path())); |
96 ASSERT_EQ(version->GetString(), "9.9.9.9"); | 94 ASSERT_EQ(version->GetString(), "9.9.9.9"); |
97 } | 95 } |
98 | 96 |
99 TEST_F(SetupUtilTest, ProgramCompare) { | |
100 using installer::ProgramCompare; | |
101 ScopedTempDir temp_dir; | |
102 | |
103 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
104 | |
105 FilePath some_long_dir(temp_dir.path().Append(L"Some Long Directory Name")); | |
106 FilePath expect(some_long_dir.Append(L"file.txt")); | |
107 FilePath expect_upcase(some_long_dir.Append(L"FILE.txt")); | |
108 FilePath other(some_long_dir.Append(L"otherfile.txt")); | |
109 | |
110 // Tests where the expected file doesn't exist. | |
111 | |
112 // Paths don't match. | |
113 EXPECT_FALSE(ProgramCompare(expect).Evaluate(L"\"" + other.value() + L"\"")); | |
114 // Paths match exactly. | |
115 EXPECT_TRUE(ProgramCompare(expect).Evaluate(L"\"" + expect.value() + L"\"")); | |
116 // Paths differ by case. | |
117 EXPECT_TRUE(ProgramCompare(expect).Evaluate( | |
118 L"\"" + expect_upcase.value() + L"\"")); | |
119 | |
120 // Tests where the expected file exists. | |
121 static const char data[] = "data"; | |
122 ASSERT_TRUE(file_util::CreateDirectory(some_long_dir)); | |
123 ASSERT_NE(-1, file_util::WriteFile(expect, data, arraysize(data) - 1)); | |
124 // Paths don't match. | |
125 EXPECT_FALSE(ProgramCompare(expect).Evaluate(L"\"" + other.value() + L"\"")); | |
126 // Paths match exactly. | |
127 EXPECT_TRUE(ProgramCompare(expect).Evaluate(L"\"" + expect.value() + L"\"")); | |
128 // Paths differ by case. | |
129 EXPECT_TRUE(ProgramCompare(expect).Evaluate( | |
130 L"\"" + expect_upcase.value() + L"\"")); | |
131 | |
132 // Test where strings don't match, but the same file is indicated. | |
133 std::wstring short_expect; | |
134 DWORD short_len = GetShortPathName(expect.value().c_str(), | |
135 WriteInto(&short_expect, MAX_PATH), | |
136 MAX_PATH); | |
137 ASSERT_NE(static_cast<DWORD>(0), short_len); | |
138 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); | |
139 short_expect.resize(short_len); | |
140 ASSERT_FALSE(FilePath::CompareEqualIgnoreCase(expect.value(), short_expect)); | |
141 EXPECT_TRUE(ProgramCompare(expect).Evaluate(L"\"" + short_expect + L"\"")); | |
142 } | |
143 | |
144 TEST_F(SetupUtilTest, DeleteFileFromTempProcess) { | 97 TEST_F(SetupUtilTest, DeleteFileFromTempProcess) { |
145 FilePath test_file; | 98 FilePath test_file; |
146 file_util::CreateTemporaryFileInDir(test_dir_.path(), &test_file); | 99 file_util::CreateTemporaryFileInDir(test_dir_.path(), &test_file); |
147 ASSERT_TRUE(file_util::PathExists(test_file)); | 100 ASSERT_TRUE(file_util::PathExists(test_file)); |
148 file_util::WriteFile(test_file, "foo", 3); | 101 file_util::WriteFile(test_file, "foo", 3); |
149 EXPECT_TRUE(installer::DeleteFileFromTempProcess(test_file, 0)); | 102 EXPECT_TRUE(installer::DeleteFileFromTempProcess(test_file, 0)); |
150 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200)); | 103 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200)); |
151 EXPECT_FALSE(file_util::PathExists(test_file)); | 104 EXPECT_FALSE(file_util::PathExists(test_file)); |
152 } | 105 } |
OLD | NEW |