summaryrefslogtreecommitdiff
path: root/chromium/printing/printed_page_unittest.cc
blob: 9cce52a1cb831640511f485b25b1b82f3c76a060 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "printing/printed_page.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace printing {

TEST(PrintedPageTest, GetCenteredPageContentRect) {
  scoped_refptr<PrintedPage> page;
  gfx::Rect page_content;

  // No centering.
  page = new PrintedPage(1,
                         NULL,
                         gfx::Size(1200, 1200),
                         gfx::Rect(0, 0, 400, 1100),
                         0.2f);
  page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
  EXPECT_EQ(0, page_content.x());
  EXPECT_EQ(0, page_content.y());
  EXPECT_EQ(400, page_content.width());
  EXPECT_EQ(1100, page_content.height());
  EXPECT_EQ(0.2f, page->shrink_factor());

  // X centered.
  page = new PrintedPage(1,
                         NULL,
                         gfx::Size(500, 1200),
                         gfx::Rect(0, 0, 400, 1100),
                         0.8f);
  page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
  EXPECT_EQ(250, page_content.x());
  EXPECT_EQ(0, page_content.y());
  EXPECT_EQ(400, page_content.width());
  EXPECT_EQ(1100, page_content.height());
  EXPECT_EQ(0.8f, page->shrink_factor());

  // Y centered.
  page = new PrintedPage(1,
                         NULL,
                         gfx::Size(1200, 500),
                         gfx::Rect(0, 0, 400, 1100),
                         1.0f);
  page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
  EXPECT_EQ(0, page_content.x());
  EXPECT_EQ(250, page_content.y());
  EXPECT_EQ(400, page_content.width());
  EXPECT_EQ(1100, page_content.height());
  EXPECT_EQ(1.0f, page->shrink_factor());

  // Both X and Y centered.
  page = new PrintedPage(1,
                         NULL,
                         gfx::Size(500, 500),
                         gfx::Rect(0, 0, 400, 1100),
                         0.3f);
  page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
  EXPECT_EQ(250, page_content.x());
  EXPECT_EQ(250, page_content.y());
  EXPECT_EQ(400, page_content.width());
  EXPECT_EQ(1100, page_content.height());
  EXPECT_EQ(0.3f, page->shrink_factor());
}

}  // namespace printing