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

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

Issue 100573002: Move directory creation functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
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 10
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 EXPECT_FALSE(result.hidden); 175 EXPECT_FALSE(result.hidden);
176 } 176 }
177 177
178 // Shortcut on desktop. 178 // Shortcut on desktop.
179 { 179 {
180 base::ScopedTempDir temp_dir; 180 base::ScopedTempDir temp_dir;
181 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 181 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
182 base::FilePath desktop_path = temp_dir.path(); 182 base::FilePath desktop_path = temp_dir.path();
183 183
184 MockEnvironment env; 184 MockEnvironment env;
185 ASSERT_TRUE(file_util::CreateDirectory(desktop_path)); 185 ASSERT_TRUE(base::CreateDirectory(desktop_path));
186 ASSERT_FALSE(file_util::WriteFile( 186 ASSERT_FALSE(file_util::WriteFile(
187 desktop_path.AppendASCII(kTemplateFilename), 187 desktop_path.AppendASCII(kTemplateFilename),
188 "", 0)); 188 "", 0));
189 ShellIntegration::ShortcutLocations result = 189 ShellIntegration::ShortcutLocations result =
190 ShellIntegrationLinux::GetExistingShortcutLocations( 190 ShellIntegrationLinux::GetExistingShortcutLocations(
191 &env, kProfilePath, kExtensionId, desktop_path); 191 &env, kProfilePath, kExtensionId, desktop_path);
192 EXPECT_TRUE(result.on_desktop); 192 EXPECT_TRUE(result.on_desktop);
193 EXPECT_FALSE(result.in_applications_menu); 193 EXPECT_FALSE(result.in_applications_menu);
194 EXPECT_FALSE(result.in_quick_launch_bar); 194 EXPECT_FALSE(result.in_quick_launch_bar);
195 EXPECT_FALSE(result.hidden); 195 EXPECT_FALSE(result.hidden);
196 } 196 }
197 197
198 // Shortcut in applications directory. 198 // Shortcut in applications directory.
199 { 199 {
200 base::ScopedTempDir temp_dir; 200 base::ScopedTempDir temp_dir;
201 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 201 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
202 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); 202 base::FilePath apps_path = temp_dir.path().AppendASCII("applications");
203 203
204 MockEnvironment env; 204 MockEnvironment env;
205 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 205 env.Set("XDG_DATA_HOME", temp_dir.path().value());
206 ASSERT_TRUE(file_util::CreateDirectory(apps_path)); 206 ASSERT_TRUE(base::CreateDirectory(apps_path));
207 ASSERT_FALSE(file_util::WriteFile( 207 ASSERT_FALSE(file_util::WriteFile(
208 apps_path.AppendASCII(kTemplateFilename), 208 apps_path.AppendASCII(kTemplateFilename),
209 "", 0)); 209 "", 0));
210 ShellIntegration::ShortcutLocations result = 210 ShellIntegration::ShortcutLocations result =
211 ShellIntegrationLinux::GetExistingShortcutLocations( 211 ShellIntegrationLinux::GetExistingShortcutLocations(
212 &env, kProfilePath, kExtensionId); 212 &env, kProfilePath, kExtensionId);
213 EXPECT_FALSE(result.on_desktop); 213 EXPECT_FALSE(result.on_desktop);
214 EXPECT_TRUE(result.in_applications_menu); 214 EXPECT_TRUE(result.in_applications_menu);
215 EXPECT_FALSE(result.in_quick_launch_bar); 215 EXPECT_FALSE(result.in_quick_launch_bar);
216 EXPECT_FALSE(result.hidden); 216 EXPECT_FALSE(result.hidden);
217 } 217 }
218 218
219 // Shortcut in applications directory with NoDisplay=true. 219 // Shortcut in applications directory with NoDisplay=true.
220 { 220 {
221 base::ScopedTempDir temp_dir; 221 base::ScopedTempDir temp_dir;
222 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 222 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
223 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); 223 base::FilePath apps_path = temp_dir.path().AppendASCII("applications");
224 224
225 MockEnvironment env; 225 MockEnvironment env;
226 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 226 env.Set("XDG_DATA_HOME", temp_dir.path().value());
227 ASSERT_TRUE(file_util::CreateDirectory(apps_path)); 227 ASSERT_TRUE(base::CreateDirectory(apps_path));
228 ASSERT_TRUE(file_util::WriteFile( 228 ASSERT_TRUE(file_util::WriteFile(
229 apps_path.AppendASCII(kTemplateFilename), 229 apps_path.AppendASCII(kTemplateFilename),
230 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile))); 230 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile)));
231 ShellIntegration::ShortcutLocations result = 231 ShellIntegration::ShortcutLocations result =
232 ShellIntegrationLinux::GetExistingShortcutLocations( 232 ShellIntegrationLinux::GetExistingShortcutLocations(
233 &env, kProfilePath, kExtensionId); 233 &env, kProfilePath, kExtensionId);
234 // Doesn't count as being in applications menu. 234 // Doesn't count as being in applications menu.
235 EXPECT_FALSE(result.on_desktop); 235 EXPECT_FALSE(result.on_desktop);
236 EXPECT_FALSE(result.in_applications_menu); 236 EXPECT_FALSE(result.in_applications_menu);
237 EXPECT_FALSE(result.in_quick_launch_bar); 237 EXPECT_FALSE(result.in_quick_launch_bar);
238 EXPECT_TRUE(result.hidden); 238 EXPECT_TRUE(result.hidden);
239 } 239 }
240 240
241 // Shortcut on desktop and in applications directory. 241 // Shortcut on desktop and in applications directory.
242 { 242 {
243 base::ScopedTempDir temp_dir1; 243 base::ScopedTempDir temp_dir1;
244 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 244 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
245 base::FilePath desktop_path = temp_dir1.path(); 245 base::FilePath desktop_path = temp_dir1.path();
246 246
247 base::ScopedTempDir temp_dir2; 247 base::ScopedTempDir temp_dir2;
248 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 248 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
249 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications"); 249 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications");
250 250
251 MockEnvironment env; 251 MockEnvironment env;
252 ASSERT_TRUE(file_util::CreateDirectory(desktop_path)); 252 ASSERT_TRUE(base::CreateDirectory(desktop_path));
253 ASSERT_FALSE(file_util::WriteFile( 253 ASSERT_FALSE(file_util::WriteFile(
254 desktop_path.AppendASCII(kTemplateFilename), 254 desktop_path.AppendASCII(kTemplateFilename),
255 "", 0)); 255 "", 0));
256 env.Set("XDG_DATA_HOME", temp_dir2.path().value()); 256 env.Set("XDG_DATA_HOME", temp_dir2.path().value());
257 ASSERT_TRUE(file_util::CreateDirectory(apps_path)); 257 ASSERT_TRUE(base::CreateDirectory(apps_path));
258 ASSERT_FALSE(file_util::WriteFile( 258 ASSERT_FALSE(file_util::WriteFile(
259 apps_path.AppendASCII(kTemplateFilename), 259 apps_path.AppendASCII(kTemplateFilename),
260 "", 0)); 260 "", 0));
261 ShellIntegration::ShortcutLocations result = 261 ShellIntegration::ShortcutLocations result =
262 ShellIntegrationLinux::GetExistingShortcutLocations( 262 ShellIntegrationLinux::GetExistingShortcutLocations(
263 &env, kProfilePath, kExtensionId, desktop_path); 263 &env, kProfilePath, kExtensionId, desktop_path);
264 EXPECT_TRUE(result.on_desktop); 264 EXPECT_TRUE(result.on_desktop);
265 EXPECT_TRUE(result.in_applications_menu); 265 EXPECT_TRUE(result.in_applications_menu);
266 EXPECT_FALSE(result.in_quick_launch_bar); 266 EXPECT_FALSE(result.in_quick_launch_bar);
267 EXPECT_FALSE(result.hidden); 267 EXPECT_FALSE(result.hidden);
(...skipping 13 matching lines...) Expand all
281 { 281 {
282 base::ScopedTempDir temp_dir; 282 base::ScopedTempDir temp_dir;
283 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 283 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
284 284
285 MockEnvironment env; 285 MockEnvironment env;
286 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 286 env.Set("XDG_DATA_HOME", temp_dir.path().value());
287 // Create a file in a non-applications directory. This should be ignored. 287 // Create a file in a non-applications directory. This should be ignored.
288 ASSERT_TRUE(file_util::WriteFile( 288 ASSERT_TRUE(file_util::WriteFile(
289 temp_dir.path().AppendASCII(kTemplateFilename), 289 temp_dir.path().AppendASCII(kTemplateFilename),
290 kTestData2, strlen(kTestData2))); 290 kTestData2, strlen(kTestData2)));
291 ASSERT_TRUE(file_util::CreateDirectory( 291 ASSERT_TRUE(base::CreateDirectory(
292 temp_dir.path().AppendASCII("applications"))); 292 temp_dir.path().AppendASCII("applications")));
293 ASSERT_TRUE(file_util::WriteFile( 293 ASSERT_TRUE(file_util::WriteFile(
294 temp_dir.path().AppendASCII("applications") 294 temp_dir.path().AppendASCII("applications")
295 .AppendASCII(kTemplateFilename), 295 .AppendASCII(kTemplateFilename),
296 kTestData1, strlen(kTestData1))); 296 kTestData1, strlen(kTestData1)));
297 std::string contents; 297 std::string contents;
298 ASSERT_TRUE( 298 ASSERT_TRUE(
299 ShellIntegrationLinux::GetExistingShortcutContents( 299 ShellIntegrationLinux::GetExistingShortcutContents(
300 &env, kTemplateFilepath, &contents)); 300 &env, kTemplateFilepath, &contents));
301 EXPECT_EQ(kTestData1, contents); 301 EXPECT_EQ(kTestData1, contents);
302 } 302 }
303 303
304 // Test that it falls back to $HOME/.local/share/applications. 304 // Test that it falls back to $HOME/.local/share/applications.
305 { 305 {
306 base::ScopedTempDir temp_dir; 306 base::ScopedTempDir temp_dir;
307 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 307 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
308 308
309 MockEnvironment env; 309 MockEnvironment env;
310 env.Set("HOME", temp_dir.path().value()); 310 env.Set("HOME", temp_dir.path().value());
311 ASSERT_TRUE(file_util::CreateDirectory( 311 ASSERT_TRUE(base::CreateDirectory(
312 temp_dir.path().AppendASCII(".local/share/applications"))); 312 temp_dir.path().AppendASCII(".local/share/applications")));
313 ASSERT_TRUE(file_util::WriteFile( 313 ASSERT_TRUE(file_util::WriteFile(
314 temp_dir.path().AppendASCII(".local/share/applications") 314 temp_dir.path().AppendASCII(".local/share/applications")
315 .AppendASCII(kTemplateFilename), 315 .AppendASCII(kTemplateFilename),
316 kTestData1, strlen(kTestData1))); 316 kTestData1, strlen(kTestData1)));
317 std::string contents; 317 std::string contents;
318 ASSERT_TRUE( 318 ASSERT_TRUE(
319 ShellIntegrationLinux::GetExistingShortcutContents( 319 ShellIntegrationLinux::GetExistingShortcutContents(
320 &env, kTemplateFilepath, &contents)); 320 &env, kTemplateFilepath, &contents));
321 EXPECT_EQ(kTestData1, contents); 321 EXPECT_EQ(kTestData1, contents);
322 } 322 }
323 323
324 // Test that it searches $XDG_DATA_DIRS/applications. 324 // Test that it searches $XDG_DATA_DIRS/applications.
325 { 325 {
326 base::ScopedTempDir temp_dir; 326 base::ScopedTempDir temp_dir;
327 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 327 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
328 328
329 MockEnvironment env; 329 MockEnvironment env;
330 env.Set("XDG_DATA_DIRS", temp_dir.path().value()); 330 env.Set("XDG_DATA_DIRS", temp_dir.path().value());
331 ASSERT_TRUE(file_util::CreateDirectory( 331 ASSERT_TRUE(base::CreateDirectory(
332 temp_dir.path().AppendASCII("applications"))); 332 temp_dir.path().AppendASCII("applications")));
333 ASSERT_TRUE(file_util::WriteFile( 333 ASSERT_TRUE(file_util::WriteFile(
334 temp_dir.path().AppendASCII("applications") 334 temp_dir.path().AppendASCII("applications")
335 .AppendASCII(kTemplateFilename), 335 .AppendASCII(kTemplateFilename),
336 kTestData2, strlen(kTestData2))); 336 kTestData2, strlen(kTestData2)));
337 std::string contents; 337 std::string contents;
338 ASSERT_TRUE( 338 ASSERT_TRUE(
339 ShellIntegrationLinux::GetExistingShortcutContents( 339 ShellIntegrationLinux::GetExistingShortcutContents(
340 &env, kTemplateFilepath, &contents)); 340 &env, kTemplateFilepath, &contents));
341 EXPECT_EQ(kTestData2, contents); 341 EXPECT_EQ(kTestData2, contents);
342 } 342 }
343 343
344 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS. 344 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS.
345 { 345 {
346 base::ScopedTempDir temp_dir1; 346 base::ScopedTempDir temp_dir1;
347 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 347 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
348 base::ScopedTempDir temp_dir2; 348 base::ScopedTempDir temp_dir2;
349 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 349 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
350 350
351 MockEnvironment env; 351 MockEnvironment env;
352 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" + 352 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" +
353 temp_dir2.path().value()); 353 temp_dir2.path().value());
354 // Create a file in a non-applications directory. This should be ignored. 354 // Create a file in a non-applications directory. This should be ignored.
355 ASSERT_TRUE(file_util::WriteFile( 355 ASSERT_TRUE(file_util::WriteFile(
356 temp_dir1.path().AppendASCII(kTemplateFilename), 356 temp_dir1.path().AppendASCII(kTemplateFilename),
357 kTestData1, strlen(kTestData1))); 357 kTestData1, strlen(kTestData1)));
358 // Only create a findable desktop file in the second path. 358 // Only create a findable desktop file in the second path.
359 ASSERT_TRUE(file_util::CreateDirectory( 359 ASSERT_TRUE(base::CreateDirectory(
360 temp_dir2.path().AppendASCII("applications"))); 360 temp_dir2.path().AppendASCII("applications")));
361 ASSERT_TRUE(file_util::WriteFile( 361 ASSERT_TRUE(file_util::WriteFile(
362 temp_dir2.path().AppendASCII("applications") 362 temp_dir2.path().AppendASCII("applications")
363 .AppendASCII(kTemplateFilename), 363 .AppendASCII(kTemplateFilename),
364 kTestData2, strlen(kTestData2))); 364 kTestData2, strlen(kTestData2)));
365 std::string contents; 365 std::string contents;
366 ASSERT_TRUE( 366 ASSERT_TRUE(
367 ShellIntegrationLinux::GetExistingShortcutContents( 367 ShellIntegrationLinux::GetExistingShortcutContents(
368 &env, kTemplateFilepath, &contents)); 368 &env, kTemplateFilepath, &contents));
369 EXPECT_EQ(kTestData2, contents); 369 EXPECT_EQ(kTestData2, contents);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 599
600 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { 600 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) {
601 SCOPED_TRACE(i); 601 SCOPED_TRACE(i);
602 EXPECT_EQ( 602 EXPECT_EQ(
603 test_cases[i].expected_output, 603 test_cases[i].expected_output,
604 ShellIntegrationLinux::GetDirectoryFileContents( 604 ShellIntegrationLinux::GetDirectoryFileContents(
605 ASCIIToUTF16(test_cases[i].title), 605 ASCIIToUTF16(test_cases[i].title),
606 test_cases[i].icon_name)); 606 test_cases[i].icon_name));
607 } 607 }
608 } 608 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service_unittest.cc ('k') | chrome/browser/storage_monitor/media_storage_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698