OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/common/chrome_constants.h" | 9 #include "chrome/common/chrome_constants.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 ShellIntegration::GetDesktopShortcutFilename( | 33 ShellIntegration::GetDesktopShortcutFilename( |
34 GURL(test_cases[i].url)).value()) << | 34 GURL(test_cases[i].url)).value()) << |
35 " while testing " << test_cases[i].url; | 35 " while testing " << test_cases[i].url; |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 TEST(ShellIntegrationTest, GetDesktopFileContents) { | 39 TEST(ShellIntegrationTest, GetDesktopFileContents) { |
40 const struct { | 40 const struct { |
41 const char* url; | 41 const char* url; |
42 const char* title; | 42 const char* title; |
| 43 const char* icon_name; |
43 const char* template_contents; | 44 const char* template_contents; |
44 const char* expected_output; | 45 const char* expected_output; |
45 } test_cases[] = { | 46 } test_cases[] = { |
46 // Dumb case. | 47 // Dumb case. |
47 { "ignored", "ignored", "", "#!/usr/bin/env xdg-open\n" }, | 48 { "ignored", "ignored", "ignored", "", "#!/usr/bin/env xdg-open\n" }, |
48 | 49 |
49 // Real-world case. | 50 // Real-world case. |
50 { "http://gmail.com", | 51 { "http://gmail.com", |
51 "GMail", | 52 "GMail", |
| 53 "chrome-http__gmail.com", |
52 | 54 |
53 "[Desktop Entry]\n" | 55 "[Desktop Entry]\n" |
54 "Version=1.0\n" | 56 "Version=1.0\n" |
55 "Encoding=UTF-8\n" | 57 "Encoding=UTF-8\n" |
56 "Name=Google Chrome\n" | 58 "Name=Google Chrome\n" |
57 "Comment=The web browser from Google\n" | 59 "Comment=The web browser from Google\n" |
58 "Exec=/opt/google/chrome/google-chrome %U\n" | 60 "Exec=/opt/google/chrome/google-chrome %U\n" |
59 "Terminal=false\n" | 61 "Terminal=false\n" |
60 "Icon=/opt/google/chrome/product_logo_48.png\n" | 62 "Icon=/opt/google/chrome/product_logo_48.png\n" |
61 "Type=Application\n" | 63 "Type=Application\n" |
62 "Categories=Application;Network;WebBrowser;\n" | 64 "Categories=Application;Network;WebBrowser;\n" |
63 "MimeType=text/html;text/xml;application/xhtml_xml;\n", | 65 "MimeType=text/html;text/xml;application/xhtml_xml;\n", |
64 | 66 |
65 "#!/usr/bin/env xdg-open\n" | 67 "#!/usr/bin/env xdg-open\n" |
66 "[Desktop Entry]\n" | 68 "[Desktop Entry]\n" |
67 "Version=1.0\n" | 69 "Version=1.0\n" |
68 "Encoding=UTF-8\n" | 70 "Encoding=UTF-8\n" |
69 "Name=GMail\n" | 71 "Name=GMail\n" |
70 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" | 72 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" |
71 "Terminal=false\n" | 73 "Terminal=false\n" |
72 "Icon=/opt/google/chrome/product_logo_48.png\n" | 74 "Icon=chrome-http__gmail.com\n" |
73 "Type=Application\n" | 75 "Type=Application\n" |
74 "Categories=Application;Network;WebBrowser;\n" | 76 "Categories=Application;Network;WebBrowser;\n" |
75 "MimeType=text/html;text/xml;application/xhtml_xml;\n" | 77 "MimeType=text/html;text/xml;application/xhtml_xml;\n" |
76 }, | 78 }, |
77 | 79 |
78 // Make sure we don't insert duplicate shebangs. | 80 // Make sure we don't insert duplicate shebangs. |
79 { "http://gmail.com", | 81 { "http://gmail.com", |
80 "GMail", | 82 "GMail", |
| 83 "chrome-http__gmail.com", |
81 | 84 |
82 "#!/some/shebang\n" | 85 "#!/some/shebang\n" |
83 "Name=Google Chrome\n" | 86 "Name=Google Chrome\n" |
84 "Exec=/opt/google/chrome/google-chrome %U\n", | 87 "Exec=/opt/google/chrome/google-chrome %U\n", |
85 | 88 |
86 "#!/usr/bin/env xdg-open\n" | 89 "#!/usr/bin/env xdg-open\n" |
87 "Name=GMail\n" | 90 "Name=GMail\n" |
88 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" | 91 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" |
89 }, | 92 }, |
90 | 93 |
91 // Make sure i18n-ed comments are removed. | 94 // Make sure i18n-ed comments are removed. |
92 { "http://gmail.com", | 95 { "http://gmail.com", |
93 "GMail", | 96 "GMail", |
| 97 "chrome-http__gmail.com", |
94 | 98 |
95 "Name=Google Chrome\n" | 99 "Name=Google Chrome\n" |
96 "Exec=/opt/google/chrome/google-chrome %U\n" | 100 "Exec=/opt/google/chrome/google-chrome %U\n" |
97 "Comment[pl]=Jakis komentarz.\n", | 101 "Comment[pl]=Jakis komentarz.\n", |
98 | 102 |
99 "#!/usr/bin/env xdg-open\n" | 103 "#!/usr/bin/env xdg-open\n" |
100 "Name=GMail\n" | 104 "Name=GMail\n" |
101 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" | 105 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" |
102 }, | 106 }, |
103 | 107 |
| 108 // Make sure that empty icons are replaced by the chrome icon. |
| 109 { "http://gmail.com", |
| 110 "GMail", |
| 111 "", |
| 112 |
| 113 "Name=Google Chrome\n" |
| 114 "Exec=/opt/google/chrome/google-chrome %U\n" |
| 115 "Comment[pl]=Jakis komentarz.\n" |
| 116 "Icon=/opt/google/chrome/product_logo_48.png\n", |
| 117 |
| 118 "#!/usr/bin/env xdg-open\n" |
| 119 "Name=GMail\n" |
| 120 "Exec=/opt/google/chrome/google-chrome \"--app=http://gmail.com/\"\n" |
| 121 "Icon=/opt/google/chrome/product_logo_48.png\n" |
| 122 }, |
| 123 |
104 // Now we're starting to be more evil... | 124 // Now we're starting to be more evil... |
105 { "http://evil.com/evil --join-the-b0tnet", | 125 { "http://evil.com/evil --join-the-b0tnet", |
106 "Ownz0red\nExec=rm -rf /", | 126 "Ownz0red\nExec=rm -rf /", |
| 127 "chrome-http__evil.com_evil", |
107 | 128 |
108 "Name=Google Chrome\n" | 129 "Name=Google Chrome\n" |
109 "Exec=/opt/google/chrome/google-chrome %U\n", | 130 "Exec=/opt/google/chrome/google-chrome %U\n", |
110 | 131 |
111 "#!/usr/bin/env xdg-open\n" | 132 "#!/usr/bin/env xdg-open\n" |
112 "Name=http://evil.com/evil%20--join-the-b0tnet\n" | 133 "Name=http://evil.com/evil%20--join-the-b0tnet\n" |
113 "Exec=/opt/google/chrome/google-chrome " | 134 "Exec=/opt/google/chrome/google-chrome " |
114 "\"--app=http://evil.com/evil%%20--join-the-b0tnet\"\n" | 135 "\"--app=http://evil.com/evil%%20--join-the-b0tnet\"\n" |
115 }, | 136 }, |
116 { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red", | 137 { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red", |
117 "Innocent Title", | 138 "Innocent Title", |
| 139 "chrome-http__evil.com_evil", |
118 | 140 |
119 "Name=Google Chrome\n" | 141 "Name=Google Chrome\n" |
120 "Exec=/opt/google/chrome/google-chrome %U\n", | 142 "Exec=/opt/google/chrome/google-chrome %U\n", |
121 | 143 |
122 "#!/usr/bin/env xdg-open\n" | 144 "#!/usr/bin/env xdg-open\n" |
123 "Name=Innocent Title\n" | 145 "Name=Innocent Title\n" |
124 "Exec=/opt/google/chrome/google-chrome " | 146 "Exec=/opt/google/chrome/google-chrome " |
125 "\"--app=http://evil.com/evil%%20rm%%20-rf%%20/%%20%%22%%20rm%%20" | 147 "\"--app=http://evil.com/evil%%20rm%%20-rf%%20/%%20%%22%%20rm%%20" |
126 "-rf%%20HOME%%20%%3Eownz0red\"\n" | 148 "-rf%%20HOME%%20%%3Eownz0red\"\n" |
127 }, | 149 }, |
128 { "http://evil.com/evil | cat `echo ownz0red` >/dev/null\\", | 150 { "http://evil.com/evil | cat `echo ownz0red` >/dev/null\\", |
129 "Innocent Title", | 151 "Innocent Title", |
| 152 "chrome-http__evil.com_evil", |
130 | 153 |
131 "Name=Google Chrome\n" | 154 "Name=Google Chrome\n" |
132 "Exec=/opt/google/chrome/google-chrome %U\n", | 155 "Exec=/opt/google/chrome/google-chrome %U\n", |
133 | 156 |
134 "#!/usr/bin/env xdg-open\n" | 157 "#!/usr/bin/env xdg-open\n" |
135 "Name=Innocent Title\n" | 158 "Name=Innocent Title\n" |
136 "Exec=/opt/google/chrome/google-chrome " | 159 "Exec=/opt/google/chrome/google-chrome " |
137 "\"--app=http://evil.com/evil%%20%%7C%%20cat%%20%%60echo%%20ownz0red" | 160 "\"--app=http://evil.com/evil%%20%%7C%%20cat%%20%%60echo%%20ownz0red" |
138 "%%60%%20%%3E/dev/null/\"\n" | 161 "%%60%%20%%3E/dev/null/\"\n" |
139 }, | 162 }, |
140 }; | 163 }; |
141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 164 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
142 EXPECT_EQ(test_cases[i].expected_output, | 165 EXPECT_EQ(test_cases[i].expected_output, |
143 ShellIntegration::GetDesktopFileContents( | 166 ShellIntegration::GetDesktopFileContents( |
144 test_cases[i].template_contents, | 167 test_cases[i].template_contents, |
145 GURL(test_cases[i].url), | 168 GURL(test_cases[i].url), |
146 ASCIIToUTF16(test_cases[i].title))); | 169 ASCIIToUTF16(test_cases[i].title), |
| 170 test_cases[i].icon_name)); |
147 } | 171 } |
148 } | 172 } |
149 #endif // defined(OS_LINUX) | 173 #endif // defined(OS_LINUX) |
OLD | NEW |