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. 4 5 #include "chrome/test/base/test_browser_window.h" 6 7 #include "chrome/browser/ui/browser_list.h" 8 #include "chrome/browser/ui/browser_list_observer.h" 9 #include "ui/gfx/rect.h" 10 11 12 // Helpers -------------------------------------------------------------------- 13 14 namespace chrome { 15 16 namespace { 17 18 // Handles destroying a TestBrowserWindow when the Browser it is attached to is 19 // destroyed. 20 class TestBrowserWindowOwner : public chrome::BrowserListObserver { 21 public: TestBrowserWindowOwner(TestBrowserWindow * window)22 explicit TestBrowserWindowOwner(TestBrowserWindow* window) : window_(window) { 23 BrowserList::AddObserver(this); 24 } ~TestBrowserWindowOwner()25 virtual ~TestBrowserWindowOwner() { 26 BrowserList::RemoveObserver(this); 27 } 28 29 private: 30 // Overridden from BrowserListObserver: OnBrowserRemoved(Browser * browser)31 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE { 32 if (browser->window() == window_.get()) 33 delete this; 34 } 35 36 scoped_ptr<TestBrowserWindow> window_; 37 38 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowOwner); 39 }; 40 41 } // namespace 42 CreateBrowserWithTestWindowForParams(Browser::CreateParams * params)43Browser* CreateBrowserWithTestWindowForParams(Browser::CreateParams* params) { 44 TestBrowserWindow* window = new TestBrowserWindow; 45 new TestBrowserWindowOwner(window); 46 params->window = window; 47 return new Browser(*params); 48 } 49 50 } // namespace chrome 51 52 53 // TestBrowserWindow::TestLocationBar ----------------------------------------- 54 GetDestinationURL() const55GURL TestBrowserWindow::TestLocationBar::GetDestinationURL() const { 56 return GURL(); 57 } 58 59 WindowOpenDisposition GetWindowOpenDisposition() const60 TestBrowserWindow::TestLocationBar::GetWindowOpenDisposition() const { 61 return CURRENT_TAB; 62 } 63 64 ui::PageTransition GetPageTransition() const65 TestBrowserWindow::TestLocationBar::GetPageTransition() const { 66 return ui::PAGE_TRANSITION_LINK; 67 } 68 ShowPageActionPopup(const extensions::Extension * extension,bool grant_active_tab)69bool TestBrowserWindow::TestLocationBar::ShowPageActionPopup( 70 const extensions::Extension* extension, bool grant_active_tab) { 71 return false; 72 } 73 GetOmniboxView() const74const OmniboxView* TestBrowserWindow::TestLocationBar::GetOmniboxView() const { 75 return NULL; 76 } 77 GetOmniboxView()78OmniboxView* TestBrowserWindow::TestLocationBar::GetOmniboxView() { 79 return NULL; 80 } 81 82 LocationBarTesting* GetLocationBarForTesting()83 TestBrowserWindow::TestLocationBar::GetLocationBarForTesting() { 84 return NULL; 85 } 86 87 88 // TestBrowserWindow ---------------------------------------------------------- 89 TestBrowserWindow()90TestBrowserWindow::TestBrowserWindow() {} 91 ~TestBrowserWindow()92TestBrowserWindow::~TestBrowserWindow() {} 93 IsActive() const94bool TestBrowserWindow::IsActive() const { 95 return false; 96 } 97 IsAlwaysOnTop() const98bool TestBrowserWindow::IsAlwaysOnTop() const { 99 return false; 100 } 101 GetNativeWindow()102gfx::NativeWindow TestBrowserWindow::GetNativeWindow() { 103 return NULL; 104 } 105 GetBrowserWindowTesting()106BrowserWindowTesting* TestBrowserWindow::GetBrowserWindowTesting() { 107 return NULL; 108 } 109 GetStatusBubble()110StatusBubble* TestBrowserWindow::GetStatusBubble() { 111 return NULL; 112 } 113 GetRestoredBounds() const114gfx::Rect TestBrowserWindow::GetRestoredBounds() const { 115 return gfx::Rect(); 116 } 117 GetRestoredState() const118ui::WindowShowState TestBrowserWindow::GetRestoredState() const { 119 return ui::SHOW_STATE_DEFAULT; 120 } 121 GetBounds() const122gfx::Rect TestBrowserWindow::GetBounds() const { 123 return gfx::Rect(); 124 } 125 IsMaximized() const126bool TestBrowserWindow::IsMaximized() const { 127 return false; 128 } 129 IsMinimized() const130bool TestBrowserWindow::IsMinimized() const { 131 return false; 132 } 133 ShouldHideUIForFullscreen() const134bool TestBrowserWindow::ShouldHideUIForFullscreen() const { 135 return false; 136 } 137 IsFullscreen() const138bool TestBrowserWindow::IsFullscreen() const { 139 return false; 140 } 141 142 #if defined(OS_WIN) IsInMetroSnapMode() const143bool TestBrowserWindow::IsInMetroSnapMode() const { 144 return false; 145 } 146 #endif 147 IsFullscreenBubbleVisible() const148bool TestBrowserWindow::IsFullscreenBubbleVisible() const { 149 return false; 150 } 151 GetLocationBar() const152LocationBar* TestBrowserWindow::GetLocationBar() const { 153 return const_cast<TestLocationBar*>(&location_bar_); 154 } 155 PreHandleKeyboardEvent(const content::NativeWebKeyboardEvent & event,bool * is_keyboard_shortcut)156bool TestBrowserWindow::PreHandleKeyboardEvent( 157 const content::NativeWebKeyboardEvent& event, 158 bool* is_keyboard_shortcut) { 159 return false; 160 } 161 IsBookmarkBarVisible() const162bool TestBrowserWindow::IsBookmarkBarVisible() const { 163 return false; 164 } 165 IsBookmarkBarAnimating() const166bool TestBrowserWindow::IsBookmarkBarAnimating() const { 167 return false; 168 } 169 IsTabStripEditable() const170bool TestBrowserWindow::IsTabStripEditable() const { 171 return false; 172 } 173 IsToolbarVisible() const174bool TestBrowserWindow::IsToolbarVisible() const { 175 return false; 176 } 177 GetRootWindowResizerRect() const178gfx::Rect TestBrowserWindow::GetRootWindowResizerRect() const { 179 return gfx::Rect(); 180 } 181 IsDownloadShelfVisible() const182bool TestBrowserWindow::IsDownloadShelfVisible() const { 183 return false; 184 } 185 GetDownloadShelf()186DownloadShelf* TestBrowserWindow::GetDownloadShelf() { 187 return &download_shelf_; 188 } 189 GetExtraRenderViewHeight() const190int TestBrowserWindow::GetExtraRenderViewHeight() const { 191 return 0; 192 } 193 194 #if defined(OS_MACOSX) IsFullscreenWithChrome()195bool TestBrowserWindow::IsFullscreenWithChrome() { 196 return false; 197 } 198 IsFullscreenWithoutChrome()199bool TestBrowserWindow::IsFullscreenWithoutChrome() { 200 return false; 201 } 202 #endif 203 GetDispositionForPopupBounds(const gfx::Rect & bounds)204WindowOpenDisposition TestBrowserWindow::GetDispositionForPopupBounds( 205 const gfx::Rect& bounds) { 206 return NEW_POPUP; 207 } 208 CreateFindBar()209FindBar* TestBrowserWindow::CreateFindBar() { 210 return NULL; 211 } 212 213 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()214 TestBrowserWindow::GetWebContentsModalDialogHost() { 215 return NULL; 216 } 217 218 int GetRenderViewHeightInsetWithDetachedBookmarkBar()219TestBrowserWindow::GetRenderViewHeightInsetWithDetachedBookmarkBar() { 220 return 0; 221 } 222 ExecuteExtensionCommand(const extensions::Extension * extension,const extensions::Command & command)223void TestBrowserWindow::ExecuteExtensionCommand( 224 const extensions::Extension* extension, 225 const extensions::Command& command) {} 226