OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "chrome/common/chrome_switches.h" | 7 #include "chrome/common/chrome_switches.h" |
8 #include "chrome/common/print_messages.h" | 8 #include "chrome/common/print_messages.h" |
9 #include "chrome/renderer/printing/mock_printer.h" | 9 #include "chrome/renderer/printing/mock_printer.h" |
10 #include "chrome/renderer/printing/print_web_view_helper.h" | 10 #include "chrome/renderer/printing/print_web_view_helper.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // Tests that printing pages work and sending and receiving messages through | 236 // Tests that printing pages work and sending and receiving messages through |
237 // that channel all works. | 237 // that channel all works. |
238 TEST_F(PrintWebViewHelperTest, OnPrintPages) { | 238 TEST_F(PrintWebViewHelperTest, OnPrintPages) { |
239 LoadHTML(kHelloWorldHTML); | 239 LoadHTML(kHelloWorldHTML); |
240 OnPrintPages(); | 240 OnPrintPages(); |
241 | 241 |
242 VerifyPageCount(1); | 242 VerifyPageCount(1); |
243 VerifyPagesPrinted(true); | 243 VerifyPagesPrinted(true); |
244 } | 244 } |
245 | 245 |
246 #if (defined(OS_WIN) && !WIN_PDF_METAFILE_FOR_PRINTING) || defined(OS_MACOSX) | 246 #if defined(OS_MACOSX) |
247 // TODO(estade): I don't think this test is worth porting to Linux. We will have | 247 // TODO(estade): I don't think this test is worth porting to Linux. We will have |
248 // to rip out and replace most of the IPC code if we ever plan to improve | 248 // to rip out and replace most of the IPC code if we ever plan to improve |
249 // printing, and the comment below by sverrir suggests that it doesn't do much | 249 // printing, and the comment below by sverrir suggests that it doesn't do much |
250 // for us anyway. | 250 // for us anyway. |
251 TEST_F(PrintWebViewHelperTest, PrintWithIframe) { | 251 TEST_F(PrintWebViewHelperTest, PrintWithIframe) { |
252 // Document that populates an iframe. | 252 // Document that populates an iframe. |
253 const char html[] = | 253 const char html[] = |
254 "<html><body>Lorem Ipsum:" | 254 "<html><body>Lorem Ipsum:" |
255 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>" | 255 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>" |
256 " document.write(frames['sub1'].name);" | 256 " document.write(frames['sub1'].name);" |
(...skipping 20 matching lines...) Expand all Loading... |
277 const MockPrinter* printer(chrome_render_thread_->printer()); | 277 const MockPrinter* printer(chrome_render_thread_->printer()); |
278 ASSERT_EQ(1, printer->GetPrintedPages()); | 278 ASSERT_EQ(1, printer->GetPrintedPages()); |
279 const Image& image1(printer->GetPrintedPage(0)->image()); | 279 const Image& image1(printer->GetPrintedPage(0)->image()); |
280 | 280 |
281 // TODO(sverrir): Figure out a way to improve this test to actually print | 281 // TODO(sverrir): Figure out a way to improve this test to actually print |
282 // only the content of the iframe. Currently image1 will contain the full | 282 // only the content of the iframe. Currently image1 will contain the full |
283 // page. | 283 // page. |
284 EXPECT_NE(0, image1.size().width()); | 284 EXPECT_NE(0, image1.size().width()); |
285 EXPECT_NE(0, image1.size().height()); | 285 EXPECT_NE(0, image1.size().height()); |
286 } | 286 } |
287 #endif | 287 #endif // OS_MACOSX |
288 | 288 |
289 // Tests if we can print a page and verify its results. | 289 // Tests if we can print a page and verify its results. |
290 // This test prints HTML pages into a pseudo printer and check their outputs, | 290 // This test prints HTML pages into a pseudo printer and check their outputs, |
291 // i.e. a simplified version of the PrintingLayoutTextTest UI test. | 291 // i.e. a simplified version of the PrintingLayoutTextTest UI test. |
292 namespace { | 292 namespace { |
293 // Test cases used in this test. | 293 // Test cases used in this test. |
294 struct TestPageData { | 294 struct TestPageData { |
295 const char* page; | 295 const char* page; |
296 size_t printed_pages; | 296 size_t printed_pages; |
297 int width; | 297 int width; |
(...skipping 25 matching lines...) Expand all Loading... |
323 NULL, | 323 NULL, |
324 }, | 324 }, |
325 }; | 325 }; |
326 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 326 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
327 } // namespace | 327 } // namespace |
328 | 328 |
329 // TODO(estade): need to port MockPrinter to get this on Linux. This involves | 329 // TODO(estade): need to port MockPrinter to get this on Linux. This involves |
330 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the | 330 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the |
331 // metafile directly. | 331 // metafile directly. |
332 // Same for printing via PDF on Windows. | 332 // Same for printing via PDF on Windows. |
333 #if (defined(OS_WIN) && !WIN_PDF_METAFILE_FOR_PRINTING) || defined(OS_MACOSX) | 333 #if defined(OS_MACOSX) |
334 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { | 334 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { |
335 bool baseline = false; | 335 bool baseline = false; |
336 | 336 |
337 EXPECT_TRUE(chrome_render_thread_->printer() != NULL); | 337 EXPECT_TRUE(chrome_render_thread_->printer() != NULL); |
338 for (size_t i = 0; i < arraysize(kTestPages); ++i) { | 338 for (size_t i = 0; i < arraysize(kTestPages); ++i) { |
339 // Load an HTML page and print it. | 339 // Load an HTML page and print it. |
340 LoadHTML(kTestPages[i].page); | 340 LoadHTML(kTestPages[i].page); |
341 OnPrintPages(); | 341 OnPrintPages(); |
342 VerifyPagesPrinted(true); | 342 VerifyPagesPrinted(true); |
343 | 343 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 base::FilePath source_path; | 376 base::FilePath source_path; |
377 base::CreateTemporaryFile(&source_path); | 377 base::CreateTemporaryFile(&source_path); |
378 chrome_render_thread_->printer()->SaveSource(0, source_path); | 378 chrome_render_thread_->printer()->SaveSource(0, source_path); |
379 | 379 |
380 base::FilePath bitmap_path; | 380 base::FilePath bitmap_path; |
381 base::CreateTemporaryFile(&bitmap_path); | 381 base::CreateTemporaryFile(&bitmap_path); |
382 chrome_render_thread_->printer()->SaveBitmap(0, bitmap_path); | 382 chrome_render_thread_->printer()->SaveBitmap(0, bitmap_path); |
383 } | 383 } |
384 } | 384 } |
385 } | 385 } |
386 #endif | 386 #endif // OS_MACOSX |
387 | 387 |
388 // These print preview tests do not work on Chrome OS yet. | 388 // These print preview tests do not work on Chrome OS yet. |
389 #if !defined(OS_CHROMEOS) | 389 #if !defined(OS_CHROMEOS) |
390 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { | 390 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { |
391 public: | 391 public: |
392 PrintWebViewHelperPreviewTest() {} | 392 PrintWebViewHelperPreviewTest() {} |
393 virtual ~PrintWebViewHelperPreviewTest() {} | 393 virtual ~PrintWebViewHelperPreviewTest() {} |
394 | 394 |
395 protected: | 395 protected: |
396 void VerifyPrintPreviewCancelled(bool did_cancel) { | 396 void VerifyPrintPreviewCancelled(bool did_cancel) { |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 CreatePrintSettingsDictionary(&dict); | 907 CreatePrintSettingsDictionary(&dict); |
908 OnPrintForPrintPreview(dict); | 908 OnPrintForPrintPreview(dict); |
909 | 909 |
910 VerifyPrintFailed(true); | 910 VerifyPrintFailed(true); |
911 VerifyPagesPrinted(false); | 911 VerifyPagesPrinted(false); |
912 } | 912 } |
913 | 913 |
914 #endif // !defined(OS_CHROMEOS) | 914 #endif // !defined(OS_CHROMEOS) |
915 | 915 |
916 } // namespace printing | 916 } // namespace printing |
OLD | NEW |