OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_linux.h" | 5 #include "chrome/browser/shell_integration_linux.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
27 | 27 |
28 #define FPL FILE_PATH_LITERAL | 28 #define FPL FILE_PATH_LITERAL |
29 | 29 |
30 using content::BrowserThread; | 30 using content::BrowserThread; |
31 using ::testing::ElementsAre; | 31 using ::testing::ElementsAre; |
32 | 32 |
| 33 namespace shell_integration_linux { |
| 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 // Provides mock environment variables values based on a stored map. | 37 // Provides mock environment variables values based on a stored map. |
36 class MockEnvironment : public base::Environment { | 38 class MockEnvironment : public base::Environment { |
37 public: | 39 public: |
38 MockEnvironment() {} | 40 MockEnvironment() {} |
39 | 41 |
40 void Set(const std::string& name, const std::string& value) { | 42 void Set(const std::string& name, const std::string& value) { |
41 variables_[name] = value; | 43 variables_[name] = value; |
42 } | 44 } |
(...skipping 29 matching lines...) Expand all Loading... |
72 TEST(ShellIntegrationTest, GetDataWriteLocation) { | 74 TEST(ShellIntegrationTest, GetDataWriteLocation) { |
73 base::MessageLoop message_loop; | 75 base::MessageLoop message_loop; |
74 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); | 76 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); |
75 | 77 |
76 // Test that it returns $XDG_DATA_HOME. | 78 // Test that it returns $XDG_DATA_HOME. |
77 { | 79 { |
78 MockEnvironment env; | 80 MockEnvironment env; |
79 env.Set("HOME", "/home/user"); | 81 env.Set("HOME", "/home/user"); |
80 env.Set("XDG_DATA_HOME", "/user/path"); | 82 env.Set("XDG_DATA_HOME", "/user/path"); |
81 base::FilePath path; | 83 base::FilePath path; |
82 ASSERT_TRUE(ShellIntegrationLinux::GetDataWriteLocation(&env, &path)); | 84 ASSERT_TRUE(GetDataWriteLocation(&env, &path)); |
83 EXPECT_EQ(base::FilePath("/user/path"), path); | 85 EXPECT_EQ(base::FilePath("/user/path"), path); |
84 } | 86 } |
85 | 87 |
86 // Test that $XDG_DATA_HOME falls back to $HOME/.local/share. | 88 // Test that $XDG_DATA_HOME falls back to $HOME/.local/share. |
87 { | 89 { |
88 MockEnvironment env; | 90 MockEnvironment env; |
89 env.Set("HOME", "/home/user"); | 91 env.Set("HOME", "/home/user"); |
90 base::FilePath path; | 92 base::FilePath path; |
91 ASSERT_TRUE(ShellIntegrationLinux::GetDataWriteLocation(&env, &path)); | 93 ASSERT_TRUE(GetDataWriteLocation(&env, &path)); |
92 EXPECT_EQ(base::FilePath("/home/user/.local/share"), path); | 94 EXPECT_EQ(base::FilePath("/home/user/.local/share"), path); |
93 } | 95 } |
94 | 96 |
95 // Test that if neither $XDG_DATA_HOME nor $HOME are specified, it fails. | 97 // Test that if neither $XDG_DATA_HOME nor $HOME are specified, it fails. |
96 { | 98 { |
97 MockEnvironment env; | 99 MockEnvironment env; |
98 base::FilePath path; | 100 base::FilePath path; |
99 ASSERT_FALSE(ShellIntegrationLinux::GetDataWriteLocation(&env, &path)); | 101 ASSERT_FALSE(GetDataWriteLocation(&env, &path)); |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 TEST(ShellIntegrationTest, GetDataSearchLocations) { | 105 TEST(ShellIntegrationTest, GetDataSearchLocations) { |
104 base::MessageLoop message_loop; | 106 base::MessageLoop message_loop; |
105 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); | 107 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); |
106 | 108 |
107 // Test that it returns $XDG_DATA_HOME + $XDG_DATA_DIRS. | 109 // Test that it returns $XDG_DATA_HOME + $XDG_DATA_DIRS. |
108 { | 110 { |
109 MockEnvironment env; | 111 MockEnvironment env; |
110 env.Set("HOME", "/home/user"); | 112 env.Set("HOME", "/home/user"); |
111 env.Set("XDG_DATA_HOME", "/user/path"); | 113 env.Set("XDG_DATA_HOME", "/user/path"); |
112 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2"); | 114 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2"); |
113 EXPECT_THAT( | 115 EXPECT_THAT( |
114 ShellIntegrationLinux::GetDataSearchLocations(&env), | 116 GetDataSearchLocations(&env), |
115 ElementsAre(base::FilePath("/user/path"), | 117 ElementsAre(base::FilePath("/user/path"), |
116 base::FilePath("/system/path/1"), | 118 base::FilePath("/system/path/1"), |
117 base::FilePath("/system/path/2"))); | 119 base::FilePath("/system/path/2"))); |
118 } | 120 } |
119 | 121 |
120 // Test that $XDG_DATA_HOME falls back to $HOME/.local/share. | 122 // Test that $XDG_DATA_HOME falls back to $HOME/.local/share. |
121 { | 123 { |
122 MockEnvironment env; | 124 MockEnvironment env; |
123 env.Set("HOME", "/home/user"); | 125 env.Set("HOME", "/home/user"); |
124 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2"); | 126 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2"); |
125 EXPECT_THAT( | 127 EXPECT_THAT( |
126 ShellIntegrationLinux::GetDataSearchLocations(&env), | 128 GetDataSearchLocations(&env), |
127 ElementsAre(base::FilePath("/home/user/.local/share"), | 129 ElementsAre(base::FilePath("/home/user/.local/share"), |
128 base::FilePath("/system/path/1"), | 130 base::FilePath("/system/path/1"), |
129 base::FilePath("/system/path/2"))); | 131 base::FilePath("/system/path/2"))); |
130 } | 132 } |
131 | 133 |
132 // Test that if neither $XDG_DATA_HOME nor $HOME are specified, it still | 134 // Test that if neither $XDG_DATA_HOME nor $HOME are specified, it still |
133 // succeeds. | 135 // succeeds. |
134 { | 136 { |
135 MockEnvironment env; | 137 MockEnvironment env; |
136 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2"); | 138 env.Set("XDG_DATA_DIRS", "/system/path/1:/system/path/2"); |
137 EXPECT_THAT( | 139 EXPECT_THAT( |
138 ShellIntegrationLinux::GetDataSearchLocations(&env), | 140 GetDataSearchLocations(&env), |
139 ElementsAre(base::FilePath("/system/path/1"), | 141 ElementsAre(base::FilePath("/system/path/1"), |
140 base::FilePath("/system/path/2"))); | 142 base::FilePath("/system/path/2"))); |
141 } | 143 } |
142 | 144 |
143 // Test that $XDG_DATA_DIRS falls back to the two default paths. | 145 // Test that $XDG_DATA_DIRS falls back to the two default paths. |
144 { | 146 { |
145 MockEnvironment env; | 147 MockEnvironment env; |
146 env.Set("HOME", "/home/user"); | 148 env.Set("HOME", "/home/user"); |
147 env.Set("XDG_DATA_HOME", "/user/path"); | 149 env.Set("XDG_DATA_HOME", "/user/path"); |
148 EXPECT_THAT( | 150 EXPECT_THAT( |
149 ShellIntegrationLinux::GetDataSearchLocations(&env), | 151 GetDataSearchLocations(&env), |
150 ElementsAre(base::FilePath("/user/path"), | 152 ElementsAre(base::FilePath("/user/path"), |
151 base::FilePath("/usr/local/share"), | 153 base::FilePath("/usr/local/share"), |
152 base::FilePath("/usr/share"))); | 154 base::FilePath("/usr/share"))); |
153 } | 155 } |
154 } | 156 } |
155 | 157 |
156 TEST(ShellIntegrationTest, GetExistingShortcutLocations) { | 158 TEST(ShellIntegrationTest, GetExistingShortcutLocations) { |
157 base::FilePath kProfilePath("Profile 1"); | 159 base::FilePath kProfilePath("Profile 1"); |
158 const char kExtensionId[] = "test_extension"; | 160 const char kExtensionId[] = "test_extension"; |
159 const char kTemplateFilename[] = "chrome-test_extension-Profile_1.desktop"; | 161 const char kTemplateFilename[] = "chrome-test_extension-Profile_1.desktop"; |
160 base::FilePath kTemplateFilepath(kTemplateFilename); | 162 base::FilePath kTemplateFilepath(kTemplateFilename); |
161 const char kNoDisplayDesktopFile[] = "[Desktop Entry]\nNoDisplay=true"; | 163 const char kNoDisplayDesktopFile[] = "[Desktop Entry]\nNoDisplay=true"; |
162 | 164 |
163 base::MessageLoop message_loop; | 165 base::MessageLoop message_loop; |
164 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); | 166 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); |
165 | 167 |
166 // No existing shortcuts. | 168 // No existing shortcuts. |
167 { | 169 { |
168 MockEnvironment env; | 170 MockEnvironment env; |
169 web_app::ShortcutLocations result = | 171 web_app::ShortcutLocations result = |
170 ShellIntegrationLinux::GetExistingShortcutLocations( | 172 GetExistingShortcutLocations(&env, kProfilePath, kExtensionId); |
171 &env, kProfilePath, kExtensionId); | |
172 EXPECT_FALSE(result.on_desktop); | 173 EXPECT_FALSE(result.on_desktop); |
173 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE, | 174 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE, |
174 result.applications_menu_location); | 175 result.applications_menu_location); |
175 | 176 |
176 EXPECT_FALSE(result.in_quick_launch_bar); | 177 EXPECT_FALSE(result.in_quick_launch_bar); |
177 EXPECT_FALSE(result.hidden); | 178 EXPECT_FALSE(result.hidden); |
178 } | 179 } |
179 | 180 |
180 // Shortcut on desktop. | 181 // Shortcut on desktop. |
181 { | 182 { |
182 base::ScopedTempDir temp_dir; | 183 base::ScopedTempDir temp_dir; |
183 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 184 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
184 base::FilePath desktop_path = temp_dir.path(); | 185 base::FilePath desktop_path = temp_dir.path(); |
185 | 186 |
186 MockEnvironment env; | 187 MockEnvironment env; |
187 ASSERT_TRUE(base::CreateDirectory(desktop_path)); | 188 ASSERT_TRUE(base::CreateDirectory(desktop_path)); |
188 ASSERT_FALSE(base::WriteFile( | 189 ASSERT_FALSE(base::WriteFile( |
189 desktop_path.AppendASCII(kTemplateFilename), | 190 desktop_path.AppendASCII(kTemplateFilename), |
190 "", 0)); | 191 "", 0)); |
191 web_app::ShortcutLocations result = | 192 web_app::ShortcutLocations result = GetExistingShortcutLocations( |
192 ShellIntegrationLinux::GetExistingShortcutLocations( | 193 &env, kProfilePath, kExtensionId, desktop_path); |
193 &env, kProfilePath, kExtensionId, desktop_path); | |
194 EXPECT_TRUE(result.on_desktop); | 194 EXPECT_TRUE(result.on_desktop); |
195 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE, | 195 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE, |
196 result.applications_menu_location); | 196 result.applications_menu_location); |
197 | 197 |
198 EXPECT_FALSE(result.in_quick_launch_bar); | 198 EXPECT_FALSE(result.in_quick_launch_bar); |
199 EXPECT_FALSE(result.hidden); | 199 EXPECT_FALSE(result.hidden); |
200 } | 200 } |
201 | 201 |
202 // Shortcut in applications directory. | 202 // Shortcut in applications directory. |
203 { | 203 { |
204 base::ScopedTempDir temp_dir; | 204 base::ScopedTempDir temp_dir; |
205 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 205 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
206 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); | 206 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); |
207 | 207 |
208 MockEnvironment env; | 208 MockEnvironment env; |
209 env.Set("XDG_DATA_HOME", temp_dir.path().value()); | 209 env.Set("XDG_DATA_HOME", temp_dir.path().value()); |
210 ASSERT_TRUE(base::CreateDirectory(apps_path)); | 210 ASSERT_TRUE(base::CreateDirectory(apps_path)); |
211 ASSERT_FALSE(base::WriteFile( | 211 ASSERT_FALSE(base::WriteFile( |
212 apps_path.AppendASCII(kTemplateFilename), | 212 apps_path.AppendASCII(kTemplateFilename), |
213 "", 0)); | 213 "", 0)); |
214 web_app::ShortcutLocations result = | 214 web_app::ShortcutLocations result = |
215 ShellIntegrationLinux::GetExistingShortcutLocations( | 215 GetExistingShortcutLocations(&env, kProfilePath, kExtensionId); |
216 &env, kProfilePath, kExtensionId); | |
217 EXPECT_FALSE(result.on_desktop); | 216 EXPECT_FALSE(result.on_desktop); |
218 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, | 217 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, |
219 result.applications_menu_location); | 218 result.applications_menu_location); |
220 | 219 |
221 EXPECT_FALSE(result.in_quick_launch_bar); | 220 EXPECT_FALSE(result.in_quick_launch_bar); |
222 EXPECT_FALSE(result.hidden); | 221 EXPECT_FALSE(result.hidden); |
223 } | 222 } |
224 | 223 |
225 // Shortcut in applications directory with NoDisplay=true. | 224 // Shortcut in applications directory with NoDisplay=true. |
226 { | 225 { |
227 base::ScopedTempDir temp_dir; | 226 base::ScopedTempDir temp_dir; |
228 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 227 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
229 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); | 228 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); |
230 | 229 |
231 MockEnvironment env; | 230 MockEnvironment env; |
232 env.Set("XDG_DATA_HOME", temp_dir.path().value()); | 231 env.Set("XDG_DATA_HOME", temp_dir.path().value()); |
233 ASSERT_TRUE(base::CreateDirectory(apps_path)); | 232 ASSERT_TRUE(base::CreateDirectory(apps_path)); |
234 ASSERT_TRUE(base::WriteFile( | 233 ASSERT_TRUE(base::WriteFile( |
235 apps_path.AppendASCII(kTemplateFilename), | 234 apps_path.AppendASCII(kTemplateFilename), |
236 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile))); | 235 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile))); |
237 web_app::ShortcutLocations result = | 236 web_app::ShortcutLocations result = |
238 ShellIntegrationLinux::GetExistingShortcutLocations( | 237 GetExistingShortcutLocations(&env, kProfilePath, kExtensionId); |
239 &env, kProfilePath, kExtensionId); | |
240 // Doesn't count as being in applications menu. | 238 // Doesn't count as being in applications menu. |
241 EXPECT_FALSE(result.on_desktop); | 239 EXPECT_FALSE(result.on_desktop); |
242 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE, | 240 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE, |
243 result.applications_menu_location); | 241 result.applications_menu_location); |
244 EXPECT_FALSE(result.in_quick_launch_bar); | 242 EXPECT_FALSE(result.in_quick_launch_bar); |
245 EXPECT_TRUE(result.hidden); | 243 EXPECT_TRUE(result.hidden); |
246 } | 244 } |
247 | 245 |
248 // Shortcut on desktop and in applications directory. | 246 // Shortcut on desktop and in applications directory. |
249 { | 247 { |
250 base::ScopedTempDir temp_dir1; | 248 base::ScopedTempDir temp_dir1; |
251 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); | 249 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); |
252 base::FilePath desktop_path = temp_dir1.path(); | 250 base::FilePath desktop_path = temp_dir1.path(); |
253 | 251 |
254 base::ScopedTempDir temp_dir2; | 252 base::ScopedTempDir temp_dir2; |
255 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); | 253 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
256 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications"); | 254 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications"); |
257 | 255 |
258 MockEnvironment env; | 256 MockEnvironment env; |
259 ASSERT_TRUE(base::CreateDirectory(desktop_path)); | 257 ASSERT_TRUE(base::CreateDirectory(desktop_path)); |
260 ASSERT_FALSE(base::WriteFile( | 258 ASSERT_FALSE(base::WriteFile( |
261 desktop_path.AppendASCII(kTemplateFilename), | 259 desktop_path.AppendASCII(kTemplateFilename), |
262 "", 0)); | 260 "", 0)); |
263 env.Set("XDG_DATA_HOME", temp_dir2.path().value()); | 261 env.Set("XDG_DATA_HOME", temp_dir2.path().value()); |
264 ASSERT_TRUE(base::CreateDirectory(apps_path)); | 262 ASSERT_TRUE(base::CreateDirectory(apps_path)); |
265 ASSERT_FALSE(base::WriteFile( | 263 ASSERT_FALSE(base::WriteFile( |
266 apps_path.AppendASCII(kTemplateFilename), | 264 apps_path.AppendASCII(kTemplateFilename), |
267 "", 0)); | 265 "", 0)); |
268 web_app::ShortcutLocations result = | 266 web_app::ShortcutLocations result = GetExistingShortcutLocations( |
269 ShellIntegrationLinux::GetExistingShortcutLocations( | 267 &env, kProfilePath, kExtensionId, desktop_path); |
270 &env, kProfilePath, kExtensionId, desktop_path); | |
271 EXPECT_TRUE(result.on_desktop); | 268 EXPECT_TRUE(result.on_desktop); |
272 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, | 269 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, |
273 result.applications_menu_location); | 270 result.applications_menu_location); |
274 EXPECT_FALSE(result.in_quick_launch_bar); | 271 EXPECT_FALSE(result.in_quick_launch_bar); |
275 EXPECT_FALSE(result.hidden); | 272 EXPECT_FALSE(result.hidden); |
276 } | 273 } |
277 } | 274 } |
278 | 275 |
279 TEST(ShellIntegrationTest, GetExistingShortcutContents) { | 276 TEST(ShellIntegrationTest, GetExistingShortcutContents) { |
280 const char kTemplateFilename[] = "shortcut-test.desktop"; | 277 const char kTemplateFilename[] = "shortcut-test.desktop"; |
(...skipping 16 matching lines...) Expand all Loading... |
297 temp_dir.path().AppendASCII(kTemplateFilename), | 294 temp_dir.path().AppendASCII(kTemplateFilename), |
298 kTestData2, strlen(kTestData2))); | 295 kTestData2, strlen(kTestData2))); |
299 ASSERT_TRUE(base::CreateDirectory( | 296 ASSERT_TRUE(base::CreateDirectory( |
300 temp_dir.path().AppendASCII("applications"))); | 297 temp_dir.path().AppendASCII("applications"))); |
301 ASSERT_TRUE(base::WriteFile( | 298 ASSERT_TRUE(base::WriteFile( |
302 temp_dir.path().AppendASCII("applications") | 299 temp_dir.path().AppendASCII("applications") |
303 .AppendASCII(kTemplateFilename), | 300 .AppendASCII(kTemplateFilename), |
304 kTestData1, strlen(kTestData1))); | 301 kTestData1, strlen(kTestData1))); |
305 std::string contents; | 302 std::string contents; |
306 ASSERT_TRUE( | 303 ASSERT_TRUE( |
307 ShellIntegrationLinux::GetExistingShortcutContents( | 304 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); |
308 &env, kTemplateFilepath, &contents)); | |
309 EXPECT_EQ(kTestData1, contents); | 305 EXPECT_EQ(kTestData1, contents); |
310 } | 306 } |
311 | 307 |
312 // Test that it falls back to $HOME/.local/share/applications. | 308 // Test that it falls back to $HOME/.local/share/applications. |
313 { | 309 { |
314 base::ScopedTempDir temp_dir; | 310 base::ScopedTempDir temp_dir; |
315 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 311 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
316 | 312 |
317 MockEnvironment env; | 313 MockEnvironment env; |
318 env.Set("HOME", temp_dir.path().value()); | 314 env.Set("HOME", temp_dir.path().value()); |
319 ASSERT_TRUE(base::CreateDirectory( | 315 ASSERT_TRUE(base::CreateDirectory( |
320 temp_dir.path().AppendASCII(".local/share/applications"))); | 316 temp_dir.path().AppendASCII(".local/share/applications"))); |
321 ASSERT_TRUE(base::WriteFile( | 317 ASSERT_TRUE(base::WriteFile( |
322 temp_dir.path().AppendASCII(".local/share/applications") | 318 temp_dir.path().AppendASCII(".local/share/applications") |
323 .AppendASCII(kTemplateFilename), | 319 .AppendASCII(kTemplateFilename), |
324 kTestData1, strlen(kTestData1))); | 320 kTestData1, strlen(kTestData1))); |
325 std::string contents; | 321 std::string contents; |
326 ASSERT_TRUE( | 322 ASSERT_TRUE( |
327 ShellIntegrationLinux::GetExistingShortcutContents( | 323 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); |
328 &env, kTemplateFilepath, &contents)); | |
329 EXPECT_EQ(kTestData1, contents); | 324 EXPECT_EQ(kTestData1, contents); |
330 } | 325 } |
331 | 326 |
332 // Test that it searches $XDG_DATA_DIRS/applications. | 327 // Test that it searches $XDG_DATA_DIRS/applications. |
333 { | 328 { |
334 base::ScopedTempDir temp_dir; | 329 base::ScopedTempDir temp_dir; |
335 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 330 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
336 | 331 |
337 MockEnvironment env; | 332 MockEnvironment env; |
338 env.Set("XDG_DATA_DIRS", temp_dir.path().value()); | 333 env.Set("XDG_DATA_DIRS", temp_dir.path().value()); |
339 ASSERT_TRUE(base::CreateDirectory( | 334 ASSERT_TRUE(base::CreateDirectory( |
340 temp_dir.path().AppendASCII("applications"))); | 335 temp_dir.path().AppendASCII("applications"))); |
341 ASSERT_TRUE(base::WriteFile( | 336 ASSERT_TRUE(base::WriteFile( |
342 temp_dir.path().AppendASCII("applications") | 337 temp_dir.path().AppendASCII("applications") |
343 .AppendASCII(kTemplateFilename), | 338 .AppendASCII(kTemplateFilename), |
344 kTestData2, strlen(kTestData2))); | 339 kTestData2, strlen(kTestData2))); |
345 std::string contents; | 340 std::string contents; |
346 ASSERT_TRUE( | 341 ASSERT_TRUE( |
347 ShellIntegrationLinux::GetExistingShortcutContents( | 342 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); |
348 &env, kTemplateFilepath, &contents)); | |
349 EXPECT_EQ(kTestData2, contents); | 343 EXPECT_EQ(kTestData2, contents); |
350 } | 344 } |
351 | 345 |
352 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS. | 346 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS. |
353 { | 347 { |
354 base::ScopedTempDir temp_dir1; | 348 base::ScopedTempDir temp_dir1; |
355 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); | 349 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); |
356 base::ScopedTempDir temp_dir2; | 350 base::ScopedTempDir temp_dir2; |
357 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); | 351 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
358 | 352 |
359 MockEnvironment env; | 353 MockEnvironment env; |
360 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" + | 354 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" + |
361 temp_dir2.path().value()); | 355 temp_dir2.path().value()); |
362 // Create a file in a non-applications directory. This should be ignored. | 356 // Create a file in a non-applications directory. This should be ignored. |
363 ASSERT_TRUE(base::WriteFile( | 357 ASSERT_TRUE(base::WriteFile( |
364 temp_dir1.path().AppendASCII(kTemplateFilename), | 358 temp_dir1.path().AppendASCII(kTemplateFilename), |
365 kTestData1, strlen(kTestData1))); | 359 kTestData1, strlen(kTestData1))); |
366 // Only create a findable desktop file in the second path. | 360 // Only create a findable desktop file in the second path. |
367 ASSERT_TRUE(base::CreateDirectory( | 361 ASSERT_TRUE(base::CreateDirectory( |
368 temp_dir2.path().AppendASCII("applications"))); | 362 temp_dir2.path().AppendASCII("applications"))); |
369 ASSERT_TRUE(base::WriteFile( | 363 ASSERT_TRUE(base::WriteFile( |
370 temp_dir2.path().AppendASCII("applications") | 364 temp_dir2.path().AppendASCII("applications") |
371 .AppendASCII(kTemplateFilename), | 365 .AppendASCII(kTemplateFilename), |
372 kTestData2, strlen(kTestData2))); | 366 kTestData2, strlen(kTestData2))); |
373 std::string contents; | 367 std::string contents; |
374 ASSERT_TRUE( | 368 ASSERT_TRUE( |
375 ShellIntegrationLinux::GetExistingShortcutContents( | 369 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); |
376 &env, kTemplateFilepath, &contents)); | |
377 EXPECT_EQ(kTestData2, contents); | 370 EXPECT_EQ(kTestData2, contents); |
378 } | 371 } |
379 } | 372 } |
380 | 373 |
381 TEST(ShellIntegrationTest, GetExtensionShortcutFilename) { | 374 TEST(ShellIntegrationTest, GetExtensionShortcutFilename) { |
382 base::FilePath kProfilePath("a/b/c/Profile Name?"); | 375 base::FilePath kProfilePath("a/b/c/Profile Name?"); |
383 const char kExtensionId[] = "extensionid"; | 376 const char kExtensionId[] = "extensionid"; |
384 EXPECT_EQ(base::FilePath("chrome-extensionid-Profile_Name_.desktop"), | 377 EXPECT_EQ(base::FilePath("chrome-extensionid-Profile_Name_.desktop"), |
385 ShellIntegrationLinux::GetExtensionShortcutFilename( | 378 GetExtensionShortcutFilename(kProfilePath, kExtensionId)); |
386 kProfilePath, kExtensionId)); | |
387 } | 379 } |
388 | 380 |
389 TEST(ShellIntegrationTest, GetExistingProfileShortcutFilenames) { | 381 TEST(ShellIntegrationTest, GetExistingProfileShortcutFilenames) { |
390 base::FilePath kProfilePath("a/b/c/Profile Name?"); | 382 base::FilePath kProfilePath("a/b/c/Profile Name?"); |
391 const char kApp1Filename[] = "chrome-extension1-Profile_Name_.desktop"; | 383 const char kApp1Filename[] = "chrome-extension1-Profile_Name_.desktop"; |
392 const char kApp2Filename[] = "chrome-extension2-Profile_Name_.desktop"; | 384 const char kApp2Filename[] = "chrome-extension2-Profile_Name_.desktop"; |
393 const char kUnrelatedAppFilename[] = "chrome-extension-Other_Profile.desktop"; | 385 const char kUnrelatedAppFilename[] = "chrome-extension-Other_Profile.desktop"; |
394 | 386 |
395 base::MessageLoop message_loop; | 387 base::MessageLoop message_loop; |
396 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); | 388 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); |
397 | 389 |
398 base::ScopedTempDir temp_dir; | 390 base::ScopedTempDir temp_dir; |
399 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 391 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
400 ASSERT_EQ(0, | 392 ASSERT_EQ(0, |
401 base::WriteFile( | 393 base::WriteFile( |
402 temp_dir.path().AppendASCII(kApp1Filename), "", 0)); | 394 temp_dir.path().AppendASCII(kApp1Filename), "", 0)); |
403 ASSERT_EQ(0, | 395 ASSERT_EQ(0, |
404 base::WriteFile( | 396 base::WriteFile( |
405 temp_dir.path().AppendASCII(kApp2Filename), "", 0)); | 397 temp_dir.path().AppendASCII(kApp2Filename), "", 0)); |
406 // This file should not be returned in the results. | 398 // This file should not be returned in the results. |
407 ASSERT_EQ(0, | 399 ASSERT_EQ(0, |
408 base::WriteFile( | 400 base::WriteFile( |
409 temp_dir.path().AppendASCII(kUnrelatedAppFilename), "", 0)); | 401 temp_dir.path().AppendASCII(kUnrelatedAppFilename), "", 0)); |
410 std::vector<base::FilePath> paths = | 402 std::vector<base::FilePath> paths = |
411 ShellIntegrationLinux::GetExistingProfileShortcutFilenames( | 403 GetExistingProfileShortcutFilenames(kProfilePath, temp_dir.path()); |
412 kProfilePath, temp_dir.path()); | |
413 // Path order is arbitrary. Sort the output for consistency. | 404 // Path order is arbitrary. Sort the output for consistency. |
414 std::sort(paths.begin(), paths.end()); | 405 std::sort(paths.begin(), paths.end()); |
415 EXPECT_THAT(paths, | 406 EXPECT_THAT(paths, |
416 ElementsAre(base::FilePath(kApp1Filename), | 407 ElementsAre(base::FilePath(kApp1Filename), |
417 base::FilePath(kApp2Filename))); | 408 base::FilePath(kApp2Filename))); |
418 } | 409 } |
419 | 410 |
420 TEST(ShellIntegrationTest, GetWebShortcutFilename) { | 411 TEST(ShellIntegrationTest, GetWebShortcutFilename) { |
421 const struct { | 412 const struct { |
422 const base::FilePath::CharType* path; | 413 const base::FilePath::CharType* path; |
423 const char* url; | 414 const char* url; |
424 } test_cases[] = { | 415 } test_cases[] = { |
425 { FPL("http___foo_.desktop"), "http://foo" }, | 416 { FPL("http___foo_.desktop"), "http://foo" }, |
426 { FPL("http___foo_bar_.desktop"), "http://foo/bar/" }, | 417 { FPL("http___foo_bar_.desktop"), "http://foo/bar/" }, |
427 { FPL("http___foo_bar_a=b&c=d.desktop"), "http://foo/bar?a=b&c=d" }, | 418 { FPL("http___foo_bar_a=b&c=d.desktop"), "http://foo/bar?a=b&c=d" }, |
428 | 419 |
429 // Now we're starting to be more evil... | 420 // Now we're starting to be more evil... |
430 { FPL("http___foo_.desktop"), "http://foo/bar/baz/../../../../../" }, | 421 { FPL("http___foo_.desktop"), "http://foo/bar/baz/../../../../../" }, |
431 { FPL("http___foo_.desktop"), "http://foo/bar/././../baz/././../" }, | 422 { FPL("http___foo_.desktop"), "http://foo/bar/././../baz/././../" }, |
432 { FPL("http___.._.desktop"), "http://../../../../" }, | 423 { FPL("http___.._.desktop"), "http://../../../../" }, |
433 }; | 424 }; |
434 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 425 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
435 EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" + | 426 EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" + |
436 test_cases[i].path, | 427 test_cases[i].path, |
437 ShellIntegrationLinux::GetWebShortcutFilename( | 428 GetWebShortcutFilename(GURL(test_cases[i].url)).value()) << |
438 GURL(test_cases[i].url)).value()) << | |
439 " while testing " << test_cases[i].url; | 429 " while testing " << test_cases[i].url; |
440 } | 430 } |
441 } | 431 } |
442 | 432 |
443 TEST(ShellIntegrationTest, GetDesktopFileContents) { | 433 TEST(ShellIntegrationTest, GetDesktopFileContents) { |
444 const base::FilePath kChromeExePath("/opt/google/chrome/google-chrome"); | 434 const base::FilePath kChromeExePath("/opt/google/chrome/google-chrome"); |
445 const struct { | 435 const struct { |
446 const char* url; | 436 const char* url; |
447 const char* title; | 437 const char* title; |
448 const char* icon_name; | 438 const char* icon_name; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 "Icon=chrome-http__evil.com_evil\n" | 558 "Icon=chrome-http__evil.com_evil\n" |
569 "StartupWMClass=evil.com__evil%20%7C%20cat%20%60echo%20ownz0red" | 559 "StartupWMClass=evil.com__evil%20%7C%20cat%20%60echo%20ownz0red" |
570 "%60%20%3E_dev_null\n" | 560 "%60%20%3E_dev_null\n" |
571 }, | 561 }, |
572 }; | 562 }; |
573 | 563 |
574 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 564 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
575 SCOPED_TRACE(i); | 565 SCOPED_TRACE(i); |
576 EXPECT_EQ( | 566 EXPECT_EQ( |
577 test_cases[i].expected_output, | 567 test_cases[i].expected_output, |
578 ShellIntegrationLinux::GetDesktopFileContents( | 568 GetDesktopFileContents( |
579 kChromeExePath, | 569 kChromeExePath, |
580 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), | 570 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), |
581 GURL(test_cases[i].url), | 571 GURL(test_cases[i].url), |
582 std::string(), | 572 std::string(), |
583 base::ASCIIToUTF16(test_cases[i].title), | 573 base::ASCIIToUTF16(test_cases[i].title), |
584 test_cases[i].icon_name, | 574 test_cases[i].icon_name, |
585 base::FilePath(), | 575 base::FilePath(), |
586 test_cases[i].categories, | 576 test_cases[i].categories, |
587 test_cases[i].nodisplay)); | 577 test_cases[i].nodisplay)); |
588 } | 578 } |
589 } | 579 } |
590 | 580 |
591 TEST(ShellIntegrationTest, GetDesktopFileContentsAppList) { | 581 TEST(ShellIntegrationTest, GetDesktopFileContentsAppList) { |
592 const base::FilePath kChromeExePath("/opt/google/chrome/google-chrome"); | 582 const base::FilePath kChromeExePath("/opt/google/chrome/google-chrome"); |
593 CommandLine command_line(kChromeExePath); | 583 base::CommandLine command_line(kChromeExePath); |
594 command_line.AppendSwitch("--show-app-list"); | 584 command_line.AppendSwitch("--show-app-list"); |
595 EXPECT_EQ( | 585 EXPECT_EQ( |
596 "#!/usr/bin/env xdg-open\n" | 586 "#!/usr/bin/env xdg-open\n" |
597 "[Desktop Entry]\n" | 587 "[Desktop Entry]\n" |
598 "Version=1.0\n" | 588 "Version=1.0\n" |
599 "Terminal=false\n" | 589 "Terminal=false\n" |
600 "Type=Application\n" | 590 "Type=Application\n" |
601 "Name=Chrome App Launcher\n" | 591 "Name=Chrome App Launcher\n" |
602 "Exec=/opt/google/chrome/google-chrome --show-app-list\n" | 592 "Exec=/opt/google/chrome/google-chrome --show-app-list\n" |
603 "Icon=chrome_app_list\n" | 593 "Icon=chrome_app_list\n" |
604 "Categories=Network;WebBrowser;\n" | 594 "Categories=Network;WebBrowser;\n" |
605 "StartupWMClass=chrome-app-list\n", | 595 "StartupWMClass=chrome-app-list\n", |
606 ShellIntegrationLinux::GetDesktopFileContentsForCommand( | 596 GetDesktopFileContentsForCommand( |
607 command_line, | 597 command_line, |
608 "chrome-app-list", | 598 "chrome-app-list", |
609 GURL(), | 599 GURL(), |
610 base::ASCIIToUTF16("Chrome App Launcher"), | 600 base::ASCIIToUTF16("Chrome App Launcher"), |
611 "chrome_app_list", | 601 "chrome_app_list", |
612 "Network;WebBrowser;", | 602 "Network;WebBrowser;", |
613 false)); | 603 false)); |
614 } | 604 } |
615 | 605 |
616 TEST(ShellIntegrationTest, GetDirectoryFileContents) { | 606 TEST(ShellIntegrationTest, GetDirectoryFileContents) { |
(...skipping 24 matching lines...) Expand all Loading... |
641 #if defined(GOOGLE_CHROME_BUILD) | 631 #if defined(GOOGLE_CHROME_BUILD) |
642 "Icon=google-chrome\n" | 632 "Icon=google-chrome\n" |
643 #else | 633 #else |
644 "Icon=chromium-browser\n" | 634 "Icon=chromium-browser\n" |
645 #endif | 635 #endif |
646 }, | 636 }, |
647 }; | 637 }; |
648 | 638 |
649 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 639 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
650 SCOPED_TRACE(i); | 640 SCOPED_TRACE(i); |
651 EXPECT_EQ( | 641 EXPECT_EQ(test_cases[i].expected_output, |
652 test_cases[i].expected_output, | 642 GetDirectoryFileContents(base::ASCIIToUTF16(test_cases[i].title), |
653 ShellIntegrationLinux::GetDirectoryFileContents( | 643 test_cases[i].icon_name)); |
654 base::ASCIIToUTF16(test_cases[i].title), | |
655 test_cases[i].icon_name)); | |
656 } | 644 } |
657 } | 645 } |
| 646 |
| 647 } // namespace shell_integration_linux |
OLD | NEW |