Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / printing / print_preview_test.cc
blobad93a33b2747ecf4f937a7a467f90bafd9772a6a
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"
16 #include "content/public/browser/web_contents_view.h"
18 using web_modal::WebContentsModalDialogHost;
19 using web_modal::ModalDialogHostObserver;
21 namespace {
23 // Use a custom test browser window to provide a parent view to the print
24 // preview dialog.
25 class PrintPreviewTestBrowserWindow
26 : public TestBrowserWindow,
27 public WebContentsModalDialogHost {
28 public:
29 PrintPreviewTestBrowserWindow() {}
31 // BrowserWindow overrides
32 virtual WebContentsModalDialogHost* GetWebContentsModalDialogHost() OVERRIDE {
33 return this;
36 // WebContentsModalDialogHost overrides
38 // The web contents modal dialog must be parented to *something*; use the
39 // WebContents window since there is no true browser window for unit tests.
40 virtual gfx::NativeView GetHostView() const OVERRIDE {
41 return FindBrowser()->tab_strip_model()->GetActiveWebContents()->GetView()->
42 GetNativeView();
45 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE {
46 return gfx::Point();
49 virtual gfx::Size GetMaximumDialogSize() OVERRIDE {
50 return gfx::Size();
53 virtual void AddObserver(
54 ModalDialogHostObserver* observer) OVERRIDE {}
55 virtual void RemoveObserver(
56 ModalDialogHostObserver* observer) OVERRIDE {}
58 private:
59 Browser* FindBrowser() const {
60 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
61 Browser* browser = *it;
62 if (browser->window() == this)
63 return browser;
65 NOTREACHED();
66 return NULL;
69 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTestBrowserWindow);
71 } // namespace
73 PrintPreviewTest::PrintPreviewTest() {}
74 PrintPreviewTest::~PrintPreviewTest() {}
76 void PrintPreviewTest::SetUp() {
77 BrowserWithTestWindowTest::SetUp();
79 // The PluginService will be destroyed at the end of the test (due to the
80 // ShadowingAtExitManager in our base class).
81 content::PluginService::GetInstance()->Init();
82 content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting();
84 profile()->GetPrefs()->SetBoolean(prefs::kPrintPreviewDisabled, false);
87 BrowserWindow* PrintPreviewTest::CreateBrowserWindow() {
88 return new PrintPreviewTestBrowserWindow;