Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chrome/browser/shell_integration_linux_unittest.cc

Issue 231673005: Move ShortcutInfo, ShortcutLocations from ShellIntegration to web_app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/environment.h" 13 #include "base/environment.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/test/scoped_path_override.h" 21 #include "base/test/scoped_path_override.h"
22 #include "chrome/browser/web_applications/web_app.h"
23 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
24 #include "content/public/test/test_browser_thread.h" 23 #include "content/public/test/test_browser_thread.h"
25 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
27 #include "url/gurl.h" 26 #include "url/gurl.h"
28 27
29 #define FPL FILE_PATH_LITERAL 28 #define FPL FILE_PATH_LITERAL
30 29
31 using content::BrowserThread; 30 using content::BrowserThread;
32 using ::testing::ElementsAre; 31 using ::testing::ElementsAre;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const char kTemplateFilename[] = "chrome-test_extension-Profile_1.desktop"; 159 const char kTemplateFilename[] = "chrome-test_extension-Profile_1.desktop";
161 base::FilePath kTemplateFilepath(kTemplateFilename); 160 base::FilePath kTemplateFilepath(kTemplateFilename);
162 const char kNoDisplayDesktopFile[] = "[Desktop Entry]\nNoDisplay=true"; 161 const char kNoDisplayDesktopFile[] = "[Desktop Entry]\nNoDisplay=true";
163 162
164 base::MessageLoop message_loop; 163 base::MessageLoop message_loop;
165 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 164 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
166 165
167 // No existing shortcuts. 166 // No existing shortcuts.
168 { 167 {
169 MockEnvironment env; 168 MockEnvironment env;
170 ShellIntegration::ShortcutLocations result = 169 web_app::ShortcutLocations result =
171 ShellIntegrationLinux::GetExistingShortcutLocations( 170 ShellIntegrationLinux::GetExistingShortcutLocations(
172 &env, kProfilePath, kExtensionId); 171 &env, kProfilePath, kExtensionId);
173 EXPECT_FALSE(result.on_desktop); 172 EXPECT_FALSE(result.on_desktop);
174 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_NONE, 173 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE,
175 result.applications_menu_location); 174 result.applications_menu_location);
176 175
177 EXPECT_FALSE(result.in_quick_launch_bar); 176 EXPECT_FALSE(result.in_quick_launch_bar);
178 EXPECT_FALSE(result.hidden); 177 EXPECT_FALSE(result.hidden);
179 } 178 }
180 179
181 // Shortcut on desktop. 180 // Shortcut on desktop.
182 { 181 {
183 base::ScopedTempDir temp_dir; 182 base::ScopedTempDir temp_dir;
184 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 183 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
185 base::FilePath desktop_path = temp_dir.path(); 184 base::FilePath desktop_path = temp_dir.path();
186 185
187 MockEnvironment env; 186 MockEnvironment env;
188 ASSERT_TRUE(base::CreateDirectory(desktop_path)); 187 ASSERT_TRUE(base::CreateDirectory(desktop_path));
189 ASSERT_FALSE(base::WriteFile( 188 ASSERT_FALSE(base::WriteFile(
190 desktop_path.AppendASCII(kTemplateFilename), 189 desktop_path.AppendASCII(kTemplateFilename),
191 "", 0)); 190 "", 0));
192 ShellIntegration::ShortcutLocations result = 191 web_app::ShortcutLocations result =
193 ShellIntegrationLinux::GetExistingShortcutLocations( 192 ShellIntegrationLinux::GetExistingShortcutLocations(
194 &env, kProfilePath, kExtensionId, desktop_path); 193 &env, kProfilePath, kExtensionId, desktop_path);
195 EXPECT_TRUE(result.on_desktop); 194 EXPECT_TRUE(result.on_desktop);
196 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_NONE, 195 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE,
197 result.applications_menu_location); 196 result.applications_menu_location);
198 197
199 EXPECT_FALSE(result.in_quick_launch_bar); 198 EXPECT_FALSE(result.in_quick_launch_bar);
200 EXPECT_FALSE(result.hidden); 199 EXPECT_FALSE(result.hidden);
201 } 200 }
202 201
203 // Shortcut in applications directory. 202 // Shortcut in applications directory.
204 { 203 {
205 base::ScopedTempDir temp_dir; 204 base::ScopedTempDir temp_dir;
206 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 205 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
207 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); 206 base::FilePath apps_path = temp_dir.path().AppendASCII("applications");
208 207
209 MockEnvironment env; 208 MockEnvironment env;
210 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 209 env.Set("XDG_DATA_HOME", temp_dir.path().value());
211 ASSERT_TRUE(base::CreateDirectory(apps_path)); 210 ASSERT_TRUE(base::CreateDirectory(apps_path));
212 ASSERT_FALSE(base::WriteFile( 211 ASSERT_FALSE(base::WriteFile(
213 apps_path.AppendASCII(kTemplateFilename), 212 apps_path.AppendASCII(kTemplateFilename),
214 "", 0)); 213 "", 0));
215 ShellIntegration::ShortcutLocations result = 214 web_app::ShortcutLocations result =
216 ShellIntegrationLinux::GetExistingShortcutLocations( 215 ShellIntegrationLinux::GetExistingShortcutLocations(
217 &env, kProfilePath, kExtensionId); 216 &env, kProfilePath, kExtensionId);
218 EXPECT_FALSE(result.on_desktop); 217 EXPECT_FALSE(result.on_desktop);
219 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 218 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
220 result.applications_menu_location); 219 result.applications_menu_location);
221 220
222 EXPECT_FALSE(result.in_quick_launch_bar); 221 EXPECT_FALSE(result.in_quick_launch_bar);
223 EXPECT_FALSE(result.hidden); 222 EXPECT_FALSE(result.hidden);
224 } 223 }
225 224
226 // Shortcut in applications directory with NoDisplay=true. 225 // Shortcut in applications directory with NoDisplay=true.
227 { 226 {
228 base::ScopedTempDir temp_dir; 227 base::ScopedTempDir temp_dir;
229 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 228 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
230 base::FilePath apps_path = temp_dir.path().AppendASCII("applications"); 229 base::FilePath apps_path = temp_dir.path().AppendASCII("applications");
231 230
232 MockEnvironment env; 231 MockEnvironment env;
233 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 232 env.Set("XDG_DATA_HOME", temp_dir.path().value());
234 ASSERT_TRUE(base::CreateDirectory(apps_path)); 233 ASSERT_TRUE(base::CreateDirectory(apps_path));
235 ASSERT_TRUE(base::WriteFile( 234 ASSERT_TRUE(base::WriteFile(
236 apps_path.AppendASCII(kTemplateFilename), 235 apps_path.AppendASCII(kTemplateFilename),
237 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile))); 236 kNoDisplayDesktopFile, strlen(kNoDisplayDesktopFile)));
238 ShellIntegration::ShortcutLocations result = 237 web_app::ShortcutLocations result =
239 ShellIntegrationLinux::GetExistingShortcutLocations( 238 ShellIntegrationLinux::GetExistingShortcutLocations(
240 &env, kProfilePath, kExtensionId); 239 &env, kProfilePath, kExtensionId);
241 // Doesn't count as being in applications menu. 240 // Doesn't count as being in applications menu.
242 EXPECT_FALSE(result.on_desktop); 241 EXPECT_FALSE(result.on_desktop);
243 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_NONE, 242 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE,
244 result.applications_menu_location); 243 result.applications_menu_location);
245 EXPECT_FALSE(result.in_quick_launch_bar); 244 EXPECT_FALSE(result.in_quick_launch_bar);
246 EXPECT_TRUE(result.hidden); 245 EXPECT_TRUE(result.hidden);
247 } 246 }
248 247
249 // Shortcut on desktop and in applications directory. 248 // Shortcut on desktop and in applications directory.
250 { 249 {
251 base::ScopedTempDir temp_dir1; 250 base::ScopedTempDir temp_dir1;
252 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 251 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
253 base::FilePath desktop_path = temp_dir1.path(); 252 base::FilePath desktop_path = temp_dir1.path();
254 253
255 base::ScopedTempDir temp_dir2; 254 base::ScopedTempDir temp_dir2;
256 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 255 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
257 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications"); 256 base::FilePath apps_path = temp_dir2.path().AppendASCII("applications");
258 257
259 MockEnvironment env; 258 MockEnvironment env;
260 ASSERT_TRUE(base::CreateDirectory(desktop_path)); 259 ASSERT_TRUE(base::CreateDirectory(desktop_path));
261 ASSERT_FALSE(base::WriteFile( 260 ASSERT_FALSE(base::WriteFile(
262 desktop_path.AppendASCII(kTemplateFilename), 261 desktop_path.AppendASCII(kTemplateFilename),
263 "", 0)); 262 "", 0));
264 env.Set("XDG_DATA_HOME", temp_dir2.path().value()); 263 env.Set("XDG_DATA_HOME", temp_dir2.path().value());
265 ASSERT_TRUE(base::CreateDirectory(apps_path)); 264 ASSERT_TRUE(base::CreateDirectory(apps_path));
266 ASSERT_FALSE(base::WriteFile( 265 ASSERT_FALSE(base::WriteFile(
267 apps_path.AppendASCII(kTemplateFilename), 266 apps_path.AppendASCII(kTemplateFilename),
268 "", 0)); 267 "", 0));
269 ShellIntegration::ShortcutLocations result = 268 web_app::ShortcutLocations result =
270 ShellIntegrationLinux::GetExistingShortcutLocations( 269 ShellIntegrationLinux::GetExistingShortcutLocations(
271 &env, kProfilePath, kExtensionId, desktop_path); 270 &env, kProfilePath, kExtensionId, desktop_path);
272 EXPECT_TRUE(result.on_desktop); 271 EXPECT_TRUE(result.on_desktop);
273 EXPECT_EQ(ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 272 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
274 result.applications_menu_location); 273 result.applications_menu_location);
275 EXPECT_FALSE(result.in_quick_launch_bar); 274 EXPECT_FALSE(result.in_quick_launch_bar);
276 EXPECT_FALSE(result.hidden); 275 EXPECT_FALSE(result.hidden);
277 } 276 }
278 } 277 }
279 278
280 TEST(ShellIntegrationTest, GetExistingShortcutContents) { 279 TEST(ShellIntegrationTest, GetExistingShortcutContents) {
281 const char kTemplateFilename[] = "shortcut-test.desktop"; 280 const char kTemplateFilename[] = "shortcut-test.desktop";
282 base::FilePath kTemplateFilepath(kTemplateFilename); 281 base::FilePath kTemplateFilepath(kTemplateFilename);
283 const char kTestData1[] = "a magical testing string"; 282 const char kTestData1[] = "a magical testing string";
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 637
639 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { 638 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) {
640 SCOPED_TRACE(i); 639 SCOPED_TRACE(i);
641 EXPECT_EQ( 640 EXPECT_EQ(
642 test_cases[i].expected_output, 641 test_cases[i].expected_output,
643 ShellIntegrationLinux::GetDirectoryFileContents( 642 ShellIntegrationLinux::GetDirectoryFileContents(
644 base::ASCIIToUTF16(test_cases[i].title), 643 base::ASCIIToUTF16(test_cases[i].title),
645 test_cases[i].icon_name)); 644 test_cases[i].icon_name));
646 } 645 }
647 } 646 }
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration_linux.cc ('k') | chrome/browser/ui/app_list/app_list_service_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698