| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/auto_reset.h" |
| 6 #include "chrome/browser/printing/print_view_manager_common.h" |
| 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 11 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "components/prefs/pref_service.h" |
| 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 16 |
| 17 namespace printing { |
| 18 |
| 19 namespace { |
| 20 |
| 21 class PrintPreviewObserver : PrintPreviewUI::TestingDelegate { |
| 22 public: |
| 23 PrintPreviewObserver() { PrintPreviewUI::SetDelegateForTesting(this); } |
| 24 ~PrintPreviewObserver() { PrintPreviewUI::SetDelegateForTesting(nullptr); } |
| 25 |
| 26 void WaitUntilPreviewIsReady() { |
| 27 if (rendered_page_count_ >= total_page_count_) |
| 28 return; |
| 29 |
| 30 base::RunLoop run_loop; |
| 31 base::AutoReset<base::RunLoop*> auto_reset(&run_loop_, &run_loop); |
| 32 run_loop.Run(); |
| 33 } |
| 34 |
| 35 private: |
| 36 // PrintPreviewUI::TestingDelegate implementation. |
| 37 void DidGetPreviewPageCount(int page_count) override { |
| 38 total_page_count_ = page_count; |
| 39 } |
| 40 |
| 41 // PrintPreviewUI::TestingDelegate implementation. |
| 42 void DidRenderPreviewPage(content::WebContents* preview_dialog) override { |
| 43 ++rendered_page_count_; |
| 44 CHECK(rendered_page_count_ <= total_page_count_); |
| 45 if (rendered_page_count_ == total_page_count_ && run_loop_) { |
| 46 run_loop_->Quit(); |
| 47 } |
| 48 } |
| 49 |
| 50 int total_page_count_ = 1; |
| 51 int rendered_page_count_ = 0; |
| 52 base::RunLoop* run_loop_ = nullptr; |
| 53 }; |
| 54 |
| 55 } // namespace |
| 56 |
| 57 class PrintBrowserTest : public InProcessBrowserTest { |
| 58 public: |
| 59 PrintBrowserTest() {} |
| 60 ~PrintBrowserTest() override {} |
| 61 |
| 62 void PrintAndWaitUntilPreviewIsReady(bool print_only_selection) { |
| 63 PrintPreviewObserver print_preview_observer; |
| 64 |
| 65 printing::StartPrint(browser()->tab_strip_model()->GetActiveWebContents(), |
| 66 /*print_preview_disabled=*/false, |
| 67 print_only_selection); |
| 68 |
| 69 print_preview_observer.WaitUntilPreviewIsReady(); |
| 70 } |
| 71 }; |
| 72 |
| 73 // Printing only a selection containing iframes is partially supported. |
| 74 // Iframes aren't currently displayed. This test passes whenever the print |
| 75 // preview is rendered (i.e. no timeout in the test). |
| 76 // This test shouldn't crash. See https://crbug.com/732780. |
| 77 IN_PROC_BROWSER_TEST_F(PrintBrowserTest, SelectionContainsIframe) { |
| 78 ASSERT_TRUE(embedded_test_server()->Start()); |
| 79 GURL url(embedded_test_server()->GetURL("/printing/selection_iframe.html")); |
| 80 ui_test_utils::NavigateToURL(browser(), url); |
| 81 |
| 82 PrintAndWaitUntilPreviewIsReady(/*print_only_selection=*/true); |
| 83 } |
| 84 |
| 85 } // namespace printing |
| OLD | NEW |