Chromium Code Reviews| Index: chrome/browser/printing/print_preview_browsertest.cc |
| diff --git a/chrome/browser/printing/print_preview_browsertest.cc b/chrome/browser/printing/print_preview_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8ea34f925fdf9ee3087320f266e6410bb18e6cfb |
| --- /dev/null |
| +++ b/chrome/browser/printing/print_preview_browsertest.cc |
| @@ -0,0 +1,83 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/auto_reset.h" |
| +#include "chrome/browser/printing/print_view_manager_common.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "net/dns/mock_host_resolver.h" |
|
Lei Zhang
2017/06/21 07:36:32
Not used?
arthursonzogni
2017/06/21 14:01:20
Yes, thanks!
Done.
|
| +#include "net/test/embedded_test_server/embedded_test_server.h" |
| + |
| +namespace printing { |
| + |
| +namespace { |
|
Lei Zhang
2017/06/21 07:36:32
nit: new line after, and before the end of the ano
arthursonzogni
2017/06/21 14:01:20
Done.
|
| +class PrintPreviewObserver : PrintPreviewUI::TestingDelegate { |
| + public: |
| + PrintPreviewObserver() { PrintPreviewUI::SetDelegateForTesting(this); } |
| + ~PrintPreviewObserver() { PrintPreviewUI::SetDelegateForTesting(NULL); } |
|
Lei Zhang
2017/06/21 07:36:32
nit: s/NULL/nullptr/
arthursonzogni
2017/06/21 14:01:20
Done.
|
| + |
| + void WaitUntilPreviewIsReady() { |
| + if (rendered_page_count_ >= total_page_count_) |
| + return; |
| + |
| + base::RunLoop run_loop; |
| + base::AutoReset<base::RunLoop*> auto_reset(&run_loop_, &run_loop); |
| + run_loop.Run(); |
| + } |
| + |
| + private: |
| + // PrintPreviewUI::TestingDelegate implementation. |
| + void DidGetPreviewPageCount(int page_count) override { |
| + total_page_count_ = page_count; |
| + } |
|
Lei Zhang
2017/06/21 07:36:32
nit: blank line after.
arthursonzogni
2017/06/21 14:01:19
Done.
|
| + // PrintPreviewUI::TestingDelegate implementation. |
| + void DidRenderPreviewPage(content::WebContents* preview_dialog) override { |
| + ++rendered_page_count_; |
| + CHECK(rendered_page_count_ <= total_page_count_); |
| + if (rendered_page_count_ == total_page_count_ && run_loop_) { |
| + run_loop_->Quit(); |
| + } |
| + } |
| + |
| + int total_page_count_ = 1; |
| + int rendered_page_count_ = 0; |
| + base::RunLoop* run_loop_ = nullptr; |
| +}; |
| +} // namespace |
| + |
| +class PrintPreviewBrowserTest : public InProcessBrowserTest { |
| + public: |
| + PrintPreviewBrowserTest() {} |
| + ~PrintPreviewBrowserTest() override {} |
| + |
| + void PrintAndWaitUntilPreviewIsReady(bool print_only_selection) { |
| + PrintPreviewObserver print_preview_observer; |
| + |
| + printing::StartPrint(browser()->tab_strip_model()->GetActiveWebContents(), |
| + false, /* print_preview_disabled */ |
|
Lei Zhang
2017/06/21 07:36:32
I've been told the latest and greatest way is to w
arthursonzogni
2017/06/21 14:01:20
Done.
Lei Zhang
2017/06/21 16:17:48
I didn't write it with the right spacing. I meant
arthursonzogni
2017/06/21 16:26:22
Done.
|
| + print_only_selection); |
| + |
| + print_preview_observer.WaitUntilPreviewIsReady(); |
| + } |
| +}; |
| + |
| +// Printing only a selection containing iframes is partially supported. |
| +// Iframes aren't currently displayed. This test passes whenever the print |
| +// preview is rendered (i.e. no timeout in the test). |
| +// This test shouldn't crash. See https://crbug.com/732780. |
| +IN_PROC_BROWSER_TEST_F(PrintPreviewBrowserTest, SelectionContainsIframe) { |
| + ASSERT_TRUE(embedded_test_server()->Start()); |
| + GURL url(embedded_test_server()->GetURL("/printing/selection_iframe.html")); |
| + ui_test_utils::NavigateToURL(browser(), url); |
| + |
| + PrintAndWaitUntilPreviewIsReady(true /* print_only_selection */); |
|
Lei Zhang
2017/06/21 16:17:48
Same nit as above.
arthursonzogni
2017/06/21 16:26:22
Done.
|
| +} |
| + |
| +} // namespace printing |