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

Side by Side Diff: chrome/browser/printing/print_preview_browsertest.cc

Issue 2944873002: Printing: Disable subframes when printing a selection. (Closed)
Patch Set: Fix names conflicts. Created 3 years, 6 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
OLDNEW
(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/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.
16 #include "net/test/embedded_test_server/embedded_test_server.h"
17
18 namespace printing {
19
20 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.
21 class PrintPreviewObserver : PrintPreviewUI::TestingDelegate {
22 public:
23 PrintPreviewObserver() { PrintPreviewUI::SetDelegateForTesting(this); }
24 ~PrintPreviewObserver() { PrintPreviewUI::SetDelegateForTesting(NULL); }
Lei Zhang 2017/06/21 07:36:32 nit: s/NULL/nullptr/
arthursonzogni 2017/06/21 14:01:20 Done.
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 }
Lei Zhang 2017/06/21 07:36:32 nit: blank line after.
arthursonzogni 2017/06/21 14:01:19 Done.
40 // PrintPreviewUI::TestingDelegate implementation.
41 void DidRenderPreviewPage(content::WebContents* preview_dialog) override {
42 ++rendered_page_count_;
43 CHECK(rendered_page_count_ <= total_page_count_);
44 if (rendered_page_count_ == total_page_count_ && run_loop_) {
45 run_loop_->Quit();
46 }
47 }
48
49 int total_page_count_ = 1;
50 int rendered_page_count_ = 0;
51 base::RunLoop* run_loop_ = nullptr;
52 };
53 } // namespace
54
55 class PrintPreviewBrowserTest : public InProcessBrowserTest {
56 public:
57 PrintPreviewBrowserTest() {}
58 ~PrintPreviewBrowserTest() override {}
59
60 void PrintAndWaitUntilPreviewIsReady(bool print_only_selection) {
61 PrintPreviewObserver print_preview_observer;
62
63 printing::StartPrint(browser()->tab_strip_model()->GetActiveWebContents(),
64 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.
65 print_only_selection);
66
67 print_preview_observer.WaitUntilPreviewIsReady();
68 }
69 };
70
71 // Printing only a selection containing iframes is partially supported.
72 // Iframes aren't currently displayed. This test passes whenever the print
73 // preview is rendered (i.e. no timeout in the test).
74 // This test shouldn't crash. See https://crbug.com/732780.
75 IN_PROC_BROWSER_TEST_F(PrintPreviewBrowserTest, SelectionContainsIframe) {
76 ASSERT_TRUE(embedded_test_server()->Start());
77 GURL url(embedded_test_server()->GetURL("/printing/selection_iframe.html"));
78 ui_test_utils::NavigateToURL(browser(), url);
79
80 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.
81 }
82
83 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698