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 8 namespace printing { 9 10 TEST(PrintedPageTest, GetCenteredPageContentRect) { 11 scoped_refptr<PrintedPage> page; 12 gfx::Rect page_content; 13 14 // No centering. 15 page = new PrintedPage( 16 1, NULL, gfx::Size(1200, 1200), gfx::Rect(0, 0, 400, 1100)); 17 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); 18 EXPECT_EQ(0, page_content.x()); 19 EXPECT_EQ(0, page_content.y()); 20 EXPECT_EQ(400, page_content.width()); 21 EXPECT_EQ(1100, page_content.height()); 22 23 // X centered. 24 page = new PrintedPage( 25 1, NULL, gfx::Size(500, 1200), gfx::Rect(0, 0, 400, 1100)); 26 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); 27 EXPECT_EQ(250, page_content.x()); 28 EXPECT_EQ(0, page_content.y()); 29 EXPECT_EQ(400, page_content.width()); 30 EXPECT_EQ(1100, page_content.height()); 31 32 // Y centered. 33 page = new PrintedPage( 34 1, NULL, gfx::Size(1200, 500), gfx::Rect(0, 0, 400, 1100)); 35 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); 36 EXPECT_EQ(0, page_content.x()); 37 EXPECT_EQ(250, page_content.y()); 38 EXPECT_EQ(400, page_content.width()); 39 EXPECT_EQ(1100, page_content.height()); 40 41 // Both X and Y centered. 42 page = 43 new PrintedPage(1, NULL, gfx::Size(500, 500), gfx::Rect(0, 0, 400, 1100)); 44 page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content); 45 EXPECT_EQ(250, page_content.x()); 46 EXPECT_EQ(250, page_content.y()); 47 EXPECT_EQ(400, page_content.width()); 48 EXPECT_EQ(1100, page_content.height()); 49 } 50 51 #if defined(OS_WIN) 52 TEST(PrintedPageTest, Shrink) { 53 scoped_refptr<PrintedPage> page = new PrintedPage( 54 1, NULL, gfx::Size(1200, 1200), gfx::Rect(0, 0, 400, 1100)); 55 EXPECT_EQ(0.0f, page->shrink_factor()); 56 page->set_shrink_factor(0.2f); 57 EXPECT_EQ(0.2f, page->shrink_factor()); 58 page->set_shrink_factor(0.7f); 59 EXPECT_EQ(0.7f, page->shrink_factor()); 60 } 61 #endif // OS_WIN 62 63 } // namespace printing 64