printed_page_unittest.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2011 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 "printing/printed_page.h"
6#include "testing/gtest/include/gtest/gtest.h"
7
8namespace printing {
9
10TEST(PrintedPageTest, GetCenteredPageContentRect) {
11  scoped_refptr<PrintedPage> page;
12  gfx::Rect page_content;
13
14  // No centering.
15  page = new PrintedPage(1,
16                         NULL,
17                         gfx::Size(1200, 1200),
18                         gfx::Rect(0, 0, 400, 1100),
19                         0.2f);
20  page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
21  EXPECT_EQ(0, page_content.x());
22  EXPECT_EQ(0, page_content.y());
23  EXPECT_EQ(400, page_content.width());
24  EXPECT_EQ(1100, page_content.height());
25  EXPECT_EQ(0.2f, page->shrink_factor());
26
27  // X centered.
28  page = new PrintedPage(1,
29                         NULL,
30                         gfx::Size(500, 1200),
31                         gfx::Rect(0, 0, 400, 1100),
32                         0.8f);
33  page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
34  EXPECT_EQ(250, page_content.x());
35  EXPECT_EQ(0, page_content.y());
36  EXPECT_EQ(400, page_content.width());
37  EXPECT_EQ(1100, page_content.height());
38  EXPECT_EQ(0.8f, page->shrink_factor());
39
40  // Y centered.
41  page = new PrintedPage(1,
42                         NULL,
43                         gfx::Size(1200, 500),
44                         gfx::Rect(0, 0, 400, 1100),
45                         1.0f);
46  page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
47  EXPECT_EQ(0, page_content.x());
48  EXPECT_EQ(250, page_content.y());
49  EXPECT_EQ(400, page_content.width());
50  EXPECT_EQ(1100, page_content.height());
51  EXPECT_EQ(1.0f, page->shrink_factor());
52
53  // Both X and Y centered.
54  page = new PrintedPage(1,
55                         NULL,
56                         gfx::Size(500, 500),
57                         gfx::Rect(0, 0, 400, 1100),
58                         0.3f);
59  page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
60  EXPECT_EQ(250, page_content.x());
61  EXPECT_EQ(250, page_content.y());
62  EXPECT_EQ(400, page_content.width());
63  EXPECT_EQ(1100, page_content.height());
64  EXPECT_EQ(0.3f, page->shrink_factor());
65}
66
67}  // namespace printing
68