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