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

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

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 179 }
180 180
181 // Shortcut on desktop. 181 // Shortcut on desktop.
182 { 182 {
183 base::ScopedTempDir temp_dir; 183 base::ScopedTempDir temp_dir;
184 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 184 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
185 base::FilePath desktop_path = temp_dir.path(); 185 base::FilePath desktop_path = temp_dir.path();
186 186
187 MockEnvironment env; 187 MockEnvironment env;
188 ASSERT_TRUE(base::CreateDirectory(desktop_path)); 188 ASSERT_TRUE(base::CreateDirectory(desktop_path));
189 ASSERT_FALSE(file_util::WriteFile( 189 ASSERT_FALSE(base::WriteFile(
190 desktop_path.AppendASCII(kTemplateFilename), 190 desktop_path.AppendASCII(kTemplateFilename),
191 "", 0)); 191 "", 0));
192 ShellIntegration::ShortcutLocations result = 192 ShellIntegration::ShortcutLocations result =
193 ShellIntegrationLinux::GetExistingShortcutLocations( 193 ShellIntegrationLinux::GetExistingShortcutLocations(
194 &env, kProfilePath, kExtensionId, desktop_path); 194 &env, kProfilePath, kExtensionId, desktop_path);
195 EXPECT_TRUE(result.on_desktop); 195 EXPECT_TRUE(result.on_desktop);
196 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_NONE, 196 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_NONE,
197 result.applications_menu_location); 197 result.applications_menu_location);
198 198
199 EXPECT_FALSE(result.in_quick_launch_bar); 199 EXPECT_FALSE(result.in_quick_launch_bar);
200 EXPECT_FALSE(result.hidden); 200 EXPECT_FALSE(result.hidden);
201 } 201 }
202 202
203 // Shortcut in applications directory. 203 // Shortcut in applications directory.
204 { 204 {
205 base::ScopedTempDir temp_dir; 205 base::ScopedTempDir temp_dir;
206 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 206 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
207 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); 207 base::FilePath apps_path = temp_dir.path().AppendASCII("applications");
208 208
209 MockEnvironment env; 209 MockEnvironment env;
210 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 210 env.Set("XDG_DATA_HOME", temp_dir.path().value());
211 ASSERT_TRUE(base::CreateDirectory(apps_path)); 211 ASSERT_TRUE(base::CreateDirectory(apps_path));
212 ASSERT_FALSE(file_util::WriteFile( 212 ASSERT_FALSE(base::WriteFile(
213 apps_path.AppendASCII(kTemplateFilename), 213 apps_path.AppendASCII(kTemplateFilename),
214 "", 0)); 214 "", 0));
215 ShellIntegration::ShortcutLocations result = 215 ShellIntegration::ShortcutLocations result =
216 ShellIntegrationLinux::GetExistingShortcutLocations( 216 ShellIntegrationLinux::GetExistingShortcutLocations(
217 &env, kProfilePath, kExtensionId); 217 &env, kProfilePath, kExtensionId);
218 EXPECT_FALSE(result.on_desktop); 218 EXPECT_FALSE(result.on_desktop);
219 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 219 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
220 result.applications_menu_location); 220 result.applications_menu_location);
221 221
222 EXPECT_FALSE(result.in_quick_launch_bar); 222 EXPECT_FALSE(result.in_quick_launch_bar);
223 EXPECT_FALSE(result.hidden); 223 EXPECT_FALSE(result.hidden);
224 } 224 }
225 225
226 // Shortcut in applications directory with NoDisplay=true. 226 // Shortcut in applications directory with NoDisplay=true.
227 { 227 {
228 base::ScopedTempDir temp_dir; 228 base::ScopedTempDir temp_dir;
229 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 229 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
230 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); 230 base::FilePath apps_path = temp_dir.path().AppendASCII("applications");
231 231
232 MockEnvironment env; 232 MockEnvironment env;
233 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 233 env.Set("XDG_DATA_HOME", temp_dir.path().value());
234 ASSERT_TRUE(base::CreateDirectory(apps_path)); 234 ASSERT_TRUE(base::CreateDirectory(apps_path));
235 ASSERT_TRUE(file_util::WriteFile( 235 ASSERT_TRUE(base::WriteFile(
236 apps_path.AppendASCII(kTemplateFilename), 236 apps_path.AppendASCII(kTemplateFilename),
237 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile))); 237 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile)));
238 ShellIntegration::ShortcutLocations result = 238 ShellIntegration::ShortcutLocations result =
239 ShellIntegrationLinux::GetExistingShortcutLocations( 239 ShellIntegrationLinux::GetExistingShortcutLocations(
240 &env, kProfilePath, kExtensionId); 240 &env, kProfilePath, kExtensionId);
241 // Doesn't count as being in applications menu. 241 // Doesn't count as being in applications menu.
242 EXPECT_FALSE(result.on_desktop); 242 EXPECT_FALSE(result.on_desktop);
243 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_NONE, 243 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_NONE,
244 result.applications_menu_location); 244 result.applications_menu_location);
245 EXPECT_FALSE(result.in_quick_launch_bar); 245 EXPECT_FALSE(result.in_quick_launch_bar);
246 EXPECT_TRUE(result.hidden); 246 EXPECT_TRUE(result.hidden);
247 } 247 }
248 248
249 // Shortcut on desktop and in applications directory. 249 // Shortcut on desktop and in applications directory.
250 { 250 {
251 base::ScopedTempDir temp_dir1; 251 base::ScopedTempDir temp_dir1;
252 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 252 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
253 base::FilePath desktop_path = temp_dir1.path(); 253 base::FilePath desktop_path = temp_dir1.path();
254 254
255 base::ScopedTempDir temp_dir2; 255 base::ScopedTempDir temp_dir2;
256 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 256 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
257 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications"); 257 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications");
258 258
259 MockEnvironment env; 259 MockEnvironment env;
260 ASSERT_TRUE(base::CreateDirectory(desktop_path)); 260 ASSERT_TRUE(base::CreateDirectory(desktop_path));
261 ASSERT_FALSE(file_util::WriteFile( 261 ASSERT_FALSE(base::WriteFile(
262 desktop_path.AppendASCII(kTemplateFilename), 262 desktop_path.AppendASCII(kTemplateFilename),
263 "", 0)); 263 "", 0));
264 env.Set("XDG_DATA_HOME", temp_dir2.path().value()); 264 env.Set("XDG_DATA_HOME", temp_dir2.path().value());
265 ASSERT_TRUE(base::CreateDirectory(apps_path)); 265 ASSERT_TRUE(base::CreateDirectory(apps_path));
266 ASSERT_FALSE(file_util::WriteFile( 266 ASSERT_FALSE(base::WriteFile(
267 apps_path.AppendASCII(kTemplateFilename), 267 apps_path.AppendASCII(kTemplateFilename),
268 "", 0)); 268 "", 0));
269 ShellIntegration::ShortcutLocations result = 269 ShellIntegration::ShortcutLocations result =
270 ShellIntegrationLinux::GetExistingShortcutLocations( 270 ShellIntegrationLinux::GetExistingShortcutLocations(
271 &env, kProfilePath, kExtensionId, desktop_path); 271 &env, kProfilePath, kExtensionId, desktop_path);
272 EXPECT_TRUE(result.on_desktop); 272 EXPECT_TRUE(result.on_desktop);
273 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 273 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
274 result.applications_menu_location); 274 result.applications_menu_location);
275 EXPECT_FALSE(result.in_quick_launch_bar); 275 EXPECT_FALSE(result.in_quick_launch_bar);
276 EXPECT_FALSE(result.hidden); 276 EXPECT_FALSE(result.hidden);
(...skipping 10 matching lines...) Expand all
287 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 287 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
288 288
289 // Test that it searches $XDG_DATA_HOME/applications. 289 // Test that it searches $XDG_DATA_HOME/applications.
290 { 290 {
291 base::ScopedTempDir temp_dir; 291 base::ScopedTempDir temp_dir;
292 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 292 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
293 293
294 MockEnvironment env; 294 MockEnvironment env;
295 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 295 env.Set("XDG_DATA_HOME", temp_dir.path().value());
296 // Create a file in a non-applications directory. This should be ignored. 296 // Create a file in a non-applications directory. This should be ignored.
297 ASSERT_TRUE(file_util::WriteFile( 297 ASSERT_TRUE(base::WriteFile(
298 temp_dir.path().AppendASCII(kTemplateFilename), 298 temp_dir.path().AppendASCII(kTemplateFilename),
299 kTestData2, strlen(kTestData2))); 299 kTestData2, strlen(kTestData2)));
300 ASSERT_TRUE(base::CreateDirectory( 300 ASSERT_TRUE(base::CreateDirectory(
301 temp_dir.path().AppendASCII("applications"))); 301 temp_dir.path().AppendASCII("applications")));
302 ASSERT_TRUE(file_util::WriteFile( 302 ASSERT_TRUE(base::WriteFile(
303 temp_dir.path().AppendASCII("applications") 303 temp_dir.path().AppendASCII("applications")
304 .AppendASCII(kTemplateFilename), 304 .AppendASCII(kTemplateFilename),
305 kTestData1, strlen(kTestData1))); 305 kTestData1, strlen(kTestData1)));
306 std::string contents; 306 std::string contents;
307 ASSERT_TRUE( 307 ASSERT_TRUE(
308 ShellIntegrationLinux::GetExistingShortcutContents( 308 ShellIntegrationLinux::GetExistingShortcutContents(
309 &env, kTemplateFilepath, &contents)); 309 &env, kTemplateFilepath, &contents));
310 EXPECT_EQ(kTestData1, contents); 310 EXPECT_EQ(kTestData1, contents);
311 } 311 }
312 312
313 // Test that it falls back to $HOME/.local/share/applications. 313 // Test that it falls back to $HOME/.local/share/applications.
314 { 314 {
315 base::ScopedTempDir temp_dir; 315 base::ScopedTempDir temp_dir;
316 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 316 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
317 317
318 MockEnvironment env; 318 MockEnvironment env;
319 env.Set("HOME", temp_dir.path().value()); 319 env.Set("HOME", temp_dir.path().value());
320 ASSERT_TRUE(base::CreateDirectory( 320 ASSERT_TRUE(base::CreateDirectory(
321 temp_dir.path().AppendASCII(".local/share/applications"))); 321 temp_dir.path().AppendASCII(".local/share/applications")));
322 ASSERT_TRUE(file_util::WriteFile( 322 ASSERT_TRUE(base::WriteFile(
323 temp_dir.path().AppendASCII(".local/share/applications") 323 temp_dir.path().AppendASCII(".local/share/applications")
324 .AppendASCII(kTemplateFilename), 324 .AppendASCII(kTemplateFilename),
325 kTestData1, strlen(kTestData1))); 325 kTestData1, strlen(kTestData1)));
326 std::string contents; 326 std::string contents;
327 ASSERT_TRUE( 327 ASSERT_TRUE(
328 ShellIntegrationLinux::GetExistingShortcutContents( 328 ShellIntegrationLinux::GetExistingShortcutContents(
329 &env, kTemplateFilepath, &contents)); 329 &env, kTemplateFilepath, &contents));
330 EXPECT_EQ(kTestData1, contents); 330 EXPECT_EQ(kTestData1, contents);
331 } 331 }
332 332
333 // Test that it searches $XDG_DATA_DIRS/applications. 333 // Test that it searches $XDG_DATA_DIRS/applications.
334 { 334 {
335 base::ScopedTempDir temp_dir; 335 base::ScopedTempDir temp_dir;
336 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 336 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
337 337
338 MockEnvironment env; 338 MockEnvironment env;
339 env.Set("XDG_DATA_DIRS", temp_dir.path().value()); 339 env.Set("XDG_DATA_DIRS", temp_dir.path().value());
340 ASSERT_TRUE(base::CreateDirectory( 340 ASSERT_TRUE(base::CreateDirectory(
341 temp_dir.path().AppendASCII("applications"))); 341 temp_dir.path().AppendASCII("applications")));
342 ASSERT_TRUE(file_util::WriteFile( 342 ASSERT_TRUE(base::WriteFile(
343 temp_dir.path().AppendASCII("applications") 343 temp_dir.path().AppendASCII("applications")
344 .AppendASCII(kTemplateFilename), 344 .AppendASCII(kTemplateFilename),
345 kTestData2, strlen(kTestData2))); 345 kTestData2, strlen(kTestData2)));
346 std::string contents; 346 std::string contents;
347 ASSERT_TRUE( 347 ASSERT_TRUE(
348 ShellIntegrationLinux::GetExistingShortcutContents( 348 ShellIntegrationLinux::GetExistingShortcutContents(
349 &env, kTemplateFilepath, &contents)); 349 &env, kTemplateFilepath, &contents));
350 EXPECT_EQ(kTestData2, contents); 350 EXPECT_EQ(kTestData2, contents);
351 } 351 }
352 352
353 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS. 353 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS.
354 { 354 {
355 base::ScopedTempDir temp_dir1; 355 base::ScopedTempDir temp_dir1;
356 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 356 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
357 base::ScopedTempDir temp_dir2; 357 base::ScopedTempDir temp_dir2;
358 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 358 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
359 359
360 MockEnvironment env; 360 MockEnvironment env;
361 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" + 361 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" +
362 temp_dir2.path().value()); 362 temp_dir2.path().value());
363 // Create a file in a non-applications directory. This should be ignored. 363 // Create a file in a non-applications directory. This should be ignored.
364 ASSERT_TRUE(file_util::WriteFile( 364 ASSERT_TRUE(base::WriteFile(
365 temp_dir1.path().AppendASCII(kTemplateFilename), 365 temp_dir1.path().AppendASCII(kTemplateFilename),
366 kTestData1, strlen(kTestData1))); 366 kTestData1, strlen(kTestData1)));
367 // Only create a findable desktop file in the second path. 367 // Only create a findable desktop file in the second path.
368 ASSERT_TRUE(base::CreateDirectory( 368 ASSERT_TRUE(base::CreateDirectory(
369 temp_dir2.path().AppendASCII("applications"))); 369 temp_dir2.path().AppendASCII("applications")));
370 ASSERT_TRUE(file_util::WriteFile( 370 ASSERT_TRUE(base::WriteFile(
371 temp_dir2.path().AppendASCII("applications") 371 temp_dir2.path().AppendASCII("applications")
372 .AppendASCII(kTemplateFilename), 372 .AppendASCII(kTemplateFilename),
373 kTestData2, strlen(kTestData2))); 373 kTestData2, strlen(kTestData2)));
374 std::string contents; 374 std::string contents;
375 ASSERT_TRUE( 375 ASSERT_TRUE(
376 ShellIntegrationLinux::GetExistingShortcutContents( 376 ShellIntegrationLinux::GetExistingShortcutContents(
377 &env, kTemplateFilepath, &contents)); 377 &env, kTemplateFilepath, &contents));
378 EXPECT_EQ(kTestData2, contents); 378 EXPECT_EQ(kTestData2, contents);
379 } 379 }
380 } 380 }
(...skipping 11 matching lines...) Expand all
392 const char kApp1Filename[] = "chrome-extension1-Profile_Name_.desktop"; 392 const char kApp1Filename[] = "chrome-extension1-Profile_Name_.desktop";
393 const char kApp2Filename[] = "chrome-extension2-Profile_Name_.desktop"; 393 const char kApp2Filename[] = "chrome-extension2-Profile_Name_.desktop";
394 const char kUnrelatedAppFilename[] = "chrome-extension-Other_Profile.desktop"; 394 const char kUnrelatedAppFilename[] = "chrome-extension-Other_Profile.desktop";
395 395
396 base::MessageLoop message_loop; 396 base::MessageLoop message_loop;
397 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 397 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
398 398
399 base::ScopedTempDir temp_dir; 399 base::ScopedTempDir temp_dir;
400 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 400 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
401 ASSERT_EQ(0, 401 ASSERT_EQ(0,
402 file_util::WriteFile( 402 base::WriteFile(
403 temp_dir.path().AppendASCII(kApp1Filename), "", 0)); 403 temp_dir.path().AppendASCII(kApp1Filename), "", 0));
404 ASSERT_EQ(0, 404 ASSERT_EQ(0,
405 file_util::WriteFile( 405 base::WriteFile(
406 temp_dir.path().AppendASCII(kApp2Filename), "", 0)); 406 temp_dir.path().AppendASCII(kApp2Filename), "", 0));
407 // This file should not be returned in the results. 407 // This file should not be returned in the results.
408 ASSERT_EQ(0, 408 ASSERT_EQ(0,
409 file_util::WriteFile( 409 base::WriteFile(
410 temp_dir.path().AppendASCII(kUnrelatedAppFilename), "", 0)); 410 temp_dir.path().AppendASCII(kUnrelatedAppFilename), "", 0));
411 std::vector<base::FilePath> paths = 411 std::vector<base::FilePath> paths =
412 ShellIntegrationLinux::GetExistingProfileShortcutFilenames( 412 ShellIntegrationLinux::GetExistingProfileShortcutFilenames(
413 kProfilePath, temp_dir.path()); 413 kProfilePath, temp_dir.path());
414 // Path order is arbitrary. Sort the output for consistency. 414 // Path order is arbitrary. Sort the output for consistency.
415 std::sort(paths.begin(), paths.end()); 415 std::sort(paths.begin(), paths.end());
416 EXPECT_THAT(paths, 416 EXPECT_THAT(paths,
417 ElementsAre(base::FilePath(kApp1Filename), 417 ElementsAre(base::FilePath(kApp1Filename),
418 base::FilePath(kApp2Filename))); 418 base::FilePath(kApp2Filename)));
419 } 419 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 638
639 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { 639 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) {
640 SCOPED_TRACE(i); 640 SCOPED_TRACE(i);
641 EXPECT_EQ( 641 EXPECT_EQ(
642 test_cases[i].expected_output, 642 test_cases[i].expected_output,
643 ShellIntegrationLinux::GetDirectoryFileContents( 643 ShellIntegrationLinux::GetDirectoryFileContents(
644 base::ASCIIToUTF16(test_cases[i].title), 644 base::ASCIIToUTF16(test_cases[i].title),
645 test_cases[i].icon_name)); 645 test_cases[i].icon_name));
646 } 646 }
647 } 647 }
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration_linux.cc ('k') | chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698