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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 static const char kFileContents[] = "This is a target."; | 26 static const char kFileContents[] = "This is a target."; |
27 static const char kFileContents2[] = "This is another target."; | 27 static const char kFileContents2[] = "This is another target."; |
28 | 28 |
29 class ShortcutTest : public testing::Test { | 29 class ShortcutTest : public testing::Test { |
30 protected: | 30 protected: |
31 void SetUp() override { | 31 void SetUp() override { |
32 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 32 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
33 ASSERT_TRUE(temp_dir_2_.CreateUniqueTempDir()); | 33 ASSERT_TRUE(temp_dir_2_.CreateUniqueTempDir()); |
34 | 34 |
35 link_file_ = temp_dir_.path().Append(L"My Link.lnk"); | 35 link_file_ = temp_dir_.GetPath().Append(L"My Link.lnk"); |
36 | 36 |
37 // Shortcut 1's properties | 37 // Shortcut 1's properties |
38 { | 38 { |
39 const FilePath target_file(temp_dir_.path().Append(L"Target 1.txt")); | 39 const FilePath target_file(temp_dir_.GetPath().Append(L"Target 1.txt")); |
40 WriteFile(target_file, kFileContents, arraysize(kFileContents)); | 40 WriteFile(target_file, kFileContents, arraysize(kFileContents)); |
41 | 41 |
42 link_properties_.set_target(target_file); | 42 link_properties_.set_target(target_file); |
43 link_properties_.set_working_dir(temp_dir_.path()); | 43 link_properties_.set_working_dir(temp_dir_.GetPath()); |
44 link_properties_.set_arguments(L"--magic --awesome"); | 44 link_properties_.set_arguments(L"--magic --awesome"); |
45 link_properties_.set_description(L"Chrome is awesome."); | 45 link_properties_.set_description(L"Chrome is awesome."); |
46 link_properties_.set_icon(link_properties_.target, 4); | 46 link_properties_.set_icon(link_properties_.target, 4); |
47 link_properties_.set_app_id(L"Chrome"); | 47 link_properties_.set_app_id(L"Chrome"); |
48 link_properties_.set_dual_mode(false); | 48 link_properties_.set_dual_mode(false); |
49 } | 49 } |
50 | 50 |
51 // Shortcut 2's properties (all different from properties of shortcut 1). | 51 // Shortcut 2's properties (all different from properties of shortcut 1). |
52 { | 52 { |
53 const FilePath target_file_2(temp_dir_.path().Append(L"Target 2.txt")); | 53 const FilePath target_file_2(temp_dir_.GetPath().Append(L"Target 2.txt")); |
54 WriteFile(target_file_2, kFileContents2, arraysize(kFileContents2)); | 54 WriteFile(target_file_2, kFileContents2, arraysize(kFileContents2)); |
55 | 55 |
56 FilePath icon_path_2; | 56 FilePath icon_path_2; |
57 CreateTemporaryFileInDir(temp_dir_.path(), &icon_path_2); | 57 CreateTemporaryFileInDir(temp_dir_.GetPath(), &icon_path_2); |
58 | 58 |
59 link_properties_2_.set_target(target_file_2); | 59 link_properties_2_.set_target(target_file_2); |
60 link_properties_2_.set_working_dir(temp_dir_2_.path()); | 60 link_properties_2_.set_working_dir(temp_dir_2_.path()); |
61 link_properties_2_.set_arguments(L"--super --crazy"); | 61 link_properties_2_.set_arguments(L"--super --crazy"); |
62 link_properties_2_.set_description(L"The best in the west."); | 62 link_properties_2_.set_description(L"The best in the west."); |
63 link_properties_2_.set_icon(icon_path_2, 0); | 63 link_properties_2_.set_icon(icon_path_2, 0); |
64 link_properties_2_.set_app_id(L"Chrome.UserLevelCrazySuffix"); | 64 link_properties_2_.set_app_id(L"Chrome.UserLevelCrazySuffix"); |
65 link_properties_2_.set_dual_mode(true); | 65 link_properties_2_.set_dual_mode(true); |
66 } | 66 } |
67 } | 67 } |
(...skipping 13 matching lines...) Expand all Loading... |
81 }; | 81 }; |
82 | 82 |
83 } // namespace | 83 } // namespace |
84 | 84 |
85 TEST_F(ShortcutTest, CreateAndResolveShortcutProperties) { | 85 TEST_F(ShortcutTest, CreateAndResolveShortcutProperties) { |
86 uint32_t valid_properties = ShortcutProperties::PROPERTIES_BASIC; | 86 uint32_t valid_properties = ShortcutProperties::PROPERTIES_BASIC; |
87 if (GetVersion() >= VERSION_WIN7) | 87 if (GetVersion() >= VERSION_WIN7) |
88 valid_properties |= ShortcutProperties::PROPERTIES_WIN7; | 88 valid_properties |= ShortcutProperties::PROPERTIES_WIN7; |
89 | 89 |
90 // Test all properties. | 90 // Test all properties. |
91 FilePath file_1(temp_dir_.path().Append(L"Link1.lnk")); | 91 FilePath file_1(temp_dir_.GetPath().Append(L"Link1.lnk")); |
92 ASSERT_TRUE(CreateOrUpdateShortcutLink( | 92 ASSERT_TRUE(CreateOrUpdateShortcutLink( |
93 file_1, link_properties_, SHORTCUT_CREATE_ALWAYS)); | 93 file_1, link_properties_, SHORTCUT_CREATE_ALWAYS)); |
94 | 94 |
95 ShortcutProperties properties_read_1; | 95 ShortcutProperties properties_read_1; |
96 ASSERT_TRUE(ResolveShortcutProperties( | 96 ASSERT_TRUE(ResolveShortcutProperties( |
97 file_1, ShortcutProperties::PROPERTIES_ALL, &properties_read_1)); | 97 file_1, ShortcutProperties::PROPERTIES_ALL, &properties_read_1)); |
98 EXPECT_EQ(valid_properties, properties_read_1.options); | 98 EXPECT_EQ(valid_properties, properties_read_1.options); |
99 ValidatePathsAreEqual(link_properties_.target, properties_read_1.target); | 99 ValidatePathsAreEqual(link_properties_.target, properties_read_1.target); |
100 ValidatePathsAreEqual(link_properties_.working_dir, | 100 ValidatePathsAreEqual(link_properties_.working_dir, |
101 properties_read_1.working_dir); | 101 properties_read_1.working_dir); |
102 EXPECT_EQ(link_properties_.arguments, properties_read_1.arguments); | 102 EXPECT_EQ(link_properties_.arguments, properties_read_1.arguments); |
103 EXPECT_EQ(link_properties_.description, properties_read_1.description); | 103 EXPECT_EQ(link_properties_.description, properties_read_1.description); |
104 ValidatePathsAreEqual(link_properties_.icon, properties_read_1.icon); | 104 ValidatePathsAreEqual(link_properties_.icon, properties_read_1.icon); |
105 EXPECT_EQ(link_properties_.icon_index, properties_read_1.icon_index); | 105 EXPECT_EQ(link_properties_.icon_index, properties_read_1.icon_index); |
106 if (GetVersion() >= VERSION_WIN7) { | 106 if (GetVersion() >= VERSION_WIN7) { |
107 EXPECT_EQ(link_properties_.app_id, properties_read_1.app_id); | 107 EXPECT_EQ(link_properties_.app_id, properties_read_1.app_id); |
108 EXPECT_EQ(link_properties_.dual_mode, properties_read_1.dual_mode); | 108 EXPECT_EQ(link_properties_.dual_mode, properties_read_1.dual_mode); |
109 } | 109 } |
110 | 110 |
111 // Test simple shortcut with no special properties set. | 111 // Test simple shortcut with no special properties set. |
112 FilePath file_2(temp_dir_.path().Append(L"Link2.lnk")); | 112 FilePath file_2(temp_dir_.GetPath().Append(L"Link2.lnk")); |
113 ShortcutProperties only_target_properties; | 113 ShortcutProperties only_target_properties; |
114 only_target_properties.set_target(link_properties_.target); | 114 only_target_properties.set_target(link_properties_.target); |
115 ASSERT_TRUE(CreateOrUpdateShortcutLink( | 115 ASSERT_TRUE(CreateOrUpdateShortcutLink( |
116 file_2, only_target_properties, SHORTCUT_CREATE_ALWAYS)); | 116 file_2, only_target_properties, SHORTCUT_CREATE_ALWAYS)); |
117 | 117 |
118 ShortcutProperties properties_read_2; | 118 ShortcutProperties properties_read_2; |
119 ASSERT_TRUE(ResolveShortcutProperties( | 119 ASSERT_TRUE(ResolveShortcutProperties( |
120 file_2, ShortcutProperties::PROPERTIES_ALL, &properties_read_2)); | 120 file_2, ShortcutProperties::PROPERTIES_ALL, &properties_read_2)); |
121 EXPECT_EQ(valid_properties, properties_read_2.options); | 121 EXPECT_EQ(valid_properties, properties_read_2.options); |
122 ValidatePathsAreEqual(only_target_properties.target, | 122 ValidatePathsAreEqual(only_target_properties.target, |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 ASSERT_TRUE(CreateOrUpdateShortcutLink( | 316 ASSERT_TRUE(CreateOrUpdateShortcutLink( |
317 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING)); | 317 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING)); |
318 | 318 |
319 ShortcutProperties expected_properties(link_properties_2_); | 319 ShortcutProperties expected_properties(link_properties_2_); |
320 expected_properties.set_arguments(link_properties_.arguments); | 320 expected_properties.set_arguments(link_properties_.arguments); |
321 ValidateShortcut(link_file_, expected_properties); | 321 ValidateShortcut(link_file_, expected_properties); |
322 } | 322 } |
323 | 323 |
324 } // namespace win | 324 } // namespace win |
325 } // namespace base | 325 } // namespace base |
OLD | NEW |