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.
5 #include "chrome/browser/printing/print_preview_test.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_iterator.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/test_browser_window.h"
11 #include "components/web_modal/web_contents_modal_dialog_host.h"
12 #include "content/public/browser/plugin_service.h"
13 #include "content/public/browser/web_contents.h"
15 using web_modal::WebContentsModalDialogHost
;
16 using web_modal::ModalDialogHostObserver
;
20 // Use a custom test browser window to provide a parent view to the print
22 class PrintPreviewTestBrowserWindow
23 : public TestBrowserWindow
,
24 public WebContentsModalDialogHost
{
26 PrintPreviewTestBrowserWindow() {}
28 // BrowserWindow overrides
29 virtual WebContentsModalDialogHost
* GetWebContentsModalDialogHost() OVERRIDE
{
33 // WebContentsModalDialogHost overrides
35 // The web contents modal dialog must be parented to *something*; use the
36 // WebContents window since there is no true browser window for unit tests.
37 virtual gfx::NativeView
GetHostView() const OVERRIDE
{
38 return FindBrowser()->tab_strip_model()->GetActiveWebContents()->
42 virtual gfx::Point
GetDialogPosition(const gfx::Size
& size
) OVERRIDE
{
46 virtual gfx::Size
GetMaximumDialogSize() OVERRIDE
{
50 virtual void AddObserver(
51 ModalDialogHostObserver
* observer
) OVERRIDE
{}
52 virtual void RemoveObserver(
53 ModalDialogHostObserver
* observer
) OVERRIDE
{}
56 Browser
* FindBrowser() const {
57 for (chrome::BrowserIterator it
; !it
.done(); it
.Next()) {
58 Browser
* browser
= *it
;
59 if (browser
->window() == this)
66 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTestBrowserWindow
);
70 PrintPreviewTest::PrintPreviewTest() {}
71 PrintPreviewTest::~PrintPreviewTest() {}
73 void PrintPreviewTest::SetUp() {
74 BrowserWithTestWindowTest::SetUp();
76 // The PluginService will be destroyed at the end of the test (due to the
77 // ShadowingAtExitManager in our base class).
78 content::PluginService::GetInstance()->Init();
79 content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting();
82 BrowserWindow
* PrintPreviewTest::CreateBrowserWindow() {
83 return new PrintPreviewTestBrowserWindow
;