#include <objbase.h> // For CoInitialize().
#include "base/base_paths.h"
-#include "base/file_util.h"
+#include "base/files/file_util.h"
#include "base/location.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "chrome/browser/profiles/profile_shortcut_manager.h"
#include "chrome/browser/profiles/profile_shortcut_manager_win.h"
#include "chrome/browser/shell_integration.h"
+#include "chrome/grit/chromium_strings.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/product.h"
#include "chrome/installer/util/shell_util.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/test/test_browser_thread.h"
-#include "grit/chromium_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
fake_system_desktop_(base::DIR_COMMON_DESKTOP) {
}
- virtual void SetUp() OVERRIDE {
+ virtual void SetUp() override {
CoInitialize(NULL);
TestingBrowserProcess* browser_process =
profile_3_path_ = CreateProfileDirectory(profile_3_name_);
}
- virtual void TearDown() OVERRIDE {
+ virtual void TearDown() override {
message_loop_.RunUntilIdle();
// Delete all profiles and ensure their shortcuts got removed.
for (int i = 0; i < num_profiles; ++i) {
const base::FilePath profile_path =
profile_info_cache_->GetPathOfProfileAtIndex(0);
- string16 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0);
+ base::string16 profile_name =
+ profile_info_cache_->GetNameOfProfileAtIndex(0);
profile_info_cache_->DeleteProfileFromCache(profile_path);
RunPendingTasks();
ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name));
}
}
- base::FilePath CreateProfileDirectory(const string16& profile_name) {
+ base::FilePath CreateProfileDirectory(const base::string16& profile_name) {
const base::FilePath profile_path =
profile_info_cache_->GetUserDataDir().Append(profile_name);
- file_util::CreateDirectory(profile_path);
+ base::CreateDirectory(profile_path);
return profile_path;
}
ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_))
<< location.ToString();
profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_,
- string16(), 0, std::string());
+ base::string16(), 0, std::string());
// Also create a non-badged shortcut for Chrome, which is conveniently done
// by |CreateProfileShortcut()| since there is only one profile.
profile_shortcut_manager_->CreateProfileShortcut(profile_1_path_);
// Returns the default shortcut path for this profile.
base::FilePath GetDefaultShortcutPathForProfile(
- const string16& profile_name) {
+ const base::string16& profile_name) {
return GetUserShortcutsDirectory().Append(
profiles::internal::GetShortcutFilenameForProfile(profile_name,
GetDistribution()));
}
// Returns true if the shortcut for this profile exists.
- bool ProfileShortcutExistsAtDefaultPath(const string16& profile_name) {
+ bool ProfileShortcutExistsAtDefaultPath(const base::string16& profile_name) {
return base::PathExists(
GetDefaultShortcutPathForProfile(profile_name));
}
// Calls base::win::ValidateShortcut() with expected properties for
// |profile_name|'s shortcut.
void ValidateProfileShortcut(const tracked_objects::Location& location,
- const string16& profile_name,
+ const base::string16& profile_name,
const base::FilePath& profile_path) {
ValidateProfileShortcutAtPath(
location, GetDefaultShortcutPathForProfile(profile_name), profile_path);
base::win::ShortcutProperties expected_properties;
expected_properties.set_target(GetExePath());
- expected_properties.set_arguments(string16());
+ expected_properties.set_arguments(base::string16());
expected_properties.set_icon(GetExePath(), 0);
expected_properties.set_description(GetDistribution()->GetAppDescription());
expected_properties.set_dual_mode(false);
void ValidateNonProfileShortcut(const tracked_objects::Location& location) {
const base::FilePath shortcut_path =
- GetDefaultShortcutPathForProfile(string16());
+ GetDefaultShortcutPathForProfile(base::string16());
ValidateNonProfileShortcutAtPath(location, shortcut_path);
}
void CreateProfileWithShortcut(const tracked_objects::Location& location,
- const string16& profile_name,
+ const base::string16& profile_name,
const base::FilePath& profile_path) {
ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name))
<< location.ToString();
profile_info_cache_->AddProfileToCache(profile_path, profile_name,
- string16(), 0, std::string());
+ base::string16(), 0, std::string());
profile_shortcut_manager_->CreateProfileShortcut(profile_path);
RunPendingTasks();
ValidateProfileShortcut(location, profile_name, profile_path);
// returns its path. Fails the test if an error occurs.
base::FilePath CreateRegularShortcutWithName(
const tracked_objects::Location& location,
- const string16& shortcut_name) {
+ const base::string16& shortcut_name) {
const base::FilePath shortcut_path =
GetUserShortcutsDirectory().Append(shortcut_name + installer::kLnkExt);
EXPECT_FALSE(base::PathExists(shortcut_path)) << location.ToString();
void RenameProfile(const tracked_objects::Location& location,
const base::FilePath& profile_path,
- const string16& new_profile_name) {
+ const base::string16& new_profile_name) {
const size_t profile_index =
profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_);
ASSERT_NE(std::string::npos, profile_index);
ProfileInfoCache* profile_info_cache_;
base::ScopedPathOverride fake_user_desktop_;
base::ScopedPathOverride fake_system_desktop_;
- string16 profile_1_name_;
+ base::string16 profile_1_name_;
base::FilePath profile_1_path_;
- string16 profile_2_name_;
+ base::string16 profile_2_name_;
base::FilePath profile_2_path_;
- string16 profile_3_name_;
+ base::string16 profile_3_name_;
base::FilePath profile_3_path_;
};
TEST_F(ProfileShortcutManagerTest, ShortcutFilename) {
- const string16 kProfileName = L"Harry";
+ const base::string16 kProfileName = L"Harry";
BrowserDistribution* distribution = GetDistribution();
- const string16 expected_name = kProfileName + L" - " +
+ const base::string16 expected_name = kProfileName + L" - " +
l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME) + installer::kLnkExt;
EXPECT_EQ(expected_name,
profiles::internal::GetShortcutFilenameForProfile(kProfileName,
}
TEST_F(ProfileShortcutManagerTest, ShortcutLongFilenameIsTrimmed) {
- const string16 kLongProfileName = L"Harry Harry Harry Harry Harry Harry Harry"
+ const base::string16 kLongProfileName =
+ L"Harry Harry Harry Harry Harry Harry Harry"
L"Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry"
L"Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry";
- const string16 file_name =
+ const base::string16 file_name =
profiles::internal::GetShortcutFilenameForProfile(kLongProfileName,
GetDistribution());
EXPECT_LT(file_name.size(), kLongProfileName.size());
}
TEST_F(ProfileShortcutManagerTest, ShortcutFilenameStripsReservedCharacters) {
- const string16 kProfileName = L"<Harry/>";
- const string16 kSanitizedProfileName = L"Harry";
+ const base::string16 kProfileName = L"<Harry/>";
+ const base::string16 kSanitizedProfileName = L"Harry";
BrowserDistribution* distribution = GetDistribution();
- const string16 expected_name = kSanitizedProfileName + L" - " +
+ const base::string16 expected_name = kSanitizedProfileName + L" - " +
l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME) + installer::kLnkExt;
EXPECT_EQ(expected_name,
profiles::internal::GetShortcutFilenameForProfile(kProfileName,
EXPECT_EQ(
distribution->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
installer::kLnkExt,
- profiles::internal::GetShortcutFilenameForProfile(string16(),
+ profiles::internal::GetShortcutFilenameForProfile(base::string16(),
distribution));
}
TEST_F(ProfileShortcutManagerTest, ShortcutFlags) {
- const string16 kProfileName = L"MyProfileX";
+ const base::string16 kProfileName = L"MyProfileX";
const base::FilePath profile_path =
profile_info_cache_->GetUserDataDir().Append(kProfileName);
EXPECT_EQ(L"--profile-directory=\"" + kProfileName + L"\"",
// Cause an update in ProfileShortcutManager by modifying the profile info
// cache.
- const string16 new_profile_2_name = L"New Profile Name";
+ const base::string16 new_profile_2_name = L"New Profile Name";
RenameProfile(FROM_HERE, profile_2_path_, new_profile_2_name);
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_);
TEST_F(ProfileShortcutManagerTest, CreateSecondProfileBadgesFirstShortcut) {
SetupDefaultProfileShortcut(FROM_HERE);
// Assert that a shortcut without a profile name exists.
- ASSERT_TRUE(ProfileShortcutExistsAtDefaultPath(string16()));
+ ASSERT_TRUE(ProfileShortcutExistsAtDefaultPath(base::string16()));
// Create a second profile without a shortcut.
profile_info_cache_->AddProfileToCache(profile_2_path_, profile_2_name_,
- string16(), 0, std::string());
+ base::string16(), 0, std::string());
RunPendingTasks();
// Ensure that the second profile doesn't have a shortcut and that the first
// profile's shortcut got renamed and badged.
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
- EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16()));
+ EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16()));
ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
}
CreateProfileWithShortcut(FROM_HERE, profile_3_name_, profile_3_path_);
const base::FilePath non_profile_shortcut_path =
- GetDefaultShortcutPathForProfile(string16());
+ GetDefaultShortcutPathForProfile(base::string16());
const base::FilePath profile_1_shortcut_path =
GetDefaultShortcutPathForProfile(profile_1_name_);
const base::FilePath profile_2_shortcut_path =
// Verify that the original shortcut received the profile's name.
ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
// Verify that a default shortcut no longer exists.
- EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16()));
+ EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16()));
}
TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcuts) {
profile_2_path_);
// Now, rename the profile.
- const string16 new_profile_2_name = L"New profile";
+ const base::string16 new_profile_2_name = L"New profile";
RenameProfile(FROM_HERE, profile_2_path_, new_profile_2_name);
// The original shortcut should be renamed but the copied shortcut should
// Delete the shortcut that got created for this profile and instead make
// a new one without any command-line flags.
- ASSERT_TRUE(base::DeleteFile(GetDefaultShortcutPathForProfile(string16()),
- false));
+ ASSERT_TRUE(base::DeleteFile(
+ GetDefaultShortcutPathForProfile(base::string16()), false));
const base::FilePath regular_shortcut_path =
CreateRegularShortcutWithName(FROM_HERE,
GetDistribution()->GetShortcutName(
// Delete the shortcut that got created for this profile and instead make
// two new ones without any command-line flags.
- ASSERT_TRUE(base::DeleteFile(GetDefaultShortcutPathForProfile(string16()),
- false));
+ ASSERT_TRUE(base::DeleteFile(
+ GetDefaultShortcutPathForProfile(base::string16()), false));
const base::FilePath regular_shortcut_path =
CreateRegularShortcutWithName(FROM_HERE,
GetDistribution()->GetShortcutName(
// Create the initial profile.
profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_,
- string16(), 0, std::string());
+ base::string16(), 0, std::string());
RunPendingTasks();
ASSERT_EQ(1U, profile_info_cache_->GetNumberOfProfiles());
// Ensure system-level continues to exist and user-level was not created.
EXPECT_TRUE(base::PathExists(system_level_shortcut_path));
EXPECT_FALSE(base::PathExists(
- GetDefaultShortcutPathForProfile(string16())));
+ GetDefaultShortcutPathForProfile(base::string16())));
// Create another profile with a shortcut and ensure both profiles receive
// user-level profile shortcuts and the system-level one still exists.
// Create a third profile without a shortcut and ensure it doesn't get one.
profile_info_cache_->AddProfileToCache(profile_3_path_, profile_3_name_,
- string16(), 0, std::string());
+ base::string16(), 0, std::string());
RunPendingTasks();
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_));
RunPendingTasks();
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_));
- const string16 new_profile_3_name = L"New Name 3";
+ const base::string16 new_profile_3_name = L"New Name 3";
profile_info_cache_->SetNameOfProfileAtIndex(
profile_info_cache_->GetIndexOfProfileWithPath(profile_3_path_),
new_profile_3_name);
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(new_profile_3_name));
// Rename the second profile and ensure its shortcut got renamed.
- const string16 new_profile_2_name = L"New Name 2";
+ const base::string16 new_profile_2_name = L"New Name 2";
profile_info_cache_->SetNameOfProfileAtIndex(
profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_),
new_profile_2_name);
RunPendingTasks();
EXPECT_TRUE(base::PathExists(system_level_shortcut_path));
- EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16()));
+ EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16()));
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_));
EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
}
// Verify that only the system-level shortcut still exists.
EXPECT_TRUE(base::PathExists(system_level_shortcut_path));
EXPECT_FALSE(base::PathExists(
- GetDefaultShortcutPathForProfile(string16())));
+ GetDefaultShortcutPathForProfile(base::string16())));
EXPECT_FALSE(base::PathExists(profile_1_shortcut_path));
EXPECT_FALSE(base::PathExists(profile_2_shortcut_path));
}