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

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

Issue 108193019: Installer: adding ResolveShortcutProperties(); updating shortcut icons during shortcut migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing path comparison in ShortcutTest. Created 6 years, 11 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 (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_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.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 "base/win/windows_version.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace base { 18 namespace base {
18 namespace win { 19 namespace win {
19 20
20 namespace { 21 namespace {
21 22
22 static const char kFileContents[] = "This is a target."; 23 static const char kFileContents[] = "This is a target.";
23 static const char kFileContents2[] = "This is another target."; 24 static const char kFileContents2[] = "This is another target.";
24 25
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 74
74 // Properties for the created shortcut. 75 // Properties for the created shortcut.
75 ShortcutProperties link_properties_; 76 ShortcutProperties link_properties_;
76 77
77 // Properties for the updated shortcut. 78 // Properties for the updated shortcut.
78 ShortcutProperties link_properties_2_; 79 ShortcutProperties link_properties_2_;
79 }; 80 };
80 81
81 } // namespace 82 } // namespace
82 83
84 TEST_F(ShortcutTest, CreateAndResolveShortcutProperties) {
85 uint32 valid_properties = ShortcutProperties::PROPERTIES_BASIC;
86 if (GetVersion() >= VERSION_WIN7)
87 valid_properties |= ShortcutProperties::PROPERTIES_WIN7;
88
89 // Test all properties.
90 FilePath file_1(temp_dir_.path().Append(L"Link1.lnk"));
91 ASSERT_TRUE(CreateOrUpdateShortcutLink(
92 file_1, link_properties_, SHORTCUT_CREATE_ALWAYS));
93
94 ShortcutProperties properties_read_1;
95 ASSERT_TRUE(ResolveShortcutProperties(
96 file_1, ShortcutProperties::PROPERTIES_ALL, &properties_read_1));
97 EXPECT_EQ(link_properties_.options, valid_properties);
98 EXPECT_TRUE(FilePath::CompareEqualIgnoreCase(
99 link_properties_.target.value(), properties_read_1.target.value()));
100 EXPECT_TRUE(FilePath::CompareEqualIgnoreCase(
101 link_properties_.working_dir.value(),
102 properties_read_1.working_dir.value()));
103 EXPECT_EQ(link_properties_.arguments, properties_read_1.arguments);
104 EXPECT_EQ(link_properties_.description, properties_read_1.description);
105 EXPECT_TRUE(FilePath::CompareEqualIgnoreCase(
106 link_properties_.icon.value(), properties_read_1.icon.value()));
107 EXPECT_EQ(link_properties_.icon_index, properties_read_1.icon_index);
108 if (GetVersion() >= VERSION_WIN7) {
109 EXPECT_EQ(link_properties_.app_id, properties_read_1.app_id);
110 EXPECT_EQ(link_properties_.dual_mode, properties_read_1.dual_mode);
111 }
112
113 // Test simple shortcut with no special properties set.
114 FilePath file_2(temp_dir_.path().Append(L"Link2.lnk"));
115 ShortcutProperties only_target_properties;
116 only_target_properties.set_target(link_properties_.target);
117 ASSERT_TRUE(CreateOrUpdateShortcutLink(
118 file_2, only_target_properties, SHORTCUT_CREATE_ALWAYS));
119
120 ShortcutProperties properties_read_2;
121 ASSERT_TRUE(ResolveShortcutProperties(
122 file_2, ShortcutProperties::PROPERTIES_ALL, &properties_read_2));
123 EXPECT_EQ(valid_properties, properties_read_2.options);
124 EXPECT_TRUE(FilePath::CompareEqualIgnoreCase(
125 only_target_properties.target.value(), properties_read_2.target.value()));
126 EXPECT_TRUE(FilePath::CompareEqualIgnoreCase(
127 FilePath().value(), properties_read_2.working_dir.value()));
128 EXPECT_EQ(L"", properties_read_2.arguments);
129 EXPECT_EQ(L"", properties_read_2.description);
130 EXPECT_TRUE(FilePath::CompareEqualIgnoreCase(
131 FilePath().value(), properties_read_2.icon.value()));
132 EXPECT_EQ(0, properties_read_2.icon_index);
133 if (GetVersion() >= VERSION_WIN7) {
134 EXPECT_EQ(L"", properties_read_2.app_id);
135 EXPECT_FALSE(properties_read_2.dual_mode);
136 }
137 }
138
83 TEST_F(ShortcutTest, CreateAndResolveShortcut) { 139 TEST_F(ShortcutTest, CreateAndResolveShortcut) {
84 ShortcutProperties only_target_properties; 140 ShortcutProperties only_target_properties;
85 only_target_properties.set_target(link_properties_.target); 141 only_target_properties.set_target(link_properties_.target);
86 142
87 ASSERT_TRUE(CreateOrUpdateShortcutLink( 143 ASSERT_TRUE(CreateOrUpdateShortcutLink(
88 link_file_, only_target_properties, SHORTCUT_CREATE_ALWAYS)); 144 link_file_, only_target_properties, SHORTCUT_CREATE_ALWAYS));
89 145
90 FilePath resolved_name; 146 FilePath resolved_name;
91 EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL)); 147 EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL));
92 148
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 ASSERT_TRUE(CreateOrUpdateShortcutLink( 320 ASSERT_TRUE(CreateOrUpdateShortcutLink(
265 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING)); 321 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING));
266 322
267 ShortcutProperties expected_properties(link_properties_2_); 323 ShortcutProperties expected_properties(link_properties_2_);
268 expected_properties.set_arguments(link_properties_.arguments); 324 expected_properties.set_arguments(link_properties_.arguments);
269 ValidateShortcut(link_file_, expected_properties); 325 ValidateShortcut(link_file_, expected_properties);
270 } 326 }
271 327
272 } // namespace win 328 } // namespace win
273 } // namespace base 329 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698