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/page_setup.h" | 5 #include "printing/page_setup.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <time.h> | 8 #include <time.h> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 EXPECT_EQ(setup.effective_margins().top, 2); | 183 EXPECT_EQ(setup.effective_margins().top, 2); |
184 EXPECT_EQ(setup.effective_margins().right, 3); | 184 EXPECT_EQ(setup.effective_margins().right, 3); |
185 EXPECT_EQ(setup.effective_margins().bottom, 4); | 185 EXPECT_EQ(setup.effective_margins().bottom, 4); |
186 | 186 |
187 setup.ForceRequestedMargins(margins); | 187 setup.ForceRequestedMargins(margins); |
188 EXPECT_EQ(setup.effective_margins().left, 0); | 188 EXPECT_EQ(setup.effective_margins().left, 0); |
189 EXPECT_EQ(setup.effective_margins().top, 0); | 189 EXPECT_EQ(setup.effective_margins().top, 0); |
190 EXPECT_EQ(setup.effective_margins().right, 0); | 190 EXPECT_EQ(setup.effective_margins().right, 0); |
191 EXPECT_EQ(setup.effective_margins().bottom, 0); | 191 EXPECT_EQ(setup.effective_margins().bottom, 0); |
192 } | 192 } |
193 | |
194 TEST(PageSetupTest, FlipOrientation) { | |
195 // Margins. | |
196 printing::PageMargins margins; | |
197 margins.header = 2; | |
198 margins.footer = 2; | |
199 margins.left = 4; | |
200 margins.top = 14; | |
201 margins.right = 5; | |
202 margins.bottom = 7; | |
203 int kTextHeight = 3; | |
204 | |
205 // Page description. | |
206 gfx::Size page_size(100, 70); | |
207 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.
| |
208 | |
209 // Make the calculations. | |
210 printing::PageSetup setup; | |
211 setup.Init(page_size, printable_area, kTextHeight); | |
212 setup.SetRequestedMargins(margins); | |
213 | |
214 // 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.
| |
215 printing::PageMargins effective_margins; | |
216 effective_margins.header = std::max(margins.header, printable_area.y()); | |
217 effective_margins.left = std::max(margins.left, printable_area.x()); | |
218 effective_margins.top = std::max(margins.top, | |
219 effective_margins.header + kTextHeight); | |
220 effective_margins.footer = std::max(margins.footer, | |
221 page_size.height() - | |
222 printable_area.bottom()); | |
223 effective_margins.right = std::max(margins.right, | |
224 page_size.width() - | |
225 printable_area.right()); | |
226 effective_margins.bottom = std::max(margins.bottom, | |
227 effective_margins.footer + kTextHeight); | |
228 | |
229 // Calculate the overlay area. | |
230 gfx::Rect overlay_area(effective_margins.left, effective_margins.header, | |
231 page_size.width() - effective_margins.right - | |
232 effective_margins.left, | |
233 page_size.height() - effective_margins.footer - | |
234 effective_margins.header); | |
235 | |
236 // Calculate the content area. | |
237 gfx::Rect content_area(overlay_area.x(), | |
238 effective_margins.top, | |
239 overlay_area.width(), | |
240 page_size.height() - effective_margins.bottom - | |
241 effective_margins.top); | |
242 | |
243 // Test values. | |
244 EXPECT_EQ(page_size, setup.physical_size()); | |
245 EXPECT_EQ(overlay_area, setup.overlay_area()) << " " << | |
246 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.
| |
247 " " << kTextHeight; | |
248 EXPECT_EQ(content_area, setup.content_area()) << " " << | |
249 page_size.ToString() << " " << printable_area.ToString() << | |
250 " " << kTextHeight; | |
251 | |
252 EXPECT_EQ(setup.effective_margins().left, 4); | |
253 EXPECT_EQ(setup.effective_margins().top, 14); | |
254 EXPECT_EQ(setup.effective_margins().right, 5); | |
255 EXPECT_EQ(setup.effective_margins().bottom, 20); | |
256 | |
257 // Flip the orientation | |
258 setup.FlipOrientation(); | |
259 | |
260 // Expected values. | |
261 gfx::Size flipped_page_size(70, 100); | |
262 gfx::Rect flipped_printable_area(3, 5, 50, 92); | |
263 gfx::Rect flipped_overlay_area(14, 5, 39, 92); | |
264 gfx::Rect flipped_content_area(14, 8, 39, 86); | |
265 | |
266 // Test values. | |
267 EXPECT_EQ(flipped_page_size, setup.physical_size()); | |
268 EXPECT_EQ(flipped_overlay_area, setup.overlay_area()) << " " << | |
269 flipped_page_size.ToString() << " " << flipped_printable_area.ToString(); | |
270 EXPECT_EQ(flipped_content_area, setup.content_area()) << " " << | |
271 flipped_page_size.ToString() << " " << flipped_printable_area.ToString(); | |
272 EXPECT_EQ(flipped_printable_area, setup.printable_area()); | |
273 | |
274 // Margin values are updated as per the flipped values. | |
275 EXPECT_EQ(setup.effective_margins().left, 14); | |
276 EXPECT_EQ(setup.effective_margins().top, 8); | |
277 EXPECT_EQ(setup.effective_margins().right, 17); | |
278 EXPECT_EQ(setup.effective_margins().bottom, 6); | |
279 | |
280 // Force requested margins and flip the orientation. | |
281 setup.Init(page_size, printable_area, kTextHeight); | |
282 setup.ForceRequestedMargins(margins); | |
283 EXPECT_EQ(setup.effective_margins().left, 4); | |
284 EXPECT_EQ(setup.effective_margins().top, 14); | |
285 EXPECT_EQ(setup.effective_margins().right, 5); | |
286 EXPECT_EQ(setup.effective_margins().bottom, 7); | |
287 | |
288 // Flip the orientation | |
289 setup.FlipOrientation(); | |
290 | |
291 // Expected values. | |
292 gfx::Rect new_overlay_area(14, 2, 49, 96); | |
293 gfx::Rect new_content_area(14, 5, 49, 91); | |
294 | |
295 // Test values. | |
296 EXPECT_EQ(flipped_page_size, setup.physical_size()); | |
297 EXPECT_EQ(new_overlay_area, setup.overlay_area()); | |
298 EXPECT_EQ(new_content_area, setup.content_area()); | |
299 EXPECT_EQ(flipped_printable_area, setup.printable_area()); | |
300 | |
301 // Margins values are changed respectively. | |
302 EXPECT_EQ(setup.effective_margins().left,14); | |
303 EXPECT_EQ(setup.effective_margins().top, 5); | |
304 EXPECT_EQ(setup.effective_margins().right, 7); | |
305 EXPECT_EQ(setup.effective_margins().bottom, 4); | |
306 } | |
OLD | NEW |