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

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

Issue 12386077: shell_integration_linux: Follow the XDG Base Directory Specification. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Swap /usr/share and /usr/local/share to match the spec. Created 7 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
« 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 (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 #include "chrome/browser/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <map> 8 #include <map>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 #else // CHROMIUM_BUILD 112 #else // CHROMIUM_BUILD
113 const char kTemplateFilename[] = "chromium-browser.desktop"; 113 const char kTemplateFilename[] = "chromium-browser.desktop";
114 #endif 114 #endif
115 115
116 const char kTestData1[] = "a magical testing string"; 116 const char kTestData1[] = "a magical testing string";
117 const char kTestData2[] = "a different testing string"; 117 const char kTestData2[] = "a different testing string";
118 118
119 MessageLoop message_loop; 119 MessageLoop message_loop;
120 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 120 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
121 121
122 // Test that it searches $XDG_DATA_HOME/applications.
122 { 123 {
123 base::ScopedTempDir temp_dir; 124 base::ScopedTempDir temp_dir;
124 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 125 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
125 126
126 MockEnvironment env; 127 MockEnvironment env;
127 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 128 env.Set("XDG_DATA_HOME", temp_dir.path().value());
129 // Create a file in a non-applications directory. This should be ignored.
128 ASSERT_TRUE(file_util::WriteFile( 130 ASSERT_TRUE(file_util::WriteFile(
129 temp_dir.path().AppendASCII(kTemplateFilename), 131 temp_dir.path().AppendASCII(kTemplateFilename),
132 kTestData2, strlen(kTestData2)));
133 ASSERT_TRUE(file_util::CreateDirectory(
134 temp_dir.path().AppendASCII("applications")));
135 ASSERT_TRUE(file_util::WriteFile(
136 temp_dir.path().AppendASCII("applications")
137 .AppendASCII(kTemplateFilename),
130 kTestData1, strlen(kTestData1))); 138 kTestData1, strlen(kTestData1)));
131 std::string contents; 139 std::string contents;
132 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, 140 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
141 &contents));
142 EXPECT_EQ(kTestData1, contents);
143 }
144
145 // Test that it falls back to $HOME/.local/share/applications.
146 {
147 base::ScopedTempDir temp_dir;
148 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
149
150 MockEnvironment env;
151 env.Set("HOME", temp_dir.path().value());
152 ASSERT_TRUE(file_util::CreateDirectory(
153 temp_dir.path().AppendASCII(".local/share/applications")));
154 ASSERT_TRUE(file_util::WriteFile(
155 temp_dir.path().AppendASCII(".local/share/applications")
156 .AppendASCII(kTemplateFilename),
157 kTestData1, strlen(kTestData1)));
158 std::string contents;
159 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
133 &contents)); 160 &contents));
134 EXPECT_EQ(kTestData1, contents); 161 EXPECT_EQ(kTestData1, contents);
135 } 162 }
136 163
164 // Test that it searches $XDG_DATA_DIRS/applications.
137 { 165 {
138 base::ScopedTempDir temp_dir; 166 base::ScopedTempDir temp_dir;
139 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 167 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
140 168
141 MockEnvironment env; 169 MockEnvironment env;
142 env.Set("XDG_DATA_DIRS", temp_dir.path().value()); 170 env.Set("XDG_DATA_DIRS", temp_dir.path().value());
143 ASSERT_TRUE(file_util::CreateDirectory( 171 ASSERT_TRUE(file_util::CreateDirectory(
144 temp_dir.path().AppendASCII("applications"))); 172 temp_dir.path().AppendASCII("applications")));
145 ASSERT_TRUE(file_util::WriteFile( 173 ASSERT_TRUE(file_util::WriteFile(
146 temp_dir.path().AppendASCII("applications") 174 temp_dir.path().AppendASCII("applications")
147 .AppendASCII(kTemplateFilename), 175 .AppendASCII(kTemplateFilename),
148 kTestData2, strlen(kTestData2))); 176 kTestData2, strlen(kTestData2)));
149 std::string contents; 177 std::string contents;
150 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, 178 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
151 &contents)); 179 &contents));
152 EXPECT_EQ(kTestData2, contents); 180 EXPECT_EQ(kTestData2, contents);
153 } 181 }
154 182
183 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS.
155 { 184 {
156 base::ScopedTempDir temp_dir; 185 base::ScopedTempDir temp_dir1;
157 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 186 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
187 base::ScopedTempDir temp_dir2;
188 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
158 189
159 MockEnvironment env; 190 MockEnvironment env;
160 env.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" + 191 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" +
161 temp_dir.path().AppendASCII("applications").value()); 192 temp_dir2.path().value());
193 // Create a file in a non-applications directory. This should be ignored.
194 ASSERT_TRUE(file_util::WriteFile(
195 temp_dir1.path().AppendASCII(kTemplateFilename),
196 kTestData1, strlen(kTestData1)));
197 // Only create a findable desktop file in the second path.
162 ASSERT_TRUE(file_util::CreateDirectory( 198 ASSERT_TRUE(file_util::CreateDirectory(
163 temp_dir.path().AppendASCII("applications"))); 199 temp_dir2.path().AppendASCII("applications")));
164 ASSERT_TRUE(file_util::WriteFile( 200 ASSERT_TRUE(file_util::WriteFile(
165 temp_dir.path().AppendASCII(kTemplateFilename), 201 temp_dir2.path().AppendASCII("applications")
166 kTestData1, strlen(kTestData1)));
167 ASSERT_TRUE(file_util::WriteFile(
168 temp_dir.path().AppendASCII("applications")
169 .AppendASCII(kTemplateFilename), 202 .AppendASCII(kTemplateFilename),
170 kTestData2, strlen(kTestData2))); 203 kTestData2, strlen(kTestData2)));
171 std::string contents; 204 std::string contents;
172 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, 205 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
173 &contents)); 206 &contents));
174 EXPECT_EQ(kTestData1, contents); 207 EXPECT_EQ(kTestData2, contents);
175 } 208 }
176 } 209 }
177 210
178 TEST(ShellIntegrationTest, GetWebShortcutFilename) { 211 TEST(ShellIntegrationTest, GetWebShortcutFilename) {
179 const struct { 212 const struct {
180 const base::FilePath::CharType* path; 213 const base::FilePath::CharType* path;
181 const char* url; 214 const char* url;
182 } test_cases[] = { 215 } test_cases[] = {
183 { FPL("http___foo_.desktop"), "http://foo" }, 216 { FPL("http___foo_.desktop"), "http://foo" },
184 { FPL("http___foo_bar_.desktop"), "http://foo/bar/" }, 217 { FPL("http___foo_bar_.desktop"), "http://foo/bar/" },
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), 441 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)),
409 GURL(test_cases[i].url), 442 GURL(test_cases[i].url),
410 "", 443 "",
411 base::FilePath(), 444 base::FilePath(),
412 ASCIIToUTF16(test_cases[i].title), 445 ASCIIToUTF16(test_cases[i].title),
413 test_cases[i].icon_name, 446 test_cases[i].icon_name,
414 base::FilePath())); 447 base::FilePath()));
415 } 448 }
416 } 449 }
417 #endif 450 #endif
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