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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 PrintHostMsg_DidPrintPage::ID); | 181 PrintHostMsg_DidPrintPage::ID); |
182 bool did_print_msg = (NULL != print_msg); | 182 bool did_print_msg = (NULL != print_msg); |
183 ASSERT_EQ(printed, did_print_msg); | 183 ASSERT_EQ(printed, did_print_msg); |
184 if (printed) { | 184 if (printed) { |
185 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; | 185 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; |
186 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); | 186 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); |
187 EXPECT_EQ(0, post_did_print_page_param.a.page_number); | 187 EXPECT_EQ(0, post_did_print_page_param.a.page_number); |
188 } | 188 } |
189 #endif // defined(OS_CHROMEOS) | 189 #endif // defined(OS_CHROMEOS) |
190 } | 190 } |
191 | |
192 #if !defined(OS_WIN) | |
193 void OnPrintPages() { | 191 void OnPrintPages() { |
194 PrintWebViewHelper::Get(view_)->OnPrintPages(); | 192 PrintWebViewHelper::Get(view_)->OnPrintPages(); |
195 ProcessPendingMessages(); | 193 ProcessPendingMessages(); |
196 } | 194 } |
197 #endif // !OS_WIN | |
198 | 195 |
199 void VerifyPreviewRequest(bool requested) { | 196 void VerifyPreviewRequest(bool requested) { |
200 const IPC::Message* print_msg = | 197 const IPC::Message* print_msg = |
201 render_thread_->sink().GetUniqueMessageMatching( | 198 render_thread_->sink().GetUniqueMessageMatching( |
202 PrintHostMsg_SetupScriptedPrintPreview::ID); | 199 PrintHostMsg_SetupScriptedPrintPreview::ID); |
203 bool did_print_msg = (NULL != print_msg); | 200 bool did_print_msg = (NULL != print_msg); |
204 ASSERT_EQ(requested, did_print_msg); | 201 ASSERT_EQ(requested, did_print_msg); |
205 } | 202 } |
206 | 203 |
207 void OnPrintPreview(const base::DictionaryValue& dict) { | 204 void OnPrintPreview(const base::DictionaryValue& dict) { |
(...skipping 21 matching lines...) Expand all Loading... |
229 virtual ~PrintWebViewHelperTest() {} | 226 virtual ~PrintWebViewHelperTest() {} |
230 | 227 |
231 virtual void SetUp() OVERRIDE { | 228 virtual void SetUp() OVERRIDE { |
232 ChromeRenderViewTest::SetUp(); | 229 ChromeRenderViewTest::SetUp(); |
233 } | 230 } |
234 | 231 |
235 protected: | 232 protected: |
236 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); | 233 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); |
237 }; | 234 }; |
238 | 235 |
239 #if !defined(OS_WIN) | |
240 // Tests that printing pages work and sending and receiving messages through | 236 // Tests that printing pages work and sending and receiving messages through |
241 // that channel all works. | 237 // that channel all works. |
242 TEST_F(PrintWebViewHelperTest, OnPrintPages) { | 238 TEST_F(PrintWebViewHelperTest, OnPrintPages) { |
243 LoadHTML(kHelloWorldHTML); | 239 LoadHTML(kHelloWorldHTML); |
244 OnPrintPages(); | 240 OnPrintPages(); |
245 | 241 |
246 VerifyPageCount(1); | 242 VerifyPageCount(1); |
247 VerifyPagesPrinted(true); | 243 VerifyPagesPrinted(true); |
248 } | 244 } |
249 #endif // !OS_WIN | |
250 | 245 |
251 #if defined(OS_MACOSX) && !defined(OS_WIN) | 246 #if defined(OS_MACOSX) |
252 // 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 |
253 // 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 |
254 // 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 |
255 // for us anyway. | 250 // for us anyway. |
256 TEST_F(PrintWebViewHelperTest, PrintWithIframe) { | 251 TEST_F(PrintWebViewHelperTest, PrintWithIframe) { |
257 // Document that populates an iframe. | 252 // Document that populates an iframe. |
258 const char html[] = | 253 const char html[] = |
259 "<html><body>Lorem Ipsum:" | 254 "<html><body>Lorem Ipsum:" |
260 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>" | 255 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>" |
261 " document.write(frames['sub1'].name);" | 256 " document.write(frames['sub1'].name);" |
(...skipping 20 matching lines...) Expand all Loading... |
282 const MockPrinter* printer(chrome_render_thread_->printer()); | 277 const MockPrinter* printer(chrome_render_thread_->printer()); |
283 ASSERT_EQ(1, printer->GetPrintedPages()); | 278 ASSERT_EQ(1, printer->GetPrintedPages()); |
284 const Image& image1(printer->GetPrintedPage(0)->image()); | 279 const Image& image1(printer->GetPrintedPage(0)->image()); |
285 | 280 |
286 // 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 |
287 // 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 |
288 // page. | 283 // page. |
289 EXPECT_NE(0, image1.size().width()); | 284 EXPECT_NE(0, image1.size().width()); |
290 EXPECT_NE(0, image1.size().height()); | 285 EXPECT_NE(0, image1.size().height()); |
291 } | 286 } |
292 #endif // OS_MACOSX && !OS_WIN | 287 #endif // OS_MACOSX |
293 | 288 |
294 // Tests if we can print a page and verify its results. | 289 // Tests if we can print a page and verify its results. |
295 // 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, |
296 // i.e. a simplified version of the PrintingLayoutTextTest UI test. | 291 // i.e. a simplified version of the PrintingLayoutTextTest UI test. |
297 namespace { | 292 namespace { |
298 // Test cases used in this test. | 293 // Test cases used in this test. |
299 struct TestPageData { | 294 struct TestPageData { |
300 const char* page; | 295 const char* page; |
301 size_t printed_pages; | 296 size_t printed_pages; |
302 int width; | 297 int width; |
(...skipping 25 matching lines...) Expand all Loading... |
328 NULL, | 323 NULL, |
329 }, | 324 }, |
330 }; | 325 }; |
331 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 326 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
332 } // namespace | 327 } // namespace |
333 | 328 |
334 // 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 |
335 // 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 |
336 // metafile directly. | 331 // metafile directly. |
337 // Same for printing via PDF on Windows. | 332 // Same for printing via PDF on Windows. |
338 #if defined(OS_MACOSX) && !defined(OS_WIN) | 333 #if defined(OS_MACOSX) |
339 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { | 334 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { |
340 bool baseline = false; | 335 bool baseline = false; |
341 | 336 |
342 EXPECT_TRUE(chrome_render_thread_->printer() != NULL); | 337 EXPECT_TRUE(chrome_render_thread_->printer() != NULL); |
343 for (size_t i = 0; i < arraysize(kTestPages); ++i) { | 338 for (size_t i = 0; i < arraysize(kTestPages); ++i) { |
344 // Load an HTML page and print it. | 339 // Load an HTML page and print it. |
345 LoadHTML(kTestPages[i].page); | 340 LoadHTML(kTestPages[i].page); |
346 OnPrintPages(); | 341 OnPrintPages(); |
347 VerifyPagesPrinted(true); | 342 VerifyPagesPrinted(true); |
348 | 343 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 base::FilePath source_path; | 376 base::FilePath source_path; |
382 base::CreateTemporaryFile(&source_path); | 377 base::CreateTemporaryFile(&source_path); |
383 chrome_render_thread_->printer()->SaveSource(0, source_path); | 378 chrome_render_thread_->printer()->SaveSource(0, source_path); |
384 | 379 |
385 base::FilePath bitmap_path; | 380 base::FilePath bitmap_path; |
386 base::CreateTemporaryFile(&bitmap_path); | 381 base::CreateTemporaryFile(&bitmap_path); |
387 chrome_render_thread_->printer()->SaveBitmap(0, bitmap_path); | 382 chrome_render_thread_->printer()->SaveBitmap(0, bitmap_path); |
388 } | 383 } |
389 } | 384 } |
390 } | 385 } |
391 #endif // OS_MACOSX && !OS_WIN | 386 #endif // OS_MACOSX |
392 | 387 |
393 // These print preview tests do not work on Chrome OS yet. | 388 // These print preview tests do not work on Chrome OS yet. |
394 #if !defined(OS_CHROMEOS) | 389 #if !defined(OS_CHROMEOS) |
395 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { | 390 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { |
396 public: | 391 public: |
397 PrintWebViewHelperPreviewTest() {} | 392 PrintWebViewHelperPreviewTest() {} |
398 virtual ~PrintWebViewHelperPreviewTest() {} | 393 virtual ~PrintWebViewHelperPreviewTest() {} |
399 | 394 |
400 protected: | 395 protected: |
401 void VerifyPrintPreviewCancelled(bool did_cancel) { | 396 void VerifyPrintPreviewCancelled(bool did_cancel) { |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 CreatePrintSettingsDictionary(&dict); | 907 CreatePrintSettingsDictionary(&dict); |
913 OnPrintForPrintPreview(dict); | 908 OnPrintForPrintPreview(dict); |
914 | 909 |
915 VerifyPrintFailed(true); | 910 VerifyPrintFailed(true); |
916 VerifyPagesPrinted(false); | 911 VerifyPagesPrinted(false); |
917 } | 912 } |
918 | 913 |
919 #endif // !defined(OS_CHROMEOS) | 914 #endif // !defined(OS_CHROMEOS) |
920 | 915 |
921 } // namespace printing | 916 } // namespace printing |
OLD | NEW |