diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 22:13:55 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 22:13:55 +0000 |
commit | 9423d941cb200b789d482895ac644fe38d6bc048 (patch) | |
tree | 3e82d246d3ce5a1bb4eeade7a1aebff27748814d /chrome/test | |
parent | 127788d038548a56be833f863c9936714f6452cb (diff) | |
download | chromium_src-9423d941cb200b789d482895ac644fe38d6bc048.zip chromium_src-9423d941cb200b789d482895ac644fe38d6bc048.tar.gz chromium_src-9423d941cb200b789d482895ac644fe38d6bc048.tar.bz2 |
Remove the TestTabContents. This makes BrowserWithTestWindow use the
TestRenderViewHost instead. There are some changes to browser_commands_unittest
to support this. Now that we're using proper TabContentes, I had to stub out
a FocusManager call since there isn't a proper view hierarchy created.
Remove TabContents collection and switching from the NavigationController. I
tried to keep the same interface to the NavigationController since I tried that
in a previous patch and the change blew up.
Remove the TabContents factory. Callers now create a WebContents directly.
Review URL: http://codereview.chromium.org/67113
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13707 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/browser_with_test_window_test.cc | 49 | ||||
-rw-r--r-- | chrome/test/browser_with_test_window_test.h | 49 | ||||
-rw-r--r-- | chrome/test/test_tab_contents.cc | 20 | ||||
-rw-r--r-- | chrome/test/test_tab_contents.h | 102 | ||||
-rw-r--r-- | chrome/test/unit/unittests.vcproj | 8 |
5 files changed, 57 insertions, 171 deletions
diff --git a/chrome/test/browser_with_test_window_test.cc b/chrome/test/browser_with_test_window_test.cc index 3c2e879..1881a54 100644 --- a/chrome/test/browser_with_test_window_test.cc +++ b/chrome/test/browser_with_test_window_test.cc @@ -9,7 +9,9 @@ #include "chrome/test/test_browser_window.h" #include "chrome/test/testing_profile.h" -BrowserWithTestWindowTest::BrowserWithTestWindowTest() { +BrowserWithTestWindowTest::BrowserWithTestWindowTest() + : rph_factory_(), + rvh_factory_(&rph_factory_) { OleInitialize(NULL); } @@ -17,8 +19,6 @@ 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()); @@ -33,7 +33,6 @@ BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { // loop. browser_.reset(NULL); window_.reset(NULL); - tab_contents_factory_.reset(NULL); profile_.reset(NULL); MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); @@ -42,31 +41,35 @@ BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { OleUninitialize(); } -void BrowserWithTestWindowTest::AddTestingTab(Browser* browser) { - TestTabContents* tab_contents = tab_contents_factory_->CreateInstanceImpl(); - tab_contents->SetupController(profile()); - browser->tabstrip_model()->AddTabContents( - tab_contents, 0, PageTransition::TYPED, true); +TestRenderViewHost* BrowserWithTestWindowTest::TestRenderViewHostForTab( + TabContents* tab_contents) { + return static_cast<TestRenderViewHost*>( + tab_contents->AsWebContents()->render_view_host()); +} + +void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { + TabContents* new_tab = browser->AddTabWithURL(url, GURL(), + PageTransition::TYPED, true, + 0, NULL); + CommitPendingLoadAsNewNavigation(new_tab->controller(), url); +} + +void BrowserWithTestWindowTest::CommitPendingLoadAsNewNavigation( + NavigationController* controller, + const GURL& url) { + TestRenderViewHost* test_rvh = + TestRenderViewHostForTab(controller->tab_contents()); + MockRenderProcessHost* mock_rph = static_cast<MockRenderProcessHost*>( + test_rvh->process()); + + test_rvh->SendNavigate(mock_rph->max_page_id() + 1, url); } void BrowserWithTestWindowTest::NavigateAndCommit( NavigationController* controller, const GURL& url) { controller->LoadURL(url, GURL(), 0); - - // Commit the load. - // TODO(brettw) once this uses TestRenderViewHost, we should call SendNavigate - // on it instead of doing this stuff. - ViewHostMsg_FrameNavigate_Params params; - params.page_id = reinterpret_cast<TestTabContents*>( - controller->tab_contents())->GetNextPageID(); - params.url = url; - params.transition = PageTransition::LINK; - params.should_update_history = false; - params.gesture = NavigationGestureUser; - params.is_post = false; - NavigationController::LoadCommittedDetails details; - controller->RendererDidNavigate(params, &details); + CommitPendingLoadAsNewNavigation(controller, url); } void BrowserWithTestWindowTest::NavigateAndCommitActiveTab(const GURL& url) { diff --git a/chrome/test/browser_with_test_window_test.h b/chrome/test/browser_with_test_window_test.h index dfcb520..eb5d02a 100644 --- a/chrome/test/browser_with_test_window_test.h +++ b/chrome/test/browser_with_test_window_test.h @@ -8,24 +8,33 @@ #include <string> #include "base/message_loop.h" -#include "chrome/test/test_tab_contents.h" +#include "chrome/browser/renderer_host/test_render_view_host.h" #include "testing/gtest/include/gtest/gtest.h" class Browser; +class GURL; +class NavigationController; class TestBrowserWindow; class TestingProfile; // Base class for browser based unit tests. BrowserWithTestWindowTest creates a // Browser with a TestingProfile and TestBrowserWindow. To add a tab use -// AddTestingTab. This adds a Tab whose TabContents is a TestTabContents. -// Use the method test_url_with_path to obtain a URL that targets the -// TestTabContents. For example, the following adds a tab and navigates to +// AddTestingTab. For example, the following adds a tab and navigates to // two URLs that target the TestTabContents: -// AddTestingTab(browser()); -// browser()->OpenURL(test_url_with_path("1"), GURL(), CURRENT_TAB, -// PageTransition::TYPED); -// browser()->OpenURL(test_url_with_path("1"), GURL(), CURRENT_TAB, +// +// // Add a new tab and navigate it. This will be at index 0. +// AddTab(browser(), GURL("http://foo/1")); +// NavigationController* controller = +// browser()->GetTabContentsAt(0)->controller(); +// +// // Navigate somewhere else. +// GURL url2("http://foo/2"); +// NavigateAndCommit(controller, url2); +// +// // This is equivalent to the above, and lets you test pending navigations. +// browser()->OpenURL(GURL("http://foo/2"), GURL(), CURRENT_TAB, // PageTransition::TYPED); +// CommitPendingLoadAsNewNavigation(controller, url2); // // Subclasses must invoke BrowserWithTestWindowTest::SetUp as it is responsible // for creating the various objects of this class. @@ -36,21 +45,23 @@ class BrowserWithTestWindowTest : public testing::Test { virtual void SetUp(); + // Returns the current RenderViewHost for the current tab as a + // TestRenderViewHost. + TestRenderViewHost* TestRenderViewHostForTab(TabContents* tab_contents); + protected: Browser* browser() const { return browser_.get(); } TestingProfile* profile() const { return profile_.get(); } - // Adds a tab to |browser| whose TabContents comes from a - // TestTabContentsFactory. Use test_url_with_path to obtain a URL that - // that uses the newly created TabContents. - void AddTestingTab(Browser* browser); + // Adds a tab to |browser| with the given URL and commits the load. + // This is a convenience function. The new tab will be added at index 0. + void AddTab(Browser* browser, const GURL& url); - // Returns a GURL that targets the testing TabContents created by way of - // AddTestingTab. - GURL test_url_with_path(const std::string& path) const { - return tab_contents_factory_->test_url_with_path(path); - } + // Commits the pending load as if we went to a new page (as opposed to back or + // forward). + void CommitPendingLoadAsNewNavigation(NavigationController* controller, + const GURL& url); // Creates a pending navigation on the given navigation controller to the // given URL with the default parameters and the commits the load with a page @@ -67,10 +78,12 @@ class BrowserWithTestWindowTest : public testing::Test { MessageLoopForUI ui_loop_; scoped_ptr<TestingProfile> profile_; - scoped_ptr<TestTabContentsFactory> tab_contents_factory_; scoped_ptr<TestBrowserWindow> window_; scoped_ptr<Browser> browser_; + MockRenderProcessHostFactory rph_factory_; + TestRenderViewHostFactory rvh_factory_; + DISALLOW_COPY_AND_ASSIGN(BrowserWithTestWindowTest); }; diff --git a/chrome/test/test_tab_contents.cc b/chrome/test/test_tab_contents.cc deleted file mode 100644 index 92bec46..0000000 --- a/chrome/test/test_tab_contents.cc +++ /dev/null @@ -1,20 +0,0 @@ -// 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/test_tab_contents.h" - -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/common/render_messages.h" - -// static -SiteInstance* TestTabContents::site_instance_ = NULL; - -TestTabContents::TestTabContents(TabContentsType type) - : TabContents(type), - next_page_id_(1) { -} - -bool TestTabContents::NavigateToPendingEntry(bool reload) { - return true; -} diff --git a/chrome/test/test_tab_contents.h b/chrome/test/test_tab_contents.h deleted file mode 100644 index 91d3114..0000000 --- a/chrome/test/test_tab_contents.h +++ /dev/null @@ -1,102 +0,0 @@ -// 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. - -#ifndef CHROME_BROWSER_TEST_TEST_TAB_CONTENTS_H_ -#define CHROME_BROWSER_TEST_TEST_TAB_CONTENTS_H_ - -#include "base/string_util.h" -#include "chrome/browser/tab_contents/tab_contents_factory.h" -#include "chrome/browser/tab_contents/tab_contents.h" - -// TabContents typed created by TestTabContentsFactory. -class TestTabContents : public TabContents { - public: - explicit TestTabContents(TabContentsType type); - - // Sets the site instance used by *ALL* TestTabContents. - static void set_site_instance(SiteInstance* site_instance) { - site_instance_ = site_instance; - } - - int GetNextPageID() { - return next_page_id_++; - } - - // Overridden from TabContents so we can provide a non-NULL site instance in - // some cases. To use, the test will have to set the site_instance_ member - // variable to some site instance it creates. - virtual SiteInstance* GetSiteInstance() const { - return site_instance_; - } - - // Overrides to be more like WebContents (don't autocommit). - virtual bool NavigateToPendingEntry(bool reload); - - private: - static SiteInstance* site_instance_; - - int next_page_id_; - - DISALLOW_COPY_AND_ASSIGN(TestTabContents); -}; - -// TestTabContentsFactory is a TabContentsFactory that can be used for tests. -// -// Use the CreateAndRegisterFactory method to create and register a new -// TestTabContentsFactory. You can use scheme() to determine the resulting -// scheme and type() for the resulting TabContentsType. -// -// TestTabContentsFactory unregisters itself from the TabContentsFactory in its -// destructor. -class TestTabContentsFactory : public TabContentsFactory { - public: - // Creates a new TestTabContentsFactory and registers it for the next - // free TabContentsType. The destructor unregisters the factory. - static TestTabContentsFactory* CreateAndRegisterFactory() { - TabContentsType new_type = TabContentsFactory::NextUnusedType(); - TestTabContentsFactory* new_factory = - new TestTabContentsFactory( - new_type, "test" + IntToString(static_cast<int>(new_type))); - TabContents::RegisterFactory(new_type, new_factory); - return new_factory; - } - - TestTabContentsFactory(TabContentsType type, const std::string& scheme) - : type_(type), - scheme_(scheme) { - } - - ~TestTabContentsFactory() { - TabContents::RegisterFactory(type_, NULL); - } - - virtual TabContents* CreateInstance() { - return CreateInstanceImpl(); - } - - TestTabContents* CreateInstanceImpl() { - return new TestTabContents(type_); - } - - virtual bool CanHandleURL(const GURL& url) { - return url.SchemeIs(scheme_.c_str()); - } - - const std::string& scheme() const { return scheme_; } - - GURL test_url_with_path(const std::string& path) const { - return GURL(scheme() + ":" + path); - } - - TabContentsType type() const { return type_; } - - private: - TabContentsType type_; - - const std::string scheme_; - - DISALLOW_COPY_AND_ASSIGN(TestTabContentsFactory); -}; - -#endif // CHROME_BROWSER_TEST_TEST_TAB_CONTENTS_H_ diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index 4711923f..ecf0c17 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -835,14 +835,6 @@ > </File> <File - RelativePath="..\test_tab_contents.cc" - > - </File> - <File - RelativePath="..\test_tab_contents.h" - > - </File> - <File RelativePath="..\..\browser\tab_contents\test_web_contents.cc" > </File> |