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: 22 explicit TestBrowserWindowOwner(TestBrowserWindow* window) : window_(window) { 23 BrowserList::AddObserver(this); 24 } 25 virtual ~TestBrowserWindowOwner() { 26 BrowserList::RemoveObserver(this); 27 } 28 29 private: 30 // Overridden from BrowserListObserver: 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 43 Browser* 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 55 GURL TestBrowserWindow::TestLocationBar::GetDestinationURL() const { 56 return GURL(); 57 } 58 59 WindowOpenDisposition 60 TestBrowserWindow::TestLocationBar::GetWindowOpenDisposition() const { 61 return CURRENT_TAB; 62 } 63 64 ui::PageTransition 65 TestBrowserWindow::TestLocationBar::GetPageTransition() const { 66 return ui::PAGE_TRANSITION_LINK; 67 } 68 69 bool TestBrowserWindow::TestLocationBar::ShowPageActionPopup( 70 const extensions::Extension* extension, bool grant_active_tab) { 71 return false; 72 } 73 74 const OmniboxView* TestBrowserWindow::TestLocationBar::GetOmniboxView() const { 75 return NULL; 76 } 77 78 OmniboxView* TestBrowserWindow::TestLocationBar::GetOmniboxView() { 79 return NULL; 80 } 81 82 LocationBarTesting* 83 TestBrowserWindow::TestLocationBar::GetLocationBarForTesting() { 84 return NULL; 85 } 86 87 88 // TestBrowserWindow ---------------------------------------------------------- 89 90 TestBrowserWindow::TestBrowserWindow() {} 91 92 TestBrowserWindow::~TestBrowserWindow() {} 93 94 bool TestBrowserWindow::IsActive() const { 95 return false; 96 } 97 98 bool TestBrowserWindow::IsAlwaysOnTop() const { 99 return false; 100 } 101 102 gfx::NativeWindow TestBrowserWindow::GetNativeWindow() { 103 return NULL; 104 } 105 106 BrowserWindowTesting* TestBrowserWindow::GetBrowserWindowTesting() { 107 return NULL; 108 } 109 110 StatusBubble* TestBrowserWindow::GetStatusBubble() { 111 return NULL; 112 } 113 114 gfx::Rect TestBrowserWindow::GetRestoredBounds() const { 115 return gfx::Rect(); 116 } 117 118 ui::WindowShowState TestBrowserWindow::GetRestoredState() const { 119 return ui::SHOW_STATE_DEFAULT; 120 } 121 122 gfx::Rect TestBrowserWindow::GetBounds() const { 123 return gfx::Rect(); 124 } 125 126 bool TestBrowserWindow::IsMaximized() const { 127 return false; 128 } 129 130 bool TestBrowserWindow::IsMinimized() const { 131 return false; 132 } 133 134 bool TestBrowserWindow::ShouldHideUIForFullscreen() const { 135 return false; 136 } 137 138 bool TestBrowserWindow::IsFullscreen() const { 139 return false; 140 } 141 142 #if defined(OS_WIN) 143 bool TestBrowserWindow::IsInMetroSnapMode() const { 144 return false; 145 } 146 #endif 147 148 bool TestBrowserWindow::IsFullscreenBubbleVisible() const { 149 return false; 150 } 151 152 LocationBar* TestBrowserWindow::GetLocationBar() const { 153 return const_cast<TestLocationBar*>(&location_bar_); 154 } 155 156 bool TestBrowserWindow::PreHandleKeyboardEvent( 157 const content::NativeWebKeyboardEvent& event, 158 bool* is_keyboard_shortcut) { 159 return false; 160 } 161 162 bool TestBrowserWindow::IsBookmarkBarVisible() const { 163 return false; 164 } 165 166 bool TestBrowserWindow::IsBookmarkBarAnimating() const { 167 return false; 168 } 169 170 bool TestBrowserWindow::IsTabStripEditable() const { 171 return false; 172 } 173 174 bool TestBrowserWindow::IsToolbarVisible() const { 175 return false; 176 } 177 178 gfx::Rect TestBrowserWindow::GetRootWindowResizerRect() const { 179 return gfx::Rect(); 180 } 181 182 bool TestBrowserWindow::IsDownloadShelfVisible() const { 183 return false; 184 } 185 186 DownloadShelf* TestBrowserWindow::GetDownloadShelf() { 187 return &download_shelf_; 188 } 189 190 int TestBrowserWindow::GetExtraRenderViewHeight() const { 191 return 0; 192 } 193 194 #if defined(OS_MACOSX) 195 bool TestBrowserWindow::IsFullscreenWithChrome() { 196 return false; 197 } 198 199 bool TestBrowserWindow::IsFullscreenWithoutChrome() { 200 return false; 201 } 202 #endif 203 204 WindowOpenDisposition TestBrowserWindow::GetDispositionForPopupBounds( 205 const gfx::Rect& bounds) { 206 return NEW_POPUP; 207 } 208 209 FindBar* TestBrowserWindow::CreateFindBar() { 210 return NULL; 211 } 212 213 web_modal::WebContentsModalDialogHost* 214 TestBrowserWindow::GetWebContentsModalDialogHost() { 215 return NULL; 216 } 217 218 int 219 TestBrowserWindow::GetRenderViewHeightInsetWithDetachedBookmarkBar() { 220 return 0; 221 } 222 223 void TestBrowserWindow::ExecuteExtensionCommand( 224 const extensions::Extension* extension, 225 const extensions::Command& command) {} 226