Upload upstream chromium 73.0.3683.0
[platform/framework/web/chromium-efl.git] / printing / printing_utils_unittest.cc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "printing/printing_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace printing {
12
13 namespace {
14
15 const size_t kTestLength = 8;
16
17 std::string Simplify(const std::string& title) {
18   return base::UTF16ToUTF8(
19       SimplifyDocumentTitleWithLength(base::UTF8ToUTF16(title), kTestLength));
20 }
21
22 std::string Format(const std::string& owner, const std::string& title) {
23   return base::UTF16ToUTF8(FormatDocumentTitleWithOwnerAndLength(
24       base::UTF8ToUTF16(owner), base::UTF8ToUTF16(title), kTestLength));
25 }
26
27 }  // namespace
28
29 TEST(PrintingUtilsTest, SimplifyDocumentTitle) {
30   EXPECT_EQ("", Simplify(""));
31   EXPECT_EQ("abcdefgh", Simplify("abcdefgh"));
32   EXPECT_EQ("abc...ij", Simplify("abcdefghij"));
33   EXPECT_EQ("Controls", Simplify("C\ron\nt\15rols"));
34   EXPECT_EQ("C:_foo_", Simplify("C:\\foo\\"));
35   EXPECT_EQ("", Simplify("\n\r\n\r\t\r"));
36 }
37
38 TEST(PrintingUtilsTest, FormatDocumentTitleWithOwner) {
39   EXPECT_EQ(": ", Format("", ""));
40   EXPECT_EQ("abc: ", Format("abc", ""));
41   EXPECT_EQ(": 123", Format("", "123"));
42   EXPECT_EQ("abc: 123", Format("abc", "123"));
43   EXPECT_EQ("abc: 0.9", Format("abc", "0123456789"));
44   EXPECT_EQ("ab...j: ", Format("abcdefghij", "123"));
45   EXPECT_EQ("xyz: _.o", Format("xyz", "\\f\\oo"));
46   EXPECT_EQ("ab...j: ", Format("abcdefghij", "0123456789"));
47 }
48
49 }  // namespace printing