diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-14 15:51:10 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-14 15:51:10 +0000 |
commit | be3877f74da87b5be2b549f733b5705c9607ec82 (patch) | |
tree | a00fa6c37daf0467801e2cbb06660b360a6d449e /chrome/test/browser_with_test_window_test.cc | |
parent | 57a020e92927a379ab514db5836cb4550e6e444b (diff) | |
download | chromium_src-be3877f74da87b5be2b549f733b5705c9607ec82.zip chromium_src-be3877f74da87b5be2b549f733b5705c9607ec82.tar.gz chromium_src-be3877f74da87b5be2b549f733b5705c9607ec82.tar.bz2 |
Provides the infrastructure for Browser unit tests that create a
BrowserWindow with only a TabStrip. I also converted two ui tests over
to unit tests to make sure it all worked. I had to add a bunch of null
checks to Browser and a couple of other places.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/17386
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8007 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/browser_with_test_window_test.cc')
-rw-r--r-- | chrome/test/browser_with_test_window_test.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/chrome/test/browser_with_test_window_test.cc b/chrome/test/browser_with_test_window_test.cc new file mode 100644 index 0000000..35b3dafc --- /dev/null +++ b/chrome/test/browser_with_test_window_test.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/browser_with_test_window_test.h" + +#include "chrome/browser/browser.h" +#include "chrome/test/test_browser_window.h" +#include "chrome/test/testing_profile.h" + +BrowserWithTestWindowTest::BrowserWithTestWindowTest() { + OleInitialize(NULL); +} + +void BrowserWithTestWindowTest::SetUp() { + // NOTE: I have a feeling we're going to want virtual methods for creating + // these, as such they're in SetUp instead of the constructor. + profile_.reset(new TestingProfile()); + tab_contents_factory_.reset( + TestTabContentsFactory::CreateAndRegisterFactory()); + browser_.reset(new Browser(Browser::TYPE_NORMAL, profile())); + window_.reset(new TestBrowserWindow(browser())); + browser_->set_window(window_.get()); +} + +BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { + // Make sure we close all tabs, otherwise Browser isn't happy in its + // destructor. + browser()->CloseAllTabs(); + + // A Task is leaked if we don't destroy everything, then run the message + // loop. + browser_.reset(NULL); + window_.reset(NULL); + tab_contents_factory_.reset(NULL); + profile_.reset(NULL); + + MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); + MessageLoop::current()->Run(); + + OleUninitialize(); +} + +void BrowserWithTestWindowTest::AddTestingTab(Browser* browser) { + TestTabContents* tab_contents = tab_contents_factory_->CreateInstanceImpl(); + tab_contents->set_commit_on_navigate(true); + tab_contents->SetupController(profile()); + browser->tabstrip_model()->AddTabContents( + tab_contents, 0, PageTransition::TYPED, true); +} |