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/browser/browser_commands_unittest.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/browser/browser_commands_unittest.cc')
-rw-r--r-- | chrome/browser/browser_commands_unittest.cc | 74 |
1 files changed, 74 insertions, 0 deletions
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()); +} |