OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/scoped_handle.h" | 6 #include "base/scoped_handle.h" |
7 #include "chrome/installer/util/browser_distribution.h" | 7 #include "chrome/installer/util/browser_distribution.h" |
8 #include "chrome/installer/util/google_update_constants.h" | 8 #include "chrome/installer/util/google_update_constants.h" |
9 #include "chrome/installer/util/master_preferences.h" | 9 #include "chrome/installer/util/master_preferences.h" |
10 #include "chrome/installer/util/package.h" | 10 #include "chrome/installer/util/package.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 EXPECT_FALSE(file_util::PathExists(installer_dir)); | 51 EXPECT_FALSE(file_util::PathExists(installer_dir)); |
52 file_util::CreateDirectory(installer_dir); | 52 file_util::CreateDirectory(installer_dir); |
53 EXPECT_TRUE(file_util::PathExists(new_version_dir)); | 53 EXPECT_TRUE(file_util::PathExists(new_version_dir)); |
54 | 54 |
55 file_util::CreateDirectory(old_version_dir); | 55 file_util::CreateDirectory(old_version_dir); |
56 EXPECT_TRUE(file_util::PathExists(old_version_dir)); | 56 EXPECT_TRUE(file_util::PathExists(old_version_dir)); |
57 | 57 |
58 // Create a fake chrome.dll key file in the old version directory. This | 58 // Create a fake chrome.dll key file in the old version directory. This |
59 // should prevent the old version directory from getting deleted. | 59 // should prevent the old version directory from getting deleted. |
60 FilePath old_chrome_dll(old_version_dir.Append(installer_util::kChromeDll)); | 60 FilePath old_chrome_dll(old_version_dir.Append(installer::kChromeDll)); |
61 EXPECT_FALSE(file_util::PathExists(old_chrome_dll)); | 61 EXPECT_FALSE(file_util::PathExists(old_chrome_dll)); |
62 | 62 |
63 // Hold on to the file exclusively to prevent the directory from | 63 // Hold on to the file exclusively to prevent the directory from |
64 // being deleted. | 64 // being deleted. |
65 ScopedHandle file(::CreateFile(old_chrome_dll.value().c_str(), GENERIC_READ, | 65 ScopedHandle file(::CreateFile(old_chrome_dll.value().c_str(), GENERIC_READ, |
66 0, NULL, OPEN_ALWAYS, 0, NULL)); | 66 0, NULL, OPEN_ALWAYS, 0, NULL)); |
67 EXPECT_TRUE(file.IsValid()); | 67 EXPECT_TRUE(file.IsValid()); |
68 EXPECT_TRUE(file_util::PathExists(old_chrome_dll)); | 68 EXPECT_TRUE(file_util::PathExists(old_chrome_dll)); |
69 | 69 |
70 package->RemoveOldVersionDirectories(*new_version.get()); | 70 package->RemoveOldVersionDirectories(*new_version.get()); |
71 // The old directory should still exist. | 71 // The old directory should still exist. |
72 EXPECT_TRUE(file_util::PathExists(old_version_dir)); | 72 EXPECT_TRUE(file_util::PathExists(old_version_dir)); |
73 EXPECT_TRUE(file_util::PathExists(new_version_dir)); | 73 EXPECT_TRUE(file_util::PathExists(new_version_dir)); |
74 | 74 |
75 // Now close the file handle to make it possible to delete our key file. | 75 // Now close the file handle to make it possible to delete our key file. |
76 file.Close(); | 76 file.Close(); |
77 | 77 |
78 package->RemoveOldVersionDirectories(*new_version.get()); | 78 package->RemoveOldVersionDirectories(*new_version.get()); |
79 // The new directory should still exist. | 79 // The new directory should still exist. |
80 EXPECT_TRUE(file_util::PathExists(new_version_dir)); | 80 EXPECT_TRUE(file_util::PathExists(new_version_dir)); |
81 | 81 |
82 // Now, the old directory and key file should be gone. | 82 // Now, the old directory and key file should be gone. |
83 EXPECT_FALSE(file_util::PathExists(old_chrome_dll)); | 83 EXPECT_FALSE(file_util::PathExists(old_chrome_dll)); |
84 EXPECT_FALSE(file_util::PathExists(old_version_dir)); | 84 EXPECT_FALSE(file_util::PathExists(old_version_dir)); |
85 } | 85 } |
86 | 86 |
87 TEST_F(PackageTest, WithProduct) { | 87 TEST_F(PackageTest, WithProduct) { |
88 TempRegKeyOverride::DeleteAllTempKeys(); | 88 TempRegKeyOverride::DeleteAllTempKeys(); |
89 | 89 |
90 const installer_util::MasterPreferences& prefs = | 90 const installer::MasterPreferences& prefs = |
91 installer_util::MasterPreferences::ForCurrentProcess(); | 91 installer::MasterPreferences::ForCurrentProcess(); |
92 | 92 |
93 // TODO(tommi): We should mock this and use our mocked distribution. | 93 // TODO(tommi): We should mock this and use our mocked distribution. |
94 const bool system_level = true; | 94 const bool system_level = true; |
95 BrowserDistribution* distribution = | 95 BrowserDistribution* distribution = |
96 BrowserDistribution::GetSpecificDistribution( | 96 BrowserDistribution::GetSpecificDistribution( |
97 BrowserDistribution::CHROME_BROWSER, prefs); | 97 BrowserDistribution::CHROME_BROWSER, prefs); |
98 scoped_refptr<Package> package(new Package(test_dir_.path())); | 98 scoped_refptr<Package> package(new Package(test_dir_.path())); |
99 scoped_refptr<Product> product(new Product(distribution, | 99 scoped_refptr<Product> product(new Product(distribution, |
100 system_level, | 100 system_level, |
101 package.get())); | 101 package.get())); |
(...skipping 17 matching lines...) Expand all Loading... |
119 scoped_ptr<Version> found_version(package->GetCurrentVersion()); | 119 scoped_ptr<Version> found_version(package->GetCurrentVersion()); |
120 EXPECT_TRUE(found_version.get() != NULL); | 120 EXPECT_TRUE(found_version.get() != NULL); |
121 if (found_version.get()) { | 121 if (found_version.get()) { |
122 EXPECT_TRUE(current_version->IsEqual(*found_version.get())); | 122 EXPECT_TRUE(current_version->IsEqual(*found_version.get())); |
123 } | 123 } |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 TempRegKeyOverride::DeleteAllTempKeys(); | 127 TempRegKeyOverride::DeleteAllTempKeys(); |
128 } | 128 } |
OLD | NEW |