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

Side by Side Diff: chrome/browser/shell_integration_win_unittest.cc

Issue 11712003: [Fixit-Dec-2012] Also add dual_mode to Start Menu shortcuts in MigrateChromiumShortcuts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: grt++ Created 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/shell_integration.h"
6
7 #include <vector>
8
9 #include "base/file_path.h"
10 #include "base/file_util.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "base/string_number_conversions.h"
13 #include "base/test/test_shortcut_win.h"
14 #include "base/win/scoped_com_initializer.h"
15 #include "base/win/windows_version.h"
16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_paths_internal.h"
18 #include "chrome/installer/util/browser_distribution.h"
19 #include "chrome/installer/util/shell_util.h"
20 #include "chrome/installer/util/util_constants.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 namespace {
24
25 class ShellIntegrationWinMigrateShortcutTest : public testing::Test {
26 protected:
27 virtual void SetUp() OVERRIDE {
28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
29
30 // A path to a random target.
31 FilePath other_target;
32 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &other_target);
33
34 // This doesn't need to actually have a base name of "chrome.exe".
35 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &chrome_exe_);
36
37 chrome_app_id_ =
38 ShellUtil::GetBrowserModelId(BrowserDistribution::GetDistribution(),
39 true);
40
41 // A temporary object to pass properties to AddTestShortcut().
42 base::win::ShortcutProperties temp_properties;
43
44 // Shortcut 0 doesn't point to chrome.exe and thus should never be migrated.
45 temp_properties.set_target(other_target);
46 temp_properties.set_app_id(L"Dumbo");
47 temp_properties.set_dual_mode(false);
48 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
49
50 // Shortcut 1 points to chrome.exe and thus should be migrated.
51 temp_properties.set_target(chrome_exe_);
52 temp_properties.set_app_id(L"Dumbo");
53 temp_properties.set_dual_mode(false);
54 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
55
56 // Shortcut 2 points to chrome.exe, but already has the right appid and thus
57 // should only be migrated if dual_mode is desired.
58 temp_properties.set_target(chrome_exe_);
59 temp_properties.set_app_id(chrome_app_id_);
60 temp_properties.set_dual_mode(false);
61 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
62
63 // Shortcut 3 is like shortcut 2 except it has dual_mode and thus should
64 // never be migrated.
65 temp_properties.set_target(chrome_exe_);
66 temp_properties.set_app_id(chrome_app_id_);
67 temp_properties.set_dual_mode(true);
68 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
69
70 // Shortcut 4 is like shortcut 1, but it's appid is a prefix of the expected
71 // appid instead of being totally different.
72 string16 chrome_app_id_is_prefix(chrome_app_id_);
73 chrome_app_id_is_prefix.push_back(L'1');
74 temp_properties.set_target(chrome_exe_);
75 temp_properties.set_app_id(chrome_app_id_is_prefix);
76 temp_properties.set_dual_mode(false);
77 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
78
79 // Shortcut 5 is like shortcut 1, but it's appid is of the same size as the
80 // expected appid.
81 string16 same_size_as_chrome_app_id(L'1', chrome_app_id_.size());
82 temp_properties.set_target(chrome_exe_);
83 temp_properties.set_app_id(same_size_as_chrome_app_id);
84 temp_properties.set_dual_mode(false);
85 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
86
87 // Shortcut 6 doesn't have an app_id, nor is dual_mode even set; they should
88 // be set as expected upon migration.
89 base::win::ShortcutProperties no_properties;
90 no_properties.set_target(chrome_exe_);
91 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(no_properties));
92 }
93
94 void AddTestShortcut(
95 const base::win::ShortcutProperties& shortcut_properties) {
96 shortcuts_properties_.push_back(shortcut_properties);
97 FilePath shortcut_path =
98 temp_dir_.path().Append(base::IntToString16(shortcuts_.size()) +
99 installer::kLnkExt);
100 shortcuts_.push_back(shortcut_path);
101 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
102 shortcut_path, shortcut_properties,
103 base::win::SHORTCUT_CREATE_ALWAYS));
104 }
105
106 base::win::ScopedCOMInitializer com_initializer_;
107 base::ScopedTempDir temp_dir_;
108
109 // The path to a fake chrome.exe.
110 FilePath chrome_exe_;
111
112 // Test shortcuts.
113 std::vector<FilePath> shortcuts_;
114
115 // Initial properties for the test shortcuts.
116 std::vector<base::win::ShortcutProperties> shortcuts_properties_;
117
118 // Chrome's AppUserModelId.
119 string16 chrome_app_id_;
120 };
121
122 } // namespace
123
124 // Test migration when not checking for dual mode.
125 TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) {
126 if (base::win::GetVersion() < base::win::VERSION_WIN7)
127 return;
128
129 EXPECT_EQ(4,
130 ShellIntegration::MigrateShortcutsInPathInternal(
131 chrome_exe_, temp_dir_.path(), false));
132
133 // Only shortcut 1, 4, 5, and 6 should have been migrated.
134 shortcuts_properties_[1].set_app_id(chrome_app_id_);
135 shortcuts_properties_[4].set_app_id(chrome_app_id_);
136 shortcuts_properties_[5].set_app_id(chrome_app_id_);
137 shortcuts_properties_[6].set_app_id(chrome_app_id_);
138
139 for (size_t i = 0; i < shortcuts_.size(); ++i)
140 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]);
141 }
142
143 // Test migration when also checking for dual mode.
144 TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) {
145 if (base::win::GetVersion() < base::win::VERSION_WIN7)
146 return;
147
148 EXPECT_EQ(5,
149 ShellIntegration::MigrateShortcutsInPathInternal(
150 chrome_exe_, temp_dir_.path(), true));
151
152 // Shortcut 1, 4, 5, and 6 should have had both their app_id and dual_mode
153 // properties fixed and shortcut 2 should also have had it's dual_mode
154 // property fixed.
155 shortcuts_properties_[1].set_app_id(chrome_app_id_);
156 shortcuts_properties_[4].set_app_id(chrome_app_id_);
157 shortcuts_properties_[5].set_app_id(chrome_app_id_);
158 shortcuts_properties_[6].set_app_id(chrome_app_id_);
159
160 shortcuts_properties_[1].set_dual_mode(true);
161 shortcuts_properties_[2].set_dual_mode(true);
162 shortcuts_properties_[4].set_dual_mode(true);
163 shortcuts_properties_[5].set_dual_mode(true);
164 shortcuts_properties_[6].set_dual_mode(true);
165
166 for (size_t i = 0; i < shortcuts_.size(); ++i)
167 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]);
168 }
169
170 TEST(ShellIntegrationWinTest, GetAppModelIdForProfileTest) {
171 const string16 base_app_id(
172 BrowserDistribution::GetDistribution()->GetBaseAppId());
173
174 // Empty profile path should get chrome::kBrowserAppID
175 FilePath empty_path;
176 EXPECT_EQ(base_app_id,
177 ShellIntegration::GetAppModelIdForProfile(base_app_id, empty_path));
178
179 // Default profile path should get chrome::kBrowserAppID
180 FilePath default_user_data_dir;
181 chrome::GetDefaultUserDataDirectory(&default_user_data_dir);
182 FilePath default_profile_path =
183 default_user_data_dir.AppendASCII(chrome::kInitialProfile);
184 EXPECT_EQ(base_app_id,
185 ShellIntegration::GetAppModelIdForProfile(base_app_id,
186 default_profile_path));
187
188 // Non-default profile path should get chrome::kBrowserAppID joined with
189 // profile info.
190 FilePath profile_path(FILE_PATH_LITERAL("root"));
191 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd"));
192 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test"));
193 EXPECT_EQ(base_app_id + L".udd.UserDataTest",
194 ShellIntegration::GetAppModelIdForProfile(base_app_id,
195 profile_path));
196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698