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

Side by Side Diff: chrome/browser/shell_integration_linux_unittest.cc

Issue 827013004: Linux: Change ShellIntegration code to use GetXDGDirectory(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comment Created 5 years, 11 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
« no previous file with comments | « chrome/browser/shell_integration_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/shell_integration_linux.h" 5 #include "chrome/browser/shell_integration_linux.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdlib> 8 #include <cstdlib>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 } // namespace 93 } // namespace
94 94
95 TEST(ShellIntegrationTest, GetDataWriteLocation) { 95 TEST(ShellIntegrationTest, GetDataWriteLocation) {
96 base::MessageLoop message_loop; 96 base::MessageLoop message_loop;
97 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 97 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
98 98
99 // Test that it returns $XDG_DATA_HOME. 99 // Test that it returns $XDG_DATA_HOME.
100 { 100 {
101 MockEnvironment env; 101 MockEnvironment env;
102 env.Set("HOME", "/home/user"); 102 base::ScopedPathOverride home_override(base::DIR_HOME,
103 base::FilePath("/home/user"),
104 true /* absolute? */,
105 false /* create? */);
103 env.Set("XDG_DATA_HOME", "/user/path"); 106 env.Set("XDG_DATA_HOME", "/user/path");
104 base::FilePath path; 107 base::FilePath path = GetDataWriteLocation(&env);
105 ASSERT_TRUE(GetDataWriteLocation(&env, &path));
106 EXPECT_EQ("/user/path", path.value()); 108 EXPECT_EQ("/user/path", path.value());
107 } 109 }
108 110
109 // Test that $XDG_DATA_HOME falls back to $HOME/.local/share. 111 // Test that $XDG_DATA_HOME falls back to $HOME/.local/share.
110 { 112 {
111 MockEnvironment env; 113 MockEnvironment env;
112 env.Set("HOME", "/home/user"); 114 base::ScopedPathOverride home_override(base::DIR_HOME,
113 base::FilePath path; 115 base::FilePath("/home/user"),
114 ASSERT_TRUE(GetDataWriteLocation(&env, &path)); 116 true /* absolute? */,
117 false /* create? */);
118 base::FilePath path = GetDataWriteLocation(&env);
115 EXPECT_EQ("/home/user/.local/share", path.value()); 119 EXPECT_EQ("/home/user/.local/share", path.value());
116 } 120 }
117
118 // Test that if neither $XDG_DATA_HOME nor $HOME are specified, it fails.
119 {
120 MockEnvironment env;
121 base::FilePath path;
122 ASSERT_FALSE(GetDataWriteLocation(&env, &path));
123 }
124 } 121 }
125 122
126 TEST(ShellIntegrationTest, GetDataSearchLocations) { 123 TEST(ShellIntegrationTest, GetDataSearchLocations) {
127 base::MessageLoop message_loop; 124 base::MessageLoop message_loop;
128 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 125 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
129 126
130 // Test that it returns $XDG_DATA_HOME + $XDG_DATA_DIRS. 127 // Test that it returns $XDG_DATA_HOME + $XDG_DATA_DIRS.
131 { 128 {
132 MockEnvironment env; 129 MockEnvironment env;
133 env.Set("HOME", "/home/user"); 130 base::ScopedPathOverride home_override(base::DIR_HOME,
131 base::FilePath("/home/user"),
132 true /* absolute? */,
133 false /* create? */);
134 env.Set("XDG_DATA_HOME", "/user/path"); 134 env.Set("XDG_DATA_HOME", "/user/path");
135 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2"); 135 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2");
136 EXPECT_THAT( 136 EXPECT_THAT(
137 FilePathsToStrings(GetDataSearchLocations(&env)), 137 FilePathsToStrings(GetDataSearchLocations(&env)),
138 ElementsAre("/user/path", 138 ElementsAre("/user/path",
139 "/system/path/1", 139 "/system/path/1",
140 "/system/path/2")); 140 "/system/path/2"));
141 } 141 }
142 142
143 // Test that $XDG_DATA_HOME falls back to $HOME/.local/share. 143 // Test that $XDG_DATA_HOME falls back to $HOME/.local/share.
144 { 144 {
145 MockEnvironment env; 145 MockEnvironment env;
146 env.Set("HOME", "/home/user"); 146 base::ScopedPathOverride home_override(base::DIR_HOME,
147 base::FilePath("/home/user"),
148 true /* absolute? */,
149 false /* create? */);
147 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2"); 150 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2");
148 EXPECT_THAT( 151 EXPECT_THAT(
149 FilePathsToStrings(GetDataSearchLocations(&env)), 152 FilePathsToStrings(GetDataSearchLocations(&env)),
150 ElementsAre("/home/user/.local/share", 153 ElementsAre("/home/user/.local/share",
151 "/system/path/1", 154 "/system/path/1",
152 "/system/path/2")); 155 "/system/path/2"));
153 } 156 }
154 157
155 // Test that if neither $XDG_DATA_HOME nor $HOME are specified, it still 158 // Test that if neither $XDG_DATA_HOME nor $HOME are specified, it still
156 // succeeds. 159 // succeeds.
157 { 160 {
158 MockEnvironment env; 161 MockEnvironment env;
159 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2"); 162 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2");
160 EXPECT_THAT( 163 std::vector<std::string> results =
161 FilePathsToStrings(GetDataSearchLocations(&env)), 164 FilePathsToStrings(GetDataSearchLocations(&env));
162 ElementsAre("/system/path/1", 165 ASSERT_EQ(3U, results.size());
163 "/system/path/2")); 166 EXPECT_FALSE(results[0].empty());
167 EXPECT_EQ("/system/path/1", results[1]);
168 EXPECT_EQ("/system/path/2", results[2]);
164 } 169 }
165 170
166 // Test that $XDG_DATA_DIRS falls back to the two default paths. 171 // Test that $XDG_DATA_DIRS falls back to the two default paths.
167 { 172 {
168 MockEnvironment env; 173 MockEnvironment env;
169 env.Set("HOME", "/home/user"); 174 base::ScopedPathOverride home_override(base::DIR_HOME,
175 base::FilePath("/home/user"),
176 true /* absolute? */,
177 false /* create? */);
170 env.Set("XDG_DATA_HOME", "/user/path"); 178 env.Set("XDG_DATA_HOME", "/user/path");
171 EXPECT_THAT( 179 EXPECT_THAT(
172 FilePathsToStrings(GetDataSearchLocations(&env)), 180 FilePathsToStrings(GetDataSearchLocations(&env)),
173 ElementsAre("/user/path", 181 ElementsAre("/user/path",
174 "/usr/local/share", 182 "/usr/local/share",
175 "/usr/share")); 183 "/usr/share"));
176 } 184 }
177 } 185 }
178 186
179 TEST(ShellIntegrationTest, GetExistingShortcutLocations) { 187 TEST(ShellIntegrationTest, GetExistingShortcutLocations) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); 317 GetExistingShortcutContents(&env, kTemplateFilepath, &contents));
310 EXPECT_EQ(kTestData1, contents); 318 EXPECT_EQ(kTestData1, contents);
311 } 319 }
312 320
313 // Test that it falls back to $HOME/.local/share/applications. 321 // Test that it falls back to $HOME/.local/share/applications.
314 { 322 {
315 base::ScopedTempDir temp_dir; 323 base::ScopedTempDir temp_dir;
316 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 324 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
317 325
318 MockEnvironment env; 326 MockEnvironment env;
319 env.Set("HOME", temp_dir.path().value()); 327 base::ScopedPathOverride home_override(base::DIR_HOME,
328 temp_dir.path(),
329 true /* absolute? */,
330 false /* create? */);
320 ASSERT_TRUE(base::CreateDirectory( 331 ASSERT_TRUE(base::CreateDirectory(
321 temp_dir.path().Append(".local/share/applications"))); 332 temp_dir.path().Append(".local/share/applications")));
322 ASSERT_TRUE(WriteString( 333 ASSERT_TRUE(WriteString(
323 temp_dir.path().Append(".local/share/applications") 334 temp_dir.path().Append(".local/share/applications")
324 .Append(kTemplateFilename), 335 .Append(kTemplateFilename),
325 kTestData1)); 336 kTestData1));
326 std::string contents; 337 std::string contents;
327 ASSERT_TRUE( 338 ASSERT_TRUE(
328 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); 339 GetExistingShortcutContents(&env, kTemplateFilepath, &contents));
329 EXPECT_EQ(kTestData1, contents); 340 EXPECT_EQ(kTestData1, contents);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 645
635 for (size_t i = 0; i < arraysize(test_cases); i++) { 646 for (size_t i = 0; i < arraysize(test_cases); i++) {
636 SCOPED_TRACE(i); 647 SCOPED_TRACE(i);
637 EXPECT_EQ(test_cases[i].expected_output, 648 EXPECT_EQ(test_cases[i].expected_output,
638 GetDirectoryFileContents(base::ASCIIToUTF16(test_cases[i].title), 649 GetDirectoryFileContents(base::ASCIIToUTF16(test_cases[i].title),
639 test_cases[i].icon_name)); 650 test_cases[i].icon_name));
640 } 651 }
641 } 652 }
642 653
643 } // namespace shell_integration_linux 654 } // namespace shell_integration_linux
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698