| 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, |
| 16 NULL, | 16 NULL, |
| 17 gfx::Size(1200, 1200), | 17 gfx::Size(1200, 1200), |
| 18 gfx::Rect(0, 0, 400, 1100)); | 18 gfx::Rect(0, 0, 400, 1100), |
| 19 0.2f); |
| 19 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); | 20 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); |
| 20 EXPECT_EQ(0, page_content.x()); | 21 EXPECT_EQ(0, page_content.x()); |
| 21 EXPECT_EQ(0, page_content.y()); | 22 EXPECT_EQ(0, page_content.y()); |
| 22 EXPECT_EQ(400, page_content.width()); | 23 EXPECT_EQ(400, page_content.width()); |
| 23 EXPECT_EQ(1100, page_content.height()); | 24 EXPECT_EQ(1100, page_content.height()); |
| 25 EXPECT_EQ(0.2f, page->shrink_factor()); |
| 24 | 26 |
| 25 // X centered. | 27 // X centered. |
| 26 page = new PrintedPage(1, | 28 page = new PrintedPage(1, |
| 27 NULL, | 29 NULL, |
| 28 gfx::Size(500, 1200), | 30 gfx::Size(500, 1200), |
| 29 gfx::Rect(0, 0, 400, 1100)); | 31 gfx::Rect(0, 0, 400, 1100), |
| 32 0.8f); |
| 30 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); | 33 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); |
| 31 EXPECT_EQ(250, page_content.x()); | 34 EXPECT_EQ(250, page_content.x()); |
| 32 EXPECT_EQ(0, page_content.y()); | 35 EXPECT_EQ(0, page_content.y()); |
| 33 EXPECT_EQ(400, page_content.width()); | 36 EXPECT_EQ(400, page_content.width()); |
| 34 EXPECT_EQ(1100, page_content.height()); | 37 EXPECT_EQ(1100, page_content.height()); |
| 38 EXPECT_EQ(0.8f, page->shrink_factor()); |
| 35 | 39 |
| 36 // Y centered. | 40 // Y centered. |
| 37 page = new PrintedPage(1, | 41 page = new PrintedPage(1, |
| 38 NULL, | 42 NULL, |
| 39 gfx::Size(1200, 500), | 43 gfx::Size(1200, 500), |
| 40 gfx::Rect(0, 0, 400, 1100)); | 44 gfx::Rect(0, 0, 400, 1100), |
| 45 1.0f); |
| 41 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); | 46 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); |
| 42 EXPECT_EQ(0, page_content.x()); | 47 EXPECT_EQ(0, page_content.x()); |
| 43 EXPECT_EQ(250, page_content.y()); | 48 EXPECT_EQ(250, page_content.y()); |
| 44 EXPECT_EQ(400, page_content.width()); | 49 EXPECT_EQ(400, page_content.width()); |
| 45 EXPECT_EQ(1100, page_content.height()); | 50 EXPECT_EQ(1100, page_content.height()); |
| 51 EXPECT_EQ(1.0f, page->shrink_factor()); |
| 46 | 52 |
| 47 // Both X and Y centered. | 53 // Both X and Y centered. |
| 48 page = new PrintedPage(1, | 54 page = new PrintedPage(1, |
| 49 NULL, | 55 NULL, |
| 50 gfx::Size(500, 500), | 56 gfx::Size(500, 500), |
| 51 gfx::Rect(0, 0, 400, 1100)); | 57 gfx::Rect(0, 0, 400, 1100), |
| 58 0.3f); |
| 52 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); | 59 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); |
| 53 EXPECT_EQ(250, page_content.x()); | 60 EXPECT_EQ(250, page_content.x()); |
| 54 EXPECT_EQ(250, page_content.y()); | 61 EXPECT_EQ(250, page_content.y()); |
| 55 EXPECT_EQ(400, page_content.width()); | 62 EXPECT_EQ(400, page_content.width()); |
| 56 EXPECT_EQ(1100, page_content.height()); | 63 EXPECT_EQ(1100, page_content.height()); |
| 64 EXPECT_EQ(0.3f, page->shrink_factor()); |
| 57 } | 65 } |
| 58 | 66 |
| 59 } // namespace printing | 67 } // namespace printing |
| OLD | NEW |