Return std::u16string from chrome_pdf::FormatPageSize()
When the function was first introduced, std::u16string was not able to be used. Meanwhile, add a TODO about initializing the resource bundle. Bug: 911896 Change-Id: Ie83ebb396ef13228ffb699c3e760a624e2b90b5f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2733730 Auto-Submit: Daniel Hosseinian <dhoss@chromium.org> Reviewed-by: K. Moon <kmoon@chromium.org> Commit-Queue: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/master@{#859655}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
1fdb369eb9
commit
71d0bec246
@ -9,7 +9,6 @@
|
||||
#include "base/i18n/number_formatting.h"
|
||||
#include "base/i18n/rtl.h"
|
||||
#include "base/optional.h"
|
||||
#include "base/strings/string16.h"
|
||||
#include "components/strings/grit/components_strings.h"
|
||||
#include "printing/units.h"
|
||||
#include "third_party/icu/source/i18n/unicode/ulocdata.h"
|
||||
@ -38,20 +37,20 @@ constexpr float ConvertPointsToMillimeters(int length_points) {
|
||||
|
||||
// Formats a length given in points. The formatted length is in inches and
|
||||
// contains two fractional digits.
|
||||
base::string16 FormatLengthInInches(int length_points) {
|
||||
std::u16string FormatLengthInInches(int length_points) {
|
||||
return base::FormatDouble(ConvertPointsToInches(length_points),
|
||||
/*fractional_digits=*/2);
|
||||
}
|
||||
|
||||
// Formats a length given in points. The formatted length is in millimeters and
|
||||
// contains no fractional digits.
|
||||
base::string16 FormatLengthInMillimeters(int length_points) {
|
||||
std::u16string FormatLengthInMillimeters(int length_points) {
|
||||
return base::FormatDouble(ConvertPointsToMillimeters(length_points),
|
||||
/*fractional_digits=*/0);
|
||||
}
|
||||
|
||||
// Returns the localized string for the orientation.
|
||||
base::string16 GetOrientation(const gfx::Size& size) {
|
||||
std::u16string GetOrientation(const gfx::Size& size) {
|
||||
// TODO(crbug.com/1184345): Add a string for square sizes such that they are
|
||||
// not displayed as "portrait".
|
||||
return l10n_util::GetStringUTF16(
|
||||
@ -70,7 +69,7 @@ bool ShowInches() {
|
||||
|
||||
} // namespace
|
||||
|
||||
base::string16 FormatPageSize(const base::Optional<gfx::Size>& size_points) {
|
||||
std::u16string FormatPageSize(const base::Optional<gfx::Size>& size_points) {
|
||||
if (!size_points.has_value())
|
||||
return l10n_util::GetStringUTF16(IDS_PDF_PROPERTIES_PAGE_SIZE_VARIABLE);
|
||||
|
||||
|
@ -5,8 +5,9 @@
|
||||
#ifndef PDF_UI_FORMAT_PAGE_SIZE_H_
|
||||
#define PDF_UI_FORMAT_PAGE_SIZE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/optional.h"
|
||||
#include "base/strings/string16.h"
|
||||
|
||||
namespace gfx {
|
||||
class Size;
|
||||
@ -22,7 +23,7 @@ namespace chrome_pdf {
|
||||
// -> 11.00 x 8.50 in (landscape)
|
||||
//
|
||||
// Returns the string "Varies" if `size_points` is `base::nullopt`.
|
||||
base::string16 FormatPageSize(const base::Optional<gfx::Size>& size_points);
|
||||
std::u16string FormatPageSize(const base::Optional<gfx::Size>& size_points);
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "base/i18n/number_formatting.h"
|
||||
#include "base/i18n/rtl.h"
|
||||
#include "base/optional.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "components/strings/grit/components_strings.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -24,35 +23,35 @@ namespace chrome_pdf {
|
||||
|
||||
namespace {
|
||||
|
||||
bool GetPageSizeString(int message_id, base::string16* value) {
|
||||
std::string utf8;
|
||||
bool GetPageSizeString(int message_id, std::u16string* value) {
|
||||
switch (message_id) {
|
||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_VALUE_INCH:
|
||||
utf8 = "$1 × $2 in ($3)";
|
||||
*value = u"$1 × $2 in ($3)";
|
||||
break;
|
||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_VALUE_MM:
|
||||
utf8 = "$1 × $2 mm ($3)";
|
||||
*value = u"$1 × $2 mm ($3)";
|
||||
break;
|
||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_PORTRAIT:
|
||||
utf8 = "portrait";
|
||||
*value = u"portrait";
|
||||
break;
|
||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_LANDSCAPE:
|
||||
utf8 = "landscape";
|
||||
*value = u"landscape";
|
||||
break;
|
||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_VARIABLE:
|
||||
utf8 = "Varies";
|
||||
*value = u"Varies";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
*value = base::UTF8ToUTF16(utf8);
|
||||
return true;
|
||||
}
|
||||
|
||||
class FormatPageSizeTest : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
// TODO(crbug.com/1184524): Consider initializing a resource bundle instance
|
||||
// for all tests in `pdf_unittests`.
|
||||
// `pdf_unittests` does not have a resource bundle that needs to be restored
|
||||
// at the end of the test.
|
||||
ASSERT_FALSE(ui::ResourceBundle::HasSharedInstance());
|
||||
@ -85,14 +84,10 @@ class FormatPageSizeTest : public testing::Test {
|
||||
NiceMock<ui::MockResourceBundleDelegate> mock_resource_delegate_;
|
||||
};
|
||||
|
||||
std::string FormatPageSizeUtf8(const base::Optional<gfx::Size>& size_points) {
|
||||
return base::UTF16ToUTF8(FormatPageSize(size_points));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(FormatPageSizeTest, NoUniformSize) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(base::nullopt), "Varies");
|
||||
EXPECT_EQ(FormatPageSize(base::nullopt), u"Varies");
|
||||
}
|
||||
|
||||
class FormatPageSizeMillimetersTest : public FormatPageSizeTest {
|
||||
@ -101,24 +96,24 @@ class FormatPageSizeMillimetersTest : public FormatPageSizeTest {
|
||||
};
|
||||
|
||||
TEST_F(FormatPageSizeMillimetersTest, EmptySize) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size()), "0 × 0 mm (portrait)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size()), u"0 × 0 mm (portrait)");
|
||||
}
|
||||
|
||||
TEST_F(FormatPageSizeMillimetersTest, Portrait) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(100, 200)), "35 × 71 mm (portrait)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size(100, 200)), u"35 × 71 mm (portrait)");
|
||||
}
|
||||
|
||||
TEST_F(FormatPageSizeMillimetersTest, Landscape) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(200, 100)), "71 × 35 mm (landscape)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size(200, 100)), u"71 × 35 mm (landscape)");
|
||||
}
|
||||
|
||||
TEST_F(FormatPageSizeMillimetersTest, Square) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(100, 100)), "35 × 35 mm (portrait)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size(100, 100)), u"35 × 35 mm (portrait)");
|
||||
}
|
||||
|
||||
TEST_F(FormatPageSizeMillimetersTest, Large) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(72000, 72000)),
|
||||
"25,400 × 25,400 mm (portrait)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size(72000, 72000)),
|
||||
u"25,400 × 25,400 mm (portrait)");
|
||||
}
|
||||
|
||||
class FormatPageSizeMillimetersPeriodSeparatorTest : public FormatPageSizeTest {
|
||||
@ -127,8 +122,8 @@ class FormatPageSizeMillimetersPeriodSeparatorTest : public FormatPageSizeTest {
|
||||
};
|
||||
|
||||
TEST_F(FormatPageSizeMillimetersPeriodSeparatorTest, Large) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(72000, 72000)),
|
||||
"25.400 × 25.400 mm (portrait)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size(72000, 72000)),
|
||||
u"25.400 × 25.400 mm (portrait)");
|
||||
}
|
||||
|
||||
class FormatPageSizeInchesTest : public FormatPageSizeTest {
|
||||
@ -137,27 +132,24 @@ class FormatPageSizeInchesTest : public FormatPageSizeTest {
|
||||
};
|
||||
|
||||
TEST_F(FormatPageSizeInchesTest, EmptySize) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size()), "0.00 × 0.00 in (portrait)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size()), u"0.00 × 0.00 in (portrait)");
|
||||
}
|
||||
|
||||
TEST_F(FormatPageSizeInchesTest, Portrait) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(100, 200)),
|
||||
"1.39 × 2.78 in (portrait)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size(100, 200)), u"1.39 × 2.78 in (portrait)");
|
||||
}
|
||||
|
||||
TEST_F(FormatPageSizeInchesTest, Landscape) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(200, 100)),
|
||||
"2.78 × 1.39 in (landscape)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size(200, 100)), u"2.78 × 1.39 in (landscape)");
|
||||
}
|
||||
|
||||
TEST_F(FormatPageSizeInchesTest, Square) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(100, 100)),
|
||||
"1.39 × 1.39 in (portrait)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size(100, 100)), u"1.39 × 1.39 in (portrait)");
|
||||
}
|
||||
|
||||
TEST_F(FormatPageSizeInchesTest, Large) {
|
||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(72000, 72000)),
|
||||
"1,000.00 × 1,000.00 in (portrait)");
|
||||
EXPECT_EQ(FormatPageSize(gfx::Size(72000, 72000)),
|
||||
u"1,000.00 × 1,000.00 in (portrait)");
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
Reference in New Issue
Block a user