Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: chrome/renderer/print_web_view_helper_browsertest.cc

Issue 7647010: Print preview page selection should not require a rerendering of draft pages. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix win browser_test failures. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/base/render_view_test.h" 8 #include "chrome/test/base/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 25 matching lines...) Expand all
36 void CreatePrintSettingsDictionary(DictionaryValue* dict) { 36 void CreatePrintSettingsDictionary(DictionaryValue* dict) {
37 dict->SetBoolean(printing::kSettingLandscape, false); 37 dict->SetBoolean(printing::kSettingLandscape, false);
38 dict->SetBoolean(printing::kSettingCollate, false); 38 dict->SetBoolean(printing::kSettingCollate, false);
39 dict->SetBoolean(printing::kSettingColor, false); 39 dict->SetBoolean(printing::kSettingColor, false);
40 dict->SetBoolean(printing::kSettingPrintToPDF, true); 40 dict->SetBoolean(printing::kSettingPrintToPDF, true);
41 dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX); 41 dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX);
42 dict->SetInteger(printing::kSettingCopies, 1); 42 dict->SetInteger(printing::kSettingCopies, 1);
43 dict->SetString(printing::kSettingDeviceName, "dummy"); 43 dict->SetString(printing::kSettingDeviceName, "dummy");
44 dict->SetInteger(printing::kPreviewRequestID, 12345); 44 dict->SetInteger(printing::kPreviewRequestID, 12345);
45 dict->SetBoolean(printing::kIsFirstRequest, true); 45 dict->SetBoolean(printing::kIsFirstRequest, true);
46 dict->SetBoolean(printing::kSettingGenerateDraftData, true);
46 } 47 }
47 48
48 } // namespace 49 } // namespace
49 50
50 class PrintWebViewHelperTestBase : public RenderViewTest { 51 class PrintWebViewHelperTestBase : public RenderViewTest {
51 public: 52 public:
52 PrintWebViewHelperTestBase() {} 53 PrintWebViewHelperTestBase() {}
53 ~PrintWebViewHelperTestBase() {} 54 ~PrintWebViewHelperTestBase() {}
54 55
55 protected: 56 protected:
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 protected: 315 protected:
315 void VerifyPrintPreviewFailed(bool did_fail) { 316 void VerifyPrintPreviewFailed(bool did_fail) {
316 bool print_preview_failed = (render_thread_.sink().GetUniqueMessageMatching( 317 bool print_preview_failed = (render_thread_.sink().GetUniqueMessageMatching(
317 PrintHostMsg_PrintPreviewFailed::ID) != NULL); 318 PrintHostMsg_PrintPreviewFailed::ID) != NULL);
318 EXPECT_EQ(did_fail, print_preview_failed); 319 EXPECT_EQ(did_fail, print_preview_failed);
319 } 320 }
320 321
321 void VerifyPrintPreviewGenerated(bool generated_preview) { 322 void VerifyPrintPreviewGenerated(bool generated_preview) {
322 const IPC::Message* preview_msg = 323 const IPC::Message* preview_msg =
323 render_thread_.sink().GetUniqueMessageMatching( 324 render_thread_.sink().GetUniqueMessageMatching(
324 PrintHostMsg_PagesReadyForPreview::ID); 325 PrintHostMsg_MetafileReadyForPrinting::ID);
325 bool did_get_preview_msg = (NULL != preview_msg); 326 bool did_get_preview_msg = (NULL != preview_msg);
326 ASSERT_EQ(generated_preview, did_get_preview_msg); 327 ASSERT_EQ(generated_preview, did_get_preview_msg);
327 if (did_get_preview_msg) { 328 if (did_get_preview_msg) {
328 PrintHostMsg_PagesReadyForPreview::Param preview_param; 329 PrintHostMsg_MetafileReadyForPrinting::Param preview_param;
329 PrintHostMsg_PagesReadyForPreview::Read(preview_msg, &preview_param); 330 PrintHostMsg_MetafileReadyForPrinting::Read(preview_msg, &preview_param);
330 EXPECT_NE(0, preview_param.a.document_cookie); 331 EXPECT_NE(0, preview_param.a.document_cookie);
331 EXPECT_NE(0, preview_param.a.expected_pages_count); 332 EXPECT_NE(0, preview_param.a.expected_pages_count);
332 EXPECT_NE(0U, preview_param.a.data_size); 333 EXPECT_NE(0U, preview_param.a.data_size);
333 } 334 }
334 } 335 }
335 336
336 void VerifyPrintFailed(bool did_fail) { 337 void VerifyPrintFailed(bool did_fail) {
337 bool print_failed = (render_thread_.sink().GetUniqueMessageMatching( 338 bool print_failed = (render_thread_.sink().GetUniqueMessageMatching(
338 PrintHostMsg_PrintingFailed::ID) != NULL); 339 PrintHostMsg_PrintingFailed::ID) != NULL);
339 EXPECT_EQ(did_fail, print_failed); 340 EXPECT_EQ(did_fail, print_failed);
340 } 341 }
341 342
343 // |page_number| is 0-based.
344 void VerifyDidPreviewPage(bool generate_draft_pages, int page_number) {
345 bool msg_found = false;
346 size_t msg_count = render_thread_.sink().message_count();
347 for (size_t i = 0; i < msg_count; ++i) {
348 const IPC::Message* msg = render_thread_.sink().GetMessageAt(i);
349 if (msg->type() == PrintHostMsg_DidPreviewPage::ID) {
350 PrintHostMsg_DidPreviewPage::Param page_param;
351 PrintHostMsg_DidPreviewPage::Read(msg, &page_param);
352 if (page_param.a.page_number == page_number) {
353 msg_found = true;
354 if (generate_draft_pages)
355 EXPECT_NE(0U, page_param.a.data_size);
356 else
357 EXPECT_EQ(0U, page_param.a.data_size);
358 break;
359 }
360 }
361 }
362 ASSERT_EQ(true, msg_found);
363 }
364
342 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); 365 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest);
343 }; 366 };
344 367
345 // Tests that print preview work and sending and receiving messages through 368 // Tests that print preview work and sending and receiving messages through
346 // that channel all works. 369 // that channel all works.
347 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { 370 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) {
348 LoadHTML(kHelloWorldHTML); 371 LoadHTML(kHelloWorldHTML);
349 372
350 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); 373 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview();
351 // Fill in some dummy values. 374 // Fill in some dummy values.
352 DictionaryValue dict; 375 DictionaryValue dict;
353 CreatePrintSettingsDictionary(&dict); 376 CreatePrintSettingsDictionary(&dict);
354 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); 377 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict);
355 378
356 // Need to finish simulating print preview. 379 // Need to finish simulating print preview.
357 // Generate the page and finalize it. 380 // Generate the page and finalize it.
358 PrintWebViewHelper::Get(view_)->OnContinuePreview( 381 PrintWebViewHelper::Get(view_)->OnContinuePreview();
359 printing::INVALID_PAGE_INDEX); 382
360 PrintWebViewHelper::Get(view_)->OnContinuePreview( 383 // Verify that we did create the draft metafile for the first page.
361 printing::INVALID_PAGE_INDEX); 384 VerifyDidPreviewPage(true, 0);
385 PrintWebViewHelper::Get(view_)->OnContinuePreview();
362 386
363 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); 387 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining());
364 VerifyPrintPreviewFailed(false); 388 VerifyPrintPreviewFailed(false);
389 VerifyPrintPreviewGenerated(true);
390 VerifyPagesPrinted(false);
391 }
392
393 // Test to verify that complete metafile is generated for a subset of pages
394 // without creating draft pages.
395 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) {
396 LoadHTML(kHelloWorldHTML);
397
398 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview();
399 // Fill in some dummy values.
400 DictionaryValue dict;
401 CreatePrintSettingsDictionary(&dict);
402
403 // Set a page range and update the dictionary to generate only the complete
404 // metafile with the selected pages. Page numbers used in the dictionary
405 // are 1-based.
406 DictionaryValue* page_range = new DictionaryValue();
407 page_range->SetInteger(printing::kSettingPageRangeFrom, 1);
408 page_range->SetInteger(printing::kSettingPageRangeTo, 1);
409
410 ListValue* page_range_array = new ListValue();
411 page_range_array->Append(page_range);
412
413 dict.Set(printing::kSettingPageRange, page_range_array);
414 dict.SetBoolean(printing::kSettingGenerateDraftData, false);
415
416 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict);
417
418 // Need to finish simulating print preview.
419 // Generate the page and finalize it.
420 PrintWebViewHelper::Get(view_)->OnContinuePreview();
421
422 // Verify that we did not create the draft metafile for the first page.
423 VerifyDidPreviewPage(false, 0);
424 PrintWebViewHelper::Get(view_)->OnContinuePreview();
425
426 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining());
427 VerifyPrintPreviewFailed(false);
365 VerifyPrintPreviewGenerated(true); 428 VerifyPrintPreviewGenerated(true);
366 VerifyPagesPrinted(false); 429 VerifyPagesPrinted(false);
367 } 430 }
368 431
369 // Tests that print preview fails and receiving error messages through 432 // Tests that print preview fails and receiving error messages through
370 // that channel all works. 433 // that channel all works.
371 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { 434 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) {
372 LoadHTML(kHelloWorldHTML); 435 LoadHTML(kHelloWorldHTML);
373 436
374 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); 437 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview();
(...skipping 27 matching lines...) Expand all
402 LoadHTML(kPrintPreviewHTML); 465 LoadHTML(kPrintPreviewHTML);
403 466
404 // An empty dictionary should fail. 467 // An empty dictionary should fail.
405 DictionaryValue empty_dict; 468 DictionaryValue empty_dict;
406 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict); 469 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict);
407 470
408 VerifyPrintFailed(true); 471 VerifyPrintFailed(true);
409 VerifyPagesPrinted(false); 472 VerifyPagesPrinted(false);
410 } 473 }
411 #endif // !defined(OS_CHROMEOS) 474 #endif // !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698