OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/web_applications/web_app.h" | 16 #include "chrome/browser/web_applications/web_app.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/chrome_paths_internal.h" | 18 #include "chrome/common/chrome_paths_internal.h" |
19 #include "content/test/test_browser_thread.h" | 19 #include "content/test/test_browser_thread.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
24 #include "chrome/installer/util/browser_distribution.h" | 24 #include "chrome/installer/util/browser_distribution.h" |
25 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 25 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
26 #include "base/environment.h" | 26 #include "base/environment.h" |
| 27 #include "chrome/browser/shell_integration_linux.h" |
27 #endif | 28 #endif |
28 | 29 |
29 #define FPL FILE_PATH_LITERAL | 30 #define FPL FILE_PATH_LITERAL |
30 | 31 |
31 using content::BrowserThread; | 32 using content::BrowserThread; |
32 | 33 |
33 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 34 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
34 namespace { | 35 namespace { |
35 | 36 |
36 // Provides mock environment variables values based on a stored map. | 37 // Provides mock environment variables values based on a stored map. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 { | 86 { |
86 ScopedTempDir temp_dir; | 87 ScopedTempDir temp_dir; |
87 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 88 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
88 | 89 |
89 MockEnvironment env; | 90 MockEnvironment env; |
90 env.Set("XDG_DATA_HOME", temp_dir.path().value()); | 91 env.Set("XDG_DATA_HOME", temp_dir.path().value()); |
91 ASSERT_TRUE(file_util::WriteFile( | 92 ASSERT_TRUE(file_util::WriteFile( |
92 temp_dir.path().AppendASCII(kTemplateFilename), | 93 temp_dir.path().AppendASCII(kTemplateFilename), |
93 kTestData1, strlen(kTestData1))); | 94 kTestData1, strlen(kTestData1))); |
94 std::string contents; | 95 std::string contents; |
95 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env, | 96 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, |
96 &contents)); | 97 &contents)); |
97 EXPECT_EQ(kTestData1, contents); | 98 EXPECT_EQ(kTestData1, contents); |
98 } | 99 } |
99 | 100 |
100 { | 101 { |
101 ScopedTempDir temp_dir; | 102 ScopedTempDir temp_dir; |
102 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 103 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
103 | 104 |
104 MockEnvironment env; | 105 MockEnvironment env; |
105 env.Set("XDG_DATA_DIRS", temp_dir.path().value()); | 106 env.Set("XDG_DATA_DIRS", temp_dir.path().value()); |
106 ASSERT_TRUE(file_util::CreateDirectory( | 107 ASSERT_TRUE(file_util::CreateDirectory( |
107 temp_dir.path().AppendASCII("applications"))); | 108 temp_dir.path().AppendASCII("applications"))); |
108 ASSERT_TRUE(file_util::WriteFile( | 109 ASSERT_TRUE(file_util::WriteFile( |
109 temp_dir.path().AppendASCII("applications") | 110 temp_dir.path().AppendASCII("applications") |
110 .AppendASCII(kTemplateFilename), | 111 .AppendASCII(kTemplateFilename), |
111 kTestData2, strlen(kTestData2))); | 112 kTestData2, strlen(kTestData2))); |
112 std::string contents; | 113 std::string contents; |
113 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env, | 114 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, |
114 &contents)); | 115 &contents)); |
115 EXPECT_EQ(kTestData2, contents); | 116 EXPECT_EQ(kTestData2, contents); |
116 } | 117 } |
117 | 118 |
118 { | 119 { |
119 ScopedTempDir temp_dir; | 120 ScopedTempDir temp_dir; |
120 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 121 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
121 | 122 |
122 MockEnvironment env; | 123 MockEnvironment env; |
123 env.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" + | 124 env.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" + |
124 temp_dir.path().AppendASCII("applications").value()); | 125 temp_dir.path().AppendASCII("applications").value()); |
125 ASSERT_TRUE(file_util::CreateDirectory( | 126 ASSERT_TRUE(file_util::CreateDirectory( |
126 temp_dir.path().AppendASCII("applications"))); | 127 temp_dir.path().AppendASCII("applications"))); |
127 ASSERT_TRUE(file_util::WriteFile( | 128 ASSERT_TRUE(file_util::WriteFile( |
128 temp_dir.path().AppendASCII(kTemplateFilename), | 129 temp_dir.path().AppendASCII(kTemplateFilename), |
129 kTestData1, strlen(kTestData1))); | 130 kTestData1, strlen(kTestData1))); |
130 ASSERT_TRUE(file_util::WriteFile( | 131 ASSERT_TRUE(file_util::WriteFile( |
131 temp_dir.path().AppendASCII("applications") | 132 temp_dir.path().AppendASCII("applications") |
132 .AppendASCII(kTemplateFilename), | 133 .AppendASCII(kTemplateFilename), |
133 kTestData2, strlen(kTestData2))); | 134 kTestData2, strlen(kTestData2))); |
134 std::string contents; | 135 std::string contents; |
135 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env, | 136 ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env, |
136 &contents)); | 137 &contents)); |
137 EXPECT_EQ(kTestData1, contents); | 138 EXPECT_EQ(kTestData1, contents); |
138 } | 139 } |
139 } | 140 } |
140 | 141 |
141 TEST(ShellIntegrationTest, GetDesktopShortcutFilename) { | 142 TEST(ShellIntegrationTest, GetDesktopShortcutFilename) { |
142 const struct { | 143 const struct { |
143 const FilePath::CharType* path; | 144 const FilePath::CharType* path; |
144 const char* url; | 145 const char* url; |
145 } test_cases[] = { | 146 } test_cases[] = { |
146 { FPL("http___foo_.desktop"), "http://foo" }, | 147 { FPL("http___foo_.desktop"), "http://foo" }, |
147 { FPL("http___foo_bar_.desktop"), "http://foo/bar/" }, | 148 { FPL("http___foo_bar_.desktop"), "http://foo/bar/" }, |
148 { FPL("http___foo_bar_a=b&c=d.desktop"), "http://foo/bar?a=b&c=d" }, | 149 { FPL("http___foo_bar_a=b&c=d.desktop"), "http://foo/bar?a=b&c=d" }, |
149 | 150 |
150 // Now we're starting to be more evil... | 151 // Now we're starting to be more evil... |
151 { FPL("http___foo_.desktop"), "http://foo/bar/baz/../../../../../" }, | 152 { FPL("http___foo_.desktop"), "http://foo/bar/baz/../../../../../" }, |
152 { FPL("http___foo_.desktop"), "http://foo/bar/././../baz/././../" }, | 153 { FPL("http___foo_.desktop"), "http://foo/bar/././../baz/././../" }, |
153 { FPL("http___.._.desktop"), "http://../../../../" }, | 154 { FPL("http___.._.desktop"), "http://../../../../" }, |
154 }; | 155 }; |
155 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 156 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
156 EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" + | 157 EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" + |
157 test_cases[i].path, | 158 test_cases[i].path, |
158 ShellIntegration::GetDesktopShortcutFilename( | 159 ShellIntegrationLinux::GetDesktopShortcutFilename( |
159 GURL(test_cases[i].url)).value()) << | 160 GURL(test_cases[i].url)).value()) << |
160 " while testing " << test_cases[i].url; | 161 " while testing " << test_cases[i].url; |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 TEST(ShellIntegrationTest, GetDesktopFileContents) { | 165 TEST(ShellIntegrationTest, GetDesktopFileContents) { |
165 const struct { | 166 const struct { |
166 const char* url; | 167 const char* url; |
167 const char* title; | 168 const char* title; |
168 const char* icon_name; | 169 const char* icon_name; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // WMClass does not matter. | 346 // WMClass does not matter. |
346 "StartupWMClass=evil.com__evil%20%7C%20cat%20%60echo%20ownz0red" | 347 "StartupWMClass=evil.com__evil%20%7C%20cat%20%60echo%20ownz0red" |
347 "%60%20%3E_dev_null\n" | 348 "%60%20%3E_dev_null\n" |
348 #endif | 349 #endif |
349 }, | 350 }, |
350 }; | 351 }; |
351 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 352 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
352 SCOPED_TRACE(i); | 353 SCOPED_TRACE(i); |
353 EXPECT_EQ( | 354 EXPECT_EQ( |
354 test_cases[i].expected_output, | 355 test_cases[i].expected_output, |
355 ShellIntegration::GetDesktopFileContents( | 356 ShellIntegrationLinux::GetDesktopFileContents( |
356 test_cases[i].template_contents, | 357 test_cases[i].template_contents, |
357 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), | 358 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), |
358 GURL(test_cases[i].url), | 359 GURL(test_cases[i].url), |
359 "", | 360 "", |
360 false, | 361 false, |
361 FilePath(), | 362 FilePath(), |
362 FilePath(), | 363 FilePath(), |
363 ASCIIToUTF16(test_cases[i].title), | 364 ASCIIToUTF16(test_cases[i].title), |
364 test_cases[i].icon_name)); | 365 test_cases[i].icon_name)); |
365 } | 366 } |
(...skipping 16 matching lines...) Expand all Loading... |
382 // Non-default profile path should get chrome::kBrowserAppID joined with | 383 // Non-default profile path should get chrome::kBrowserAppID joined with |
383 // profile info. | 384 // profile info. |
384 FilePath profile_path(FILE_PATH_LITERAL("root")); | 385 FilePath profile_path(FILE_PATH_LITERAL("root")); |
385 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); | 386 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); |
386 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); | 387 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); |
387 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId() + | 388 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId() + |
388 L".udd.UserDataTest", | 389 L".udd.UserDataTest", |
389 ShellIntegration::GetChromiumAppId(profile_path)); | 390 ShellIntegration::GetChromiumAppId(profile_path)); |
390 } | 391 } |
391 #endif | 392 #endif |
OLD | NEW |