print_preview_test.cc revision 010d83a9304c5a91596085d917d248abff47903a
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) 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using web_modal::WebContentsModalDialogHost; 184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)using web_modal::ModalDialogHostObserver; 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace { 21a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 22a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use a custom test browser window to provide a parent view to the print 23a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// preview dialog. 24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class PrintPreviewTestBrowserWindow 25a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) : public TestBrowserWindow, 26a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public WebContentsModalDialogHost { 27a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public: 28a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) PrintPreviewTestBrowserWindow() {} 29a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 30a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // BrowserWindow overrides 31a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual WebContentsModalDialogHost* GetWebContentsModalDialogHost() OVERRIDE { 32a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return this; 33a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 34a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 35a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // WebContentsModalDialogHost overrides 36a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // The web contents modal dialog must be parented to *something*; use the 38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // WebContents window since there is no true browser window for unit tests. 39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual gfx::NativeView GetHostView() const OVERRIDE { 40010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return FindBrowser()->tab_strip_model()->GetActiveWebContents()-> 41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) GetNativeView(); 42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE { 45a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return gfx::Point(); 46a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 4858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual gfx::Size GetMaximumDialogSize() OVERRIDE { 4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return gfx::Size(); 5058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 5158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 52a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void AddObserver( 534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ModalDialogHostObserver* observer) OVERRIDE {} 54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void RemoveObserver( 554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ModalDialogHostObserver* observer) OVERRIDE {} 56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private: 58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) Browser* FindBrowser() const { 59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) for (chrome::BrowserIterator it; !it.done(); it.Next()) { 60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) Browser* browser = *it; 61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) if (browser->window() == this) 62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return browser; 63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) NOTREACHED(); 65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return NULL; 66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(PrintPreviewTestBrowserWindow); 69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}; 70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} // namespace 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)PrintPreviewTest::PrintPreviewTest() {} 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)PrintPreviewTest::~PrintPreviewTest() {} 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void PrintPreviewTest::SetUp() { 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserWithTestWindowTest::SetUp(); 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The PluginService will be destroyed at the end of the test (due to the 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ShadowingAtExitManager in our base class). 80ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch content::PluginService::GetInstance()->Init(); 81ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting(); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetPrefs()->SetBoolean(prefs::kPrintPreviewDisabled, false); 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 85a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 86a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)BrowserWindow* PrintPreviewTest::CreateBrowserWindow() { 87a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return new PrintPreviewTestBrowserWindow; 88a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 89