print_preview_test.cc revision 58537e28ecd584eab876aee8be7156509866d23a
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/printing/print_preview_test.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/ui/browser.h" 9a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/ui/browser_iterator.h" 10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/pref_names.h" 12a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/test/base/test_browser_window.h" 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "components/web_modal/web_contents_modal_dialog_host.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/plugin_service.h" 15a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/public/browser/web_contents.h" 16a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/public/browser/web_contents_view.h" 17a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using web_modal::WebContentsModalDialogHost; 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using web_modal::WebContentsModalDialogHostObserver; 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 21a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace { 22a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 23a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use a custom test browser window to provide a parent view to the print 24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// preview dialog. 25a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class PrintPreviewTestBrowserWindow 26a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) : public TestBrowserWindow, 27a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public WebContentsModalDialogHost { 28a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public: 29a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) PrintPreviewTestBrowserWindow() {} 30a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 31a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // BrowserWindow overrides 32a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual WebContentsModalDialogHost* GetWebContentsModalDialogHost() OVERRIDE { 33a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return this; 34a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 35a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 36a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // WebContentsModalDialogHost overrides 37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // The web contents modal dialog must be parented to *something*; use the 39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // WebContents window since there is no true browser window for unit tests. 40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual gfx::NativeView GetHostView() const OVERRIDE { 41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return FindBrowser()->tab_strip_model()->GetActiveWebContents()->GetView()-> 42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) GetNativeView(); 43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 45a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE { 46a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return gfx::Point(); 47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 48a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual gfx::Size GetMaximumDialogSize() OVERRIDE { 5058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return gfx::Size(); 5158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 5258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 53a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void AddObserver( 54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) WebContentsModalDialogHostObserver* observer) OVERRIDE {} 55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void RemoveObserver( 56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) WebContentsModalDialogHostObserver* observer) OVERRIDE {} 57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private: 59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) Browser* FindBrowser() const { 60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) for (chrome::BrowserIterator it; !it.done(); it.Next()) { 61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) Browser* browser = *it; 62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) if (browser->window() == this) 63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return browser; 64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) NOTREACHED(); 66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return NULL; 67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(PrintPreviewTestBrowserWindow); 70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}; 71a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} // namespace 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)PrintPreviewTest::PrintPreviewTest() {} 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)PrintPreviewTest::~PrintPreviewTest() {} 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void PrintPreviewTest::SetUp() { 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserWithTestWindowTest::SetUp(); 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The PluginService will be destroyed at the end of the test (due to the 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ShadowingAtExitManager in our base class). 81ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch content::PluginService::GetInstance()->Init(); 82ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting(); 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetPrefs()->SetBoolean(prefs::kPrintPreviewDisabled, false); 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 86a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 87a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)BrowserWindow* PrintPreviewTest::CreateBrowserWindow() { 88a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return new PrintPreviewTestBrowserWindow; 89a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 90