| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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 <windows.h> |
| 6 |
| 7 #include <fstream> |
| 8 #include <iostream> |
| 9 |
| 10 #include "base/base_paths.h" |
| 11 #include "base/file_util.h" |
| 12 #include "base/path_service.h" |
| 13 #include "base/process_util.h" |
| 14 #include "base/string_util.h" |
| 15 #include "chrome/installer/setup/setup_util.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace { |
| 19 class SetupUtilTest : public testing::Test { |
| 20 protected: |
| 21 virtual void SetUp() { |
| 22 // Name a subdirectory of the user temp directory. |
| 23 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); |
| 24 test_dir_ = test_dir_.AppendASCII("SetupUtilTest"); |
| 25 |
| 26 // Create a fresh, empty copy of this test directory. |
| 27 file_util::Delete(test_dir_, true); |
| 28 file_util::CreateDirectory(test_dir_); |
| 29 ASSERT_TRUE(file_util::PathExists(test_dir_)); |
| 30 } |
| 31 |
| 32 virtual void TearDown() { |
| 33 // Clean up test directory |
| 34 ASSERT_TRUE(file_util::Delete(test_dir_, false)); |
| 35 ASSERT_FALSE(file_util::PathExists(test_dir_)); |
| 36 } |
| 37 |
| 38 // the path to temporary directory used to contain the test operations |
| 39 FilePath test_dir_; |
| 40 }; |
| 41 }; |
| 42 |
| 43 // Test that we are parsing Chrome version correctly. |
| 44 TEST_F(SetupUtilTest, GetVersionFromDirTest) { |
| 45 // Create a version dir |
| 46 std::wstring chrome_dir(test_dir_.value()); |
| 47 file_util::AppendToPath(&chrome_dir, L"1.0.0.0"); |
| 48 CreateDirectory(chrome_dir.c_str(), NULL); |
| 49 ASSERT_TRUE(file_util::PathExists(chrome_dir)); |
| 50 scoped_ptr<installer::Version> version( |
| 51 setup_util::GetVersionFromDir(test_dir_.value())); |
| 52 ASSERT_TRUE(version->GetString() == L"1.0.0.0"); |
| 53 |
| 54 file_util::Delete(chrome_dir, true); |
| 55 ASSERT_FALSE(file_util::PathExists(chrome_dir)); |
| 56 ASSERT_TRUE(setup_util::GetVersionFromDir(test_dir_.value()) == NULL); |
| 57 |
| 58 chrome_dir = test_dir_.value(); |
| 59 file_util::AppendToPath(&chrome_dir, L"ABC"); |
| 60 CreateDirectory(chrome_dir.c_str(), NULL); |
| 61 ASSERT_TRUE(file_util::PathExists(chrome_dir)); |
| 62 ASSERT_TRUE(setup_util::GetVersionFromDir(test_dir_.value()) == NULL); |
| 63 |
| 64 chrome_dir = test_dir_.value(); |
| 65 file_util::AppendToPath(&chrome_dir, L"2.3.4.5"); |
| 66 CreateDirectory(chrome_dir.c_str(), NULL); |
| 67 ASSERT_TRUE(file_util::PathExists(chrome_dir)); |
| 68 version.reset(setup_util::GetVersionFromDir(test_dir_.value())); |
| 69 ASSERT_TRUE(version->GetString() == L"2.3.4.5"); |
| 70 } |
| OLD | NEW |