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

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_ui_interactive_browsertest.cc

Issue 12334073: Remove WebContents methods that duplicate WebContentsView methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/command_line.h"
6 #include "chrome/browser/printing/print_preview_dialog_controller.h"
7 #include "chrome/browser/printing/print_view_manager.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
11 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "content/public/browser/render_widget_host_view.h"
15 #include "content/public/test/test_utils.h"
16
17 namespace {
18
19 bool IsShowingWebContentsModalDialog(content::WebContents* tab) {
20 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
21 WebContentsModalDialogManager::FromWebContents(tab);
22 return web_contents_modal_dialog_manager->IsShowingDialog();
23 }
24
25 class PrintPreviewTest : public InProcessBrowserTest {
26 public:
27 PrintPreviewTest() {}
28
29 #if !defined(GOOGLE_CHROME_BUILD)
30 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
31 command_line->AppendSwitch(switches::kEnablePrintPreview);
32 }
33 #endif
34 };
35
36 class WebContentsDestroyedWatcher : public content::WebContentsObserver {
37 public:
38 WebContentsDestroyedWatcher(content::WebContents* web_contents,
39 const base::Closure& callback)
40 : content::WebContentsObserver(web_contents),
41 callback_(callback) {}
42
43 virtual void WebContentsDestroyed(content::WebContents* web_contents) {
44 callback_.Run();
45 }
46
47 private:
48 base::Closure callback_;
49 };
50
51 IN_PROC_BROWSER_TEST_F(PrintPreviewTest,
52 InitiatorTabGetsFocusOnPrintPreviewDialogClose) {
53 content::WebContents* initiator_tab =
54 browser()->tab_strip_model()->GetActiveWebContents();
55
56 printing::PrintPreviewDialogController* controller =
57 printing::PrintPreviewDialogController::GetInstance();
58 ASSERT_TRUE(controller);
59
60 printing::PrintViewManager* print_view_manager =
61 printing::PrintViewManager::FromWebContents(initiator_tab);
62 print_view_manager->PrintPreviewNow(false);
63
64 // Don't call GetOrCreatePreviewDialog since that would create the dialog now.
65 // The problem with doing so is that if we close it right away (which this
66 // test does), then when the IPC comes back from the renderer in the normal
67 // printing workflow that would cause the dialog to get created again (and it
68 // would be dispatched, racily, in the second nested message loop below).
69 scoped_refptr<content::MessageLoopRunner> dialog_runner =
70 new content::MessageLoopRunner;
71 controller->set_print_preview_tab_created_callback_for_testing(
72 dialog_runner->QuitClosure());
73 dialog_runner->Run();
74
75 content::WebContents* preview_dialog =
76 controller->GetPrintPreviewForContents(initiator_tab);
77
78 EXPECT_NE(initiator_tab, preview_dialog);
79 EXPECT_TRUE(IsShowingWebContentsModalDialog(initiator_tab));
80 EXPECT_FALSE(initiator_tab->GetRenderWidgetHostView()->HasFocus());
81
82 PrintPreviewUI* preview_ui = static_cast<PrintPreviewUI*>(
83 preview_dialog->GetWebUI()->GetController());
84 ASSERT_TRUE(preview_ui != NULL);
85
86 scoped_refptr<content::MessageLoopRunner> runner =
87 new content::MessageLoopRunner;
88 WebContentsDestroyedWatcher watcher(preview_dialog, runner->QuitClosure());
89
90 preview_ui->OnPrintPreviewDialogClosed();
91
92 runner->Run();
93
94 EXPECT_FALSE(IsShowingWebContentsModalDialog(initiator_tab));
95 EXPECT_TRUE(initiator_tab->GetRenderWidgetHostView()->HasFocus());
96 }
97 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698