Index: printing/page_setup_unittest.cc |
diff --git a/printing/page_setup_unittest.cc b/printing/page_setup_unittest.cc |
index 54e436c27d28a3e7e04f1c1878fcc823be7a2fe1..6f8a50bd0f160ab6de594d2374ea54d1a45b71a9 100644 |
--- a/printing/page_setup_unittest.cc |
+++ b/printing/page_setup_unittest.cc |
@@ -190,3 +190,117 @@ TEST(PageSetupTest, OutOfRangeMargins) { |
EXPECT_EQ(setup.effective_margins().right, 0); |
EXPECT_EQ(setup.effective_margins().bottom, 0); |
} |
+ |
+TEST(PageSetupTest, FlipOrientation) { |
+ // Margins. |
+ printing::PageMargins margins; |
+ margins.header = 2; |
+ margins.footer = 2; |
+ margins.left = 4; |
+ margins.top = 14; |
+ margins.right = 5; |
+ margins.bottom = 7; |
+ int kTextHeight = 3; |
+ |
+ // Page description. |
+ gfx::Size page_size(100, 70); |
+ gfx::Rect printable_area(3, 3, 92, 50); |
vandebo (ex-Chrome)
2011/11/03 17:26:35
Try to use all unique values so that things don't
kmadhusu
2011/11/03 20:46:54
Done.
|
+ |
+ // Make the calculations. |
+ printing::PageSetup setup; |
+ setup.Init(page_size, printable_area, kTextHeight); |
+ setup.SetRequestedMargins(margins); |
+ |
+ // Calculate the effective margins. |
vandebo (ex-Chrome)
2011/11/03 17:26:35
I'd rather just hardcode the expected values than
kmadhusu
2011/11/03 20:46:54
Done.
|
+ printing::PageMargins effective_margins; |
+ effective_margins.header = std::max(margins.header, printable_area.y()); |
+ effective_margins.left = std::max(margins.left, printable_area.x()); |
+ effective_margins.top = std::max(margins.top, |
+ effective_margins.header + kTextHeight); |
+ effective_margins.footer = std::max(margins.footer, |
+ page_size.height() - |
+ printable_area.bottom()); |
+ effective_margins.right = std::max(margins.right, |
+ page_size.width() - |
+ printable_area.right()); |
+ effective_margins.bottom = std::max(margins.bottom, |
+ effective_margins.footer + kTextHeight); |
+ |
+ // Calculate the overlay area. |
+ gfx::Rect overlay_area(effective_margins.left, effective_margins.header, |
+ page_size.width() - effective_margins.right - |
+ effective_margins.left, |
+ page_size.height() - effective_margins.footer - |
+ effective_margins.header); |
+ |
+ // Calculate the content area. |
+ gfx::Rect content_area(overlay_area.x(), |
+ effective_margins.top, |
+ overlay_area.width(), |
+ page_size.height() - effective_margins.bottom - |
+ effective_margins.top); |
+ |
+ // Test values. |
+ EXPECT_EQ(page_size, setup.physical_size()); |
+ EXPECT_EQ(overlay_area, setup.overlay_area()) << " " << |
+ page_size.ToString() << " " << printable_area.ToString() << |
vandebo (ex-Chrome)
2011/11/03 17:26:35
won't EXPECT_EQ print the observed and expected va
kmadhusu
2011/11/03 20:46:54
I removed these additional info. It works fine.
|
+ " " << kTextHeight; |
+ EXPECT_EQ(content_area, setup.content_area()) << " " << |
+ page_size.ToString() << " " << printable_area.ToString() << |
+ " " << kTextHeight; |
+ |
+ EXPECT_EQ(setup.effective_margins().left, 4); |
+ EXPECT_EQ(setup.effective_margins().top, 14); |
+ EXPECT_EQ(setup.effective_margins().right, 5); |
+ EXPECT_EQ(setup.effective_margins().bottom, 20); |
+ |
+ // Flip the orientation |
+ setup.FlipOrientation(); |
+ |
+ // Expected values. |
+ gfx::Size flipped_page_size(70, 100); |
+ gfx::Rect flipped_printable_area(3, 5, 50, 92); |
+ gfx::Rect flipped_overlay_area(14, 5, 39, 92); |
+ gfx::Rect flipped_content_area(14, 8, 39, 86); |
+ |
+ // Test values. |
+ EXPECT_EQ(flipped_page_size, setup.physical_size()); |
+ EXPECT_EQ(flipped_overlay_area, setup.overlay_area()) << " " << |
+ flipped_page_size.ToString() << " " << flipped_printable_area.ToString(); |
+ EXPECT_EQ(flipped_content_area, setup.content_area()) << " " << |
+ flipped_page_size.ToString() << " " << flipped_printable_area.ToString(); |
+ EXPECT_EQ(flipped_printable_area, setup.printable_area()); |
+ |
+ // Margin values are updated as per the flipped values. |
+ EXPECT_EQ(setup.effective_margins().left, 14); |
+ EXPECT_EQ(setup.effective_margins().top, 8); |
+ EXPECT_EQ(setup.effective_margins().right, 17); |
+ EXPECT_EQ(setup.effective_margins().bottom, 6); |
+ |
+ // Force requested margins and flip the orientation. |
+ setup.Init(page_size, printable_area, kTextHeight); |
+ setup.ForceRequestedMargins(margins); |
+ EXPECT_EQ(setup.effective_margins().left, 4); |
+ EXPECT_EQ(setup.effective_margins().top, 14); |
+ EXPECT_EQ(setup.effective_margins().right, 5); |
+ EXPECT_EQ(setup.effective_margins().bottom, 7); |
+ |
+ // Flip the orientation |
+ setup.FlipOrientation(); |
+ |
+ // Expected values. |
+ gfx::Rect new_overlay_area(14, 2, 49, 96); |
+ gfx::Rect new_content_area(14, 5, 49, 91); |
+ |
+ // Test values. |
+ EXPECT_EQ(flipped_page_size, setup.physical_size()); |
+ EXPECT_EQ(new_overlay_area, setup.overlay_area()); |
+ EXPECT_EQ(new_content_area, setup.content_area()); |
+ EXPECT_EQ(flipped_printable_area, setup.printable_area()); |
+ |
+ // Margins values are changed respectively. |
+ EXPECT_EQ(setup.effective_margins().left,14); |
+ EXPECT_EQ(setup.effective_margins().top, 5); |
+ EXPECT_EQ(setup.effective_margins().right, 7); |
+ EXPECT_EQ(setup.effective_margins().bottom, 4); |
+} |