[email protected] | 8806d3b | 2012-04-13 06:46:34 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 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 | |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 7 | #include <map> |
| 8 | |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 9 | #include "base/file_path.h" |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 10 | #include "base/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 11 | #include "base/files/scoped_temp_dir.h" |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 12 | #include "base/message_loop.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 13 | #include "base/stl_util.h" |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 15 | #include "base/utf_string_conversions.h" |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 16 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | 4289680 | 2009-08-28 23:39:44 | [diff] [blame] | 17 | #include "chrome/common/chrome_constants.h" |
[email protected] | e97882f | 2012-06-04 02:23:17 | [diff] [blame] | 18 | #include "content/public/test/test_browser_thread.h" |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 19 | #include "googleurl/src/gurl.h" |
| 20 | #include "testing/gtest/include/gtest/gtest.h" |
| 21 | |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 22 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 23 | #include "base/environment.h" |
[email protected] | 98566d7a | 2012-04-17 00:28:56 | [diff] [blame] | 24 | #include "chrome/browser/shell_integration_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 25 | #endif |
[email protected] | 3bc6043 | 2010-03-12 11:15:13 | [diff] [blame] | 26 | |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 27 | #define FPL FILE_PATH_LITERAL |
| 28 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 29 | using content::BrowserThread; |
| 30 | |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 31 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 32 | namespace { |
| 33 | |
| 34 | // Provides mock environment variables values based on a stored map. |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 35 | class MockEnvironment : public base::Environment { |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 36 | public: |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 37 | MockEnvironment() {} |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 38 | |
| 39 | void Set(const std::string& name, const std::string& value) { |
| 40 | variables_[name] = value; |
| 41 | } |
| 42 | |
[email protected] | 3ba7e08 | 2010-08-07 02:57:59 | [diff] [blame] | 43 | virtual bool GetVar(const char* variable_name, std::string* result) { |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 44 | if (ContainsKey(variables_, variable_name)) { |
| 45 | *result = variables_[variable_name]; |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | return false; |
| 50 | } |
| 51 | |
[email protected] | c87bcf00 | 2010-08-06 01:03:37 | [diff] [blame] | 52 | virtual bool SetVar(const char* variable_name, const std::string& new_value) { |
[email protected] | fc586c7 | 2010-07-31 16:55:40 | [diff] [blame] | 53 | ADD_FAILURE(); |
| 54 | return false; |
| 55 | } |
| 56 | |
[email protected] | 4fae316 | 2010-08-04 02:13:34 | [diff] [blame] | 57 | virtual bool UnSetVar(const char* variable_name) { |
[email protected] | fc586c7 | 2010-07-31 16:55:40 | [diff] [blame] | 58 | ADD_FAILURE(); |
[email protected] | e9032c6 | 2010-07-16 03:34:25 | [diff] [blame] | 59 | return false; |
[email protected] | ac7264c | 2010-07-08 13:32:51 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 62 | private: |
| 63 | std::map<std::string, std::string> variables_; |
| 64 | |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 65 | DISALLOW_COPY_AND_ASSIGN(MockEnvironment); |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace |
| 69 | |
| 70 | TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { |
| 71 | #if defined(GOOGLE_CHROME_BUILD) |
| 72 | const char kTemplateFilename[] = "google-chrome.desktop"; |
| 73 | #else // CHROMIUM_BUILD |
| 74 | const char kTemplateFilename[] = "chromium-browser.desktop"; |
| 75 | #endif |
| 76 | |
| 77 | const char kTestData1[] = "a magical testing string"; |
| 78 | const char kTestData2[] = "a different testing string"; |
| 79 | |
| 80 | MessageLoop message_loop; |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 81 | content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 82 | |
| 83 | { |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 84 | base::ScopedTempDir temp_dir; |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 85 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 86 | |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 87 | MockEnvironment env; |
| 88 | env.Set("XDG_DATA_HOME", temp_dir.path().value()); |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 89 | ASSERT_TRUE(file_util::WriteFile( |
| 90 | temp_dir.path().AppendASCII(kTemplateFilename), |
| 91 | kTestData1, strlen(kTestData1))); |
| 92 | std::string contents; |
[email protected] | 98566d7a | 2012-04-17 00:28:56 | [diff] [blame] | 93 | ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, |
| 94 | &contents)); |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 95 | EXPECT_EQ(kTestData1, contents); |
| 96 | } |
| 97 | |
| 98 | { |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 99 | base::ScopedTempDir temp_dir; |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 100 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 101 | |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 102 | MockEnvironment env; |
| 103 | env.Set("XDG_DATA_DIRS", temp_dir.path().value()); |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 104 | ASSERT_TRUE(file_util::CreateDirectory( |
| 105 | temp_dir.path().AppendASCII("applications"))); |
| 106 | ASSERT_TRUE(file_util::WriteFile( |
| 107 | temp_dir.path().AppendASCII("applications") |
| 108 | .AppendASCII(kTemplateFilename), |
| 109 | kTestData2, strlen(kTestData2))); |
| 110 | std::string contents; |
[email protected] | 98566d7a | 2012-04-17 00:28:56 | [diff] [blame] | 111 | ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, |
| 112 | &contents)); |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 113 | EXPECT_EQ(kTestData2, contents); |
| 114 | } |
| 115 | |
| 116 | { |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 117 | base::ScopedTempDir temp_dir; |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 118 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 119 | |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 120 | MockEnvironment env; |
| 121 | env.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" + |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 122 | temp_dir.path().AppendASCII("applications").value()); |
| 123 | ASSERT_TRUE(file_util::CreateDirectory( |
| 124 | temp_dir.path().AppendASCII("applications"))); |
| 125 | ASSERT_TRUE(file_util::WriteFile( |
| 126 | temp_dir.path().AppendASCII(kTemplateFilename), |
| 127 | kTestData1, strlen(kTestData1))); |
| 128 | ASSERT_TRUE(file_util::WriteFile( |
| 129 | temp_dir.path().AppendASCII("applications") |
| 130 | .AppendASCII(kTemplateFilename), |
| 131 | kTestData2, strlen(kTestData2))); |
| 132 | std::string contents; |
[email protected] | 98566d7a | 2012-04-17 00:28:56 | [diff] [blame] | 133 | ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, |
| 134 | &contents)); |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 135 | EXPECT_EQ(kTestData1, contents); |
| 136 | } |
| 137 | } |
| 138 | |
[email protected] | 0b7df36d | 2012-07-11 09:50:47 | [diff] [blame] | 139 | TEST(ShellIntegrationTest, GetWebShortcutFilename) { |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 140 | const struct { |
| 141 | const FilePath::CharType* path; |
| 142 | const char* url; |
| 143 | } test_cases[] = { |
| 144 | { FPL("http___foo_.desktop"), "http://foo" }, |
| 145 | { FPL("http___foo_bar_.desktop"), "http://foo/bar/" }, |
| 146 | { FPL("http___foo_bar_a=b&c=d.desktop"), "http://foo/bar?a=b&c=d" }, |
| 147 | |
| 148 | // Now we're starting to be more evil... |
| 149 | { FPL("http___foo_.desktop"), "http://foo/bar/baz/../../../../../" }, |
| 150 | { FPL("http___foo_.desktop"), "http://foo/bar/././../baz/././../" }, |
| 151 | { FPL("http___.._.desktop"), "http://../../../../" }, |
| 152 | }; |
| 153 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 154 | EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" + |
[email protected] | 4289680 | 2009-08-28 23:39:44 | [diff] [blame] | 155 | test_cases[i].path, |
[email protected] | 0b7df36d | 2012-07-11 09:50:47 | [diff] [blame] | 156 | ShellIntegrationLinux::GetWebShortcutFilename( |
[email protected] | 4289680 | 2009-08-28 23:39:44 | [diff] [blame] | 157 | GURL(test_cases[i].url)).value()) << |
| 158 | " while testing " << test_cases[i].url; |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 162 | TEST(ShellIntegrationTest, GetDesktopFileContents) { |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 163 | const struct { |
| 164 | const char* url; |
| 165 | const char* title; |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 166 | const char* icon_name; |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 167 | const char* template_contents; |
| 168 | const char* expected_output; |
| 169 | } test_cases[] = { |
| 170 | // Dumb case. |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 171 | { "ignored", "ignored", "ignored", "", "#!/usr/bin/env xdg-open\n" }, |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 172 | |
| 173 | // Real-world case. |
| 174 | { "http://gmail.com", |
| 175 | "GMail", |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 176 | "chrome-http__gmail.com", |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 177 | |
| 178 | "[Desktop Entry]\n" |
| 179 | "Version=1.0\n" |
| 180 | "Encoding=UTF-8\n" |
| 181 | "Name=Google Chrome\n" |
| 182 | "Comment=The web browser from Google\n" |
| 183 | "Exec=/opt/google/chrome/google-chrome %U\n" |
| 184 | "Terminal=false\n" |
| 185 | "Icon=/opt/google/chrome/product_logo_48.png\n" |
| 186 | "Type=Application\n" |
| 187 | "Categories=Application;Network;WebBrowser;\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 188 | "MimeType=text/html;text/xml;application/xhtml_xml;\n" |
| 189 | "X-Ayatana-Desktop-Shortcuts=NewWindow;\n" |
| 190 | "\n" |
| 191 | "[NewWindow Shortcut Group]\n" |
| 192 | "Name=Open New Window\n" |
| 193 | "Exec=/opt/google/chrome/google-chrome\n" |
| 194 | "TargetEnvironment=Unity\n", |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 195 | |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 196 | "#!/usr/bin/env xdg-open\n" |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 197 | "[Desktop Entry]\n" |
| 198 | "Version=1.0\n" |
| 199 | "Encoding=UTF-8\n" |
| 200 | "Name=GMail\n" |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 201 | "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 202 | "Terminal=false\n" |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 203 | "Icon=chrome-http__gmail.com\n" |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 204 | "Type=Application\n" |
| 205 | "Categories=Application;Network;WebBrowser;\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 206 | #if !defined(USE_AURA) |
| 207 | // Aura Chrome creates browser window in a single X11 window, so |
| 208 | // WMClass does not matter. |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 209 | "StartupWMClass=gmail.com\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 210 | #endif |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 211 | }, |
| 212 | |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 213 | // Make sure we don't insert duplicate shebangs. |
| 214 | { "http://gmail.com", |
| 215 | "GMail", |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 216 | "chrome-http__gmail.com", |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 217 | |
| 218 | "#!/some/shebang\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 219 | "[Desktop Entry]\n" |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 220 | "Name=Google Chrome\n" |
| 221 | "Exec=/opt/google/chrome/google-chrome %U\n", |
| 222 | |
| 223 | "#!/usr/bin/env xdg-open\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 224 | "[Desktop Entry]\n" |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 225 | "Name=GMail\n" |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 226 | "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 227 | "Icon=chrome-http__gmail.com\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 228 | #if !defined(USE_AURA) |
| 229 | // Aura Chrome creates browser window in a single X11 window, so |
| 230 | // WMClass does not matter. |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 231 | "StartupWMClass=gmail.com\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 232 | #endif |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 233 | }, |
| 234 | |
| 235 | // Make sure i18n-ed comments are removed. |
| 236 | { "http://gmail.com", |
| 237 | "GMail", |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 238 | "chrome-http__gmail.com", |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 239 | |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 240 | "[Desktop Entry]\n" |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 241 | "Name=Google Chrome\n" |
| 242 | "Exec=/opt/google/chrome/google-chrome %U\n" |
| 243 | "Comment[pl]=Jakis komentarz.\n", |
| 244 | |
| 245 | "#!/usr/bin/env xdg-open\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 246 | "[Desktop Entry]\n" |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 247 | "Name=GMail\n" |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 248 | "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 249 | "Icon=chrome-http__gmail.com\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 250 | #if !defined(USE_AURA) |
| 251 | // Aura Chrome creates browser window in a single X11 window, so |
| 252 | // WMClass does not matter. |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 253 | "StartupWMClass=gmail.com\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 254 | #endif |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 255 | }, |
| 256 | |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 257 | // Make sure that empty icons are replaced by the chrome icon. |
| 258 | { "http://gmail.com", |
| 259 | "GMail", |
| 260 | "", |
| 261 | |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 262 | "[Desktop Entry]\n" |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 263 | "Name=Google Chrome\n" |
| 264 | "Exec=/opt/google/chrome/google-chrome %U\n" |
| 265 | "Comment[pl]=Jakis komentarz.\n" |
| 266 | "Icon=/opt/google/chrome/product_logo_48.png\n", |
| 267 | |
| 268 | "#!/usr/bin/env xdg-open\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 269 | "[Desktop Entry]\n" |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 270 | "Name=GMail\n" |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 271 | "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 272 | "Icon=/opt/google/chrome/product_logo_48.png\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 273 | #if !defined(USE_AURA) |
| 274 | // Aura Chrome creates browser window in a single X11 window, so |
| 275 | // WMClass does not matter. |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 276 | "StartupWMClass=gmail.com\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 277 | #endif |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 278 | }, |
| 279 | |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 280 | // Now we're starting to be more evil... |
| 281 | { "http://evil.com/evil --join-the-b0tnet", |
| 282 | "Ownz0red\nExec=rm -rf /", |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 283 | "chrome-http__evil.com_evil", |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 284 | |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 285 | "[Desktop Entry]\n" |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 286 | "Name=Google Chrome\n" |
| 287 | "Exec=/opt/google/chrome/google-chrome %U\n", |
| 288 | |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 289 | "#!/usr/bin/env xdg-open\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 290 | "[Desktop Entry]\n" |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 291 | "Name=http://evil.com/evil%20--join-the-b0tnet\n" |
| 292 | "Exec=/opt/google/chrome/google-chrome " |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 293 | "--app=http://evil.com/evil%20--join-the-b0tnet\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 294 | "Icon=chrome-http__evil.com_evil\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 295 | #if !defined(USE_AURA) |
| 296 | // Aura Chrome creates browser window in a single X11 window, so |
| 297 | // WMClass does not matter. |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 298 | "StartupWMClass=evil.com__evil%20--join-the-b0tnet\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 299 | #endif |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 300 | }, |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 301 | { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red", |
| 302 | "Innocent Title", |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 303 | "chrome-http__evil.com_evil", |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 304 | |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 305 | "[Desktop Entry]\n" |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 306 | "Name=Google Chrome\n" |
| 307 | "Exec=/opt/google/chrome/google-chrome %U\n", |
| 308 | |
| 309 | "#!/usr/bin/env xdg-open\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 310 | "[Desktop Entry]\n" |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 311 | "Name=Innocent Title\n" |
| 312 | "Exec=/opt/google/chrome/google-chrome " |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 313 | "\"--app=http://evil.com/evil;%20rm%20-rf%20/;%20%22;%20rm%20" |
| 314 | // Note: $ is escaped as \$ within an arg to Exec, and then |
| 315 | // the \ is escaped as \\ as all strings in a Desktop file should |
| 316 | // be; finally, \\ becomes \\\\ when represented in a C++ string! |
| 317 | "-rf%20\\\\$HOME%20%3Eownz0red\"\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 318 | "Icon=chrome-http__evil.com_evil\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 319 | #if !defined(USE_AURA) |
| 320 | // Aura Chrome creates browser window in a single X11 window, so |
| 321 | // WMClass does not matter. |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 322 | "StartupWMClass=evil.com__evil;%20rm%20-rf%20_;%20%22;%20" |
| 323 | "rm%20-rf%20$HOME%20%3Eownz0red\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 324 | #endif |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 325 | }, |
[email protected] | 790613c | 2009-12-30 14:49:41 | [diff] [blame] | 326 | { "http://evil.com/evil | cat `echo ownz0red` >/dev/null", |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 327 | "Innocent Title", |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 328 | "chrome-http__evil.com_evil", |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 329 | |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 330 | "[Desktop Entry]\n" |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 331 | "Name=Google Chrome\n" |
| 332 | "Exec=/opt/google/chrome/google-chrome %U\n", |
| 333 | |
| 334 | "#!/usr/bin/env xdg-open\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 335 | "[Desktop Entry]\n" |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 336 | "Name=Innocent Title\n" |
| 337 | "Exec=/opt/google/chrome/google-chrome " |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 338 | "--app=http://evil.com/evil%20%7C%20cat%20%60echo%20ownz0red" |
| 339 | "%60%20%3E/dev/null\n" |
[email protected] | 0a96c3f | 2011-05-11 22:10:20 | [diff] [blame] | 340 | "Icon=chrome-http__evil.com_evil\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 341 | #if !defined(USE_AURA) |
| 342 | // Aura Chrome creates browser window in a single X11 window, so |
| 343 | // WMClass does not matter. |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 344 | "StartupWMClass=evil.com__evil%20%7C%20cat%20%60echo%20ownz0red" |
| 345 | "%60%20%3E_dev_null\n" |
[email protected] | a2778d3 | 2011-12-01 07:49:34 | [diff] [blame] | 346 | #endif |
[email protected] | 82810fe1 | 2009-09-25 16:21:57 | [diff] [blame] | 347 | }, |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 348 | }; |
| 349 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 350 | SCOPED_TRACE(i); |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 351 | EXPECT_EQ( |
| 352 | test_cases[i].expected_output, |
[email protected] | 98566d7a | 2012-04-17 00:28:56 | [diff] [blame] | 353 | ShellIntegrationLinux::GetDesktopFileContents( |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 354 | test_cases[i].template_contents, |
| 355 | web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), |
| 356 | GURL(test_cases[i].url), |
| 357 | "", |
[email protected] | 8806d3b | 2012-04-13 06:46:34 | [diff] [blame] | 358 | FilePath(), |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 359 | ASCIIToUTF16(test_cases[i].title), |
[email protected] | 5951c85 | 2012-06-20 00:12:53 | [diff] [blame] | 360 | test_cases[i].icon_name, |
| 361 | FilePath())); |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 362 | } |
| 363 | } |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 364 | #endif |