Commit 38864a79 authored by Fargat Sharipov's avatar Fargat Sharipov Committed by Commit Bot

Fix import from Firefox non-ascii named profiles

Replace std::string with base::string16 in some places
to be able to import from non-ASCII named Firefox profiles.
Earlier those profiles were not displayed in the dropdown
list in the profile import dialog, this CL fixes that.

Bug: 1125904
Change-Id: I117b995101e38c4e7392c186f8c58f166f4b0ce3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401518
Commit-Queue: Alexander Yashkin <a-v-y@yandex-team.ru>
Auto-Submit: Fargat Sharipov <farhit1@yandex-team.ru>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806972}
parent b094240a
......@@ -75,16 +75,17 @@ std::vector<FirefoxDetail> GetFirefoxDetailsFromDictionary(
break;
}
std::string path;
if (!root.GetStringASCII(current_profile + ".Path", &path))
base::string16 path;
if (!root.GetString(current_profile + ".Path", &path))
continue;
FirefoxDetail details;
details.path = GetProfilePath(root, current_profile);
std::string name;
root.GetStringASCII(current_profile + ".Name", &name);
base::string16 name;
root.GetString(current_profile + ".Name", &name);
// Make the profile name more presentable by replacing dashes with spaces.
base::ReplaceChars(name, "-", " ", &name);
base::ReplaceChars(name, base::ASCIIToUTF16("-"), base::ASCIIToUTF16(" "),
&name);
details.name = name;
profile_details.push_back(details);
}
......@@ -93,7 +94,7 @@ std::vector<FirefoxDetail> GetFirefoxDetailsFromDictionary(
// The name is only used to disambiguate profiles in the profile selection UI,
// which is only useful when there are multiple profiles.
if (profile_details.size() == 1) {
profile_details[0].name = "";
profile_details[0].name = base::string16();
}
return profile_details;
......
......@@ -45,7 +45,7 @@ struct FirefoxDetail {
// in stored.
base::FilePath path;
// The user specified name of the profile.
std::string name;
base::string16 name;
};
inline bool operator==(const FirefoxDetail& a1, const FirefoxDetail& a2) {
......
......@@ -9,12 +9,15 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/grit/generated_resources.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
using base::ASCIIToUTF16;
using base::UTF8ToUTF16;
using testing::UnorderedElementsAre;
namespace {
......@@ -141,7 +144,8 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
std::vector<FirefoxDetail> details =
GetFirefoxDetailsFromDictionary(single_profile, std::string());
EXPECT_THAT(details, UnorderedElementsAre(FirefoxDetail{
base::FilePath(FILE_PATH_LITERAL("first")), ""}));
base::FilePath(FILE_PATH_LITERAL("first")),
base::string16()}));
base::DictionaryValue no_default;
no_default.SetString("Profile0.Path", "first");
......@@ -152,12 +156,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
no_default.SetString("Profile1.IsRelative", "0");
std::vector<FirefoxDetail> no_default_details =
GetFirefoxDetailsFromDictionary(no_default, std::string());
EXPECT_THAT(
no_default_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), "namey"},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
"namey name"}));
EXPECT_THAT(no_default_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
ASCIIToUTF16("namey")},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
ASCIIToUTF16("namey name")}));
base::DictionaryValue default_first;
default_first.SetString("Profile0.Path", "first");
......@@ -169,12 +173,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
default_first.SetString("Profile1.IsRelative", "0");
std::vector<FirefoxDetail> default_first_details =
GetFirefoxDetailsFromDictionary(default_first, std::string());
EXPECT_THAT(
default_first_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), "namey"},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
"namey name"}));
EXPECT_THAT(default_first_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
ASCIIToUTF16("namey")},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
ASCIIToUTF16("namey name")}));
base::DictionaryValue default_second;
default_second.SetString("Profile0.Path", "first");
......@@ -186,12 +190,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
default_second.SetString("Profile1.Default", "1");
std::vector<FirefoxDetail> default_second_details =
GetFirefoxDetailsFromDictionary(default_second, std::string());
EXPECT_THAT(
default_second_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), "namey"},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
"namey name"}));
EXPECT_THAT(default_second_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
ASCIIToUTF16("namey")},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
ASCIIToUTF16("namey name")}));
// Firefox format from version 67
base::DictionaryValue default_single_install;
......@@ -215,11 +219,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
std::vector<FirefoxDetail> default_single_install_unknown_profile_details =
GetFirefoxDetailsFromDictionary(default_single_install_unknown_profile,
std::string());
EXPECT_THAT(
default_single_install_unknown_profile_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), ""},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")), ""}));
EXPECT_THAT(default_single_install_unknown_profile_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
base::string16()},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
base::string16()}));
default_single_install_unknown_profile.SetString("Install01.Default",
"first");
......@@ -233,9 +238,30 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
std::vector<FirefoxDetail> default_multiple_install_details =
GetFirefoxDetailsFromDictionary(default_single_install_unknown_profile,
std::string());
EXPECT_THAT(
default_multiple_install_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), ""},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")), ""}));
EXPECT_THAT(default_multiple_install_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
base::string16()},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
base::string16()}));
base::DictionaryValue one_of_profiles_is_not_ascii_named;
one_of_profiles_is_not_ascii_named.SetString("Profile0.Path", "first");
one_of_profiles_is_not_ascii_named.SetString("Profile0.Name", "namey");
one_of_profiles_is_not_ascii_named.SetString("Profile0.IsRelative", "0");
one_of_profiles_is_not_ascii_named.SetString("Profile1.Path",
UTF8ToUTF16("second.профиль"));
one_of_profiles_is_not_ascii_named.SetString("Profile1.Name",
UTF8ToUTF16("профиль"));
one_of_profiles_is_not_ascii_named.SetString("Profile1.IsRelative", "0");
std::vector<FirefoxDetail> one_of_profiles_is_not_ascii_named_details =
GetFirefoxDetailsFromDictionary(one_of_profiles_is_not_ascii_named,
std::string());
EXPECT_THAT(one_of_profiles_is_not_ascii_named_details,
UnorderedElementsAre(
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
ASCIIToUTF16("namey")},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second."
"профиль")),
UTF8ToUTF16("профиль")}));
}
......@@ -48,7 +48,7 @@ struct SourceProfile {
// The application locale. Stored because we can only access it from the UI
// thread on the browser process. This is only used by the Firefox importer.
std::string locale;
std::string profile;
base::string16 profile;
};
// Contains information needed for importing search engine urls.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment