This source file includes following definitions.
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/bookmark_test_helpers.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
typedef BrowserWithTestWindowTest BrowserCommandsTest;
using content::OpenURLParams;
using content::Referrer;
using content::WebContents;
TEST_F(BrowserCommandsTest, TabNavigationAccelerators) {
GURL about_blank(content::kAboutBlankURL);
AddTab(browser(), about_blank);
AddTab(browser(), about_blank);
AddTab(browser(), about_blank);
browser()->tab_strip_model()->ActivateTabAt(1, false);
CommandUpdater* updater = browser()->command_controller()->command_updater();
updater->ExecuteCommand(IDC_SELECT_TAB_0);
ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
updater->ExecuteCommand(IDC_SELECT_NEXT_TAB);
ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
updater->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB);
ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
updater->ExecuteCommand(IDC_SELECT_LAST_TAB);
ASSERT_EQ(2, browser()->tab_strip_model()->active_index());
}
TEST_F(BrowserCommandsTest, DuplicateTab) {
GURL url1("http://foo/1");
GURL url2("http://foo/2");
GURL url3("http://foo/3");
GURL url4("http://foo/4");
AddTab(browser(), url1);
NavigateAndCommitActiveTab(url2);
NavigateAndCommitActiveTab(url3);
content::NavigationController& orig_controller =
browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
orig_controller.LoadURL(
url4, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
EXPECT_EQ(3, orig_controller.GetEntryCount());
EXPECT_TRUE(orig_controller.GetPendingEntry());
size_t initial_window_count = chrome::GetTotalBrowserCount();
chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB);
size_t window_count = chrome::GetTotalBrowserCount();
ASSERT_EQ(initial_window_count, window_count);
ASSERT_EQ(2, browser()->tab_strip_model()->count());
content::NavigationController& controller =
browser()->tab_strip_model()->GetWebContentsAt(1)->GetController();
EXPECT_EQ(3, controller.GetEntryCount());
EXPECT_EQ(2, controller.GetCurrentEntryIndex());
EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
EXPECT_EQ(url3, controller.GetEntryAtIndex(2)->GetURL());
EXPECT_FALSE(controller.GetPendingEntry());
}
TEST_F(BrowserCommandsTest, ViewSource) {
GURL url1("http://foo/1");
GURL url2("http://foo/2");
AddTab(browser(), url1);
content::NavigationController& orig_controller =
browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
orig_controller.LoadURL(
url2, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
EXPECT_EQ(1, orig_controller.GetEntryCount());
EXPECT_TRUE(orig_controller.GetPendingEntry());
size_t initial_window_count = chrome::GetTotalBrowserCount();
chrome::ExecuteCommand(browser(), IDC_VIEW_SOURCE);
size_t window_count = chrome::GetTotalBrowserCount();
ASSERT_EQ(initial_window_count, window_count);
ASSERT_EQ(2, browser()->tab_strip_model()->count());
GURL view_source_url("view-source:http://foo/1");
content::NavigationController& controller =
browser()->tab_strip_model()->GetWebContentsAt(1)->GetController();
EXPECT_EQ(1, controller.GetEntryCount());
EXPECT_EQ(0, controller.GetCurrentEntryIndex());
EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
EXPECT_EQ(view_source_url, controller.GetEntryAtIndex(0)->GetVirtualURL());
EXPECT_FALSE(controller.GetPendingEntry());
}
TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
profile()->CreateBookmarkModel(true);
BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
test::WaitForBookmarkModelToLoad(model);
GURL url1("http://foo/1");
AddTab(browser(), url1);
browser()->OpenURL(OpenURLParams(
url1, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
chrome::BookmarkCurrentPage(browser());
EXPECT_EQ(profile(), browser()->profile());
EXPECT_TRUE(model->IsBookmarked(url1));
}
TEST_F(BrowserCommandsTest, BackForwardInNewTab) {
GURL url1("http://foo/1");
GURL url2("http://foo/2");
AddTab(browser(), url1);
NavigateAndCommitActiveTab(url2);
chrome::GoBack(browser(), NEW_BACKGROUND_TAB);
EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
ASSERT_EQ(2, browser()->tab_strip_model()->count());
WebContents* zeroth = browser()->tab_strip_model()->GetWebContentsAt(0);
WebContents* first = browser()->tab_strip_model()->GetWebContentsAt(1);
EXPECT_EQ(url2, zeroth->GetLastCommittedURL());
EXPECT_TRUE(zeroth->GetController().CanGoBack());
EXPECT_FALSE(zeroth->GetController().CanGoForward());
EXPECT_EQ(url1, first->GetVisibleURL());
EXPECT_FALSE(first->GetController().CanGoBack());
EXPECT_TRUE(first->GetController().CanGoForward());
browser()->tab_strip_model()->ActivateTabAt(1, true);
CommitPendingLoad(&first->GetController());
EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
chrome::GoForward(browser(), NEW_BACKGROUND_TAB);
EXPECT_EQ(url1, first->GetLastCommittedURL());
EXPECT_FALSE(first->GetController().CanGoBack());
EXPECT_TRUE(first->GetController().CanGoForward());
EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
ASSERT_EQ(3, browser()->tab_strip_model()->count());
WebContents* second = browser()->tab_strip_model()->GetWebContentsAt(2);
EXPECT_EQ(url2, second->GetVisibleURL());
EXPECT_TRUE(second->GetController().CanGoBack());
EXPECT_FALSE(second->GetController().CanGoForward());
browser()->tab_strip_model()->ActivateTabAt(2, true);
CommitPendingLoad(&second->GetController());
chrome::GoBack(browser(), NEW_FOREGROUND_TAB);
ASSERT_EQ(3, browser()->tab_strip_model()->active_index());
ASSERT_EQ(url1,
browser()->tab_strip_model()->GetActiveWebContents()->
GetVisibleURL());
CommitPendingLoad(&
browser()->tab_strip_model()->GetActiveWebContents()->GetController());
chrome::GoForward(browser(), NEW_FOREGROUND_TAB);
ASSERT_EQ(4, browser()->tab_strip_model()->active_index());
ASSERT_EQ(url2,
browser()->tab_strip_model()->GetActiveWebContents()->
GetVisibleURL());
}