Introduce ProfilerMetricsProvider
[chromium-blink-merge.git] / chrome / browser / printing / print_preview_test.cc
blob4ce8fa45f02c8cc0148fe138a31fed2d1c47e10a
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 "base/prefs/pref_service.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_iterator.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/test_browser_window.h"
13 #include "components/web_modal/web_contents_modal_dialog_host.h"
14 #include "content/public/browser/plugin_service.h"
15 #include "content/public/browser/web_contents.h"
17 using web_modal::WebContentsModalDialogHost;
18 using web_modal::ModalDialogHostObserver;
20 namespace {
22 // Use a custom test browser window to provide a parent view to the print
23 // preview dialog.
24 class PrintPreviewTestBrowserWindow
25 : public TestBrowserWindow,
26 public WebContentsModalDialogHost {
27 public:
28 PrintPreviewTestBrowserWindow() {}
30 // BrowserWindow overrides
31 virtual WebContentsModalDialogHost* GetWebContentsModalDialogHost() OVERRIDE {
32 return this;
35 // WebContentsModalDialogHost overrides
37 // The web contents modal dialog must be parented to *something*; use the
38 // WebContents window since there is no true browser window for unit tests.
39 virtual gfx::NativeView GetHostView() const OVERRIDE {
40 return FindBrowser()->tab_strip_model()->GetActiveWebContents()->
41 GetNativeView();
44 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE {
45 return gfx::Point();
48 virtual gfx::Size GetMaximumDialogSize() OVERRIDE {
49 return gfx::Size();
52 virtual void AddObserver(
53 ModalDialogHostObserver* observer) OVERRIDE {}
54 virtual void RemoveObserver(
55 ModalDialogHostObserver* observer) OVERRIDE {}
57 private:
58 Browser* FindBrowser() const {
59 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
60 Browser* browser = *it;
61 if (browser->window() == this)
62 return browser;
64 NOTREACHED();
65 return NULL;
68 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTestBrowserWindow);
70 } // namespace
72 PrintPreviewTest::PrintPreviewTest() {}
73 PrintPreviewTest::~PrintPreviewTest() {}
75 void PrintPreviewTest::SetUp() {
76 BrowserWithTestWindowTest::SetUp();
78 // The PluginService will be destroyed at the end of the test (due to the
79 // ShadowingAtExitManager in our base class).
80 content::PluginService::GetInstance()->Init();
81 content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting();
83 profile()->GetPrefs()->SetBoolean(prefs::kPrintPreviewDisabled, false);
86 BrowserWindow* PrintPreviewTest::CreateBrowserWindow() {
87 return new PrintPreviewTestBrowserWindow;