| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/shell_integration.h" |
| 6 |
| 7 #include "base/file_path.h" |
| 8 #include "base/string_util.h" |
| 9 #include "googleurl/src/gurl.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 #define FPL FILE_PATH_LITERAL |
| 13 |
| 14 #if defined(OS_LINUX) |
| 15 TEST(ShellIntegrationTest, GetDesktopShortcutFilename) { |
| 16 const struct { |
| 17 const FilePath::CharType* path; |
| 18 const char* url; |
| 19 } test_cases[] = { |
| 20 { FPL("http___foo_.desktop"), "http://foo" }, |
| 21 { FPL("http___foo_bar_.desktop"), "http://foo/bar/" }, |
| 22 { FPL("http___foo_bar_a=b&c=d.desktop"), "http://foo/bar?a=b&c=d" }, |
| 23 |
| 24 // Now we're starting to be more evil... |
| 25 { FPL("http___foo_.desktop"), "http://foo/bar/baz/../../../../../" }, |
| 26 { FPL("http___foo_.desktop"), "http://foo/bar/././../baz/././../" }, |
| 27 { FPL("http___.._.desktop"), "http://../../../../" }, |
| 28 }; |
| 29 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
| 30 EXPECT_EQ(test_cases[i].path, ShellIntegration::GetDesktopShortcutFilename( |
| 31 GURL(test_cases[i].url)).value()) << " while testing " << |
| 32 test_cases[i].url; |
| 33 } |
| 34 } |
| 35 |
| 36 TEST(ShellIntegrationTest, GetDesktopFileContents) { |
| 37 const struct { |
| 38 const char* url; |
| 39 const char* title; |
| 40 const char* template_contents; |
| 41 const char* expected_output; |
| 42 } test_cases[] = { |
| 43 // Dumb case. |
| 44 { "ignored", "ignored", "", "" }, |
| 45 |
| 46 // Real-world case. |
| 47 { "http://gmail.com", |
| 48 "GMail", |
| 49 |
| 50 "[Desktop Entry]\n" |
| 51 "Version=1.0\n" |
| 52 "Encoding=UTF-8\n" |
| 53 "Name=Google Chrome\n" |
| 54 "Comment=The web browser from Google\n" |
| 55 "Exec=/opt/google/chrome/google-chrome %U\n" |
| 56 "Terminal=false\n" |
| 57 "Icon=/opt/google/chrome/product_logo_48.png\n" |
| 58 "Type=Application\n" |
| 59 "Categories=Application;Network;WebBrowser;\n" |
| 60 "MimeType=text/html;text/xml;application/xhtml_xml;\n", |
| 61 |
| 62 "[Desktop Entry]\n" |
| 63 "Version=1.0\n" |
| 64 "Encoding=UTF-8\n" |
| 65 "Name=GMail\n" |
| 66 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" |
| 67 "Terminal=false\n" |
| 68 "Icon=/opt/google/chrome/product_logo_48.png\n" |
| 69 "Type=Application\n" |
| 70 "Categories=Application;Network;WebBrowser;\n" |
| 71 "MimeType=text/html;text/xml;application/xhtml_xml;\n" |
| 72 }, |
| 73 |
| 74 // Now we're starting to be more evil... |
| 75 { "http://evil.com/evil --join-the-b0tnet", |
| 76 "Ownz0red\nExec=rm -rf /", |
| 77 |
| 78 "Name=Google Chrome\n" |
| 79 "Exec=/opt/google/chrome/google-chrome %U\n", |
| 80 |
| 81 "Name=http://evil.com/evil%20--join-the-b0tnet\n" |
| 82 "Exec=/opt/google/chrome/google-chrome " |
| 83 "\"--app=http://evil.com/evil%%20--join-the-b0tnet\"\n" |
| 84 }, |
| 85 }; |
| 86 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
| 87 EXPECT_EQ(test_cases[i].expected_output, |
| 88 ShellIntegration::GetDesktopFileContents( |
| 89 test_cases[i].template_contents, |
| 90 GURL(test_cases[i].url), |
| 91 ASCIIToUTF16(test_cases[i].title))); |
| 92 } |
| 93 } |
| 94 #endif // defined(OS_LINUX) |
| OLD | NEW |