Chromium Code Reviews| 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 #import "chrome/common/mac/app_mode_chrome_locator.h" | 5 #import "chrome/common/mac/app_mode_chrome_locator.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/chrome_version_info.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // Return the path to the Chrome/Chromium app bundle compiled along with the | 19 // Return the path to the Chrome/Chromium app bundle compiled along with the |
| 19 // test executable. | 20 // test executable. |
| 20 void GetChromeBundlePath(base::FilePath* chrome_bundle) { | 21 void GetChromeBundlePath(base::FilePath* chrome_bundle) { |
| 21 base::FilePath path; | 22 base::FilePath path; |
| 22 PathService::Get(base::DIR_EXE, &path); | 23 PathService::Get(base::DIR_EXE, &path); |
| 23 path = path.Append(chrome::kBrowserProcessExecutableNameChromium); | 24 path = path.Append(chrome::kBrowserProcessExecutableNameChromium); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 37 TEST(ChromeLocatorTest, FindNonExistentBundle) { | 38 TEST(ChromeLocatorTest, FindNonExistentBundle) { |
| 38 base::FilePath dummy; | 39 base::FilePath dummy; |
| 39 EXPECT_FALSE(app_mode::FindBundleById(@"this.doesnt.exist", &dummy)); | 40 EXPECT_FALSE(app_mode::FindBundleById(@"this.doesnt.exist", &dummy)); |
| 40 } | 41 } |
| 41 | 42 |
| 42 TEST(ChromeLocatorTest, GetNonExistentBundleInfo) { | 43 TEST(ChromeLocatorTest, GetNonExistentBundleInfo) { |
| 43 base::ScopedTempDir temp_dir; | 44 base::ScopedTempDir temp_dir; |
| 44 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 45 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 45 | 46 |
| 46 base::FilePath executable_path; | 47 base::FilePath executable_path; |
| 47 base::string16 raw_version; | |
| 48 base::FilePath version_path; | 48 base::FilePath version_path; |
| 49 base::FilePath framework_path; | 49 base::FilePath framework_path; |
| 50 EXPECT_FALSE(app_mode::GetChromeBundleInfo(temp_dir.path(), | 50 EXPECT_FALSE(app_mode::GetChromeBundleInfo(temp_dir.path(), |
| 51 &executable_path, &raw_version, &version_path, &framework_path)); | 51 std::string(), |
| 52 &executable_path, | |
| 53 &version_path, | |
| 54 &framework_path)); | |
| 52 } | 55 } |
| 53 | 56 |
| 54 TEST(ChromeLocatorTest, GetChromeBundleInfo) { | 57 TEST(ChromeLocatorTest, GetChromeBundleInfo) { |
| 55 using app_mode::GetChromeBundleInfo; | |
| 56 | |
| 57 base::FilePath chrome_bundle_path; | 58 base::FilePath chrome_bundle_path; |
| 58 GetChromeBundlePath(&chrome_bundle_path); | 59 GetChromeBundlePath(&chrome_bundle_path); |
| 59 ASSERT_TRUE(base::DirectoryExists(chrome_bundle_path)); | 60 ASSERT_TRUE(base::DirectoryExists(chrome_bundle_path)); |
| 60 | 61 |
| 61 base::FilePath executable_path; | 62 base::FilePath executable_path; |
| 62 base::string16 raw_version; | |
| 63 base::FilePath version_path; | 63 base::FilePath version_path; |
| 64 base::FilePath framework_path; | 64 base::FilePath framework_path; |
| 65 EXPECT_TRUE(GetChromeBundleInfo(chrome_bundle_path, | 65 EXPECT_TRUE(app_mode::GetChromeBundleInfo(chrome_bundle_path, |
| 66 &executable_path, &raw_version, &version_path, &framework_path)); | 66 std::string(), |
| 67 &executable_path, | |
| 68 &version_path, | |
| 69 &framework_path)); | |
| 67 EXPECT_TRUE(base::PathExists(executable_path)); | 70 EXPECT_TRUE(base::PathExists(executable_path)); |
| 68 EXPECT_GT(raw_version.size(), 0U); | |
| 69 EXPECT_TRUE(base::DirectoryExists(version_path)); | 71 EXPECT_TRUE(base::DirectoryExists(version_path)); |
| 70 EXPECT_TRUE(base::PathExists(framework_path)); | 72 EXPECT_TRUE(base::PathExists(framework_path)); |
| 71 } | 73 } |
| 74 | |
| 75 TEST(ChromeLocatorTest, GetChromeBundleInfoWithVersion) { | |
| 76 base::FilePath chrome_bundle_path; | |
| 77 GetChromeBundlePath(&chrome_bundle_path); | |
| 78 ASSERT_TRUE(base::DirectoryExists(chrome_bundle_path)); | |
| 79 | |
| 80 base::FilePath executable_path; | |
| 81 base::FilePath version_path; | |
| 82 base::FilePath framework_path; | |
| 83 EXPECT_TRUE(app_mode::GetChromeBundleInfo(chrome_bundle_path, | |
| 84 chrome::VersionInfo().Version(), | |
| 85 &executable_path, | |
| 86 &version_path, | |
| 87 &framework_path)); | |
| 88 EXPECT_TRUE(base::PathExists(executable_path)); | |
| 89 EXPECT_TRUE(base::DirectoryExists(version_path)); | |
| 90 EXPECT_TRUE(base::PathExists(framework_path)); | |
| 91 } | |
| 92 | |
| 93 TEST(ChromeLocatorTest, GetChromeBundleInfoWithVersionFailure) { | |
| 94 base::FilePath chrome_bundle_path; | |
| 95 GetChromeBundlePath(&chrome_bundle_path); | |
| 96 ASSERT_TRUE(base::DirectoryExists(chrome_bundle_path)); | |
| 97 | |
| 98 base::FilePath executable_path; | |
| 99 base::FilePath version_path; | |
| 100 base::FilePath framework_path; | |
| 101 EXPECT_FALSE(app_mode::GetChromeBundleInfo(chrome_bundle_path, | |
| 102 std::string("invalid_version"), | |
| 103 &executable_path, | |
| 104 &version_path, | |
| 105 &framework_path)); | |
| 106 } | |
| 107 | |
| 108 TEST(ChromeLocatorTest, GetChromeBundleInfoWithVersionSuccess) { | |
| 109 base::FilePath chrome_bundle_path; | |
| 110 GetChromeBundlePath(&chrome_bundle_path); | |
| 111 ASSERT_TRUE(base::DirectoryExists(chrome_bundle_path)); | |
| 112 | |
| 113 // Symlink "valid_version" to the actual version directory. | |
| 114 ASSERT_TRUE(base::CreateSymbolicLink( | |
|
tapted
2014/08/26 07:12:48
I'm not sure what this test is for - comment?... (
jackhou1
2014/08/26 08:15:14
Done.
| |
| 115 base::FilePath(chrome::VersionInfo().Version()), | |
| 116 chrome_bundle_path.Append("Contents").Append("Versions").Append( | |
| 117 "valid_version"))); | |
| 118 | |
| 119 base::FilePath executable_path; | |
| 120 base::FilePath version_path; | |
| 121 base::FilePath framework_path; | |
| 122 EXPECT_TRUE(app_mode::GetChromeBundleInfo(chrome_bundle_path, | |
| 123 std::string("valid_version"), | |
| 124 &executable_path, | |
| 125 &version_path, | |
| 126 &framework_path)); | |
| 127 EXPECT_TRUE(base::PathExists(executable_path)); | |
| 128 EXPECT_TRUE(base::DirectoryExists(version_path)); | |
| 129 EXPECT_TRUE(base::PathExists(framework_path)); | |
| 130 } | |
| OLD | NEW |