OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/base/test_browser_window.h" | 5 #include "chrome/test/base/test_browser_window.h" |
6 | 6 |
| 7 #include "chrome/browser/ui/browser_list.h" |
| 8 #include "chrome/browser/ui/browser_list_observer.h" |
7 #include "ui/gfx/rect.h" | 9 #include "ui/gfx/rect.h" |
8 | 10 |
9 using content::NativeWebKeyboardEvent; | 11 using content::NativeWebKeyboardEvent; |
10 | 12 |
11 TestBrowserWindow::TestBrowserWindow(Browser* browser) {} | 13 TestBrowserWindow::TestBrowserWindow() {} |
12 | 14 |
13 TestBrowserWindow::~TestBrowserWindow() {} | 15 TestBrowserWindow::~TestBrowserWindow() {} |
14 | 16 |
15 bool TestBrowserWindow::IsActive() const { | 17 bool TestBrowserWindow::IsActive() const { |
16 return false; | 18 return false; |
17 } | 19 } |
18 | 20 |
19 bool TestBrowserWindow::IsAlwaysOnTop() const { | 21 bool TestBrowserWindow::IsAlwaysOnTop() const { |
20 return false; | 22 return false; |
21 } | 23 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 125 } |
124 | 126 |
125 WindowOpenDisposition TestBrowserWindow::GetDispositionForPopupBounds( | 127 WindowOpenDisposition TestBrowserWindow::GetDispositionForPopupBounds( |
126 const gfx::Rect& bounds) { | 128 const gfx::Rect& bounds) { |
127 return NEW_POPUP; | 129 return NEW_POPUP; |
128 } | 130 } |
129 | 131 |
130 FindBar* TestBrowserWindow::CreateFindBar() { | 132 FindBar* TestBrowserWindow::CreateFindBar() { |
131 return NULL; | 133 return NULL; |
132 } | 134 } |
| 135 |
| 136 namespace chrome { |
| 137 |
| 138 namespace { |
| 139 |
| 140 // Handles destroying a TestBrowserWindow when the Browser it is attached to is |
| 141 // destroyed. |
| 142 class TestBrowserWindowOwner : public chrome::BrowserListObserver { |
| 143 public: |
| 144 explicit TestBrowserWindowOwner(TestBrowserWindow* window) : window_(window) { |
| 145 BrowserList::AddObserver(this); |
| 146 } |
| 147 virtual ~TestBrowserWindowOwner() { |
| 148 BrowserList::RemoveObserver(this); |
| 149 } |
| 150 |
| 151 private: |
| 152 // Overridden from BrowserListObserver: |
| 153 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE { |
| 154 if (browser->window() == window_.get()) |
| 155 delete this; |
| 156 } |
| 157 |
| 158 scoped_ptr<TestBrowserWindow> window_; |
| 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowOwner); |
| 161 }; |
| 162 |
| 163 } // namespace |
| 164 |
| 165 Browser* CreateBrowserWithTestWindowForProfile(Profile* profile) { |
| 166 Browser::CreateParams params(profile); |
| 167 return CreateBrowserWithTestWindowForParams(¶ms); |
| 168 } |
| 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 |
OLD | NEW |