0
Files
src/pdf/ui/document_properties_unittest.cc
Arthur Sonzogni 59ac8227c5 Rename {absl => std}::optional in minor top-level dirs
Automated patch, intended to be effectively a no-op.

This patch gather the changes for every top-level directories with less
than 150 files modified:
 #  directory
--- ---------------
150 remoting
98  gpu
87  chromecast
79  mojo
70  storage
65  fuchsia_web
46  sandbox
44  android_webview
38  google_apis
27  pdf
25  printing
20  headless
13  ipc
11  crypto
10  sql
3   dbus
2   testing
2   skia
2   gin
2   apps
1   rlz
1   codelabs

Context:
https://groups.google.com/a/chromium.org/g/cxx/c/nBD_1LaanTc/m/ghh-ZZhWAwAJ?utm_medium=email&utm_source=footer

As of https://crrev.com/1204351, absl::optional is now a type alias for
std::optional. We should migrate toward it.

Script:
```

function replace {
  echo "Replacing $1 by $2"
  git grep -l "$1" \
		| cut -f1 -d: \
		| grep \
			-e "^codelabs" \
			-e "^rlz" \
			-e "^apps" \
			-e "^gin" \
			-e "^skia" \
			-e "^testing" \
			-e "^dbus" \
			-e "^sql" \
			-e "^crypto" \
			-e "^ipc" \
			-e "^headless" \
			-e "^printing" \
			-e "^pdf" \
			-e "^google_apis" \
			-e "^android_webview" \
			-e "^sandbox" \
			-e "^fuchsia_web" \
			-e "^storage" \
			-e "^mojo" \
			-e "^chromecast" \
			-e "^gpu" \
			-e "^remoting" \
		| sort \
		| uniq \
		| grep \
			-e "\.h" \
			-e "\.cc" \
			-e "\.mm" \
			-e "\.py" \
	  | xargs sed -i "s/$1/$2/g"
}

replace "absl::make_optional" "std::make_optional"
replace "absl::optional" "std::optional"
replace "absl::nullopt" "std::nullopt"
replace "absl::in_place" "std::in_place"
replace "absl::in_place_t" "std::in_place_t"
replace "\"third_party\/abseil-cpp\/absl\/types\/optional.h\"" "<optional>"
git cl format
```

CQ_INCLUDE_TRYBOTS=luci.chrome.try:chromeos-betty-pi-arc-chrome

Bug: chromium:1500249
Change-Id: I0eca8ff96f5712ba746ac8d8da93d03a86d8292c
AX-Relnotes: n/a.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5009410
Reviewed-by: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1222826}
2023-11-10 09:46:54 +00:00

123 lines
3.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ui/document_properties.h"
#include <string>
#include <optional>
#include "base/i18n/number_formatting.h"
#include "base/i18n/rtl.h"
#include "pdf/document_metadata.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
namespace chrome_pdf {
namespace {
using ::testing::IsEmpty;
class FormatPageSizeTest : public testing::Test {
protected:
void SetUp() override {
const std::string locale(GetLocale());
if (!locale.empty()) {
base::i18n::SetICUDefaultLocale(locale);
base::ResetFormattersForTesting();
}
}
void TearDown() override {
base::i18n::SetICUDefaultLocale(default_locale_);
base::ResetFormattersForTesting();
}
virtual std::string GetLocale() const { return std::string(); }
private:
std::string default_locale_{base::i18n::GetConfiguredLocale()};
};
} // namespace
TEST_F(FormatPageSizeTest, NoUniformSize) {
EXPECT_EQ(FormatPageSize(std::nullopt), u"Varies");
}
class FormatPageSizeMillimetersTest : public FormatPageSizeTest {
protected:
std::string GetLocale() const override { return "en_CA"; }
};
TEST_F(FormatPageSizeMillimetersTest, EmptySize) {
EXPECT_EQ(FormatPageSize(gfx::Size()), u"0 × 0 mm (square)");
}
TEST_F(FormatPageSizeMillimetersTest, Portrait) {
EXPECT_EQ(FormatPageSize(gfx::Size(100, 200)), u"35 × 71 mm (portrait)");
}
TEST_F(FormatPageSizeMillimetersTest, Landscape) {
EXPECT_EQ(FormatPageSize(gfx::Size(200, 100)), u"71 × 35 mm (landscape)");
}
TEST_F(FormatPageSizeMillimetersTest, Square) {
EXPECT_EQ(FormatPageSize(gfx::Size(100, 100)), u"35 × 35 mm (square)");
}
TEST_F(FormatPageSizeMillimetersTest, Large) {
EXPECT_EQ(FormatPageSize(gfx::Size(72000, 72000)),
u"25,400 × 25,400 mm (square)");
}
class FormatPageSizeMillimetersPeriodSeparatorTest : public FormatPageSizeTest {
protected:
std::string GetLocale() const override { return "de_DE"; }
};
TEST_F(FormatPageSizeMillimetersPeriodSeparatorTest, Large) {
EXPECT_EQ(FormatPageSize(gfx::Size(72000, 72000)),
u"25.400 × 25.400 mm (square)");
}
class FormatPageSizeInchesTest : public FormatPageSizeTest {
protected:
std::string GetLocale() const override { return "en_US"; }
};
TEST_F(FormatPageSizeInchesTest, EmptySize) {
EXPECT_EQ(FormatPageSize(gfx::Size()), u"0.00 × 0.00 in (square)");
}
TEST_F(FormatPageSizeInchesTest, Portrait) {
EXPECT_EQ(FormatPageSize(gfx::Size(100, 200)), u"1.39 × 2.78 in (portrait)");
}
TEST_F(FormatPageSizeInchesTest, Landscape) {
EXPECT_EQ(FormatPageSize(gfx::Size(200, 100)), u"2.78 × 1.39 in (landscape)");
}
TEST_F(FormatPageSizeInchesTest, Square) {
EXPECT_EQ(FormatPageSize(gfx::Size(100, 100)), u"1.39 × 1.39 in (square)");
}
TEST_F(FormatPageSizeInchesTest, Large) {
EXPECT_EQ(FormatPageSize(gfx::Size(72000, 72000)),
u"1,000.00 × 1,000.00 in (square)");
}
TEST(FormatPdfVersion, Valid) {
EXPECT_EQ(FormatPdfVersion(PdfVersion::k1_7), "1.7");
EXPECT_EQ(FormatPdfVersion(PdfVersion::k2_0), "2.0");
}
TEST(FormatPdfVersion, Invalid) {
EXPECT_THAT(FormatPdfVersion(PdfVersion::kUnknown), IsEmpty());
EXPECT_THAT(FormatPdfVersion(PdfVersion::k1_8), IsEmpty());
}
} // namespace chrome_pdf