Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1968)

Unified Diff: chrome/test/base/test_browser_window.cc

Issue 10692195: Consolidate Browser Creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/base/test_browser_window.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/base/test_browser_window.cc
===================================================================
--- chrome/test/base/test_browser_window.cc (revision 148382)
+++ chrome/test/base/test_browser_window.cc (working copy)
@@ -4,11 +4,13 @@
#include "chrome/test/base/test_browser_window.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "ui/gfx/rect.h"
using content::NativeWebKeyboardEvent;
-TestBrowserWindow::TestBrowserWindow(Browser* browser) {}
+TestBrowserWindow::TestBrowserWindow() {}
TestBrowserWindow::~TestBrowserWindow() {}
@@ -130,3 +132,46 @@
FindBar* TestBrowserWindow::CreateFindBar() {
return NULL;
}
+
+namespace chrome {
+
+namespace {
+
+// Handles destroying a TestBrowserWindow when the Browser it is attached to is
+// destroyed.
+class TestBrowserWindowOwner : public chrome::BrowserListObserver {
+ public:
+ explicit TestBrowserWindowOwner(TestBrowserWindow* window) : window_(window) {
+ BrowserList::AddObserver(this);
+ }
+ virtual ~TestBrowserWindowOwner() {
+ BrowserList::RemoveObserver(this);
+ }
+
+ private:
+ // Overridden from BrowserListObserver:
+ virtual void OnBrowserRemoved(Browser* browser) OVERRIDE {
+ if (browser->window() == window_.get())
+ delete this;
+ }
+
+ scoped_ptr<TestBrowserWindow> window_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowOwner);
+};
+
+} // namespace
+
+Browser* CreateBrowserWithTestWindowForProfile(Profile* profile) {
+ Browser::CreateParams params(profile);
+ return CreateBrowserWithTestWindowForParams(&params);
+}
+
+Browser* CreateBrowserWithTestWindowForParams(Browser::CreateParams* params) {
+ TestBrowserWindow* window = new TestBrowserWindow;
+ new TestBrowserWindowOwner(window);
+ params->window = window;
+ return new Browser(*params);
+}
+
+} // namespace chrome
« no previous file with comments | « chrome/test/base/test_browser_window.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698