OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/common/chrome_constants.h" | 9 #include "chrome/common/chrome_constants.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 TEST(ShellIntegrationTest, GetDesktopFileContents) { | 39 TEST(ShellIntegrationTest, GetDesktopFileContents) { |
40 const struct { | 40 const struct { |
41 const char* url; | 41 const char* url; |
42 const char* title; | 42 const char* title; |
43 const char* template_contents; | 43 const char* template_contents; |
44 const char* expected_output; | 44 const char* expected_output; |
45 } test_cases[] = { | 45 } test_cases[] = { |
46 // Dumb case. | 46 // Dumb case. |
47 { "ignored", "ignored", "", "" }, | 47 { "ignored", "ignored", "", "#!/usr/bin/env xdg-open\n" }, |
48 | 48 |
49 // Real-world case. | 49 // Real-world case. |
50 { "http://gmail.com", | 50 { "http://gmail.com", |
51 "GMail", | 51 "GMail", |
52 | 52 |
53 "[Desktop Entry]\n" | 53 "[Desktop Entry]\n" |
54 "Version=1.0\n" | 54 "Version=1.0\n" |
55 "Encoding=UTF-8\n" | 55 "Encoding=UTF-8\n" |
56 "Name=Google Chrome\n" | 56 "Name=Google Chrome\n" |
57 "Comment=The web browser from Google\n" | 57 "Comment=The web browser from Google\n" |
58 "Exec=/opt/google/chrome/google-chrome %U\n" | 58 "Exec=/opt/google/chrome/google-chrome %U\n" |
59 "Terminal=false\n" | 59 "Terminal=false\n" |
60 "Icon=/opt/google/chrome/product_logo_48.png\n" | 60 "Icon=/opt/google/chrome/product_logo_48.png\n" |
61 "Type=Application\n" | 61 "Type=Application\n" |
62 "Categories=Application;Network;WebBrowser;\n" | 62 "Categories=Application;Network;WebBrowser;\n" |
63 "MimeType=text/html;text/xml;application/xhtml_xml;\n", | 63 "MimeType=text/html;text/xml;application/xhtml_xml;\n", |
64 | 64 |
| 65 "#!/usr/bin/env xdg-open\n" |
65 "[Desktop Entry]\n" | 66 "[Desktop Entry]\n" |
66 "Version=1.0\n" | 67 "Version=1.0\n" |
67 "Encoding=UTF-8\n" | 68 "Encoding=UTF-8\n" |
68 "Name=GMail\n" | 69 "Name=GMail\n" |
69 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" | 70 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" |
70 "Terminal=false\n" | 71 "Terminal=false\n" |
71 "Icon=/opt/google/chrome/product_logo_48.png\n" | 72 "Icon=/opt/google/chrome/product_logo_48.png\n" |
72 "Type=Application\n" | 73 "Type=Application\n" |
73 "Categories=Application;Network;WebBrowser;\n" | 74 "Categories=Application;Network;WebBrowser;\n" |
74 "MimeType=text/html;text/xml;application/xhtml_xml;\n" | 75 "MimeType=text/html;text/xml;application/xhtml_xml;\n" |
75 }, | 76 }, |
76 | 77 |
| 78 // Make sure we don't insert duplicate shebangs. |
| 79 { "http://gmail.com", |
| 80 "GMail", |
| 81 |
| 82 "#!/some/shebang\n" |
| 83 "Name=Google Chrome\n" |
| 84 "Exec=/opt/google/chrome/google-chrome %U\n", |
| 85 |
| 86 "#!/usr/bin/env xdg-open\n" |
| 87 "Name=GMail\n" |
| 88 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" |
| 89 }, |
| 90 |
| 91 // Make sure i18n-ed comments are removed. |
| 92 { "http://gmail.com", |
| 93 "GMail", |
| 94 |
| 95 "Name=Google Chrome\n" |
| 96 "Exec=/opt/google/chrome/google-chrome %U\n" |
| 97 "Comment[pl]=Jakis komentarz.\n", |
| 98 |
| 99 "#!/usr/bin/env xdg-open\n" |
| 100 "Name=GMail\n" |
| 101 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" |
| 102 }, |
| 103 |
77 // Now we're starting to be more evil... | 104 // Now we're starting to be more evil... |
78 { "http://evil.com/evil --join-the-b0tnet", | 105 { "http://evil.com/evil --join-the-b0tnet", |
79 "Ownz0red\nExec=rm -rf /", | 106 "Ownz0red\nExec=rm -rf /", |
80 | 107 |
81 "Name=Google Chrome\n" | 108 "Name=Google Chrome\n" |
82 "Exec=/opt/google/chrome/google-chrome %U\n", | 109 "Exec=/opt/google/chrome/google-chrome %U\n", |
83 | 110 |
| 111 "#!/usr/bin/env xdg-open\n" |
84 "Name=http://evil.com/evil%20--join-the-b0tnet\n" | 112 "Name=http://evil.com/evil%20--join-the-b0tnet\n" |
85 "Exec=/opt/google/chrome/google-chrome " | 113 "Exec=/opt/google/chrome/google-chrome " |
86 "\"--app=http://evil.com/evil%%20--join-the-b0tnet\"\n" | 114 "\"--app=http://evil.com/evil%%20--join-the-b0tnet\"\n" |
87 }, | 115 }, |
| 116 { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red", |
| 117 "Innocent Title", |
| 118 |
| 119 "Name=Google Chrome\n" |
| 120 "Exec=/opt/google/chrome/google-chrome %U\n", |
| 121 |
| 122 "#!/usr/bin/env xdg-open\n" |
| 123 "Name=Innocent Title\n" |
| 124 "Exec=/opt/google/chrome/google-chrome " |
| 125 "\"--app=http://evil.com/evil%%20rm%%20-rf%%20/%%20%%22%%20rm%%20" |
| 126 "-rf%%20HOME%%20%%3Eownz0red\"\n" |
| 127 }, |
| 128 { "http://evil.com/evil | cat `echo ownz0red` >/dev/null\\", |
| 129 "Innocent Title", |
| 130 |
| 131 "Name=Google Chrome\n" |
| 132 "Exec=/opt/google/chrome/google-chrome %U\n", |
| 133 |
| 134 "#!/usr/bin/env xdg-open\n" |
| 135 "Name=Innocent Title\n" |
| 136 "Exec=/opt/google/chrome/google-chrome " |
| 137 "\"--app=http://evil.com/evil%%20%%7C%%20cat%%20%%60echo%%20ownz0red" |
| 138 "%%60%%20%%3E/dev/null/\"\n" |
| 139 }, |
88 }; | 140 }; |
89 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
90 EXPECT_EQ(test_cases[i].expected_output, | 142 EXPECT_EQ(test_cases[i].expected_output, |
91 ShellIntegration::GetDesktopFileContents( | 143 ShellIntegration::GetDesktopFileContents( |
92 test_cases[i].template_contents, | 144 test_cases[i].template_contents, |
93 GURL(test_cases[i].url), | 145 GURL(test_cases[i].url), |
94 ASCIIToUTF16(test_cases[i].title))); | 146 ASCIIToUTF16(test_cases[i].title))); |
95 } | 147 } |
96 } | 148 } |
97 #endif // defined(OS_LINUX) | 149 #endif // defined(OS_LINUX) |
OLD | NEW |