Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/common/mac/app_mode_chrome_locator_unittest.mm

Issue 501303002: [Mac] Make app shims load the same framework version as the running Chrome process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, GetChromeBundleInfoWithLatestVersion) {
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, GetChromeBundleInfoWithInvalidVersion) {
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 // This still passes because it should default to the latest version.
102 EXPECT_TRUE(app_mode::GetChromeBundleInfo(chrome_bundle_path,
103 std::string("invalid_version"),
104 &executable_path,
105 &version_path,
106 &framework_path));
107 EXPECT_TRUE(base::PathExists(executable_path));
108 EXPECT_TRUE(base::DirectoryExists(version_path));
109 EXPECT_TRUE(base::PathExists(framework_path));
110 }
111
112 TEST(ChromeLocatorTest, GetChromeBundleInfoWithPreviousVersion) {
113 base::FilePath chrome_bundle_path;
114 GetChromeBundlePath(&chrome_bundle_path);
115 ASSERT_TRUE(base::DirectoryExists(chrome_bundle_path));
116
117 // Make a symlink that pretends to be a previous version.
118 base::FilePath fake_version_directory = chrome_bundle_path.Append("Contents")
119 .Append("Versions")
120 .Append("previous_version");
121 EXPECT_TRUE(base::CreateSymbolicLink(
122 base::FilePath(chrome::VersionInfo().Version()), fake_version_directory));
123
124 base::FilePath executable_path;
125 base::FilePath version_path;
126 base::FilePath framework_path;
127 EXPECT_TRUE(app_mode::GetChromeBundleInfo(chrome_bundle_path,
128 std::string("previous_version"),
129 &executable_path,
130 &version_path,
131 &framework_path));
132 EXPECT_TRUE(base::PathExists(executable_path));
133 EXPECT_TRUE(base::DirectoryExists(version_path));
134 EXPECT_TRUE(base::PathExists(framework_path));
135
136 base::DeleteFile(fake_version_directory, false);
137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698