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

Side by Side Diff: base/win/shortcut_unittest.cc

Issue 12294008: Fix more remaining FilePath -> base::FilePath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
« no previous file with comments | « base/win/event_trace_controller_unittest.cc ('k') | chrome/app/breakpad_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/win/shortcut.h" 5 #include "base/win/shortcut.h"
6 6
7 #include <string> 7 #include <string>
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/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/test/test_file_util.h" 12 #include "base/test/test_file_util.h"
13 #include "base/test/test_shortcut_win.h" 13 #include "base/test/test_shortcut_win.h"
14 #include "base/win/scoped_com_initializer.h" 14 #include "base/win/scoped_com_initializer.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace base {
18 namespace win {
19
17 namespace { 20 namespace {
18 21
19 static const char kFileContents[] = "This is a target."; 22 static const char kFileContents[] = "This is a target.";
20 static const char kFileContents2[] = "This is another target."; 23 static const char kFileContents2[] = "This is another target.";
21 24
22 class ShortcutTest : public testing::Test { 25 class ShortcutTest : public testing::Test {
23 protected: 26 protected:
24 virtual void SetUp() OVERRIDE { 27 virtual void SetUp() OVERRIDE {
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
26 ASSERT_TRUE(temp_dir_2_.CreateUniqueTempDir()); 29 ASSERT_TRUE(temp_dir_2_.CreateUniqueTempDir());
(...skipping 27 matching lines...) Expand all
54 link_properties_2_.set_target(target_file_2); 57 link_properties_2_.set_target(target_file_2);
55 link_properties_2_.set_working_dir(temp_dir_2_.path()); 58 link_properties_2_.set_working_dir(temp_dir_2_.path());
56 link_properties_2_.set_arguments(L"--super --crazy"); 59 link_properties_2_.set_arguments(L"--super --crazy");
57 link_properties_2_.set_description(L"The best in the west."); 60 link_properties_2_.set_description(L"The best in the west.");
58 link_properties_2_.set_icon(icon_path_2, 0); 61 link_properties_2_.set_icon(icon_path_2, 0);
59 link_properties_2_.set_app_id(L"Chrome.UserLevelCrazySuffix"); 62 link_properties_2_.set_app_id(L"Chrome.UserLevelCrazySuffix");
60 link_properties_2_.set_dual_mode(true); 63 link_properties_2_.set_dual_mode(true);
61 } 64 }
62 } 65 }
63 66
64 base::win::ScopedCOMInitializer com_initializer_; 67 ScopedCOMInitializer com_initializer_;
65 base::ScopedTempDir temp_dir_; 68 ScopedTempDir temp_dir_;
66 base::ScopedTempDir temp_dir_2_; 69 ScopedTempDir temp_dir_2_;
67 70
68 // The link file to be created/updated in the shortcut tests below. 71 // The link file to be created/updated in the shortcut tests below.
69 FilePath link_file_; 72 FilePath link_file_;
70 73
71 // Properties for the created shortcut. 74 // Properties for the created shortcut.
72 base::win::ShortcutProperties link_properties_; 75 ShortcutProperties link_properties_;
73 76
74 // Properties for the updated shortcut. 77 // Properties for the updated shortcut.
75 base::win::ShortcutProperties link_properties_2_; 78 ShortcutProperties link_properties_2_;
76 }; 79 };
77 80
78 } // namespace 81 } // namespace
79 82
80 TEST_F(ShortcutTest, CreateAndResolveShortcut) { 83 TEST_F(ShortcutTest, CreateAndResolveShortcut) {
81 base::win::ShortcutProperties only_target_properties; 84 ShortcutProperties only_target_properties;
82 only_target_properties.set_target(link_properties_.target); 85 only_target_properties.set_target(link_properties_.target);
83 86
84 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 87 ASSERT_TRUE(CreateOrUpdateShortcutLink(
85 link_file_, only_target_properties, base::win::SHORTCUT_CREATE_ALWAYS)); 88 link_file_, only_target_properties, SHORTCUT_CREATE_ALWAYS));
86 89
87 FilePath resolved_name; 90 FilePath resolved_name;
88 EXPECT_TRUE(base::win::ResolveShortcut(link_file_, &resolved_name, NULL)); 91 EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL));
89 92
90 char read_contents[arraysize(kFileContents)]; 93 char read_contents[arraysize(kFileContents)];
91 file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents)); 94 file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents));
92 EXPECT_STREQ(kFileContents, read_contents); 95 EXPECT_STREQ(kFileContents, read_contents);
93 } 96 }
94 97
95 TEST_F(ShortcutTest, ResolveShortcutWithArgs) { 98 TEST_F(ShortcutTest, ResolveShortcutWithArgs) {
96 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 99 ASSERT_TRUE(CreateOrUpdateShortcutLink(
97 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); 100 link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
98 101
99 FilePath resolved_name; 102 FilePath resolved_name;
100 string16 args; 103 string16 args;
101 EXPECT_TRUE(base::win::ResolveShortcut(link_file_, &resolved_name, &args)); 104 EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, &args));
102 105
103 char read_contents[arraysize(kFileContents)]; 106 char read_contents[arraysize(kFileContents)];
104 file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents)); 107 file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents));
105 EXPECT_STREQ(kFileContents, read_contents); 108 EXPECT_STREQ(kFileContents, read_contents);
106 EXPECT_EQ(link_properties_.arguments, args); 109 EXPECT_EQ(link_properties_.arguments, args);
107 } 110 }
108 111
109 TEST_F(ShortcutTest, CreateShortcutWithOnlySomeProperties) { 112 TEST_F(ShortcutTest, CreateShortcutWithOnlySomeProperties) {
110 base::win::ShortcutProperties target_and_args_properties; 113 ShortcutProperties target_and_args_properties;
111 target_and_args_properties.set_target(link_properties_.target); 114 target_and_args_properties.set_target(link_properties_.target);
112 target_and_args_properties.set_arguments(link_properties_.arguments); 115 target_and_args_properties.set_arguments(link_properties_.arguments);
113 116
114 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 117 ASSERT_TRUE(CreateOrUpdateShortcutLink(
115 link_file_, target_and_args_properties, 118 link_file_, target_and_args_properties,
116 base::win::SHORTCUT_CREATE_ALWAYS)); 119 SHORTCUT_CREATE_ALWAYS));
117 120
118 base::win::ValidateShortcut(link_file_, target_and_args_properties); 121 ValidateShortcut(link_file_, target_and_args_properties);
119 } 122 }
120 123
121 TEST_F(ShortcutTest, CreateShortcutVerifyProperties) { 124 TEST_F(ShortcutTest, CreateShortcutVerifyProperties) {
122 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 125 ASSERT_TRUE(CreateOrUpdateShortcutLink(
123 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); 126 link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
124 127
125 base::win::ValidateShortcut(link_file_, link_properties_); 128 ValidateShortcut(link_file_, link_properties_);
126 } 129 }
127 130
128 TEST_F(ShortcutTest, UpdateShortcutVerifyProperties) { 131 TEST_F(ShortcutTest, UpdateShortcutVerifyProperties) {
129 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 132 ASSERT_TRUE(CreateOrUpdateShortcutLink(
130 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); 133 link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
131 134
132 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 135 ASSERT_TRUE(CreateOrUpdateShortcutLink(
133 link_file_, link_properties_2_, base::win::SHORTCUT_UPDATE_EXISTING)); 136 link_file_, link_properties_2_, SHORTCUT_UPDATE_EXISTING));
134 137
135 base::win::ValidateShortcut(link_file_, link_properties_2_); 138 ValidateShortcut(link_file_, link_properties_2_);
136 } 139 }
137 140
138 TEST_F(ShortcutTest, UpdateShortcutUpdateOnlyTargetAndResolve) { 141 TEST_F(ShortcutTest, UpdateShortcutUpdateOnlyTargetAndResolve) {
139 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 142 ASSERT_TRUE(CreateOrUpdateShortcutLink(
140 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); 143 link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
141 144
142 base::win::ShortcutProperties update_only_target_properties; 145 ShortcutProperties update_only_target_properties;
143 update_only_target_properties.set_target(link_properties_2_.target); 146 update_only_target_properties.set_target(link_properties_2_.target);
144 147
145 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 148 ASSERT_TRUE(CreateOrUpdateShortcutLink(
146 link_file_, update_only_target_properties, 149 link_file_, update_only_target_properties,
147 base::win::SHORTCUT_UPDATE_EXISTING)); 150 SHORTCUT_UPDATE_EXISTING));
148 151
149 base::win::ShortcutProperties expected_properties = link_properties_; 152 ShortcutProperties expected_properties = link_properties_;
150 expected_properties.set_target(link_properties_2_.target); 153 expected_properties.set_target(link_properties_2_.target);
151 base::win::ValidateShortcut(link_file_, expected_properties); 154 ValidateShortcut(link_file_, expected_properties);
152 155
153 FilePath resolved_name; 156 FilePath resolved_name;
154 EXPECT_TRUE(base::win::ResolveShortcut(link_file_, &resolved_name, NULL)); 157 EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL));
155 158
156 char read_contents[arraysize(kFileContents2)]; 159 char read_contents[arraysize(kFileContents2)];
157 file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents)); 160 file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents));
158 EXPECT_STREQ(kFileContents2, read_contents); 161 EXPECT_STREQ(kFileContents2, read_contents);
159 } 162 }
160 163
161 TEST_F(ShortcutTest, UpdateShortcutMakeDualMode) { 164 TEST_F(ShortcutTest, UpdateShortcutMakeDualMode) {
162 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 165 ASSERT_TRUE(CreateOrUpdateShortcutLink(
163 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); 166 link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
164 167
165 base::win::ShortcutProperties make_dual_mode_properties; 168 ShortcutProperties make_dual_mode_properties;
166 make_dual_mode_properties.set_dual_mode(true); 169 make_dual_mode_properties.set_dual_mode(true);
167 170
168 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 171 ASSERT_TRUE(CreateOrUpdateShortcutLink(
169 link_file_, make_dual_mode_properties, 172 link_file_, make_dual_mode_properties,
170 base::win::SHORTCUT_UPDATE_EXISTING)); 173 SHORTCUT_UPDATE_EXISTING));
171 174
172 base::win::ShortcutProperties expected_properties = link_properties_; 175 ShortcutProperties expected_properties = link_properties_;
173 expected_properties.set_dual_mode(true); 176 expected_properties.set_dual_mode(true);
174 base::win::ValidateShortcut(link_file_, expected_properties); 177 ValidateShortcut(link_file_, expected_properties);
175 } 178 }
176 179
177 TEST_F(ShortcutTest, UpdateShortcutRemoveDualMode) { 180 TEST_F(ShortcutTest, UpdateShortcutRemoveDualMode) {
178 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 181 ASSERT_TRUE(CreateOrUpdateShortcutLink(
179 link_file_, link_properties_2_, base::win::SHORTCUT_CREATE_ALWAYS)); 182 link_file_, link_properties_2_, SHORTCUT_CREATE_ALWAYS));
180 183
181 base::win::ShortcutProperties remove_dual_mode_properties; 184 ShortcutProperties remove_dual_mode_properties;
182 remove_dual_mode_properties.set_dual_mode(false); 185 remove_dual_mode_properties.set_dual_mode(false);
183 186
184 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 187 ASSERT_TRUE(CreateOrUpdateShortcutLink(
185 link_file_, remove_dual_mode_properties, 188 link_file_, remove_dual_mode_properties,
186 base::win::SHORTCUT_UPDATE_EXISTING)); 189 SHORTCUT_UPDATE_EXISTING));
187 190
188 base::win::ShortcutProperties expected_properties = link_properties_2_; 191 ShortcutProperties expected_properties = link_properties_2_;
189 expected_properties.set_dual_mode(false); 192 expected_properties.set_dual_mode(false);
190 base::win::ValidateShortcut(link_file_, expected_properties); 193 ValidateShortcut(link_file_, expected_properties);
191 } 194 }
192 195
193 TEST_F(ShortcutTest, UpdateShortcutClearArguments) { 196 TEST_F(ShortcutTest, UpdateShortcutClearArguments) {
194 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 197 ASSERT_TRUE(CreateOrUpdateShortcutLink(
195 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); 198 link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
196 199
197 base::win::ShortcutProperties clear_arguments_properties; 200 ShortcutProperties clear_arguments_properties;
198 clear_arguments_properties.set_arguments(string16()); 201 clear_arguments_properties.set_arguments(string16());
199 202
200 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 203 ASSERT_TRUE(CreateOrUpdateShortcutLink(
201 link_file_, clear_arguments_properties, 204 link_file_, clear_arguments_properties,
202 base::win::SHORTCUT_UPDATE_EXISTING)); 205 SHORTCUT_UPDATE_EXISTING));
203 206
204 base::win::ShortcutProperties expected_properties = link_properties_; 207 ShortcutProperties expected_properties = link_properties_;
205 expected_properties.set_arguments(string16()); 208 expected_properties.set_arguments(string16());
206 base::win::ValidateShortcut(link_file_, expected_properties); 209 ValidateShortcut(link_file_, expected_properties);
207 } 210 }
208 211
209 TEST_F(ShortcutTest, FailUpdateShortcutThatDoesNotExist) { 212 TEST_F(ShortcutTest, FailUpdateShortcutThatDoesNotExist) {
210 ASSERT_FALSE(base::win::CreateOrUpdateShortcutLink( 213 ASSERT_FALSE(CreateOrUpdateShortcutLink(
211 link_file_, link_properties_, base::win::SHORTCUT_UPDATE_EXISTING)); 214 link_file_, link_properties_, SHORTCUT_UPDATE_EXISTING));
212 ASSERT_FALSE(file_util::PathExists(link_file_)); 215 ASSERT_FALSE(file_util::PathExists(link_file_));
213 } 216 }
214 217
215 TEST_F(ShortcutTest, ReplaceShortcutAllProperties) { 218 TEST_F(ShortcutTest, ReplaceShortcutAllProperties) {
216 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 219 ASSERT_TRUE(CreateOrUpdateShortcutLink(
217 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); 220 link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
218 221
219 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 222 ASSERT_TRUE(CreateOrUpdateShortcutLink(
220 link_file_, link_properties_2_, base::win::SHORTCUT_REPLACE_EXISTING)); 223 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING));
221 224
222 base::win::ValidateShortcut(link_file_, link_properties_2_); 225 ValidateShortcut(link_file_, link_properties_2_);
223 } 226 }
224 227
225 TEST_F(ShortcutTest, ReplaceShortcutSomeProperties) { 228 TEST_F(ShortcutTest, ReplaceShortcutSomeProperties) {
226 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 229 ASSERT_TRUE(CreateOrUpdateShortcutLink(
227 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); 230 link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
228 231
229 base::win::ShortcutProperties new_properties; 232 ShortcutProperties new_properties;
230 new_properties.set_target(link_properties_2_.target); 233 new_properties.set_target(link_properties_2_.target);
231 new_properties.set_arguments(link_properties_2_.arguments); 234 new_properties.set_arguments(link_properties_2_.arguments);
232 new_properties.set_description(link_properties_2_.description); 235 new_properties.set_description(link_properties_2_.description);
233 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 236 ASSERT_TRUE(CreateOrUpdateShortcutLink(
234 link_file_, new_properties, base::win::SHORTCUT_REPLACE_EXISTING)); 237 link_file_, new_properties, SHORTCUT_REPLACE_EXISTING));
235 238
236 // Expect only properties in |new_properties| to be set, all other properties 239 // Expect only properties in |new_properties| to be set, all other properties
237 // should have been overwritten. 240 // should have been overwritten.
238 base::win::ShortcutProperties expected_properties(new_properties); 241 ShortcutProperties expected_properties(new_properties);
239 expected_properties.set_working_dir(FilePath()); 242 expected_properties.set_working_dir(FilePath());
240 expected_properties.set_icon(FilePath(), 0); 243 expected_properties.set_icon(FilePath(), 0);
241 expected_properties.set_app_id(string16()); 244 expected_properties.set_app_id(string16());
242 expected_properties.set_dual_mode(false); 245 expected_properties.set_dual_mode(false);
243 base::win::ValidateShortcut(link_file_, expected_properties); 246 ValidateShortcut(link_file_, expected_properties);
244 } 247 }
245 248
246 TEST_F(ShortcutTest, FailReplaceShortcutThatDoesNotExist) { 249 TEST_F(ShortcutTest, FailReplaceShortcutThatDoesNotExist) {
247 ASSERT_FALSE(base::win::CreateOrUpdateShortcutLink( 250 ASSERT_FALSE(CreateOrUpdateShortcutLink(
248 link_file_, link_properties_, base::win::SHORTCUT_REPLACE_EXISTING)); 251 link_file_, link_properties_, SHORTCUT_REPLACE_EXISTING));
249 ASSERT_FALSE(file_util::PathExists(link_file_)); 252 ASSERT_FALSE(file_util::PathExists(link_file_));
250 } 253 }
251 254
252 // Test that the old arguments remain on the replaced shortcut when not 255 // Test that the old arguments remain on the replaced shortcut when not
253 // otherwise specified. 256 // otherwise specified.
254 TEST_F(ShortcutTest, ReplaceShortcutKeepOldArguments) { 257 TEST_F(ShortcutTest, ReplaceShortcutKeepOldArguments) {
255 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 258 ASSERT_TRUE(CreateOrUpdateShortcutLink(
256 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); 259 link_file_, link_properties_, SHORTCUT_CREATE_ALWAYS));
257 260
258 // Do not explicitly set the arguments. 261 // Do not explicitly set the arguments.
259 link_properties_2_.options &= 262 link_properties_2_.options &=
260 ~base::win::ShortcutProperties::PROPERTIES_ARGUMENTS; 263 ~ShortcutProperties::PROPERTIES_ARGUMENTS;
261 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 264 ASSERT_TRUE(CreateOrUpdateShortcutLink(
262 link_file_, link_properties_2_, base::win::SHORTCUT_REPLACE_EXISTING)); 265 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING));
263 266
264 base::win::ShortcutProperties expected_properties(link_properties_2_); 267 ShortcutProperties expected_properties(link_properties_2_);
265 expected_properties.set_arguments(link_properties_.arguments); 268 expected_properties.set_arguments(link_properties_.arguments);
266 base::win::ValidateShortcut(link_file_, expected_properties); 269 ValidateShortcut(link_file_, expected_properties);
267 } 270 }
271
272 } // namespace win
273 } // namespace base
OLDNEW
« no previous file with comments | « base/win/event_trace_controller_unittest.cc ('k') | chrome/app/breakpad_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698