Chromium Code Reviews| Index: chrome/browser/shell_integration_win_unittest.cc |
| diff --git a/chrome/browser/shell_integration_win_unittest.cc b/chrome/browser/shell_integration_win_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..082198f41b1e2167c1bb5b268d4ca9c0ab75a7e5 |
| --- /dev/null |
| +++ b/chrome/browser/shell_integration_win_unittest.cc |
| @@ -0,0 +1,174 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/shell_integration.h" |
| + |
| +#include "base/file_path.h" |
| +#include "base/file_util.h" |
| +#include "base/files/scoped_temp_dir.h" |
| +#include "base/string_number_conversions.h" |
| +#include "base/test/test_shortcut_win.h" |
| +#include "base/win/scoped_com_initializer.h" |
| +#include "base/win/windows_version.h" |
| +#include "chrome/common/chrome_constants.h" |
| +#include "chrome/common/chrome_paths_internal.h" |
| +#include "chrome/installer/util/browser_distribution.h" |
| +#include "chrome/installer/util/shell_util.h" |
| +#include "chrome/installer/util/util_constants.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +class ShellIntegrationWinMigrateShortcutTest : public testing::Test { |
| + protected: |
| + virtual void SetUp() OVERRIDE { |
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| + |
| + // A path to a random target. |
| + FilePath other_target; |
| + file_util::CreateTemporaryFile(&other_target); |
|
grt (UTC plus 2)
2013/01/03 02:30:44
could these files be placed in temp_dir_ so they'r
gab
2013/01/03 21:14:57
Done.
|
| + |
| + // This doesn't need to actually have a base name of "chrome.exe". |
| + file_util::CreateTemporaryFile(&chrome_exe_); |
| + |
| + chrome_app_id_ = |
| + ShellUtil::GetBrowserModelId(BrowserDistribution::GetDistribution(), |
| + true); |
| + |
| + // Shortcut 0 doesn't point to chrome.exe and thus should never be migrated. |
| + shortcuts_properties_[0].set_target(other_target); |
| + shortcuts_properties_[0].set_app_id(L"Dumbo"); |
| + shortcuts_properties_[0].set_dual_mode(false); |
| + |
| + // Shortcut 1 points to chrome.exe and thus should be migrated. |
| + shortcuts_properties_[1].set_target(chrome_exe_); |
| + shortcuts_properties_[1].set_app_id(L"Dumbo"); |
| + shortcuts_properties_[1].set_dual_mode(false); |
| + |
| + // Shortcut 2 points to chrome.exe, but already has the right appid and thus |
| + // should only be migrated if dual_mode is desired. |
| + shortcuts_properties_[2].set_target(chrome_exe_); |
| + shortcuts_properties_[2].set_app_id(chrome_app_id_); |
| + shortcuts_properties_[2].set_dual_mode(false); |
| + |
| + // Shortcut 3 is like shortcut 2 except it has dual_mode and thus should |
| + // never be migrated. |
| + shortcuts_properties_[3].set_target(chrome_exe_); |
| + shortcuts_properties_[3].set_app_id(chrome_app_id_); |
| + shortcuts_properties_[3].set_dual_mode(true); |
| + |
| + // Shortcut 4 is like shortcut 1, but it's appid is a prefix of the expected |
| + // appid instead of being totally different. |
| + string16 chrome_app_id_is_prefix(chrome_app_id_); |
| + chrome_app_id_is_prefix.push_back(L'1'); |
| + shortcuts_properties_[4].set_target(chrome_exe_); |
| + shortcuts_properties_[4].set_app_id(chrome_app_id_is_prefix); |
| + shortcuts_properties_[4].set_dual_mode(false); |
| + |
| + // Shortcut 5 is like shortcut 1, but it's appid is of the same size as the |
| + // expected appid. |
| + string16 same_size_as_chrome_app_id(L'1', chrome_app_id_.size()); |
| + shortcuts_properties_[5].set_target(chrome_exe_); |
| + shortcuts_properties_[5].set_app_id(same_size_as_chrome_app_id); |
| + shortcuts_properties_[5].set_dual_mode(false); |
| + |
| + for (int i = 0; i < kNumTestShortcuts; i++) { |
| + shortcuts_[i] = temp_dir_.path().Append(base::IntToString16(i) + |
| + installer::kLnkExt); |
| + ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| + shortcuts_[i], shortcuts_properties_[i], |
| + base::win::SHORTCUT_CREATE_ALWAYS)); |
| + } |
| + } |
| + |
| + static const int kNumTestShortcuts = 6; |
| + |
| + base::win::ScopedCOMInitializer com_initializer_; |
| + base::ScopedTempDir temp_dir_; |
| + |
| + // The path to a fake chrome.exe. |
| + FilePath chrome_exe_; |
| + |
| + // Test shortcuts. |
| + FilePath shortcuts_[kNumTestShortcuts]; |
|
grt (UTC plus 2)
2013/01/03 02:30:44
suggest making this a vector so you don't need kNu
gab
2013/01/03 21:14:57
Done.
|
| + |
| + // Inititial properties for the test shortcuts. |
| + base::win::ShortcutProperties shortcuts_properties_[kNumTestShortcuts]; |
|
grt (UTC plus 2)
2013/01/03 02:30:44
vectorize this, too?
gab
2013/01/03 21:14:57
Done.
|
| + |
| + // This Chrome's AppUserModelId. |
| + string16 chrome_app_id_; |
| +}; |
| + |
| +} // namespace |
| + |
| +// Test migration when not checking for dual mode. |
| +TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) { |
| + if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| + return; |
| + |
| + EXPECT_EQ(3, |
| + shell_integration::internals::MigrateShortcutsInPath( |
| + chrome_exe_, temp_dir_.path(), false)); |
| + |
| + // Only shortcut 1, 4, and 5 should have been migrated. |
| + shortcuts_properties_[1].set_app_id(chrome_app_id_); |
| + shortcuts_properties_[4].set_app_id(chrome_app_id_); |
| + shortcuts_properties_[5].set_app_id(chrome_app_id_); |
| + |
| + for (int i = 0; i < kNumTestShortcuts; i++) |
| + base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); |
| +} |
| + |
| +// Test migration when also checking for dual mode. |
| +TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) { |
| + if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| + return; |
| + |
| + EXPECT_EQ(4, |
| + shell_integration::internals::MigrateShortcutsInPath( |
| + chrome_exe_, temp_dir_.path(), true)); |
| + |
| + // Shortcut 1, 4, and 5 should have had both their app_id and dual_mode |
| + // properties fixed and shortcut 2 should also have had it's dual_mode |
| + // property fixed. |
| + shortcuts_properties_[1].set_app_id(chrome_app_id_); |
| + shortcuts_properties_[4].set_app_id(chrome_app_id_); |
| + shortcuts_properties_[5].set_app_id(chrome_app_id_); |
| + |
| + shortcuts_properties_[1].set_dual_mode(true); |
| + shortcuts_properties_[2].set_dual_mode(true); |
| + shortcuts_properties_[4].set_dual_mode(true); |
| + shortcuts_properties_[5].set_dual_mode(true); |
| + |
| + for (int i = 0; i < kNumTestShortcuts; i++) |
| + base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); |
| +} |
| + |
| +TEST(ShellIntegrationWinTest, GetAppModelIdForProfileTest) { |
| + const string16 base_app_id( |
| + BrowserDistribution::GetDistribution()->GetBaseAppId()); |
| + |
| + // Empty profile path should get chrome::kBrowserAppID |
| + FilePath empty_path; |
| + EXPECT_EQ(base_app_id, |
| + ShellIntegration::GetAppModelIdForProfile(base_app_id, empty_path)); |
| + |
| + // Default profile path should get chrome::kBrowserAppID |
| + FilePath default_user_data_dir; |
| + chrome::GetDefaultUserDataDirectory(&default_user_data_dir); |
| + FilePath default_profile_path = |
| + default_user_data_dir.AppendASCII(chrome::kInitialProfile); |
| + EXPECT_EQ(base_app_id, |
| + ShellIntegration::GetAppModelIdForProfile(base_app_id, |
| + default_profile_path)); |
| + |
| + // Non-default profile path should get chrome::kBrowserAppID joined with |
| + // profile info. |
| + FilePath profile_path(FILE_PATH_LITERAL("root")); |
| + profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); |
| + profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); |
| + EXPECT_EQ(base_app_id + L".udd.UserDataTest", |
| + ShellIntegration::GetAppModelIdForProfile(base_app_id, |
| + profile_path)); |
| +} |