| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 base::MessageLoop message_loop; | 163 base::MessageLoop message_loop; |
| 164 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); | 164 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); |
| 165 | 165 |
| 166 // No existing shortcuts. | 166 // No existing shortcuts. |
| 167 { | 167 { |
| 168 MockEnvironment env; | 168 MockEnvironment env; |
| 169 ShellIntegration::ShortcutLocations result = | 169 ShellIntegration::ShortcutLocations result = |
| 170 ShellIntegrationLinux::GetExistingShortcutLocations( | 170 ShellIntegrationLinux::GetExistingShortcutLocations( |
| 171 &env, kProfilePath, kExtensionId); | 171 &env, kProfilePath, kExtensionId); |
| 172 EXPECT_FALSE(result.on_desktop); | 172 EXPECT_FALSE(result.on_desktop); |
| 173 EXPECT_FALSE(result.in_applications_menu); | 173 EXPECT_EQ(result.applications_menu_location, |
| 174 ShellIntegration::APP_MENU_LOCATION_NONE); |
| 175 |
| 174 EXPECT_FALSE(result.in_quick_launch_bar); | 176 EXPECT_FALSE(result.in_quick_launch_bar); |
| 175 EXPECT_FALSE(result.hidden); | 177 EXPECT_FALSE(result.hidden); |
| 176 } | 178 } |
| 177 | 179 |
| 178 // Shortcut on desktop. | 180 // Shortcut on desktop. |
| 179 { | 181 { |
| 180 base::ScopedTempDir temp_dir; | 182 base::ScopedTempDir temp_dir; |
| 181 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 183 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 182 base::FilePath desktop_path = temp_dir.path(); | 184 base::FilePath desktop_path = temp_dir.path(); |
| 183 | 185 |
| 184 MockEnvironment env; | 186 MockEnvironment env; |
| 185 ASSERT_TRUE(file_util::CreateDirectory(desktop_path)); | 187 ASSERT_TRUE(file_util::CreateDirectory(desktop_path)); |
| 186 ASSERT_FALSE(file_util::WriteFile( | 188 ASSERT_FALSE(file_util::WriteFile( |
| 187 desktop_path.AppendASCII(kTemplateFilename), | 189 desktop_path.AppendASCII(kTemplateFilename), |
| 188 "", 0)); | 190 "", 0)); |
| 189 ShellIntegration::ShortcutLocations result = | 191 ShellIntegration::ShortcutLocations result = |
| 190 ShellIntegrationLinux::GetExistingShortcutLocations( | 192 ShellIntegrationLinux::GetExistingShortcutLocations( |
| 191 &env, kProfilePath, kExtensionId, desktop_path); | 193 &env, kProfilePath, kExtensionId, desktop_path); |
| 192 EXPECT_TRUE(result.on_desktop); | 194 EXPECT_TRUE(result.on_desktop); |
| 193 EXPECT_FALSE(result.in_applications_menu); | 195 EXPECT_EQ(result.applications_menu_location, |
| 196 ShellIntegration::APP_MENU_LOCATION_NONE); |
| 197 |
| 194 EXPECT_FALSE(result.in_quick_launch_bar); | 198 EXPECT_FALSE(result.in_quick_launch_bar); |
| 195 EXPECT_FALSE(result.hidden); | 199 EXPECT_FALSE(result.hidden); |
| 196 } | 200 } |
| 197 | 201 |
| 198 // Shortcut in applications directory. | 202 // Shortcut in applications directory. |
| 199 { | 203 { |
| 200 base::ScopedTempDir temp_dir; | 204 base::ScopedTempDir temp_dir; |
| 201 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 205 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 202 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); | 206 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); |
| 203 | 207 |
| 204 MockEnvironment env; | 208 MockEnvironment env; |
| 205 env.Set("XDG_DATA_HOME", temp_dir.path().value()); | 209 env.Set("XDG_DATA_HOME", temp_dir.path().value()); |
| 206 ASSERT_TRUE(file_util::CreateDirectory(apps_path)); | 210 ASSERT_TRUE(file_util::CreateDirectory(apps_path)); |
| 207 ASSERT_FALSE(file_util::WriteFile( | 211 ASSERT_FALSE(file_util::WriteFile( |
| 208 apps_path.AppendASCII(kTemplateFilename), | 212 apps_path.AppendASCII(kTemplateFilename), |
| 209 "", 0)); | 213 "", 0)); |
| 210 ShellIntegration::ShortcutLocations result = | 214 ShellIntegration::ShortcutLocations result = |
| 211 ShellIntegrationLinux::GetExistingShortcutLocations( | 215 ShellIntegrationLinux::GetExistingShortcutLocations( |
| 212 &env, kProfilePath, kExtensionId); | 216 &env, kProfilePath, kExtensionId); |
| 213 EXPECT_FALSE(result.on_desktop); | 217 EXPECT_FALSE(result.on_desktop); |
| 214 EXPECT_TRUE(result.in_applications_menu); | 218 EXPECT_EQ(result.applications_menu_location, |
| 219 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS); |
| 220 |
| 215 EXPECT_FALSE(result.in_quick_launch_bar); | 221 EXPECT_FALSE(result.in_quick_launch_bar); |
| 216 EXPECT_FALSE(result.hidden); | 222 EXPECT_FALSE(result.hidden); |
| 217 } | 223 } |
| 218 | 224 |
| 219 // Shortcut in applications directory with NoDisplay=true. | 225 // Shortcut in applications directory with NoDisplay=true. |
| 220 { | 226 { |
| 221 base::ScopedTempDir temp_dir; | 227 base::ScopedTempDir temp_dir; |
| 222 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 228 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 223 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); | 229 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); |
| 224 | 230 |
| 225 MockEnvironment env; | 231 MockEnvironment env; |
| 226 env.Set("XDG_DATA_HOME", temp_dir.path().value()); | 232 env.Set("XDG_DATA_HOME", temp_dir.path().value()); |
| 227 ASSERT_TRUE(file_util::CreateDirectory(apps_path)); | 233 ASSERT_TRUE(file_util::CreateDirectory(apps_path)); |
| 228 ASSERT_TRUE(file_util::WriteFile( | 234 ASSERT_TRUE(file_util::WriteFile( |
| 229 apps_path.AppendASCII(kTemplateFilename), | 235 apps_path.AppendASCII(kTemplateFilename), |
| 230 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile))); | 236 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile))); |
| 231 ShellIntegration::ShortcutLocations result = | 237 ShellIntegration::ShortcutLocations result = |
| 232 ShellIntegrationLinux::GetExistingShortcutLocations( | 238 ShellIntegrationLinux::GetExistingShortcutLocations( |
| 233 &env, kProfilePath, kExtensionId); | 239 &env, kProfilePath, kExtensionId); |
| 234 // Doesn't count as being in applications menu. | 240 // Doesn't count as being in applications menu. |
| 235 EXPECT_FALSE(result.on_desktop); | 241 EXPECT_FALSE(result.on_desktop); |
| 236 EXPECT_FALSE(result.in_applications_menu); | 242 EXPECT_EQ(result.applications_menu_location, |
| 243 ShellIntegration::APP_MENU_LOCATION_NONE); |
| 237 EXPECT_FALSE(result.in_quick_launch_bar); | 244 EXPECT_FALSE(result.in_quick_launch_bar); |
| 238 EXPECT_TRUE(result.hidden); | 245 EXPECT_TRUE(result.hidden); |
| 239 } | 246 } |
| 240 | 247 |
| 241 // Shortcut on desktop and in applications directory. | 248 // Shortcut on desktop and in applications directory. |
| 242 { | 249 { |
| 243 base::ScopedTempDir temp_dir1; | 250 base::ScopedTempDir temp_dir1; |
| 244 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); | 251 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); |
| 245 base::FilePath desktop_path = temp_dir1.path(); | 252 base::FilePath desktop_path = temp_dir1.path(); |
| 246 | 253 |
| 247 base::ScopedTempDir temp_dir2; | 254 base::ScopedTempDir temp_dir2; |
| 248 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); | 255 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 249 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications"); | 256 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications"); |
| 250 | 257 |
| 251 MockEnvironment env; | 258 MockEnvironment env; |
| 252 ASSERT_TRUE(file_util::CreateDirectory(desktop_path)); | 259 ASSERT_TRUE(file_util::CreateDirectory(desktop_path)); |
| 253 ASSERT_FALSE(file_util::WriteFile( | 260 ASSERT_FALSE(file_util::WriteFile( |
| 254 desktop_path.AppendASCII(kTemplateFilename), | 261 desktop_path.AppendASCII(kTemplateFilename), |
| 255 "", 0)); | 262 "", 0)); |
| 256 env.Set("XDG_DATA_HOME", temp_dir2.path().value()); | 263 env.Set("XDG_DATA_HOME", temp_dir2.path().value()); |
| 257 ASSERT_TRUE(file_util::CreateDirectory(apps_path)); | 264 ASSERT_TRUE(file_util::CreateDirectory(apps_path)); |
| 258 ASSERT_FALSE(file_util::WriteFile( | 265 ASSERT_FALSE(file_util::WriteFile( |
| 259 apps_path.AppendASCII(kTemplateFilename), | 266 apps_path.AppendASCII(kTemplateFilename), |
| 260 "", 0)); | 267 "", 0)); |
| 261 ShellIntegration::ShortcutLocations result = | 268 ShellIntegration::ShortcutLocations result = |
| 262 ShellIntegrationLinux::GetExistingShortcutLocations( | 269 ShellIntegrationLinux::GetExistingShortcutLocations( |
| 263 &env, kProfilePath, kExtensionId, desktop_path); | 270 &env, kProfilePath, kExtensionId, desktop_path); |
| 264 EXPECT_TRUE(result.on_desktop); | 271 EXPECT_TRUE(result.on_desktop); |
| 265 EXPECT_TRUE(result.in_applications_menu); | 272 EXPECT_EQ(result.applications_menu_location, |
| 273 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS); |
| 266 EXPECT_FALSE(result.in_quick_launch_bar); | 274 EXPECT_FALSE(result.in_quick_launch_bar); |
| 267 EXPECT_FALSE(result.hidden); | 275 EXPECT_FALSE(result.hidden); |
| 268 } | 276 } |
| 269 } | 277 } |
| 270 | 278 |
| 271 TEST(ShellIntegrationTest, GetExistingShortcutContents) { | 279 TEST(ShellIntegrationTest, GetExistingShortcutContents) { |
| 272 const char kTemplateFilename[] = "shortcut-test.desktop"; | 280 const char kTemplateFilename[] = "shortcut-test.desktop"; |
| 273 base::FilePath kTemplateFilepath(kTemplateFilename); | 281 base::FilePath kTemplateFilepath(kTemplateFilename); |
| 274 const char kTestData1[] = "a magical testing string"; | 282 const char kTestData1[] = "a magical testing string"; |
| 275 const char kTestData2[] = "a different testing string"; | 283 const char kTestData2[] = "a different testing string"; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 607 |
| 600 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 608 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
| 601 SCOPED_TRACE(i); | 609 SCOPED_TRACE(i); |
| 602 EXPECT_EQ( | 610 EXPECT_EQ( |
| 603 test_cases[i].expected_output, | 611 test_cases[i].expected_output, |
| 604 ShellIntegrationLinux::GetDirectoryFileContents( | 612 ShellIntegrationLinux::GetDirectoryFileContents( |
| 605 ASCIIToUTF16(test_cases[i].title), | 613 ASCIIToUTF16(test_cases[i].title), |
| 606 test_cases[i].icon_name)); | 614 test_cases[i].icon_name)); |
| 607 } | 615 } |
| 608 } | 616 } |
| OLD | NEW |