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( ...@@ -75,16 +75,17 @@ std::vector<FirefoxDetail> GetFirefoxDetailsFromDictionary(
break; break;
} }
std::string path; base::string16 path;
if (!root.GetStringASCII(current_profile + ".Path", &path)) if (!root.GetString(current_profile + ".Path", &path))
continue; continue;
FirefoxDetail details; FirefoxDetail details;
details.path = GetProfilePath(root, current_profile); details.path = GetProfilePath(root, current_profile);
std::string name; base::string16 name;
root.GetStringASCII(current_profile + ".Name", &name); root.GetString(current_profile + ".Name", &name);
// Make the profile name more presentable by replacing dashes with spaces. // 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; details.name = name;
profile_details.push_back(details); profile_details.push_back(details);
} }
...@@ -93,7 +94,7 @@ std::vector<FirefoxDetail> GetFirefoxDetailsFromDictionary( ...@@ -93,7 +94,7 @@ std::vector<FirefoxDetail> GetFirefoxDetailsFromDictionary(
// The name is only used to disambiguate profiles in the profile selection UI, // The name is only used to disambiguate profiles in the profile selection UI,
// which is only useful when there are multiple profiles. // which is only useful when there are multiple profiles.
if (profile_details.size() == 1) { if (profile_details.size() == 1) {
profile_details[0].name = ""; profile_details[0].name = base::string16();
} }
return profile_details; return profile_details;
......
...@@ -45,7 +45,7 @@ struct FirefoxDetail { ...@@ -45,7 +45,7 @@ struct FirefoxDetail {
// in stored. // in stored.
base::FilePath path; base::FilePath path;
// The user specified name of the profile. // The user specified name of the profile.
std::string name; base::string16 name;
}; };
inline bool operator==(const FirefoxDetail& a1, const FirefoxDetail& a2) { inline bool operator==(const FirefoxDetail& a1, const FirefoxDetail& a2) {
......
...@@ -9,12 +9,15 @@ ...@@ -9,12 +9,15 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
using base::ASCIIToUTF16;
using base::UTF8ToUTF16;
using testing::UnorderedElementsAre; using testing::UnorderedElementsAre;
namespace { namespace {
...@@ -141,7 +144,8 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) { ...@@ -141,7 +144,8 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
std::vector<FirefoxDetail> details = std::vector<FirefoxDetail> details =
GetFirefoxDetailsFromDictionary(single_profile, std::string()); GetFirefoxDetailsFromDictionary(single_profile, std::string());
EXPECT_THAT(details, UnorderedElementsAre(FirefoxDetail{ EXPECT_THAT(details, UnorderedElementsAre(FirefoxDetail{
base::FilePath(FILE_PATH_LITERAL("first")), ""})); base::FilePath(FILE_PATH_LITERAL("first")),
base::string16()}));
base::DictionaryValue no_default; base::DictionaryValue no_default;
no_default.SetString("Profile0.Path", "first"); no_default.SetString("Profile0.Path", "first");
...@@ -152,12 +156,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) { ...@@ -152,12 +156,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
no_default.SetString("Profile1.IsRelative", "0"); no_default.SetString("Profile1.IsRelative", "0");
std::vector<FirefoxDetail> no_default_details = std::vector<FirefoxDetail> no_default_details =
GetFirefoxDetailsFromDictionary(no_default, std::string()); GetFirefoxDetailsFromDictionary(no_default, std::string());
EXPECT_THAT( EXPECT_THAT(no_default_details,
no_default_details, UnorderedElementsAre(
UnorderedElementsAre( FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), "namey"}, ASCIIToUTF16("namey")},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")), FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
"namey name"})); ASCIIToUTF16("namey name")}));
base::DictionaryValue default_first; base::DictionaryValue default_first;
default_first.SetString("Profile0.Path", "first"); default_first.SetString("Profile0.Path", "first");
...@@ -169,12 +173,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) { ...@@ -169,12 +173,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
default_first.SetString("Profile1.IsRelative", "0"); default_first.SetString("Profile1.IsRelative", "0");
std::vector<FirefoxDetail> default_first_details = std::vector<FirefoxDetail> default_first_details =
GetFirefoxDetailsFromDictionary(default_first, std::string()); GetFirefoxDetailsFromDictionary(default_first, std::string());
EXPECT_THAT( EXPECT_THAT(default_first_details,
default_first_details, UnorderedElementsAre(
UnorderedElementsAre( FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), "namey"}, ASCIIToUTF16("namey")},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")), FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
"namey name"})); ASCIIToUTF16("namey name")}));
base::DictionaryValue default_second; base::DictionaryValue default_second;
default_second.SetString("Profile0.Path", "first"); default_second.SetString("Profile0.Path", "first");
...@@ -186,12 +190,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) { ...@@ -186,12 +190,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
default_second.SetString("Profile1.Default", "1"); default_second.SetString("Profile1.Default", "1");
std::vector<FirefoxDetail> default_second_details = std::vector<FirefoxDetail> default_second_details =
GetFirefoxDetailsFromDictionary(default_second, std::string()); GetFirefoxDetailsFromDictionary(default_second, std::string());
EXPECT_THAT( EXPECT_THAT(default_second_details,
default_second_details, UnorderedElementsAre(
UnorderedElementsAre( FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), "namey"}, ASCIIToUTF16("namey")},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")), FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
"namey name"})); ASCIIToUTF16("namey name")}));
// Firefox format from version 67 // Firefox format from version 67
base::DictionaryValue default_single_install; base::DictionaryValue default_single_install;
...@@ -215,11 +219,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) { ...@@ -215,11 +219,12 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
std::vector<FirefoxDetail> default_single_install_unknown_profile_details = std::vector<FirefoxDetail> default_single_install_unknown_profile_details =
GetFirefoxDetailsFromDictionary(default_single_install_unknown_profile, GetFirefoxDetailsFromDictionary(default_single_install_unknown_profile,
std::string()); std::string());
EXPECT_THAT( EXPECT_THAT(default_single_install_unknown_profile_details,
default_single_install_unknown_profile_details, UnorderedElementsAre(
UnorderedElementsAre( FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), ""}, base::string16()},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")), ""})); FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")),
base::string16()}));
default_single_install_unknown_profile.SetString("Install01.Default", default_single_install_unknown_profile.SetString("Install01.Default",
"first"); "first");
...@@ -233,9 +238,30 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) { ...@@ -233,9 +238,30 @@ TEST(FirefoxImporterUtilsTest, GetFirefoxProfilePath) {
std::vector<FirefoxDetail> default_multiple_install_details = std::vector<FirefoxDetail> default_multiple_install_details =
GetFirefoxDetailsFromDictionary(default_single_install_unknown_profile, GetFirefoxDetailsFromDictionary(default_single_install_unknown_profile,
std::string()); std::string());
EXPECT_THAT( EXPECT_THAT(default_multiple_install_details,
default_multiple_install_details, UnorderedElementsAre(
UnorderedElementsAre( FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")),
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("first")), ""}, base::string16()},
FirefoxDetail{base::FilePath(FILE_PATH_LITERAL("second")), ""})); 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 { ...@@ -48,7 +48,7 @@ struct SourceProfile {
// The application locale. Stored because we can only access it from the UI // 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. // thread on the browser process. This is only used by the Firefox importer.
std::string locale; std::string locale;
std::string profile; base::string16 profile;
}; };
// Contains information needed for importing search engine urls. // 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