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 "chrome/common/chrome_switches.h" | 5 #include "chrome/common/chrome_switches.h" |
6 #include "chrome/common/print_messages.h" | 6 #include "chrome/common/print_messages.h" |
7 #include "chrome/renderer/print_web_view_helper.h" | 7 #include "chrome/renderer/print_web_view_helper.h" |
8 #include "chrome/test/render_view_test.h" | 8 #include "chrome/test/render_view_test.h" |
9 #include "printing/print_job_constants.h" | 9 #include "printing/print_job_constants.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // Append the print preview switch before creating the PrintWebViewHelper. | 304 // Append the print preview switch before creating the PrintWebViewHelper. |
305 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_MACOSX) | 305 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_MACOSX) |
306 CommandLine::ForCurrentProcess()->AppendSwitch( | 306 CommandLine::ForCurrentProcess()->AppendSwitch( |
307 switches::kEnablePrintPreview); | 307 switches::kEnablePrintPreview); |
308 #endif | 308 #endif |
309 | 309 |
310 RenderViewTest::SetUp(); | 310 RenderViewTest::SetUp(); |
311 } | 311 } |
312 | 312 |
313 protected: | 313 protected: |
314 void VerifyPrintPreviewCancelled(bool did_cancel) { | |
315 bool print_preview_cancelled = | |
316 (render_thread_.sink().GetUniqueMessageMatching( | |
317 PrintHostMsg_PrintPreviewCancelled::ID) != NULL); | |
318 EXPECT_EQ(did_cancel, print_preview_cancelled); | |
319 } | |
320 | |
321 void VerifyPrintPreviewFailed(bool did_fail) { | 314 void VerifyPrintPreviewFailed(bool did_fail) { |
322 bool print_preview_failed = (render_thread_.sink().GetUniqueMessageMatching( | 315 bool print_preview_failed = (render_thread_.sink().GetUniqueMessageMatching( |
323 PrintHostMsg_PrintPreviewFailed::ID) != NULL); | 316 PrintHostMsg_PrintPreviewFailed::ID) != NULL); |
324 EXPECT_EQ(did_fail, print_preview_failed); | 317 EXPECT_EQ(did_fail, print_preview_failed); |
325 } | 318 } |
326 | 319 |
327 void VerifyPrintPreviewGenerated(bool generated_preview) { | 320 void VerifyPrintPreviewGenerated(bool generated_preview) { |
328 const IPC::Message* preview_msg = | 321 const IPC::Message* preview_msg = |
329 render_thread_.sink().GetUniqueMessageMatching( | 322 render_thread_.sink().GetUniqueMessageMatching( |
330 PrintHostMsg_PagesReadyForPreview::ID); | 323 PrintHostMsg_PagesReadyForPreview::ID); |
(...skipping 15 matching lines...) Expand all Loading... |
346 } | 339 } |
347 | 340 |
348 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); | 341 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); |
349 }; | 342 }; |
350 | 343 |
351 // Tests that print preview work and sending and receiving messages through | 344 // Tests that print preview work and sending and receiving messages through |
352 // that channel all works. | 345 // that channel all works. |
353 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { | 346 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { |
354 LoadHTML(kHelloWorldHTML); | 347 LoadHTML(kHelloWorldHTML); |
355 | 348 |
| 349 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); |
356 // Fill in some dummy values. | 350 // Fill in some dummy values. |
357 DictionaryValue dict; | 351 DictionaryValue dict; |
358 CreatePrintSettingsDictionary(&dict); | 352 CreatePrintSettingsDictionary(&dict); |
359 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); | 353 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); |
360 | 354 |
361 VerifyPrintPreviewCancelled(false); | 355 // Need to finish simulating print preview. |
| 356 // Generate the page and finalize it. |
| 357 PrintWebViewHelper::Get(view_)->OnContinuePreview(); |
| 358 PrintWebViewHelper::Get(view_)->OnContinuePreview(); |
| 359 |
| 360 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); |
362 VerifyPrintPreviewFailed(false); | 361 VerifyPrintPreviewFailed(false); |
363 VerifyPrintPreviewGenerated(true); | 362 VerifyPrintPreviewGenerated(true); |
364 VerifyPagesPrinted(false); | 363 VerifyPagesPrinted(false); |
365 } | 364 } |
366 | 365 |
367 // Tests that cancelling a print preview works correctly. | |
368 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel) { | |
369 LoadHTML(kPrintPreviewHTML); | |
370 | |
371 // Cancel the print preview. | |
372 render_thread_.set_cancel_print_preview(true); | |
373 | |
374 // Fill in some dummy values. | |
375 DictionaryValue dict; | |
376 CreatePrintSettingsDictionary(&dict); | |
377 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); | |
378 | |
379 VerifyPrintPreviewCancelled(true); | |
380 VerifyPrintPreviewFailed(false); | |
381 VerifyPrintPreviewGenerated(false); | |
382 VerifyPagesPrinted(false); | |
383 } | |
384 | |
385 // Tests that print preview fails and receiving error messages through | 366 // Tests that print preview fails and receiving error messages through |
386 // that channel all works. | 367 // that channel all works. |
387 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { | 368 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { |
388 LoadHTML(kHelloWorldHTML); | 369 LoadHTML(kHelloWorldHTML); |
389 | 370 |
| 371 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); |
390 // An empty dictionary should fail. | 372 // An empty dictionary should fail. |
391 DictionaryValue empty_dict; | 373 DictionaryValue empty_dict; |
392 PrintWebViewHelper::Get(view_)->OnPrintPreview(empty_dict); | 374 PrintWebViewHelper::Get(view_)->OnPrintPreview(empty_dict); |
393 | 375 |
394 VerifyPrintPreviewCancelled(false); | 376 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); |
395 VerifyPrintPreviewFailed(true); | 377 VerifyPrintPreviewFailed(true); |
396 VerifyPrintPreviewGenerated(false); | 378 VerifyPrintPreviewGenerated(false); |
397 VerifyPagesPrinted(false); | 379 VerifyPagesPrinted(false); |
398 } | 380 } |
399 | 381 |
400 // Tests that printing from print preview works and sending and receiving | 382 // Tests that printing from print preview works and sending and receiving |
401 // messages through that channel all works. | 383 // messages through that channel all works. |
402 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { | 384 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { |
403 LoadHTML(kPrintPreviewHTML); | 385 LoadHTML(kPrintPreviewHTML); |
404 | 386 |
(...skipping 12 matching lines...) Expand all Loading... |
417 LoadHTML(kPrintPreviewHTML); | 399 LoadHTML(kPrintPreviewHTML); |
418 | 400 |
419 // An empty dictionary should fail. | 401 // An empty dictionary should fail. |
420 DictionaryValue empty_dict; | 402 DictionaryValue empty_dict; |
421 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict); | 403 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict); |
422 | 404 |
423 VerifyPrintFailed(true); | 405 VerifyPrintFailed(true); |
424 VerifyPagesPrinted(false); | 406 VerifyPagesPrinted(false); |
425 } | 407 } |
426 #endif // !defined(OS_CHROMEOS) | 408 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |