Home | History | Annotate | Download | only in base
      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 using content::NativeWebKeyboardEvent;
     12 
     13 TestBrowserWindow::TestBrowserWindow() {}
     14 
     15 TestBrowserWindow::~TestBrowserWindow() {}
     16 
     17 bool TestBrowserWindow::IsActive() const {
     18   return false;
     19 }
     20 
     21 bool TestBrowserWindow::IsAlwaysOnTop() const {
     22   return false;
     23 }
     24 
     25 gfx::NativeWindow TestBrowserWindow::GetNativeWindow() {
     26   return NULL;
     27 }
     28 
     29 BrowserWindowTesting* TestBrowserWindow::GetBrowserWindowTesting() {
     30   return NULL;
     31 }
     32 
     33 StatusBubble* TestBrowserWindow::GetStatusBubble() {
     34   return NULL;
     35 }
     36 
     37 gfx::Rect TestBrowserWindow::GetRestoredBounds() const {
     38   return gfx::Rect();
     39 }
     40 
     41 ui::WindowShowState TestBrowserWindow::GetRestoredState() const {
     42   return ui::SHOW_STATE_DEFAULT;
     43 }
     44 
     45 gfx::Rect TestBrowserWindow::GetBounds() const {
     46   return gfx::Rect();
     47 }
     48 
     49 bool TestBrowserWindow::IsMaximized() const {
     50   return false;
     51 }
     52 
     53 bool TestBrowserWindow::IsMinimized() const {
     54   return false;
     55 }
     56 
     57 bool TestBrowserWindow::ShouldHideUIForFullscreen() const {
     58   return false;
     59 }
     60 
     61 bool TestBrowserWindow::IsFullscreen() const {
     62   return false;
     63 }
     64 
     65 #if defined(OS_WIN)
     66 bool TestBrowserWindow::IsInMetroSnapMode() const {
     67   return false;
     68 }
     69 #endif
     70 
     71 bool TestBrowserWindow::IsFullscreenBubbleVisible() const {
     72   return false;
     73 }
     74 
     75 LocationBar* TestBrowserWindow::GetLocationBar() const {
     76   return const_cast<TestLocationBar*>(&location_bar_);
     77 }
     78 
     79 bool TestBrowserWindow::PreHandleKeyboardEvent(
     80     const NativeWebKeyboardEvent& event,
     81     bool* is_keyboard_shortcut) {
     82   return false;
     83 }
     84 
     85 bool TestBrowserWindow::IsBookmarkBarVisible() const {
     86   return false;
     87 }
     88 
     89 bool TestBrowserWindow::IsBookmarkBarAnimating() const {
     90   return false;
     91 }
     92 
     93 bool TestBrowserWindow::IsTabStripEditable() const {
     94   return false;
     95 }
     96 
     97 bool TestBrowserWindow::IsToolbarVisible() const {
     98   return false;
     99 }
    100 
    101 gfx::Rect TestBrowserWindow::GetRootWindowResizerRect() const {
    102   return gfx::Rect();
    103 }
    104 
    105 bool TestBrowserWindow::IsDownloadShelfVisible() const {
    106   return false;
    107 }
    108 
    109 DownloadShelf* TestBrowserWindow::GetDownloadShelf() {
    110   return &download_shelf_;
    111 }
    112 
    113 int TestBrowserWindow::GetExtraRenderViewHeight() const {
    114   return 0;
    115 }
    116 
    117 #if defined(OS_MACOSX)
    118 bool TestBrowserWindow::IsFullscreenWithChrome() {
    119   return false;
    120 }
    121 
    122 bool TestBrowserWindow::IsFullscreenWithoutChrome() {
    123   return false;
    124 }
    125 #endif
    126 
    127 WindowOpenDisposition TestBrowserWindow::GetDispositionForPopupBounds(
    128     const gfx::Rect& bounds) {
    129   return NEW_POPUP;
    130 }
    131 
    132 FindBar* TestBrowserWindow::CreateFindBar() {
    133   return NULL;
    134 }
    135 
    136 web_modal::WebContentsModalDialogHost*
    137     TestBrowserWindow::GetWebContentsModalDialogHost() {
    138   return NULL;
    139 }
    140 
    141 namespace chrome {
    142 
    143 namespace {
    144 
    145 // Handles destroying a TestBrowserWindow when the Browser it is attached to is
    146 // destroyed.
    147 class TestBrowserWindowOwner : public chrome::BrowserListObserver {
    148  public:
    149   explicit TestBrowserWindowOwner(TestBrowserWindow* window) : window_(window) {
    150     BrowserList::AddObserver(this);
    151   }
    152   virtual ~TestBrowserWindowOwner() {
    153     BrowserList::RemoveObserver(this);
    154   }
    155 
    156  private:
    157   // Overridden from BrowserListObserver:
    158   virtual void OnBrowserRemoved(Browser* browser) OVERRIDE {
    159     if (browser->window() == window_.get())
    160       delete this;
    161   }
    162 
    163   scoped_ptr<TestBrowserWindow> window_;
    164 
    165   DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowOwner);
    166 };
    167 
    168 }  // namespace
    169 
    170 Browser* CreateBrowserWithTestWindowForParams(Browser::CreateParams* params) {
    171   TestBrowserWindow* window = new TestBrowserWindow;
    172   new TestBrowserWindowOwner(window);
    173   params->window = window;
    174   return new Browser(*params);
    175 }
    176 
    177 }  // namespace chrome
    178