1 // Copyright 2017 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.
5 #include "printing/printed_document.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "testing/gtest/include/gtest/gtest.h"
11 TEST(PrintedDocumentTest, GetCenteredPageContentRect) {
12 scoped_refptr<PrintedDocument> document;
13 PrintSettings settings;
14 gfx::Rect page_content;
15 const base::string16 name(base::ASCIIToUTF16("name"));
18 document = base::MakeRefCounted<PrintedDocument>(settings, name, 1);
19 gfx::Size page_size = gfx::Size(1200, 1200);
20 gfx::Rect page_content_rect = gfx::Rect(0, 0, 400, 1100);
21 page_content = document->GetCenteredPageContentRect(
22 gfx::Size(1000, 1000), page_size, page_content_rect);
23 EXPECT_EQ(0, page_content.x());
24 EXPECT_EQ(0, page_content.y());
25 EXPECT_EQ(400, page_content.width());
26 EXPECT_EQ(1100, page_content.height());
29 document = base::MakeRefCounted<PrintedDocument>(settings, name, 1);
30 page_size = gfx::Size(500, 1200);
31 page_content = document->GetCenteredPageContentRect(
32 gfx::Size(1000, 1000), page_size, page_content_rect);
33 EXPECT_EQ(250, page_content.x());
34 EXPECT_EQ(0, page_content.y());
35 EXPECT_EQ(400, page_content.width());
36 EXPECT_EQ(1100, page_content.height());
39 document = base::MakeRefCounted<PrintedDocument>(settings, name, 1);
40 page_size = gfx::Size(1200, 500);
41 page_content = document->GetCenteredPageContentRect(
42 gfx::Size(1000, 1000), page_size, page_content_rect);
43 EXPECT_EQ(0, page_content.x());
44 EXPECT_EQ(250, page_content.y());
45 EXPECT_EQ(400, page_content.width());
46 EXPECT_EQ(1100, page_content.height());
48 // Both X and Y centered.
49 document = base::MakeRefCounted<PrintedDocument>(settings, name, 1);
50 page_size = gfx::Size(500, 500),
51 page_content = document->GetCenteredPageContentRect(
52 gfx::Size(1000, 1000), page_size, page_content_rect);
53 EXPECT_EQ(250, page_content.x());
54 EXPECT_EQ(250, page_content.y());
55 EXPECT_EQ(400, page_content.width());
56 EXPECT_EQ(1100, page_content.height());
59 } // namespace printing