diff options
author | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-06 04:12:36 +0000 |
---|---|---|
committer | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-06 04:12:36 +0000 |
commit | 58bf9256cac6bbc0bece01cfaf966893bfa0c5b6 (patch) | |
tree | 12790826e5a9c309f0362a1dd6ab1a2c1c0f009b /chrome/browser/shell_integration_unittest.cc | |
parent | 76f269e5bf439557c731aa89ce27c9b858df11a1 (diff) | |
download | chromium_src-58bf9256cac6bbc0bece01cfaf966893bfa0c5b6.zip chromium_src-58bf9256cac6bbc0bece01cfaf966893bfa0c5b6.tar.gz chromium_src-58bf9256cac6bbc0bece01cfaf966893bfa0c5b6.tar.bz2 |
shell_integration_linux: Follow the XDG Base Directory Specification.
GetDesktopShortcutTemplate now:
- Searches $XDG_DATA_HOME/applications instead of $XDG_DATA_HOME.
- If $XDG_DATA_HOME is not found, falls back to $HOME/.local/share/applications.
- No longer searches $XDG_DATA_DIRS (without /applications).
- Only searches /usr/local/share/applications and /usr/share/applications if
$XDG_DATA_DIRS is not found.
- Searches /usr/local/share/applications before /usr/share/applications.
BUG=179751
Review URL: https://chromiumcodereview.appspot.com/12386077
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/shell_integration_unittest.cc')
-rw-r--r-- | chrome/browser/shell_integration_unittest.cc | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/chrome/browser/shell_integration_unittest.cc b/chrome/browser/shell_integration_unittest.cc index 39ca70a..186e14f 100644 --- a/chrome/browser/shell_integration_unittest.cc +++ b/chrome/browser/shell_integration_unittest.cc @@ -119,14 +119,41 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { MessageLoop message_loop; content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); + // Test that it searches $XDG_DATA_HOME/applications. { base::ScopedTempDir temp_dir; ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); MockEnvironment env; env.Set("XDG_DATA_HOME", temp_dir.path().value()); + // Create a file in a non-applications directory. This should be ignored. ASSERT_TRUE(file_util::WriteFile( temp_dir.path().AppendASCII(kTemplateFilename), + kTestData2, strlen(kTestData2))); + ASSERT_TRUE(file_util::CreateDirectory( + temp_dir.path().AppendASCII("applications"))); + ASSERT_TRUE(file_util::WriteFile( + temp_dir.path().AppendASCII("applications") + .AppendASCII(kTemplateFilename), + kTestData1, strlen(kTestData1))); + std::string contents; + ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, + &contents)); + EXPECT_EQ(kTestData1, contents); + } + + // Test that it falls back to $HOME/.local/share/applications. + { + base::ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + + MockEnvironment env; + env.Set("HOME", temp_dir.path().value()); + ASSERT_TRUE(file_util::CreateDirectory( + temp_dir.path().AppendASCII(".local/share/applications"))); + ASSERT_TRUE(file_util::WriteFile( + temp_dir.path().AppendASCII(".local/share/applications") + .AppendASCII(kTemplateFilename), kTestData1, strlen(kTestData1))); std::string contents; ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, @@ -134,6 +161,7 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { EXPECT_EQ(kTestData1, contents); } + // Test that it searches $XDG_DATA_DIRS/applications. { base::ScopedTempDir temp_dir; ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); @@ -152,26 +180,31 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { EXPECT_EQ(kTestData2, contents); } + // Test that it searches $X/applications for each X in $XDG_DATA_DIRS. { - base::ScopedTempDir temp_dir; - ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + base::ScopedTempDir temp_dir1; + ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); + base::ScopedTempDir temp_dir2; + ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); MockEnvironment env; - env.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" + - temp_dir.path().AppendASCII("applications").value()); - ASSERT_TRUE(file_util::CreateDirectory( - temp_dir.path().AppendASCII("applications"))); + env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" + + temp_dir2.path().value()); + // Create a file in a non-applications directory. This should be ignored. ASSERT_TRUE(file_util::WriteFile( - temp_dir.path().AppendASCII(kTemplateFilename), + temp_dir1.path().AppendASCII(kTemplateFilename), kTestData1, strlen(kTestData1))); + // Only create a findable desktop file in the second path. + ASSERT_TRUE(file_util::CreateDirectory( + temp_dir2.path().AppendASCII("applications"))); ASSERT_TRUE(file_util::WriteFile( - temp_dir.path().AppendASCII("applications") + temp_dir2.path().AppendASCII("applications") .AppendASCII(kTemplateFilename), kTestData2, strlen(kTestData2))); std::string contents; ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, &contents)); - EXPECT_EQ(kTestData1, contents); + EXPECT_EQ(kTestData2, contents); } } |