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

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

Issue 12208085: On Linux, automatically create app shortcuts on install or update. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Work around obscure crash due to bug in glib <= 2.32. 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
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 private: 99 private:
100 // Map from name to original value, or the empty string if there was no 100 // Map from name to original value, or the empty string if there was no
101 // previous value. 101 // previous value.
102 std::map<std::string, std::string> old_variables_; 102 std::map<std::string, std::string> old_variables_;
103 103
104 DISALLOW_COPY_AND_ASSIGN(ScopedEnvironment); 104 DISALLOW_COPY_AND_ASSIGN(ScopedEnvironment);
105 }; 105 };
106 106
107 } // namespace 107 } // namespace
108 108
109 TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { 109 TEST(ShellIntegrationTest, GetExistingShortcutLocations) {
110 #if defined(GOOGLE_CHROME_BUILD) 110 base::FilePath kProfilePath("Default");
111 const char kTemplateFilename[] = "google-chrome.desktop"; 111 const char kExtensionId[] = "test_extension";
112 #else // CHROMIUM_BUILD 112 const char kTemplateFilename[] = "chrome-test_extension-Default.desktop";
113 const char kTemplateFilename[] = "chromium-browser.desktop"; 113 base::FilePath kTemplateFilepath(kTemplateFilename);
114 #endif 114 const char kNoDisplayDesktopFile[] = "[Desktop Entry]\nNoDisplay=true";
115 115
116 MessageLoop message_loop;
117 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
118
119 // No existing shortcuts.
120 {
121 MockEnvironment env;
122 ShellIntegration::ShortcutLocations result =
123 ShellIntegrationLinux::GetExistingShortcutLocations(
124 &env, kProfilePath, kExtensionId);
125 EXPECT_FALSE(result.on_desktop);
126 EXPECT_FALSE(result.in_applications_menu);
127 EXPECT_FALSE(result.in_quick_launch_bar);
128 EXPECT_FALSE(result.hidden);
129 }
130
131 // Shortcut on desktop.
132 {
133 base::ScopedTempDir temp_dir;
134 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
135 base::FilePath desktop_path = temp_dir.path();
136
137 MockEnvironment env;
138 ASSERT_TRUE(file_util::CreateDirectory(desktop_path));
139 ASSERT_FALSE(file_util::WriteFile(
140 desktop_path.AppendASCII(kTemplateFilename),
141 "", 0));
142 ShellIntegration::ShortcutLocations result =
143 ShellIntegrationLinux::GetExistingShortcutLocations(
144 &env, kProfilePath, kExtensionId, desktop_path);
145 EXPECT_TRUE(result.on_desktop);
146 EXPECT_FALSE(result.in_applications_menu);
147 EXPECT_FALSE(result.in_quick_launch_bar);
148 EXPECT_FALSE(result.hidden);
149 }
150
151 // Shortcut in applications directory.
152 {
153 base::ScopedTempDir temp_dir;
154 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
155 base::FilePath apps_path = temp_dir.path().AppendASCII("applications");
156
157 MockEnvironment env;
158 env.Set("XDG_DATA_HOME", temp_dir.path().value());
159 ASSERT_TRUE(file_util::CreateDirectory(apps_path));
160 ASSERT_FALSE(file_util::WriteFile(
161 apps_path.AppendASCII(kTemplateFilename),
162 "", 0));
163 ShellIntegration::ShortcutLocations result =
164 ShellIntegrationLinux::GetExistingShortcutLocations(
165 &env, kProfilePath, kExtensionId);
166 EXPECT_FALSE(result.on_desktop);
167 EXPECT_TRUE(result.in_applications_menu);
168 EXPECT_FALSE(result.in_quick_launch_bar);
169 EXPECT_FALSE(result.hidden);
170 }
171
172 // Shortcut in applications directory with NoDisplay=true.
173 {
174 base::ScopedTempDir temp_dir;
175 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
176 base::FilePath apps_path = temp_dir.path().AppendASCII("applications");
177
178 MockEnvironment env;
179 env.Set("XDG_DATA_HOME", temp_dir.path().value());
180 ASSERT_TRUE(file_util::CreateDirectory(apps_path));
181 ASSERT_TRUE(file_util::WriteFile(
182 apps_path.AppendASCII(kTemplateFilename),
183 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile)));
184 ShellIntegration::ShortcutLocations result =
185 ShellIntegrationLinux::GetExistingShortcutLocations(
186 &env, kProfilePath, kExtensionId);
187 // Doesn't count as being in applications menu.
188 EXPECT_FALSE(result.on_desktop);
189 EXPECT_FALSE(result.in_applications_menu);
190 EXPECT_FALSE(result.in_quick_launch_bar);
191 EXPECT_TRUE(result.hidden);
192 }
193
194 // Shortcut on desktop and in applications directory.
195 {
196 base::ScopedTempDir temp_dir1;
197 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
198 base::FilePath desktop_path = temp_dir1.path();
199
200 base::ScopedTempDir temp_dir2;
201 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
202 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications");
203
204 MockEnvironment env;
205 ASSERT_TRUE(file_util::CreateDirectory(desktop_path));
206 ASSERT_FALSE(file_util::WriteFile(
207 desktop_path.AppendASCII(kTemplateFilename),
208 "", 0));
209 env.Set("XDG_DATA_HOME", temp_dir2.path().value());
210 ASSERT_TRUE(file_util::CreateDirectory(apps_path));
211 ASSERT_FALSE(file_util::WriteFile(
212 apps_path.AppendASCII(kTemplateFilename),
213 "", 0));
214 ShellIntegration::ShortcutLocations result =
215 ShellIntegrationLinux::GetExistingShortcutLocations(
216 &env, kProfilePath, kExtensionId, desktop_path);
217 EXPECT_TRUE(result.on_desktop);
218 EXPECT_TRUE(result.in_applications_menu);
219 EXPECT_FALSE(result.in_quick_launch_bar);
220 EXPECT_FALSE(result.hidden);
221 }
222 }
223
224 TEST(ShellIntegrationTest, GetExistingShortcutContents) {
225 const char kTemplateFilename[] = "shortcut-test.desktop";
226 base::FilePath kTemplateFilepath(kTemplateFilename);
116 const char kTestData1[] = "a magical testing string"; 227 const char kTestData1[] = "a magical testing string";
117 const char kTestData2[] = "a different testing string"; 228 const char kTestData2[] = "a different testing string";
118 229
119 MessageLoop message_loop; 230 MessageLoop message_loop;
120 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 231 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
121 232
122 // Test that it searches $XDG_DATA_HOME/applications. 233 // Test that it searches $XDG_DATA_HOME/applications.
123 { 234 {
124 base::ScopedTempDir temp_dir; 235 base::ScopedTempDir temp_dir;
125 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 236 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
126 237
127 MockEnvironment env; 238 MockEnvironment env;
128 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 239 env.Set("XDG_DATA_HOME", temp_dir.path().value());
129 // Create a file in a non-applications directory. This should be ignored. 240 // Create a file in a non-applications directory. This should be ignored.
130 ASSERT_TRUE(file_util::WriteFile( 241 ASSERT_TRUE(file_util::WriteFile(
131 temp_dir.path().AppendASCII(kTemplateFilename), 242 temp_dir.path().AppendASCII(kTemplateFilename),
132 kTestData2, strlen(kTestData2))); 243 kTestData2, strlen(kTestData2)));
133 ASSERT_TRUE(file_util::CreateDirectory( 244 ASSERT_TRUE(file_util::CreateDirectory(
134 temp_dir.path().AppendASCII("applications"))); 245 temp_dir.path().AppendASCII("applications")));
135 ASSERT_TRUE(file_util::WriteFile( 246 ASSERT_TRUE(file_util::WriteFile(
136 temp_dir.path().AppendASCII("applications") 247 temp_dir.path().AppendASCII("applications")
137 .AppendASCII(kTemplateFilename), 248 .AppendASCII(kTemplateFilename),
138 kTestData1, strlen(kTestData1))); 249 kTestData1, strlen(kTestData1)));
139 std::string contents; 250 std::string contents;
140 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, 251 ASSERT_TRUE(
141 &contents)); 252 ShellIntegrationLinux::GetExistingShortcutContents(
253 &env, kTemplateFilepath, &contents));
142 EXPECT_EQ(kTestData1, contents); 254 EXPECT_EQ(kTestData1, contents);
143 } 255 }
144 256
145 // Test that it falls back to $HOME/.local/share/applications. 257 // Test that it falls back to $HOME/.local/share/applications.
146 { 258 {
147 base::ScopedTempDir temp_dir; 259 base::ScopedTempDir temp_dir;
148 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 260 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
149 261
150 MockEnvironment env; 262 MockEnvironment env;
151 env.Set("HOME", temp_dir.path().value()); 263 env.Set("HOME", temp_dir.path().value());
152 ASSERT_TRUE(file_util::CreateDirectory( 264 ASSERT_TRUE(file_util::CreateDirectory(
153 temp_dir.path().AppendASCII(".local/share/applications"))); 265 temp_dir.path().AppendASCII(".local/share/applications")));
154 ASSERT_TRUE(file_util::WriteFile( 266 ASSERT_TRUE(file_util::WriteFile(
155 temp_dir.path().AppendASCII(".local/share/applications") 267 temp_dir.path().AppendASCII(".local/share/applications")
156 .AppendASCII(kTemplateFilename), 268 .AppendASCII(kTemplateFilename),
157 kTestData1, strlen(kTestData1))); 269 kTestData1, strlen(kTestData1)));
158 std::string contents; 270 std::string contents;
159 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, 271 ASSERT_TRUE(
160 &contents)); 272 ShellIntegrationLinux::GetExistingShortcutContents(
273 &env, kTemplateFilepath, &contents));
161 EXPECT_EQ(kTestData1, contents); 274 EXPECT_EQ(kTestData1, contents);
162 } 275 }
163 276
164 // Test that it searches $XDG_DATA_DIRS/applications. 277 // Test that it searches $XDG_DATA_DIRS/applications.
165 { 278 {
166 base::ScopedTempDir temp_dir; 279 base::ScopedTempDir temp_dir;
167 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 280 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
168 281
169 MockEnvironment env; 282 MockEnvironment env;
170 env.Set("XDG_DATA_DIRS", temp_dir.path().value()); 283 env.Set("XDG_DATA_DIRS", temp_dir.path().value());
171 ASSERT_TRUE(file_util::CreateDirectory( 284 ASSERT_TRUE(file_util::CreateDirectory(
172 temp_dir.path().AppendASCII("applications"))); 285 temp_dir.path().AppendASCII("applications")));
173 ASSERT_TRUE(file_util::WriteFile( 286 ASSERT_TRUE(file_util::WriteFile(
174 temp_dir.path().AppendASCII("applications") 287 temp_dir.path().AppendASCII("applications")
175 .AppendASCII(kTemplateFilename), 288 .AppendASCII(kTemplateFilename),
176 kTestData2, strlen(kTestData2))); 289 kTestData2, strlen(kTestData2)));
177 std::string contents; 290 std::string contents;
178 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, 291 ASSERT_TRUE(
179 &contents)); 292 ShellIntegrationLinux::GetExistingShortcutContents(
293 &env, kTemplateFilepath, &contents));
180 EXPECT_EQ(kTestData2, contents); 294 EXPECT_EQ(kTestData2, contents);
181 } 295 }
182 296
183 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS. 297 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS.
184 { 298 {
185 base::ScopedTempDir temp_dir1; 299 base::ScopedTempDir temp_dir1;
186 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 300 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
187 base::ScopedTempDir temp_dir2; 301 base::ScopedTempDir temp_dir2;
188 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 302 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
189 303
190 MockEnvironment env; 304 MockEnvironment env;
191 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" + 305 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" +
192 temp_dir2.path().value()); 306 temp_dir2.path().value());
193 // Create a file in a non-applications directory. This should be ignored. 307 // Create a file in a non-applications directory. This should be ignored.
194 ASSERT_TRUE(file_util::WriteFile( 308 ASSERT_TRUE(file_util::WriteFile(
195 temp_dir1.path().AppendASCII(kTemplateFilename), 309 temp_dir1.path().AppendASCII(kTemplateFilename),
196 kTestData1, strlen(kTestData1))); 310 kTestData1, strlen(kTestData1)));
197 // Only create a findable desktop file in the second path. 311 // Only create a findable desktop file in the second path.
198 ASSERT_TRUE(file_util::CreateDirectory( 312 ASSERT_TRUE(file_util::CreateDirectory(
199 temp_dir2.path().AppendASCII("applications"))); 313 temp_dir2.path().AppendASCII("applications")));
200 ASSERT_TRUE(file_util::WriteFile( 314 ASSERT_TRUE(file_util::WriteFile(
201 temp_dir2.path().AppendASCII("applications") 315 temp_dir2.path().AppendASCII("applications")
202 .AppendASCII(kTemplateFilename), 316 .AppendASCII(kTemplateFilename),
203 kTestData2, strlen(kTestData2))); 317 kTestData2, strlen(kTestData2)));
204 std::string contents; 318 std::string contents;
205 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, 319 ASSERT_TRUE(
206 &contents)); 320 ShellIntegrationLinux::GetExistingShortcutContents(
321 &env, kTemplateFilepath, &contents));
207 EXPECT_EQ(kTestData2, contents); 322 EXPECT_EQ(kTestData2, contents);
208 } 323 }
209 } 324 }
210 325
326 TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
327 #if defined(GOOGLE_CHROME_BUILD)
328 const char kTemplateFilename[] = "google-chrome.desktop";
329 #else // CHROMIUM_BUILD
330 const char kTemplateFilename[] = "chromium-browser.desktop";
331 #endif
332
333 const char kTestData[] = "a magical testing string";
334
335 MessageLoop message_loop;
336 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
337
338 // Just do a simple test. The details are covered by
339 // GetExistingShortcutContents test.
340 {
341 base::ScopedTempDir temp_dir;
342 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
343
344 MockEnvironment env;
345 env.Set("XDG_DATA_HOME", temp_dir.path().value());
346 ASSERT_TRUE(file_util::CreateDirectory(
347 temp_dir.path().AppendASCII("applications")));
348 ASSERT_TRUE(file_util::WriteFile(
349 temp_dir.path().AppendASCII("applications")
350 .AppendASCII(kTemplateFilename),
351 kTestData, strlen(kTestData)));
352 std::string contents;
353 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
354 &contents));
355 EXPECT_EQ(kTestData, contents);
356 }
357 }
358
211 TEST(ShellIntegrationTest, GetWebShortcutFilename) { 359 TEST(ShellIntegrationTest, GetWebShortcutFilename) {
212 const struct { 360 const struct {
213 const base::FilePath::CharType* path; 361 const base::FilePath::CharType* path;
214 const char* url; 362 const char* url;
215 } test_cases[] = { 363 } test_cases[] = {
216 { FPL("http___foo_.desktop"), "http://foo" }, 364 { FPL("http___foo_.desktop"), "http://foo" },
217 { FPL("http___foo_bar_.desktop"), "http://foo/bar/" }, 365 { FPL("http___foo_bar_.desktop"), "http://foo/bar/" },
218 { FPL("http___foo_bar_a=b&c=d.desktop"), "http://foo/bar?a=b&c=d" }, 366 { FPL("http___foo_bar_a=b&c=d.desktop"), "http://foo/bar?a=b&c=d" },
219 367
220 // Now we're starting to be more evil... 368 // Now we're starting to be more evil...
221 { FPL("http___foo_.desktop"), "http://foo/bar/baz/../../../../../" }, 369 { FPL("http___foo_.desktop"), "http://foo/bar/baz/../../../../../" },
222 { FPL("http___foo_.desktop"), "http://foo/bar/././../baz/././../" }, 370 { FPL("http___foo_.desktop"), "http://foo/bar/././../baz/././../" },
223 { FPL("http___.._.desktop"), "http://../../../../" }, 371 { FPL("http___.._.desktop"), "http://../../../../" },
224 }; 372 };
225 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { 373 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) {
226 EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" + 374 EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" +
227 test_cases[i].path, 375 test_cases[i].path,
228 ShellIntegrationLinux::GetWebShortcutFilename( 376 ShellIntegrationLinux::GetWebShortcutFilename(
229 GURL(test_cases[i].url)).value()) << 377 GURL(test_cases[i].url)).value()) <<
230 " while testing " << test_cases[i].url; 378 " while testing " << test_cases[i].url;
231 } 379 }
232 } 380 }
233 381
234 TEST(ShellIntegrationTest, GetDesktopFileContents) { 382 TEST(ShellIntegrationTest, GetDesktopFileContents) {
235 const struct { 383 const struct {
236 const char* url; 384 const char* url;
237 const char* title; 385 const char* title;
238 const char* icon_name; 386 const char* icon_name;
387 bool nodisplay;
239 const char* template_contents; 388 const char* template_contents;
240 const char* expected_output; 389 const char* expected_output;
241 } test_cases[] = { 390 } test_cases[] = {
242 // Dumb case. 391 // Dumb case.
243 { "ignored", "ignored", "ignored", "", "#!/usr/bin/env xdg-open\n" }, 392 { "ignored", "ignored", "ignored", false, "", "#!/usr/bin/env xdg-open\n" },
244 393
245 // Real-world case. 394 // Real-world case.
246 { "http://gmail.com", 395 { "http://gmail.com",
247 "GMail", 396 "GMail",
248 "chrome-http__gmail.com", 397 "chrome-http__gmail.com",
398 false,
249 399
250 "[Desktop Entry]\n" 400 "[Desktop Entry]\n"
251 "Version=1.0\n" 401 "Version=1.0\n"
252 "Encoding=UTF-8\n" 402 "Encoding=UTF-8\n"
253 "Name=Google Chrome\n" 403 "Name=Google Chrome\n"
254 "GenericName=Web Browser\n" 404 "GenericName=Web Browser\n"
255 "Comment=The web browser from Google\n" 405 "Comment=The web browser from Google\n"
256 "Exec=/opt/google/chrome/google-chrome %U\n" 406 "Exec=/opt/google/chrome/google-chrome %U\n"
257 "Terminal=false\n" 407 "Terminal=false\n"
258 "Icon=/opt/google/chrome/product_logo_48.png\n" 408 "Icon=/opt/google/chrome/product_logo_48.png\n"
(...skipping 21 matching lines...) Expand all
280 // Aura Chrome does not (yet) set WMClass, so we only expect 430 // Aura Chrome does not (yet) set WMClass, so we only expect
281 // StartupWMClass on non-Aura builds. 431 // StartupWMClass on non-Aura builds.
282 "StartupWMClass=gmail.com\n" 432 "StartupWMClass=gmail.com\n"
283 #endif 433 #endif
284 }, 434 },
285 435
286 // Make sure we don't insert duplicate shebangs. 436 // Make sure we don't insert duplicate shebangs.
287 { "http://gmail.com", 437 { "http://gmail.com",
288 "GMail", 438 "GMail",
289 "chrome-http__gmail.com", 439 "chrome-http__gmail.com",
440 false,
290 441
291 "#!/some/shebang\n" 442 "#!/some/shebang\n"
292 "[Desktop Entry]\n" 443 "[Desktop Entry]\n"
293 "Name=Google Chrome\n" 444 "Name=Google Chrome\n"
294 "Exec=/opt/google/chrome/google-chrome %U\n", 445 "Exec=/opt/google/chrome/google-chrome %U\n",
295 446
296 "#!/usr/bin/env xdg-open\n" 447 "#!/usr/bin/env xdg-open\n"
297 "[Desktop Entry]\n" 448 "[Desktop Entry]\n"
298 "Name=GMail\n" 449 "Name=GMail\n"
299 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" 450 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n"
300 "Icon=chrome-http__gmail.com\n" 451 "Icon=chrome-http__gmail.com\n"
301 #if !defined(USE_AURA) 452 #if !defined(USE_AURA)
302 // Aura Chrome does not (yet) set WMClass, so we only expect 453 // Aura Chrome does not (yet) set WMClass, so we only expect
303 // StartupWMClass on non-Aura builds. 454 // StartupWMClass on non-Aura builds.
304 "StartupWMClass=gmail.com\n" 455 "StartupWMClass=gmail.com\n"
305 #endif 456 #endif
306 }, 457 },
307 458
308 // Make sure i18n-ed names and other fields are removed. 459 // Make sure i18n-ed names and other fields are removed.
309 { "http://gmail.com", 460 { "http://gmail.com",
310 "GMail", 461 "GMail",
311 "chrome-http__gmail.com", 462 "chrome-http__gmail.com",
463 false,
312 464
313 "[Desktop Entry]\n" 465 "[Desktop Entry]\n"
314 "Name=Google Chrome\n" 466 "Name=Google Chrome\n"
315 "Name[en_AU]=Google Chrome\n" 467 "Name[en_AU]=Google Chrome\n"
316 "Name[pl]=Google Chrome\n" 468 "Name[pl]=Google Chrome\n"
317 "GenericName=Web Browser\n" 469 "GenericName=Web Browser\n"
318 "GenericName[en_AU]=Web Browser\n" 470 "GenericName[en_AU]=Web Browser\n"
319 "GenericName[pl]=Navegador Web\n" 471 "GenericName[pl]=Navegador Web\n"
320 "Exec=/opt/google/chrome/google-chrome %U\n" 472 "Exec=/opt/google/chrome/google-chrome %U\n"
321 "Comment[en_AU]=Some comment.\n" 473 "Comment[en_AU]=Some comment.\n"
322 "Comment[pl]=Jakis komentarz.\n", 474 "Comment[pl]=Jakis komentarz.\n",
323 475
324 "#!/usr/bin/env xdg-open\n" 476 "#!/usr/bin/env xdg-open\n"
325 "[Desktop Entry]\n" 477 "[Desktop Entry]\n"
326 "Name=GMail\n" 478 "Name=GMail\n"
327 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" 479 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n"
328 "Icon=chrome-http__gmail.com\n" 480 "Icon=chrome-http__gmail.com\n"
329 #if !defined(USE_AURA) 481 #if !defined(USE_AURA)
330 // Aura Chrome does not (yet) set WMClass, so we only expect 482 // Aura Chrome does not (yet) set WMClass, so we only expect
331 // StartupWMClass on non-Aura builds. 483 // StartupWMClass on non-Aura builds.
332 "StartupWMClass=gmail.com\n" 484 "StartupWMClass=gmail.com\n"
333 #endif 485 #endif
334 }, 486 },
335 487
336 // Make sure that empty icons are replaced by the chrome icon. 488 // Make sure that empty icons are replaced by the chrome icon.
337 { "http://gmail.com", 489 { "http://gmail.com",
338 "GMail", 490 "GMail",
339 "", 491 "",
492 false,
340 493
341 "[Desktop Entry]\n" 494 "[Desktop Entry]\n"
342 "Name=Google Chrome\n" 495 "Name=Google Chrome\n"
343 "Exec=/opt/google/chrome/google-chrome %U\n" 496 "Exec=/opt/google/chrome/google-chrome %U\n"
344 "Comment[pl]=Jakis komentarz.\n" 497 "Comment[pl]=Jakis komentarz.\n"
345 "Icon=/opt/google/chrome/product_logo_48.png\n", 498 "Icon=/opt/google/chrome/product_logo_48.png\n",
346 499
347 "#!/usr/bin/env xdg-open\n" 500 "#!/usr/bin/env xdg-open\n"
348 "[Desktop Entry]\n" 501 "[Desktop Entry]\n"
349 "Name=GMail\n" 502 "Name=GMail\n"
350 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" 503 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n"
351 "Icon=/opt/google/chrome/product_logo_48.png\n" 504 "Icon=/opt/google/chrome/product_logo_48.png\n"
352 #if !defined(USE_AURA) 505 #if !defined(USE_AURA)
353 // Aura Chrome does not (yet) set WMClass, so we only expect 506 // Aura Chrome does not (yet) set WMClass, so we only expect
354 // StartupWMClass on non-Aura builds. 507 // StartupWMClass on non-Aura builds.
355 "StartupWMClass=gmail.com\n" 508 "StartupWMClass=gmail.com\n"
356 #endif 509 #endif
357 }, 510 },
358 511
512 // Test adding NoDisplay=true.
513 { "http://gmail.com",
514 "GMail",
515 "chrome-http__gmail.com",
516 true,
517
518 "[Desktop Entry]\n"
519 "Name=Google Chrome\n"
520 "Exec=/opt/google/chrome/google-chrome %U\n",
521
522 "#!/usr/bin/env xdg-open\n"
523 "[Desktop Entry]\n"
524 "Name=GMail\n"
525 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n"
526 "Icon=chrome-http__gmail.com\n"
527 "NoDisplay=true\n"
528 #if !defined(USE_AURA)
529 // Aura Chrome does not (yet) set WMClass, so we only expect
530 // StartupWMClass on non-Aura builds.
531 "StartupWMClass=gmail.com\n"
532 #endif
533 },
534
359 // Now we're starting to be more evil... 535 // Now we're starting to be more evil...
360 { "http://evil.com/evil --join-the-b0tnet", 536 { "http://evil.com/evil --join-the-b0tnet",
361 "Ownz0red\nExec=rm -rf /", 537 "Ownz0red\nExec=rm -rf /",
362 "chrome-http__evil.com_evil", 538 "chrome-http__evil.com_evil",
539 false,
363 540
364 "[Desktop Entry]\n" 541 "[Desktop Entry]\n"
365 "Name=Google Chrome\n" 542 "Name=Google Chrome\n"
366 "Exec=/opt/google/chrome/google-chrome %U\n", 543 "Exec=/opt/google/chrome/google-chrome %U\n",
367 544
368 "#!/usr/bin/env xdg-open\n" 545 "#!/usr/bin/env xdg-open\n"
369 "[Desktop Entry]\n" 546 "[Desktop Entry]\n"
370 "Name=http://evil.com/evil%20--join-the-b0tnet\n" 547 "Name=http://evil.com/evil%20--join-the-b0tnet\n"
371 "Exec=/opt/google/chrome/google-chrome " 548 "Exec=/opt/google/chrome/google-chrome "
372 "--app=http://evil.com/evil%20--join-the-b0tnet\n" 549 "--app=http://evil.com/evil%20--join-the-b0tnet\n"
373 "Icon=chrome-http__evil.com_evil\n" 550 "Icon=chrome-http__evil.com_evil\n"
374 #if !defined(USE_AURA) 551 #if !defined(USE_AURA)
375 // Aura Chrome does not (yet) set WMClass, so we only expect 552 // Aura Chrome does not (yet) set WMClass, so we only expect
376 // StartupWMClass on non-Aura builds. 553 // StartupWMClass on non-Aura builds.
377 "StartupWMClass=evil.com__evil%20--join-the-b0tnet\n" 554 "StartupWMClass=evil.com__evil%20--join-the-b0tnet\n"
378 #endif 555 #endif
379 }, 556 },
380 { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red", 557 { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red",
381 "Innocent Title", 558 "Innocent Title",
382 "chrome-http__evil.com_evil", 559 "chrome-http__evil.com_evil",
560 false,
383 561
384 "[Desktop Entry]\n" 562 "[Desktop Entry]\n"
385 "Name=Google Chrome\n" 563 "Name=Google Chrome\n"
386 "Exec=/opt/google/chrome/google-chrome %U\n", 564 "Exec=/opt/google/chrome/google-chrome %U\n",
387 565
388 "#!/usr/bin/env xdg-open\n" 566 "#!/usr/bin/env xdg-open\n"
389 "[Desktop Entry]\n" 567 "[Desktop Entry]\n"
390 "Name=Innocent Title\n" 568 "Name=Innocent Title\n"
391 "Exec=/opt/google/chrome/google-chrome " 569 "Exec=/opt/google/chrome/google-chrome "
392 "\"--app=http://evil.com/evil;%20rm%20-rf%20/;%20%22;%20rm%20" 570 "\"--app=http://evil.com/evil;%20rm%20-rf%20/;%20%22;%20rm%20"
393 // Note: $ is escaped as \$ within an arg to Exec, and then 571 // Note: $ is escaped as \$ within an arg to Exec, and then
394 // the \ is escaped as \\ as all strings in a Desktop file should 572 // the \ is escaped as \\ as all strings in a Desktop file should
395 // be; finally, \\ becomes \\\\ when represented in a C++ string! 573 // be; finally, \\ becomes \\\\ when represented in a C++ string!
396 "-rf%20\\\\$HOME%20%3Eownz0red\"\n" 574 "-rf%20\\\\$HOME%20%3Eownz0red\"\n"
397 "Icon=chrome-http__evil.com_evil\n" 575 "Icon=chrome-http__evil.com_evil\n"
398 #if !defined(USE_AURA) 576 #if !defined(USE_AURA)
399 // Aura Chrome does not (yet) set WMClass, so we only expect 577 // Aura Chrome does not (yet) set WMClass, so we only expect
400 // StartupWMClass on non-Aura builds. 578 // StartupWMClass on non-Aura builds.
401 "StartupWMClass=evil.com__evil;%20rm%20-rf%20_;%20%22;%20" 579 "StartupWMClass=evil.com__evil;%20rm%20-rf%20_;%20%22;%20"
402 "rm%20-rf%20$HOME%20%3Eownz0red\n" 580 "rm%20-rf%20$HOME%20%3Eownz0red\n"
403 #endif 581 #endif
404 }, 582 },
405 { "http://evil.com/evil | cat `echo ownz0red` >/dev/null", 583 { "http://evil.com/evil | cat `echo ownz0red` >/dev/null",
406 "Innocent Title", 584 "Innocent Title",
407 "chrome-http__evil.com_evil", 585 "chrome-http__evil.com_evil",
586 false,
408 587
409 "[Desktop Entry]\n" 588 "[Desktop Entry]\n"
410 "Name=Google Chrome\n" 589 "Name=Google Chrome\n"
411 "Exec=/opt/google/chrome/google-chrome %U\n", 590 "Exec=/opt/google/chrome/google-chrome %U\n",
412 591
413 "#!/usr/bin/env xdg-open\n" 592 "#!/usr/bin/env xdg-open\n"
414 "[Desktop Entry]\n" 593 "[Desktop Entry]\n"
415 "Name=Innocent Title\n" 594 "Name=Innocent Title\n"
416 "Exec=/opt/google/chrome/google-chrome " 595 "Exec=/opt/google/chrome/google-chrome "
417 "--app=http://evil.com/evil%20%7C%20cat%20%60echo%20ownz0red" 596 "--app=http://evil.com/evil%20%7C%20cat%20%60echo%20ownz0red"
(...skipping 19 matching lines...) Expand all
437 EXPECT_EQ( 616 EXPECT_EQ(
438 test_cases[i].expected_output, 617 test_cases[i].expected_output,
439 ShellIntegrationLinux::GetDesktopFileContents( 618 ShellIntegrationLinux::GetDesktopFileContents(
440 test_cases[i].template_contents, 619 test_cases[i].template_contents,
441 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), 620 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)),
442 GURL(test_cases[i].url), 621 GURL(test_cases[i].url),
443 "", 622 "",
444 base::FilePath(), 623 base::FilePath(),
445 ASCIIToUTF16(test_cases[i].title), 624 ASCIIToUTF16(test_cases[i].title),
446 test_cases[i].icon_name, 625 test_cases[i].icon_name,
447 base::FilePath())); 626 base::FilePath(),
627 test_cases[i].nodisplay));
448 } 628 }
449 } 629 }
630
450 #endif 631 #endif
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration_linux.cc ('k') | chrome/browser/web_applications/web_app_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698