| 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/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 23 matching lines...) Expand all Loading... |
| 34 "<body><p id=\"pdf-viewer\">Hello World!</p></body>"; | 34 "<body><p id=\"pdf-viewer\">Hello World!</p></body>"; |
| 35 | 35 |
| 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::kPreviewUIId, 54321); |
| 44 dict->SetInteger(printing::kPreviewRequestID, 12345); | 45 dict->SetInteger(printing::kPreviewRequestID, 12345); |
| 45 dict->SetBoolean(printing::kIsFirstRequest, true); | 46 dict->SetBoolean(printing::kIsFirstRequest, true); |
| 46 dict->SetBoolean(printing::kSettingHeaderFooterEnabled, false); | 47 dict->SetBoolean(printing::kSettingHeaderFooterEnabled, false); |
| 47 } | 48 } |
| 48 | 49 |
| 49 } // namespace | 50 } // namespace |
| 50 | 51 |
| 51 class PrintWebViewHelperTestBase : public RenderViewTest { | 52 class PrintWebViewHelperTestBase : public RenderViewTest { |
| 52 public: | 53 public: |
| 53 PrintWebViewHelperTestBase() {} | 54 PrintWebViewHelperTestBase() {} |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 // that channel all works. | 340 // that channel all works. |
| 340 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { | 341 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { |
| 341 LoadHTML(kHelloWorldHTML); | 342 LoadHTML(kHelloWorldHTML); |
| 342 | 343 |
| 343 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); | 344 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); |
| 344 // Fill in some dummy values. | 345 // Fill in some dummy values. |
| 345 DictionaryValue dict; | 346 DictionaryValue dict; |
| 346 CreatePrintSettingsDictionary(&dict); | 347 CreatePrintSettingsDictionary(&dict); |
| 347 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); | 348 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); |
| 348 | 349 |
| 349 // Need to finish simulating print preview. | |
| 350 // Generate the page and finalize it. | |
| 351 PrintWebViewHelper::Get(view_)->OnContinuePreview( | |
| 352 printing::INVALID_PAGE_INDEX); | |
| 353 PrintWebViewHelper::Get(view_)->OnContinuePreview( | |
| 354 printing::INVALID_PAGE_INDEX); | |
| 355 | |
| 356 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); | 350 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); |
| 357 VerifyPrintPreviewFailed(false); | 351 VerifyPrintPreviewFailed(false); |
| 358 VerifyPrintPreviewGenerated(true); | 352 VerifyPrintPreviewGenerated(true); |
| 359 VerifyPagesPrinted(false); | 353 VerifyPagesPrinted(false); |
| 360 } | 354 } |
| 361 | 355 |
| 362 // Tests that print preview fails and receiving error messages through | 356 // Tests that print preview fails and receiving error messages through |
| 363 // that channel all works. | 357 // that channel all works. |
| 364 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { | 358 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { |
| 365 LoadHTML(kHelloWorldHTML); | 359 LoadHTML(kHelloWorldHTML); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 395 LoadHTML(kPrintPreviewHTML); | 389 LoadHTML(kPrintPreviewHTML); |
| 396 | 390 |
| 397 // An empty dictionary should fail. | 391 // An empty dictionary should fail. |
| 398 DictionaryValue empty_dict; | 392 DictionaryValue empty_dict; |
| 399 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict); | 393 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict); |
| 400 | 394 |
| 401 VerifyPrintFailed(true); | 395 VerifyPrintFailed(true); |
| 402 VerifyPagesPrinted(false); | 396 VerifyPagesPrinted(false); |
| 403 } | 397 } |
| 404 #endif // !defined(OS_CHROMEOS) | 398 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |