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

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

Issue 2909943003: Removing useless Win7 checks + standardize its use (Closed)
Patch Set: Fix reversed conditionnal Created 3 years, 6 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/test/test_file_util.h" 15 #include "base/test/test_file_util.h"
16 #include "base/test/test_shortcut_win.h" 16 #include "base/test/test_shortcut_win.h"
17 #include "base/win/scoped_com_initializer.h" 17 #include "base/win/scoped_com_initializer.h"
18 #include "base/win/windows_version.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 19
21 namespace base { 20 namespace base {
22 namespace win { 21 namespace win {
23 22
24 namespace { 23 namespace {
25 24
26 static const char kFileContents[] = "This is a target."; 25 static const char kFileContents[] = "This is a target.";
27 static const char kFileContents2[] = "This is another target."; 26 static const char kFileContents2[] = "This is another target.";
28 27
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 ShortcutProperties link_properties_; 76 ShortcutProperties link_properties_;
78 77
79 // Properties for the updated shortcut. 78 // Properties for the updated shortcut.
80 ShortcutProperties link_properties_2_; 79 ShortcutProperties link_properties_2_;
81 }; 80 };
82 81
83 } // namespace 82 } // namespace
84 83
85 TEST_F(ShortcutTest, CreateAndResolveShortcutProperties) { 84 TEST_F(ShortcutTest, CreateAndResolveShortcutProperties) {
86 uint32_t valid_properties = ShortcutProperties::PROPERTIES_BASIC; 85 uint32_t valid_properties = ShortcutProperties::PROPERTIES_BASIC;
87 if (GetVersion() >= VERSION_WIN7) 86 valid_properties |= ShortcutProperties::PROPERTIES_WIN7;
88 valid_properties |= ShortcutProperties::PROPERTIES_WIN7;
89 87
90 // Test all properties. 88 // Test all properties.
91 FilePath file_1(temp_dir_.GetPath().Append(L"Link1.lnk")); 89 FilePath file_1(temp_dir_.GetPath().Append(L"Link1.lnk"));
92 ASSERT_TRUE(CreateOrUpdateShortcutLink( 90 ASSERT_TRUE(CreateOrUpdateShortcutLink(
93 file_1, link_properties_, SHORTCUT_CREATE_ALWAYS)); 91 file_1, link_properties_, SHORTCUT_CREATE_ALWAYS));
94 92
95 ShortcutProperties properties_read_1; 93 ShortcutProperties properties_read_1;
96 ASSERT_TRUE(ResolveShortcutProperties( 94 ASSERT_TRUE(ResolveShortcutProperties(
97 file_1, ShortcutProperties::PROPERTIES_ALL, &properties_read_1)); 95 file_1, ShortcutProperties::PROPERTIES_ALL, &properties_read_1));
98 EXPECT_EQ(valid_properties, properties_read_1.options); 96 EXPECT_EQ(valid_properties, properties_read_1.options);
99 ValidatePathsAreEqual(link_properties_.target, properties_read_1.target); 97 ValidatePathsAreEqual(link_properties_.target, properties_read_1.target);
100 ValidatePathsAreEqual(link_properties_.working_dir, 98 ValidatePathsAreEqual(link_properties_.working_dir,
101 properties_read_1.working_dir); 99 properties_read_1.working_dir);
102 EXPECT_EQ(link_properties_.arguments, properties_read_1.arguments); 100 EXPECT_EQ(link_properties_.arguments, properties_read_1.arguments);
103 EXPECT_EQ(link_properties_.description, properties_read_1.description); 101 EXPECT_EQ(link_properties_.description, properties_read_1.description);
104 ValidatePathsAreEqual(link_properties_.icon, properties_read_1.icon); 102 ValidatePathsAreEqual(link_properties_.icon, properties_read_1.icon);
105 EXPECT_EQ(link_properties_.icon_index, properties_read_1.icon_index); 103 EXPECT_EQ(link_properties_.icon_index, properties_read_1.icon_index);
106 if (GetVersion() >= VERSION_WIN7) { 104 EXPECT_EQ(link_properties_.app_id, properties_read_1.app_id);
107 EXPECT_EQ(link_properties_.app_id, properties_read_1.app_id); 105 EXPECT_EQ(link_properties_.dual_mode, properties_read_1.dual_mode);
108 EXPECT_EQ(link_properties_.dual_mode, properties_read_1.dual_mode);
109 }
110 106
111 // Test simple shortcut with no special properties set. 107 // Test simple shortcut with no special properties set.
112 FilePath file_2(temp_dir_.GetPath().Append(L"Link2.lnk")); 108 FilePath file_2(temp_dir_.GetPath().Append(L"Link2.lnk"));
113 ShortcutProperties only_target_properties; 109 ShortcutProperties only_target_properties;
114 only_target_properties.set_target(link_properties_.target); 110 only_target_properties.set_target(link_properties_.target);
115 ASSERT_TRUE(CreateOrUpdateShortcutLink( 111 ASSERT_TRUE(CreateOrUpdateShortcutLink(
116 file_2, only_target_properties, SHORTCUT_CREATE_ALWAYS)); 112 file_2, only_target_properties, SHORTCUT_CREATE_ALWAYS));
117 113
118 ShortcutProperties properties_read_2; 114 ShortcutProperties properties_read_2;
119 ASSERT_TRUE(ResolveShortcutProperties( 115 ASSERT_TRUE(ResolveShortcutProperties(
120 file_2, ShortcutProperties::PROPERTIES_ALL, &properties_read_2)); 116 file_2, ShortcutProperties::PROPERTIES_ALL, &properties_read_2));
121 EXPECT_EQ(valid_properties, properties_read_2.options); 117 EXPECT_EQ(valid_properties, properties_read_2.options);
122 ValidatePathsAreEqual(only_target_properties.target, 118 ValidatePathsAreEqual(only_target_properties.target,
123 properties_read_2.target); 119 properties_read_2.target);
124 ValidatePathsAreEqual(FilePath(), properties_read_2.working_dir); 120 ValidatePathsAreEqual(FilePath(), properties_read_2.working_dir);
125 EXPECT_EQ(L"", properties_read_2.arguments); 121 EXPECT_EQ(L"", properties_read_2.arguments);
126 EXPECT_EQ(L"", properties_read_2.description); 122 EXPECT_EQ(L"", properties_read_2.description);
127 ValidatePathsAreEqual(FilePath(), properties_read_2.icon); 123 ValidatePathsAreEqual(FilePath(), properties_read_2.icon);
128 EXPECT_EQ(0, properties_read_2.icon_index); 124 EXPECT_EQ(0, properties_read_2.icon_index);
129 if (GetVersion() >= VERSION_WIN7) { 125 EXPECT_EQ(L"", properties_read_2.app_id);
130 EXPECT_EQ(L"", properties_read_2.app_id); 126 EXPECT_FALSE(properties_read_2.dual_mode);
131 EXPECT_FALSE(properties_read_2.dual_mode);
132 }
133 } 127 }
134 128
135 TEST_F(ShortcutTest, CreateAndResolveShortcut) { 129 TEST_F(ShortcutTest, CreateAndResolveShortcut) {
136 ShortcutProperties only_target_properties; 130 ShortcutProperties only_target_properties;
137 only_target_properties.set_target(link_properties_.target); 131 only_target_properties.set_target(link_properties_.target);
138 132
139 ASSERT_TRUE(CreateOrUpdateShortcutLink( 133 ASSERT_TRUE(CreateOrUpdateShortcutLink(
140 link_file_, only_target_properties, SHORTCUT_CREATE_ALWAYS)); 134 link_file_, only_target_properties, SHORTCUT_CREATE_ALWAYS));
141 135
142 FilePath resolved_name; 136 FilePath resolved_name;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 ASSERT_TRUE(CreateOrUpdateShortcutLink( 310 ASSERT_TRUE(CreateOrUpdateShortcutLink(
317 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING)); 311 link_file_, link_properties_2_, SHORTCUT_REPLACE_EXISTING));
318 312
319 ShortcutProperties expected_properties(link_properties_2_); 313 ShortcutProperties expected_properties(link_properties_2_);
320 expected_properties.set_arguments(link_properties_.arguments); 314 expected_properties.set_arguments(link_properties_.arguments);
321 ValidateShortcut(link_file_, expected_properties); 315 ValidateShortcut(link_file_, expected_properties);
322 } 316 }
323 317
324 } // namespace win 318 } // namespace win
325 } // namespace base 319 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698