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

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: Nits; fixing test comments and coverage. 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_EQ(link_properties_.target, properties_read_1.target);
99 EXPECT_EQ(link_properties_.working_dir, properties_read_1.working_dir);
100 EXPECT_EQ(link_properties_.arguments, properties_read_1.arguments);
101 EXPECT_EQ(link_properties_.description, properties_read_1.description);
102 EXPECT_EQ(link_properties_.icon, properties_read_1.icon);
103 EXPECT_EQ(link_properties_.icon_index, properties_read_1.icon_index);
104 if (GetVersion() >= VERSION_WIN7) {
105 EXPECT_EQ(link_properties_.app_id, properties_read_1.app_id);
106 EXPECT_EQ(link_properties_.dual_mode, properties_read_1.dual_mode);
107 }
108
109 // Test simple shortcut with no special properties set.
110 FilePath file_2(temp_dir_.path().Append(L"Link2.lnk"));
111 ShortcutProperties only_target_properties;
112 only_target_properties.set_target(link_properties_.target);
113 ASSERT_TRUE(CreateOrUpdateShortcutLink(
114 file_2, only_target_properties, SHORTCUT_CREATE_ALWAYS));
115
116 ShortcutProperties properties_read_2;
117 ASSERT_TRUE(ResolveShortcutProperties(
118 file_2, ShortcutProperties::PROPERTIES_ALL, &properties_read_2));
119 EXPECT_EQ(valid_properties, properties_read_2.options);
120 EXPECT_EQ(only_target_properties.target, properties_read_2.target);
121 EXPECT_EQ(FilePath(), properties_read_2.working_dir);
122 EXPECT_EQ(L"", properties_read_2.arguments);
123 EXPECT_EQ(L"", properties_read_2.description);
124 EXPECT_EQ(FilePath(), properties_read_2.icon);
125 EXPECT_EQ(0, properties_read_2.icon_index);
126 if (GetVersion() >= VERSION_WIN7) {
127 EXPECT_EQ(L"", properties_read_2.app_id);
128 EXPECT_FALSE(properties_read_2.dual_mode);
129 }
130 }
131
83 TEST_F(ShortcutTest, CreateAndResolveShortcut) { 132 TEST_F(ShortcutTest, CreateAndResolveShortcut) {
84 ShortcutProperties only_target_properties; 133 ShortcutProperties only_target_properties;
85 only_target_properties.set_target(link_properties_.target); 134 only_target_properties.set_target(link_properties_.target);
86 135
87 ASSERT_TRUE(CreateOrUpdateShortcutLink( 136 ASSERT_TRUE(CreateOrUpdateShortcutLink(
88 link_file_, only_target_properties, SHORTCUT_CREATE_ALWAYS)); 137 link_file_, only_target_properties, SHORTCUT_CREATE_ALWAYS));
89 138
90 FilePath resolved_name; 139 FilePath resolved_name;
91 EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL)); 140 EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL));
92 141
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 ASSERT_TRUE(CreateOrUpdateShortcutLink( 313 ASSERT_TRUE(CreateOrUpdateShortcutLink(
265 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING)); 314 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING));
266 315
267 ShortcutProperties expected_properties(link_properties_2_); 316 ShortcutProperties expected_properties(link_properties_2_);
268 expected_properties.set_arguments(link_properties_.arguments); 317 expected_properties.set_arguments(link_properties_.arguments);
269 ValidateShortcut(link_file_, expected_properties); 318 ValidateShortcut(link_file_, expected_properties);
270 } 319 }
271 320
272 } // namespace win 321 } // namespace win
273 } // namespace base 322 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698