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 | |
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')
-rw-r--r-- | chrome/browser/browser.cc | 37 | ||||
-rw-r--r-- | chrome/browser/browser.h | 7 | ||||
-rw-r--r-- | chrome/browser/browser_commands_unittest.cc | 74 | ||||
-rw-r--r-- | chrome/browser/browser_uitest.cc | 90 | ||||
-rw-r--r-- | chrome/browser/browser_window.h | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents.cc | 9 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 3 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip.cc | 3 | ||||
-rw-r--r-- | chrome/browser/window_sizer.cc | 3 | ||||
-rw-r--r-- | chrome/test/browser_with_test_window_test.cc | 50 | ||||
-rw-r--r-- | chrome/test/browser_with_test_window_test.h | 71 | ||||
-rw-r--r-- | chrome/test/test_browser_window.h | 66 | ||||
-rw-r--r-- | chrome/test/test_tab_contents.h | 4 | ||||
-rw-r--r-- | chrome/test/unit/unittests.vcproj | 16 | ||||
-rw-r--r-- | chrome/views/window_delegate.cc | 5 |
15 files changed, 336 insertions, 103 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 61ea2da..6f5cb590 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -246,6 +246,8 @@ void Browser::CreateBrowserWindow() { // Show the First Run information bubble if we've been told to. PrefService* local_state = g_browser_process->local_state(); + if (!local_state) + return; if (local_state->IsPrefRegistered(prefs::kShouldShowFirstRunBubble) && local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) { // Reset the preference so we don't show the bubble for subsequent windows. @@ -1430,10 +1432,13 @@ void Browser::TabSelectedAt(TabContents* old_contents, UpdateCommandsForTabState(); // Reset the status bubble. - GetStatusBubble()->Hide(); + StatusBubble* status_bubble = GetStatusBubble(); + if (status_bubble) { + status_bubble->Hide(); - // Show the loading state (if any). - GetStatusBubble()->SetStatus(GetSelectedTabContents()->GetStatusText()); + // Show the loading state (if any). + status_bubble->SetStatus(GetSelectedTabContents()->GetStatusText()); + } // Update sessions. Don't force creation of sessions. If sessions doesn't // exist, the change will be picked up by sessions when created. @@ -1567,7 +1572,8 @@ void Browser::OpenURLFromTab(TabContents* source, // The TabContents might have changed as part of the navigation (ex: new // tab page can become WebContents). new_contents = current_tab->controller()->active_contents(); - GetStatusBubble()->Hide(); + if (GetStatusBubble()) + GetStatusBubble()->Hide(); // Synchronously update the location bar. This allows us to immediately // have the URL bar update when the user types something, rather than @@ -1681,7 +1687,8 @@ void Browser::LoadingStateChanged(TabContents* source) { if (source == GetSelectedTabContents()) { UpdateStopGoState(source->is_loading()); - GetStatusBubble()->SetStatus(GetSelectedTabContents()->GetStatusText()); + if (GetStatusBubble()) + GetStatusBubble()->SetStatus(GetSelectedTabContents()->GetStatusText()); } } @@ -1729,6 +1736,9 @@ void Browser::URLStarredChanged(TabContents* source, bool starred) { } void Browser::ContentsMouseEvent(TabContents* source, UINT message) { + if (!GetStatusBubble()) + return; + if (source == GetSelectedTabContents()) { if (message == WM_MOUSEMOVE) { GetStatusBubble()->MouseMoved(); @@ -1739,6 +1749,9 @@ void Browser::ContentsMouseEvent(TabContents* source, UINT message) { } void Browser::UpdateTargetURL(TabContents* source, const GURL& url) { + if (!GetStatusBubble()) + return; + if (source == GetSelectedTabContents()) { PrefService* prefs = profile_->GetPrefs(); GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages)); @@ -2052,14 +2065,22 @@ void Browser::UpdateCommandsForTabState() { } void Browser::UpdateStopGoState(bool is_loading) { - GetGoButton()->ChangeMode(is_loading ? + GoButton* go_button = GetGoButton(); + if (!go_button) + return; + + go_button->ChangeMode(is_loading ? GoButton::MODE_STOP : GoButton::MODE_GO); controller_.UpdateCommandEnabled(IDC_GO, !is_loading); controller_.UpdateCommandEnabled(IDC_STOP, is_loading); } void Browser::SetStarredButtonToggled(bool starred) { - window_->GetStarButton()->SetToggled(starred); + ToolbarStarToggle* star_button = window_->GetStarButton(); + if (!star_button) + return; + + star_button->SetToggled(starred); } /////////////////////////////////////////////////////////////////////////////// @@ -2153,7 +2174,7 @@ void Browser::ProcessPendingUIUpdates() { // Updating the URL happens synchronously in ScheduleUIUpdate. - if (flags & TabContents::INVALIDATE_LOAD) + if (flags & TabContents::INVALIDATE_LOAD && GetStatusBubble()) GetStatusBubble()->SetStatus(GetSelectedTabContents()->GetStatusText()); if (invalidate_tab) { // INVALIDATE_TITLE or INVALIDATE_FAVICON. diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index f3f2eda..fa3927d 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -82,6 +82,13 @@ class Browser : public TabStripModelDelegate, const std::vector<std::wstring>& user_data_dir_profiles() const { return g_browser_process->user_data_dir_profiles(); } + // Sets the BrowserWindow. This is intended for testing and generally not + // useful outside of testing. Use CreateBrowserWindow outside of testing, or + // the static convenience methods that create a BrowserWindow for you. + void set_window(BrowserWindow* window) { + DCHECK(!window_); + window_ = window; + } BrowserWindow* window() const { return window_; } ToolbarModel* toolbar_model() { return &toolbar_model_; } const SessionID& session_id() const { return session_id_; } diff --git a/chrome/browser/browser_commands_unittest.cc b/chrome/browser/browser_commands_unittest.cc new file mode 100644 index 0000000..13aa318 --- /dev/null +++ b/chrome/browser/browser_commands_unittest.cc @@ -0,0 +1,74 @@ +// 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/app/chrome_dll_resource.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/navigation_controller.h" +#include "chrome/browser/navigation_entry.h" +#include "chrome/test/browser_with_test_window_test.h" + +typedef BrowserWithTestWindowTest BrowserCommandsTest; + +// Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and +// IDC_SELECT_LAST_TAB. +TEST_F(BrowserCommandsTest, TabNavigationAccelerators) { + // Create three tabs. + AddTestingTab(browser()); + AddTestingTab(browser()); + AddTestingTab(browser()); + + // Select the second tab. + browser()->SelectTabContentsAt(1, false); + + // Navigate to the first tab using an accelerator. + browser()->ExecuteCommand(IDC_SELECT_TAB_0); + ASSERT_EQ(0, browser()->selected_index()); + + // Navigate to the second tab using the next accelerators. + browser()->ExecuteCommand(IDC_SELECT_NEXT_TAB); + ASSERT_EQ(1, browser()->selected_index()); + + // Navigate back to the first tab using the previous accelerators. + browser()->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB); + ASSERT_EQ(0, browser()->selected_index()); + + // Navigate to the last tab using the select last accelerator. + browser()->ExecuteCommand(IDC_SELECT_LAST_TAB); + ASSERT_EQ(2, browser()->selected_index()); +} + +// Tests IDC_DUPLICATE_TAB. +TEST_F(BrowserCommandsTest, DuplicateTab) { + GURL url1 = test_url_with_path("1"); + GURL url2 = test_url_with_path("2"); + GURL url3 = test_url_with_path("3"); + + // Navigate to the three urls, then go back. + AddTestingTab(browser()); + browser()->OpenURL(url1, GURL(), CURRENT_TAB, PageTransition::TYPED); + browser()->OpenURL(url2, GURL(), CURRENT_TAB, PageTransition::TYPED); + browser()->OpenURL(url3, GURL(), CURRENT_TAB, PageTransition::TYPED); + + size_t initial_window_count = BrowserList::size(); + + // Duplicate the tab. + browser()->ExecuteCommand(IDC_DUPLICATE_TAB); + + // The duplicated tab should not end up in a new window. + int window_count = BrowserList::size(); + ASSERT_EQ(initial_window_count, window_count); + + // And we should have a newly duplicated tab. + ASSERT_EQ(2, browser()->tab_count()); + + // Verify the stack of urls. + NavigationController* controller = + browser()->GetTabContentsAt(1)->controller(); + ASSERT_EQ(3, controller->GetEntryCount()); + ASSERT_EQ(2, controller->GetCurrentEntryIndex()); + ASSERT_TRUE(url1 == controller->GetEntryAtIndex(0)->url()); + ASSERT_TRUE(url2 == controller->GetEntryAtIndex(1)->url()); + ASSERT_TRUE(url3 == controller->GetEntryAtIndex(2)->url()); +} diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc index b3ad491..4574c17 100644 --- a/chrome/browser/browser_uitest.cc +++ b/chrome/browser/browser_uitest.cc @@ -123,49 +123,6 @@ TEST_F(BrowserTest, WindowsSessionEnd) { ASSERT_TRUE(exited_cleanly); } -// Tests the accelerators for tab navigation. Specifically IDC_SELECT_NEXT_TAB, -// IDC_SELECT_PREV_TAB, IDC_SELECT_TAB_0, and IDC_SELECT_LAST_TAB. -TEST_F(BrowserTest, TabNavigationAccelerators) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); - ASSERT_TRUE(window.get()); - - // Create two new tabs. This way we'll have at least three tabs to navigate - // to. - int old_tab_count = -1; - ASSERT_TRUE(window->GetTabCount(&old_tab_count)); - ASSERT_TRUE(window->ApplyAccelerator(IDC_NEW_TAB)); - int new_tab_count; - ASSERT_TRUE(window->WaitForTabCountToChange(old_tab_count, - &new_tab_count, - action_max_timeout_ms())); - ASSERT_TRUE(window->ApplyAccelerator(IDC_NEW_TAB)); - old_tab_count = new_tab_count; - ASSERT_TRUE(window->WaitForTabCountToChange(old_tab_count, - &new_tab_count, - action_max_timeout_ms())); - ASSERT_GE(new_tab_count, 2); - - // Activate the second tab. - ASSERT_TRUE(window->ActivateTab(1)); - - // Navigate to the first tab using an accelerator. - ASSERT_TRUE(window->ApplyAccelerator(IDC_SELECT_TAB_0)); - ASSERT_TRUE(window->WaitForTabToBecomeActive(0, action_max_timeout_ms())); - - // Navigate to the second tab using the next accelerators. - ASSERT_TRUE(window->ApplyAccelerator(IDC_SELECT_NEXT_TAB)); - ASSERT_TRUE(window->WaitForTabToBecomeActive(1, action_max_timeout_ms())); - - // Navigate back to the first tab using the previous accelerators. - ASSERT_TRUE(window->ApplyAccelerator(IDC_SELECT_PREVIOUS_TAB)); - ASSERT_TRUE(window->WaitForTabToBecomeActive(0, action_max_timeout_ms())); - - // Navigate to the last tab using the select last accelerator. - ASSERT_TRUE(window->ApplyAccelerator(IDC_SELECT_LAST_TAB)); - ASSERT_TRUE(window->WaitForTabToBecomeActive(new_tab_count - 1, - action_max_timeout_ms())); -} - TEST_F(BrowserTest, JavascriptAlertActivatesTab) { scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); int start_index; @@ -183,53 +140,6 @@ TEST_F(BrowserTest, JavascriptAlertActivatesTab) { action_max_timeout_ms())); } -TEST_F(BrowserTest, DuplicateTab) { - std::wstring path_prefix = test_data_directory_; - file_util::AppendToPath(&path_prefix, L"session_history"); - path_prefix += FilePath::kSeparators[0]; - GURL url1 = net::FilePathToFileURL(path_prefix + L"bot1.html"); - GURL url2 = net::FilePathToFileURL(path_prefix + L"bot2.html"); - GURL url3 = GURL("about:blank"); - - scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); - - // Navigate to the three urls, then go back. - scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); - tab_proxy->NavigateToURL(url1); - tab_proxy->NavigateToURL(url2); - tab_proxy->NavigateToURL(url3); - ASSERT_TRUE(tab_proxy->GoBack()); - - int initial_window_count; - ASSERT_TRUE(automation()->GetBrowserWindowCount(&initial_window_count)); - - // Duplicate the tab. - ASSERT_TRUE(browser_proxy->ApplyAccelerator(IDC_DUPLICATE_TAB)); - - // The duplicated tab should not end up in a new window. - int window_count; - ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); - ASSERT_TRUE(window_count == initial_window_count); - - tab_proxy.reset(browser_proxy->GetTab(1)); - ASSERT_TRUE(tab_proxy != NULL); - ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); - - // Verify the stack of urls. - GURL url; - ASSERT_TRUE(tab_proxy->GetCurrentURL(&url)); - ASSERT_EQ(url2, url); - - ASSERT_TRUE(tab_proxy->GoForward()); - ASSERT_TRUE(tab_proxy->GetCurrentURL(&url)); - ASSERT_EQ(url3, url); - - ASSERT_TRUE(tab_proxy->GoBack()); - ASSERT_TRUE(tab_proxy->GoBack()); - ASSERT_TRUE(tab_proxy->GetCurrentURL(&url)); - ASSERT_EQ(url1, url); -} - // Test that scripts can fork a new renderer process for a tab in a particular // case (which matches following a link in Gmail). The script must open a new // tab, set its window.opener to null, and redirect it to a cross-site URL. diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h index 2cd1648..aec7107 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -26,6 +26,7 @@ class Rect; // BrowserWindow interface // An interface implemented by the "view" of the Browser window. // +// NOTE: all getters, save GetTabStrip(), may return NULL. class BrowserWindow { public: // Initialize the frame. diff --git a/chrome/browser/tab_contents.cc b/chrome/browser/tab_contents.cc index 66774c6..9507cd4 100644 --- a/chrome/browser/tab_contents.cc +++ b/chrome/browser/tab_contents.cc @@ -320,11 +320,14 @@ void TabContents::CloseAllSuppressedPopups() { } void TabContents::Focus() { + HWND container_hwnd = GetContainerHWND(); + if (!container_hwnd) + return; + views::FocusManager* focus_manager = - views::FocusManager::GetFocusManager(GetContainerHWND()); + views::FocusManager::GetFocusManager(container_hwnd); DCHECK(focus_manager); - views::View* v = - focus_manager->GetViewForWindow(GetContainerHWND(), true); + views::View* v = focus_manager->GetViewForWindow(container_hwnd, true); DCHECK(v); if (v) v->RequestFocus(); diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 9d2a387..18823fd 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -1333,6 +1333,9 @@ void BrowserView::LoadingAnimationCallback() { void BrowserView::InitHangMonitor() { PrefService* pref_service = g_browser_process->local_state(); + if (!pref_service) + return; + int plugin_message_response_timeout = pref_service->GetInteger(prefs::kPluginMessageResponseTimeout); int hung_plugin_detect_freq = diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc index eff78d2..c460100 100644 --- a/chrome/browser/views/tabs/tab_strip.cc +++ b/chrome/browser/views/tabs/tab_strip.cc @@ -848,7 +848,8 @@ void TabStrip::TabInsertedAt(TabContents* contents, // Don't animate the first tab, it looks weird, and don't animate anything // if the containing window isn't visible yet. - if (GetTabCount() > 1 && IsWindowVisible(GetWidget()->GetHWND())) { + if (GetTabCount() > 1 && GetWidget() && + IsWindowVisible(GetWidget()->GetHWND())) { StartInsertTabAnimation(index); } else { Layout(); diff --git a/chrome/browser/window_sizer.cc b/chrome/browser/window_sizer.cc index c6083a7..596a7c8 100644 --- a/chrome/browser/window_sizer.cc +++ b/chrome/browser/window_sizer.cc @@ -115,6 +115,9 @@ class DefaultStateProvider : public WindowSizer::StateProvider { key.append(app_name_); } + if (!g_browser_process->local_state()) + return false; + const DictionaryValue* wp_pref = g_browser_process->local_state()->GetDictionary(key.c_str()); int top = 0, left = 0, bottom = 0, right = 0; 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); +} diff --git a/chrome/test/browser_with_test_window_test.h b/chrome/test/browser_with_test_window_test.h new file mode 100644 index 0000000..7790cf4 --- /dev/null +++ b/chrome/test/browser_with_test_window_test.h @@ -0,0 +1,71 @@ +// 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_TEST_BROWSER_WITH_TEST_WINDOW_TEST_H_ +#define CHROME_TEST_BROWSER_WITH_TEST_WINDOW_TEST_H_ + +#include <string> + +#include "base/message_loop.h" +#include "chrome/test/test_tab_contents.h" +#include "testing/gtest/include/gtest/gtest.h" + +class Browser; +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 +// 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, +// PageTransition::TYPED); +// +// Subclasses must invoke BrowserWithTestWindowTest::SetUp as it is responsible +// for creating the various objects of this class. +class BrowserWithTestWindowTest : public testing::Test { + public: + BrowserWithTestWindowTest(); + virtual ~BrowserWithTestWindowTest(); + + virtual void SetUp(); + + protected: + Browser* browser() const { return browser_.get(); } + + TestingProfile* profile() const { return profile_.get(); } + + TestTabContentsFactory* tab_contents_factory() const { + return tab_contents_factory_.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); + + // 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); + } + + private: + // We need to create a MessageLoop, otherwise a bunch of things fails. + MessageLoopForUI ui_loop_; + + scoped_ptr<TestingProfile> profile_; + scoped_ptr<TestTabContentsFactory> tab_contents_factory_; + scoped_ptr<TestBrowserWindow> window_; + scoped_ptr<Browser> browser_; + + DISALLOW_COPY_AND_ASSIGN(BrowserWithTestWindowTest); +}; + +#endif // CHROME_TEST_BROWSER_WITH_TEST_WINDOW_TEST_H_ diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h new file mode 100644 index 0000000..ce4250a --- /dev/null +++ b/chrome/test/test_browser_window.h @@ -0,0 +1,66 @@ +// 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_TEST_TEST_BROWSER_WINDOW_H_ +#define CHROME_TEST_TEST_BROWSER_WINDOW_H_ + +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_window.h" +#include "chrome/browser/views/tabs/tab_strip.h" + +// An implementation of BrowserWindow used for testing. TestBrowserWindow only +// contains a valid TabStrip, all other getters return NULL. +// See BrowserWithTestWindowTest for an example of using this class. +class TestBrowserWindow : public BrowserWindow { + public: + explicit TestBrowserWindow(Browser* browser) + : tab_strip_(browser->tabstrip_model()) { + } + ~TestBrowserWindow() {} + + virtual void Init() {} + virtual void Show() {} + virtual void SetBounds(const gfx::Rect& bounds) {} + virtual void Close() {} + virtual void Activate() {} + virtual void FlashFrame() {} + virtual void* GetNativeHandle() { return NULL; } + virtual TabStrip* GetTabStrip() const { + return const_cast<TabStrip*>(&tab_strip_); + } + virtual StatusBubble* GetStatusBubble() { return NULL; } + virtual void SelectedTabToolbarSizeChanged(bool is_animating) {} + virtual void UpdateTitleBar() {} + virtual void UpdateLoadingAnimations(bool should_animate) {} + virtual gfx::Rect GetNormalBounds() const { return gfx::Rect(); } + virtual bool IsMaximized() { return false; } + virtual ToolbarStarToggle* GetStarButton() const { return NULL; } + virtual LocationBarView* GetLocationBarView() const { return NULL; } + virtual GoButton* GetGoButton() const { return NULL; } + virtual BookmarkBarView* GetBookmarkBarView() { return NULL; } + virtual void UpdateToolbar(TabContents* contents, + bool should_restore_state) {} + virtual void FocusToolbar() {} + virtual bool IsBookmarkBarVisible() const { return false; } + virtual void ToggleBookmarkBar() {} + virtual void ShowAboutChromeDialog() {} + virtual void ShowBookmarkManager() {} + virtual void ShowReportBugDialog() {} + virtual void ShowClearBrowsingDataDialog() {} + virtual void ShowImportDialog() {} + virtual void ShowSearchEnginesDialog() {} + virtual void ShowPasswordManager() {} + virtual void ShowHTMLDialog(HtmlDialogContentsDelegate* delegate, + void* parent_window) {} + + protected: + virtual void DestroyBrowser() {} + + private: + TabStrip tab_strip_; + + DISALLOW_COPY_AND_ASSIGN(TestBrowserWindow); +}; + +#endif // CHROME_TEST_TEST_BROWSER_WINDOW_H_ diff --git a/chrome/test/test_tab_contents.h b/chrome/test/test_tab_contents.h index 13b82e4..e8b56d4 100644 --- a/chrome/test/test_tab_contents.h +++ b/chrome/test/test_tab_contents.h @@ -97,6 +97,10 @@ class TestTabContentsFactory : public TabContentsFactory { 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: diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index 439ad98..502117f 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -154,6 +154,14 @@ > </File> <File + RelativePath="..\browser_with_test_window_test.h" + > + </File> + <File + RelativePath="..\browser_with_test_window_test.cc" + > + </File> + <File RelativePath=".\chrome_test_suite.h" > </File> @@ -178,6 +186,10 @@ > </File> <File + RelativePath="..\test_browser_window.h" + > + </File> + <File RelativePath="..\test_notification_tracker.cc" > </File> @@ -315,6 +327,10 @@ > </File> <File + RelativePath="..\..\browser\browser_commands_unittest.cc" + > + </File> + <File RelativePath="..\..\common\bzip2_unittest.cc" > </File> diff --git a/chrome/views/window_delegate.cc b/chrome/views/window_delegate.cc index 381ea14..171b642 100644 --- a/chrome/views/window_delegate.cc +++ b/chrome/views/window_delegate.cc @@ -29,7 +29,7 @@ void WindowDelegate::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized, bool always_on_top) { std::wstring window_name = GetWindowName(); - if (window_name.empty()) + if (window_name.empty() || !g_browser_process->local_state()) return; DictionaryValue* window_preferences = @@ -72,6 +72,9 @@ bool WindowDelegate::GetSavedMaximizedState(bool* maximized) const { } bool WindowDelegate::GetSavedAlwaysOnTopState(bool* always_on_top) const { + if (!g_browser_process->local_state()) + return false; + std::wstring window_name = GetWindowName(); if (window_name.empty()) return false; |