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 "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."; |
25 const uint32 kPropertiesAll = ShortcutProperties::PROPERTIES_TARGET | | |
gab
2014/01/02 21:01:46
I would say it's best to put this as the last valu
huangs
2014/01/02 23:22:37
Going a step further, and defining specialized mas
| |
26 ShortcutProperties::PROPERTIES_WORKING_DIR | | |
27 ShortcutProperties::PROPERTIES_ARGUMENTS | | |
28 ShortcutProperties::PROPERTIES_DESCRIPTION | | |
29 ShortcutProperties::PROPERTIES_ICON | | |
30 ShortcutProperties::PROPERTIES_APP_ID | | |
31 ShortcutProperties::PROPERTIES_DUAL_MODE; | |
24 | 32 |
25 class ShortcutTest : public testing::Test { | 33 class ShortcutTest : public testing::Test { |
26 protected: | 34 protected: |
27 virtual void SetUp() OVERRIDE { | 35 virtual void SetUp() OVERRIDE { |
28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 36 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
29 ASSERT_TRUE(temp_dir_2_.CreateUniqueTempDir()); | 37 ASSERT_TRUE(temp_dir_2_.CreateUniqueTempDir()); |
30 | 38 |
31 link_file_ = temp_dir_.path().Append(L"My Link.lnk"); | 39 link_file_ = temp_dir_.path().Append(L"My Link.lnk"); |
32 | 40 |
33 // Shortcut 1's properties | 41 // Shortcut 1's properties |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 | 81 |
74 // Properties for the created shortcut. | 82 // Properties for the created shortcut. |
75 ShortcutProperties link_properties_; | 83 ShortcutProperties link_properties_; |
76 | 84 |
77 // Properties for the updated shortcut. | 85 // Properties for the updated shortcut. |
78 ShortcutProperties link_properties_2_; | 86 ShortcutProperties link_properties_2_; |
79 }; | 87 }; |
80 | 88 |
81 } // namespace | 89 } // namespace |
82 | 90 |
91 TEST_F(ShortcutTest, CreateAndResolveShortcutProperties) { | |
huangs
2014/01/02 20:00:01
This test takes 160 ms to 170 ms to run.
| |
92 FilePath file_1(temp_dir_.path().Append(L"Link1.lnk")); | |
93 ASSERT_TRUE(CreateOrUpdateShortcutLink( | |
94 file_1, link_properties_, SHORTCUT_CREATE_ALWAYS)); | |
95 ShortcutProperties properties_read_1; | |
96 ASSERT_TRUE( | |
97 ResolveShortcutProperties(file_1, kPropertiesAll, &properties_read_1)); | |
98 EXPECT_EQ(link_properties_.options, kPropertiesAll); | |
gab
2014/01/02 21:01:46
This will fail before Win7.
huangs
2014/01/02 23:22:37
Ah yes. Good catch!
| |
99 EXPECT_EQ(link_properties_.target, properties_read_1.target); | |
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); | |
gab
2014/01/02 21:01:46
Also test working_dir and icon_index.
Please put
huangs
2014/01/02 23:22:37
Done.
| |
103 if (GetVersion() >= VERSION_WIN7) { | |
104 EXPECT_EQ(link_properties_.app_id, properties_read_1.app_id); | |
105 EXPECT_EQ(link_properties_.dual_mode, properties_read_1.dual_mode); | |
106 } | |
107 | |
108 FilePath file_2(temp_dir_.path().Append(L"Link2.lnk")); | |
gab
2014/01/02 21:01:46
I don't think testing this twice has any added val
huangs
2014/01/02 23:22:37
Done; replacing this with a simpler shortcut.
| |
109 ASSERT_TRUE(CreateOrUpdateShortcutLink( | |
110 file_2, link_properties_2_, SHORTCUT_CREATE_ALWAYS)); | |
111 ShortcutProperties properties_read_2; | |
112 ASSERT_TRUE( | |
113 ResolveShortcutProperties(file_2, kPropertiesAll, &properties_read_2)); | |
114 EXPECT_EQ(link_properties_2_.options, kPropertiesAll); | |
115 EXPECT_EQ(link_properties_2_.target, properties_read_2.target); | |
116 EXPECT_EQ(link_properties_2_.arguments, properties_read_2.arguments); | |
117 EXPECT_EQ(link_properties_2_.description, properties_read_2.description); | |
118 EXPECT_EQ(link_properties_2_.icon, properties_read_2.icon); | |
119 if (GetVersion() >= VERSION_WIN7) { | |
120 EXPECT_EQ(link_properties_2_.app_id, properties_read_2.app_id); | |
121 EXPECT_EQ(link_properties_2_.dual_mode, properties_read_2.dual_mode); | |
122 } | |
123 } | |
124 | |
gab
2014/01/02 21:01:46
Please also add a test for resolving a shortcut wi
huangs
2014/01/02 23:22:37
Done.
| |
83 TEST_F(ShortcutTest, CreateAndResolveShortcut) { | 125 TEST_F(ShortcutTest, CreateAndResolveShortcut) { |
84 ShortcutProperties only_target_properties; | 126 ShortcutProperties only_target_properties; |
85 only_target_properties.set_target(link_properties_.target); | 127 only_target_properties.set_target(link_properties_.target); |
86 | 128 |
87 ASSERT_TRUE(CreateOrUpdateShortcutLink( | 129 ASSERT_TRUE(CreateOrUpdateShortcutLink( |
88 link_file_, only_target_properties, SHORTCUT_CREATE_ALWAYS)); | 130 link_file_, only_target_properties, SHORTCUT_CREATE_ALWAYS)); |
89 | 131 |
90 FilePath resolved_name; | 132 FilePath resolved_name; |
91 EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL)); | 133 EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL)); |
92 | 134 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 ASSERT_TRUE(CreateOrUpdateShortcutLink( | 306 ASSERT_TRUE(CreateOrUpdateShortcutLink( |
265 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING)); | 307 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING)); |
266 | 308 |
267 ShortcutProperties expected_properties(link_properties_2_); | 309 ShortcutProperties expected_properties(link_properties_2_); |
268 expected_properties.set_arguments(link_properties_.arguments); | 310 expected_properties.set_arguments(link_properties_.arguments); |
269 ValidateShortcut(link_file_, expected_properties); | 311 ValidateShortcut(link_file_, expected_properties); |
270 } | 312 } |
271 | 313 |
272 } // namespace win | 314 } // namespace win |
273 } // namespace base | 315 } // namespace base |
OLD | NEW |