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 <windows.h> | |
8 #include <objbase.h> | |
9 | |
10 #include <string> | 7 #include <string> |
11 | 8 |
12 #include "base/file_path.h" | 9 #include "base/file_path.h" |
13 #include "base/file_util.h" | 10 #include "base/file_util.h" |
14 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
15 #include "base/test/test_file_util.h" | 12 #include "base/test/test_file_util.h" |
16 #include "base/test/test_shortcut_win.h" | 13 #include "base/test/test_shortcut_win.h" |
| 14 #include "base/win/scoped_com_initializer.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
18 | 16 |
19 namespace { | 17 namespace { |
20 | 18 |
21 static const char kFileContents[] = "This is a target."; | 19 static const char kFileContents[] = "This is a target."; |
22 static const char kFileContents2[] = "This is another target."; | 20 static const char kFileContents2[] = "This is another target."; |
23 | 21 |
24 class ShortcutTest : public testing::Test { | 22 class ShortcutTest : public testing::Test { |
25 protected: | 23 protected: |
26 virtual void SetUp() OVERRIDE { | 24 virtual void SetUp() OVERRIDE { |
27 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
28 ASSERT_TRUE(temp_dir_2_.CreateUniqueTempDir()); | 26 ASSERT_TRUE(temp_dir_2_.CreateUniqueTempDir()); |
29 | 27 |
30 EXPECT_EQ(S_OK, CoInitialize(NULL)); | |
31 | |
32 link_file_ = temp_dir_.path().Append(L"My Link.lnk"); | 28 link_file_ = temp_dir_.path().Append(L"My Link.lnk"); |
33 | 29 |
34 // Shortcut 1's properties | 30 // Shortcut 1's properties |
35 { | 31 { |
36 const FilePath target_file(temp_dir_.path().Append(L"Target 1.txt")); | 32 const FilePath target_file(temp_dir_.path().Append(L"Target 1.txt")); |
37 file_util::WriteFile(target_file, kFileContents, | 33 file_util::WriteFile(target_file, kFileContents, |
38 arraysize(kFileContents)); | 34 arraysize(kFileContents)); |
39 | 35 |
40 link_properties_.set_target(target_file); | 36 link_properties_.set_target(target_file); |
41 link_properties_.set_working_dir(temp_dir_.path()); | 37 link_properties_.set_working_dir(temp_dir_.path()); |
(...skipping 16 matching lines...) Expand all Loading... |
58 link_properties_2_.set_target(target_file_2); | 54 link_properties_2_.set_target(target_file_2); |
59 link_properties_2_.set_working_dir(temp_dir_2_.path()); | 55 link_properties_2_.set_working_dir(temp_dir_2_.path()); |
60 link_properties_2_.set_arguments(L"--super --crazy"); | 56 link_properties_2_.set_arguments(L"--super --crazy"); |
61 link_properties_2_.set_description(L"The best in the west."); | 57 link_properties_2_.set_description(L"The best in the west."); |
62 link_properties_2_.set_icon(icon_path_2, 0); | 58 link_properties_2_.set_icon(icon_path_2, 0); |
63 link_properties_2_.set_app_id(L"Chrome.UserLevelCrazySuffix"); | 59 link_properties_2_.set_app_id(L"Chrome.UserLevelCrazySuffix"); |
64 link_properties_2_.set_dual_mode(true); | 60 link_properties_2_.set_dual_mode(true); |
65 } | 61 } |
66 } | 62 } |
67 | 63 |
68 virtual void TearDown() OVERRIDE { | 64 base::win::ScopedCOMInitializer com_initializer_; |
69 CoUninitialize(); | |
70 } | |
71 | |
72 ScopedTempDir temp_dir_; | 65 ScopedTempDir temp_dir_; |
73 ScopedTempDir temp_dir_2_; | 66 ScopedTempDir temp_dir_2_; |
74 | 67 |
75 // The link file to be created/updated in the shortcut tests below. | 68 // The link file to be created/updated in the shortcut tests below. |
76 FilePath link_file_; | 69 FilePath link_file_; |
77 | 70 |
78 // Properties for the created shortcut. | 71 // Properties for the created shortcut. |
79 base::win::ShortcutProperties link_properties_; | 72 base::win::ShortcutProperties link_properties_; |
80 | 73 |
81 // Properties for the updated shortcut. | 74 // Properties for the updated shortcut. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 expected_properties.set_app_id(string16()); | 241 expected_properties.set_app_id(string16()); |
249 expected_properties.set_dual_mode(false); | 242 expected_properties.set_dual_mode(false); |
250 base::win::ValidateShortcut(link_file_, expected_properties); | 243 base::win::ValidateShortcut(link_file_, expected_properties); |
251 } | 244 } |
252 | 245 |
253 TEST_F(ShortcutTest, FailTruncateShortcutThatDoesNotExist) { | 246 TEST_F(ShortcutTest, FailTruncateShortcutThatDoesNotExist) { |
254 ASSERT_FALSE(base::win::CreateOrUpdateShortcutLink( | 247 ASSERT_FALSE(base::win::CreateOrUpdateShortcutLink( |
255 link_file_, link_properties_, base::win::SHORTCUT_REPLACE_EXISTING)); | 248 link_file_, link_properties_, base::win::SHORTCUT_REPLACE_EXISTING)); |
256 ASSERT_FALSE(file_util::PathExists(link_file_)); | 249 ASSERT_FALSE(file_util::PathExists(link_file_)); |
257 } | 250 } |
OLD | NEW |