OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/printed_page.h" | 5 #include "printing/printed_page.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace printing { | 8 namespace printing { |
9 | 9 |
10 TEST(PrintedPageTest, GetCenteredPageContentRect) { | 10 TEST(PrintedPageTest, GetCenteredPageContentRect) { |
11 scoped_refptr<PrintedPage> page; | 11 scoped_refptr<PrintedPage> page; |
12 gfx::Rect page_content; | 12 gfx::Rect page_content; |
13 | 13 |
14 // No centering. | 14 // No centering. |
15 page = new PrintedPage(1, | 15 page = new PrintedPage(1, std::unique_ptr<MetafilePlayer>(), |
16 scoped_ptr<MetafilePlayer>(), | 16 gfx::Size(1200, 1200), gfx::Rect(0, 0, 400, 1100)); |
17 gfx::Size(1200, 1200), | |
18 gfx::Rect(0, 0, 400, 1100)); | |
19 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); | 17 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); |
20 EXPECT_EQ(0, page_content.x()); | 18 EXPECT_EQ(0, page_content.x()); |
21 EXPECT_EQ(0, page_content.y()); | 19 EXPECT_EQ(0, page_content.y()); |
22 EXPECT_EQ(400, page_content.width()); | 20 EXPECT_EQ(400, page_content.width()); |
23 EXPECT_EQ(1100, page_content.height()); | 21 EXPECT_EQ(1100, page_content.height()); |
24 | 22 |
25 // X centered. | 23 // X centered. |
26 page = new PrintedPage(1, | 24 page = new PrintedPage(1, std::unique_ptr<MetafilePlayer>(), |
27 scoped_ptr<MetafilePlayer>(), | 25 gfx::Size(500, 1200), gfx::Rect(0, 0, 400, 1100)); |
28 gfx::Size(500, 1200), | |
29 gfx::Rect(0, 0, 400, 1100)); | |
30 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); | 26 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); |
31 EXPECT_EQ(250, page_content.x()); | 27 EXPECT_EQ(250, page_content.x()); |
32 EXPECT_EQ(0, page_content.y()); | 28 EXPECT_EQ(0, page_content.y()); |
33 EXPECT_EQ(400, page_content.width()); | 29 EXPECT_EQ(400, page_content.width()); |
34 EXPECT_EQ(1100, page_content.height()); | 30 EXPECT_EQ(1100, page_content.height()); |
35 | 31 |
36 // Y centered. | 32 // Y centered. |
37 page = new PrintedPage(1, | 33 page = new PrintedPage(1, std::unique_ptr<MetafilePlayer>(), |
38 scoped_ptr<MetafilePlayer>(), | 34 gfx::Size(1200, 500), gfx::Rect(0, 0, 400, 1100)); |
39 gfx::Size(1200, 500), | |
40 gfx::Rect(0, 0, 400, 1100)); | |
41 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); | 35 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); |
42 EXPECT_EQ(0, page_content.x()); | 36 EXPECT_EQ(0, page_content.x()); |
43 EXPECT_EQ(250, page_content.y()); | 37 EXPECT_EQ(250, page_content.y()); |
44 EXPECT_EQ(400, page_content.width()); | 38 EXPECT_EQ(400, page_content.width()); |
45 EXPECT_EQ(1100, page_content.height()); | 39 EXPECT_EQ(1100, page_content.height()); |
46 | 40 |
47 // Both X and Y centered. | 41 // Both X and Y centered. |
48 page = new PrintedPage(1, | 42 page = new PrintedPage(1, std::unique_ptr<MetafilePlayer>(), |
49 scoped_ptr<MetafilePlayer>(), | 43 gfx::Size(500, 500), gfx::Rect(0, 0, 400, 1100)); |
50 gfx::Size(500, 500), | |
51 gfx::Rect(0, 0, 400, 1100)); | |
52 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); | 44 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); |
53 EXPECT_EQ(250, page_content.x()); | 45 EXPECT_EQ(250, page_content.x()); |
54 EXPECT_EQ(250, page_content.y()); | 46 EXPECT_EQ(250, page_content.y()); |
55 EXPECT_EQ(400, page_content.width()); | 47 EXPECT_EQ(400, page_content.width()); |
56 EXPECT_EQ(1100, page_content.height()); | 48 EXPECT_EQ(1100, page_content.height()); |
57 } | 49 } |
58 | 50 |
59 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
60 TEST(PrintedPageTest, Shrink) { | 52 TEST(PrintedPageTest, Shrink) { |
61 scoped_refptr<PrintedPage> page = | 53 scoped_refptr<PrintedPage> page = |
62 new PrintedPage(1, | 54 new PrintedPage(1, std::unique_ptr<MetafilePlayer>(), |
63 scoped_ptr<MetafilePlayer>(), | 55 gfx::Size(1200, 1200), gfx::Rect(0, 0, 400, 1100)); |
64 gfx::Size(1200, 1200), | |
65 gfx::Rect(0, 0, 400, 1100)); | |
66 EXPECT_EQ(0.0f, page->shrink_factor()); | 56 EXPECT_EQ(0.0f, page->shrink_factor()); |
67 page->set_shrink_factor(0.2f); | 57 page->set_shrink_factor(0.2f); |
68 EXPECT_EQ(0.2f, page->shrink_factor()); | 58 EXPECT_EQ(0.2f, page->shrink_factor()); |
69 page->set_shrink_factor(0.7f); | 59 page->set_shrink_factor(0.7f); |
70 EXPECT_EQ(0.7f, page->shrink_factor()); | 60 EXPECT_EQ(0.7f, page->shrink_factor()); |
71 } | 61 } |
72 #endif // OS_WIN | 62 #endif // OS_WIN |
73 | 63 |
74 } // namespace printing | 64 } // namespace printing |
OLD | NEW |