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 "chrome/installer/setup/setup_util_unittest.h" | 5 #include "chrome/installer/setup/setup_util_unittest.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/installer/setup/setup_util.h" | 22 #include "chrome/installer/setup/setup_util.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 class SetupUtilTestWithDir : public testing::Test { | 27 class SetupUtilTestWithDir : public testing::Test { |
28 protected: | 28 protected: |
29 virtual void SetUp() { | 29 virtual void SetUp() { |
30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); | 30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); |
31 data_dir_ = data_dir_.AppendASCII("installer"); | 31 data_dir_ = data_dir_.AppendASCII("installer"); |
32 ASSERT_TRUE(file_util::PathExists(data_dir_)); | 32 ASSERT_TRUE(base::PathExists(data_dir_)); |
33 | 33 |
34 // Create a temp directory for testing. | 34 // Create a temp directory for testing. |
35 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 35 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
36 } | 36 } |
37 | 37 |
38 virtual void TearDown() { | 38 virtual void TearDown() { |
39 // Clean up test directory manually so we can fail if it leaks. | 39 // Clean up test directory manually so we can fail if it leaks. |
40 ASSERT_TRUE(test_dir_.Delete()); | 40 ASSERT_TRUE(test_dir_.Delete()); |
41 } | 41 } |
42 | 42 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 91 } |
92 return false; | 92 return false; |
93 } | 93 } |
94 | 94 |
95 } // namespace | 95 } // namespace |
96 | 96 |
97 // Test that we are parsing Chrome version correctly. | 97 // Test that we are parsing Chrome version correctly. |
98 TEST_F(SetupUtilTestWithDir, ApplyDiffPatchTest) { | 98 TEST_F(SetupUtilTestWithDir, ApplyDiffPatchTest) { |
99 base::FilePath work_dir(test_dir_.path()); | 99 base::FilePath work_dir(test_dir_.path()); |
100 work_dir = work_dir.AppendASCII("ApplyDiffPatchTest"); | 100 work_dir = work_dir.AppendASCII("ApplyDiffPatchTest"); |
101 ASSERT_FALSE(file_util::PathExists(work_dir)); | 101 ASSERT_FALSE(base::PathExists(work_dir)); |
102 EXPECT_TRUE(file_util::CreateDirectory(work_dir)); | 102 EXPECT_TRUE(file_util::CreateDirectory(work_dir)); |
103 ASSERT_TRUE(file_util::PathExists(work_dir)); | 103 ASSERT_TRUE(base::PathExists(work_dir)); |
104 | 104 |
105 base::FilePath src = data_dir_.AppendASCII("archive1.7z"); | 105 base::FilePath src = data_dir_.AppendASCII("archive1.7z"); |
106 base::FilePath patch = data_dir_.AppendASCII("archive.diff"); | 106 base::FilePath patch = data_dir_.AppendASCII("archive.diff"); |
107 base::FilePath dest = work_dir.AppendASCII("archive2.7z"); | 107 base::FilePath dest = work_dir.AppendASCII("archive2.7z"); |
108 EXPECT_EQ(installer::ApplyDiffPatch(src, patch, dest, NULL), 0); | 108 EXPECT_EQ(installer::ApplyDiffPatch(src, patch, dest, NULL), 0); |
109 base::FilePath base = data_dir_.AppendASCII("archive2.7z"); | 109 base::FilePath base = data_dir_.AppendASCII("archive2.7z"); |
110 EXPECT_TRUE(file_util::ContentsEqual(dest, base)); | 110 EXPECT_TRUE(file_util::ContentsEqual(dest, base)); |
111 | 111 |
112 EXPECT_EQ(installer::ApplyDiffPatch(base::FilePath(), base::FilePath(), | 112 EXPECT_EQ(installer::ApplyDiffPatch(base::FilePath(), base::FilePath(), |
113 base::FilePath(), NULL), | 113 base::FilePath(), NULL), |
114 6); | 114 6); |
115 } | 115 } |
116 | 116 |
117 // Test that we are parsing Chrome version correctly. | 117 // Test that we are parsing Chrome version correctly. |
118 TEST_F(SetupUtilTestWithDir, GetMaxVersionFromArchiveDirTest) { | 118 TEST_F(SetupUtilTestWithDir, GetMaxVersionFromArchiveDirTest) { |
119 // Create a version dir | 119 // Create a version dir |
120 base::FilePath chrome_dir = test_dir_.path().AppendASCII("1.0.0.0"); | 120 base::FilePath chrome_dir = test_dir_.path().AppendASCII("1.0.0.0"); |
121 file_util::CreateDirectory(chrome_dir); | 121 file_util::CreateDirectory(chrome_dir); |
122 ASSERT_TRUE(file_util::PathExists(chrome_dir)); | 122 ASSERT_TRUE(base::PathExists(chrome_dir)); |
123 scoped_ptr<Version> version( | 123 scoped_ptr<Version> version( |
124 installer::GetMaxVersionFromArchiveDir(test_dir_.path())); | 124 installer::GetMaxVersionFromArchiveDir(test_dir_.path())); |
125 ASSERT_EQ(version->GetString(), "1.0.0.0"); | 125 ASSERT_EQ(version->GetString(), "1.0.0.0"); |
126 | 126 |
127 base::Delete(chrome_dir, true); | 127 base::Delete(chrome_dir, true); |
128 ASSERT_FALSE(file_util::PathExists(chrome_dir)); | 128 ASSERT_FALSE(base::PathExists(chrome_dir)); |
129 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir_.path()) == NULL); | 129 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir_.path()) == NULL); |
130 | 130 |
131 chrome_dir = test_dir_.path().AppendASCII("ABC"); | 131 chrome_dir = test_dir_.path().AppendASCII("ABC"); |
132 file_util::CreateDirectory(chrome_dir); | 132 file_util::CreateDirectory(chrome_dir); |
133 ASSERT_TRUE(file_util::PathExists(chrome_dir)); | 133 ASSERT_TRUE(base::PathExists(chrome_dir)); |
134 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir_.path()) == NULL); | 134 ASSERT_TRUE(installer::GetMaxVersionFromArchiveDir(test_dir_.path()) == NULL); |
135 | 135 |
136 chrome_dir = test_dir_.path().AppendASCII("2.3.4.5"); | 136 chrome_dir = test_dir_.path().AppendASCII("2.3.4.5"); |
137 file_util::CreateDirectory(chrome_dir); | 137 file_util::CreateDirectory(chrome_dir); |
138 ASSERT_TRUE(file_util::PathExists(chrome_dir)); | 138 ASSERT_TRUE(base::PathExists(chrome_dir)); |
139 version.reset(installer::GetMaxVersionFromArchiveDir(test_dir_.path())); | 139 version.reset(installer::GetMaxVersionFromArchiveDir(test_dir_.path())); |
140 ASSERT_EQ(version->GetString(), "2.3.4.5"); | 140 ASSERT_EQ(version->GetString(), "2.3.4.5"); |
141 | 141 |
142 // Create multiple version dirs, ensure that we select the greatest. | 142 // Create multiple version dirs, ensure that we select the greatest. |
143 chrome_dir = test_dir_.path().AppendASCII("9.9.9.9"); | 143 chrome_dir = test_dir_.path().AppendASCII("9.9.9.9"); |
144 file_util::CreateDirectory(chrome_dir); | 144 file_util::CreateDirectory(chrome_dir); |
145 ASSERT_TRUE(file_util::PathExists(chrome_dir)); | 145 ASSERT_TRUE(base::PathExists(chrome_dir)); |
146 chrome_dir = test_dir_.path().AppendASCII("1.1.1.1"); | 146 chrome_dir = test_dir_.path().AppendASCII("1.1.1.1"); |
147 file_util::CreateDirectory(chrome_dir); | 147 file_util::CreateDirectory(chrome_dir); |
148 ASSERT_TRUE(file_util::PathExists(chrome_dir)); | 148 ASSERT_TRUE(base::PathExists(chrome_dir)); |
149 | 149 |
150 version.reset(installer::GetMaxVersionFromArchiveDir(test_dir_.path())); | 150 version.reset(installer::GetMaxVersionFromArchiveDir(test_dir_.path())); |
151 ASSERT_EQ(version->GetString(), "9.9.9.9"); | 151 ASSERT_EQ(version->GetString(), "9.9.9.9"); |
152 } | 152 } |
153 | 153 |
154 TEST_F(SetupUtilTestWithDir, DeleteFileFromTempProcess) { | 154 TEST_F(SetupUtilTestWithDir, DeleteFileFromTempProcess) { |
155 base::FilePath test_file; | 155 base::FilePath test_file; |
156 file_util::CreateTemporaryFileInDir(test_dir_.path(), &test_file); | 156 file_util::CreateTemporaryFileInDir(test_dir_.path(), &test_file); |
157 ASSERT_TRUE(file_util::PathExists(test_file)); | 157 ASSERT_TRUE(base::PathExists(test_file)); |
158 file_util::WriteFile(test_file, "foo", 3); | 158 file_util::WriteFile(test_file, "foo", 3); |
159 EXPECT_TRUE(installer::DeleteFileFromTempProcess(test_file, 0)); | 159 EXPECT_TRUE(installer::DeleteFileFromTempProcess(test_file, 0)); |
160 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200)); | 160 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200)); |
161 EXPECT_FALSE(file_util::PathExists(test_file)); | 161 EXPECT_FALSE(base::PathExists(test_file)); |
162 } | 162 } |
163 | 163 |
164 // Note: This test is only valid when run at high integrity (i.e. it will fail | 164 // Note: This test is only valid when run at high integrity (i.e. it will fail |
165 // at medium integrity). | 165 // at medium integrity). |
166 TEST(SetupUtilTest, ScopedTokenPrivilegeBasic) { | 166 TEST(SetupUtilTest, ScopedTokenPrivilegeBasic) { |
167 ASSERT_FALSE(CurrentProcessHasPrivilege(kTestedPrivilege)); | 167 ASSERT_FALSE(CurrentProcessHasPrivilege(kTestedPrivilege)); |
168 | 168 |
169 { | 169 { |
170 installer::ScopedTokenPrivilege test_scoped_privilege(kTestedPrivilege); | 170 installer::ScopedTokenPrivilege test_scoped_privilege(kTestedPrivilege); |
171 ASSERT_TRUE(test_scoped_privilege.is_enabled()); | 171 ASSERT_TRUE(test_scoped_privilege.is_enabled()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // sufficiently recent operating systems. | 270 // sufficiently recent operating systems. |
271 TEST(SetupUtilTest, AdjustFromBelowNormalPriority) { | 271 TEST(SetupUtilTest, AdjustFromBelowNormalPriority) { |
272 scoped_ptr<ScopedPriorityClass> below_normal = | 272 scoped_ptr<ScopedPriorityClass> below_normal = |
273 ScopedPriorityClass::Create(BELOW_NORMAL_PRIORITY_CLASS); | 273 ScopedPriorityClass::Create(BELOW_NORMAL_PRIORITY_CLASS); |
274 ASSERT_TRUE(below_normal); | 274 ASSERT_TRUE(below_normal); |
275 if (base::win::GetVersion() > base::win::VERSION_SERVER_2003) | 275 if (base::win::GetVersion() > base::win::VERSION_SERVER_2003) |
276 EXPECT_EQ(PCCR_CHANGED, RelaunchAndDoProcessPriorityAdjustment()); | 276 EXPECT_EQ(PCCR_CHANGED, RelaunchAndDoProcessPriorityAdjustment()); |
277 else | 277 else |
278 EXPECT_EQ(PCCR_UNCHANGED, RelaunchAndDoProcessPriorityAdjustment()); | 278 EXPECT_EQ(PCCR_UNCHANGED, RelaunchAndDoProcessPriorityAdjustment()); |
279 } | 279 } |
OLD | NEW |