| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 private: | 121 private: |
| 122 base::RunLoop* const run_loop_; | 122 base::RunLoop* const run_loop_; |
| 123 DISALLOW_COPY_AND_ASSIGN(DidPreviewPageListener); | 123 DISALLOW_COPY_AND_ASSIGN(DidPreviewPageListener); |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 } // namespace | 126 } // namespace |
| 127 | 127 |
| 128 class PrintWebViewHelperTestBase : public ChromeRenderViewTest { | 128 class PrintWebViewHelperTestBase : public ChromeRenderViewTest { |
| 129 public: | 129 public: |
| 130 PrintWebViewHelperTestBase() {} | 130 PrintWebViewHelperTestBase() {} |
| 131 virtual ~PrintWebViewHelperTestBase() {} | 131 ~PrintWebViewHelperTestBase() override {} |
| 132 | 132 |
| 133 protected: | 133 protected: |
| 134 void PrintWithJavaScript() { | 134 void PrintWithJavaScript() { |
| 135 ExecuteJavaScript("window.print();"); | 135 ExecuteJavaScript("window.print();"); |
| 136 ProcessPendingMessages(); | 136 ProcessPendingMessages(); |
| 137 } | 137 } |
| 138 // The renderer should be done calculating the number of rendered pages | 138 // The renderer should be done calculating the number of rendered pages |
| 139 // according to the specified settings defined in the mock render thread. | 139 // according to the specified settings defined in the mock render thread. |
| 140 // Verify the page count is correct. | 140 // Verify the page count is correct. |
| 141 void VerifyPageCount(int count) { | 141 void VerifyPageCount(int count) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict); | 219 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict); |
| 220 ProcessPendingMessages(); | 220 ProcessPendingMessages(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase); | 223 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase); |
| 224 }; | 224 }; |
| 225 | 225 |
| 226 class PrintWebViewHelperTest : public PrintWebViewHelperTestBase { | 226 class PrintWebViewHelperTest : public PrintWebViewHelperTestBase { |
| 227 public: | 227 public: |
| 228 PrintWebViewHelperTest() {} | 228 PrintWebViewHelperTest() {} |
| 229 virtual ~PrintWebViewHelperTest() {} | 229 ~PrintWebViewHelperTest() override {} |
| 230 | 230 |
| 231 virtual void SetUp() override { | 231 void SetUp() override { ChromeRenderViewTest::SetUp(); } |
| 232 ChromeRenderViewTest::SetUp(); | |
| 233 } | |
| 234 | 232 |
| 235 protected: | 233 protected: |
| 236 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); | 234 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); |
| 237 }; | 235 }; |
| 238 | 236 |
| 239 // This tests only for platforms without print preview. | 237 // This tests only for platforms without print preview. |
| 240 #if !defined(ENABLE_FULL_PRINTING) | 238 #if !defined(ENABLE_FULL_PRINTING) |
| 241 // Tests that the renderer blocks window.print() calls if they occur too | 239 // Tests that the renderer blocks window.print() calls if they occur too |
| 242 // frequently. | 240 // frequently. |
| 243 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { | 241 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 } | 461 } |
| 464 } | 462 } |
| 465 } | 463 } |
| 466 #endif // OS_MACOSX && !DISABLE_BASIC_PRINTING | 464 #endif // OS_MACOSX && !DISABLE_BASIC_PRINTING |
| 467 | 465 |
| 468 // These print preview tests do not work on Chrome OS yet. | 466 // These print preview tests do not work on Chrome OS yet. |
| 469 #if !defined(OS_CHROMEOS) | 467 #if !defined(OS_CHROMEOS) |
| 470 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { | 468 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { |
| 471 public: | 469 public: |
| 472 PrintWebViewHelperPreviewTest() {} | 470 PrintWebViewHelperPreviewTest() {} |
| 473 virtual ~PrintWebViewHelperPreviewTest() {} | 471 ~PrintWebViewHelperPreviewTest() override {} |
| 474 | 472 |
| 475 protected: | 473 protected: |
| 476 void VerifyPrintPreviewCancelled(bool did_cancel) { | 474 void VerifyPrintPreviewCancelled(bool did_cancel) { |
| 477 bool print_preview_cancelled = | 475 bool print_preview_cancelled = |
| 478 (render_thread_->sink().GetUniqueMessageMatching( | 476 (render_thread_->sink().GetUniqueMessageMatching( |
| 479 PrintHostMsg_PrintPreviewCancelled::ID) != NULL); | 477 PrintHostMsg_PrintPreviewCancelled::ID) != NULL); |
| 480 EXPECT_EQ(did_cancel, print_preview_cancelled); | 478 EXPECT_EQ(did_cancel, print_preview_cancelled); |
| 481 } | 479 } |
| 482 | 480 |
| 483 void VerifyPrintPreviewFailed(bool did_fail) { | 481 void VerifyPrintPreviewFailed(bool did_fail) { |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 CreatePrintSettingsDictionary(&dict); | 988 CreatePrintSettingsDictionary(&dict); |
| 991 OnPrintForPrintPreview(dict); | 989 OnPrintForPrintPreview(dict); |
| 992 | 990 |
| 993 VerifyPrintFailed(true); | 991 VerifyPrintFailed(true); |
| 994 VerifyPagesPrinted(false); | 992 VerifyPagesPrinted(false); |
| 995 } | 993 } |
| 996 | 994 |
| 997 #endif // !defined(OS_CHROMEOS) | 995 #endif // !defined(OS_CHROMEOS) |
| 998 | 996 |
| 999 } // namespace printing | 997 } // namespace printing |
| OLD | NEW |