summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-05 17:05:35 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-05 17:05:35 +0000
commit3bd3b2be39ff89c234d33f0ee9620a80258cc2ca (patch)
treedc63e0e57b773a6dc7f39b3c663bfb735aadd793 /chrome
parent4801ecc5ce684ec8556769cb173506b4645c618b (diff)
downloadchromium_src-3bd3b2be39ff89c234d33f0ee9620a80258cc2ca.zip
chromium_src-3bd3b2be39ff89c234d33f0ee9620a80258cc2ca.tar.gz
chromium_src-3bd3b2be39ff89c234d33f0ee9620a80258cc2ca.tar.bz2
Remove more reliance on tab contents types.
Review URL: http://codereview.chromium.org/62041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13135 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/back_forward_menu_model_unittest.cc783
-rw-r--r--chrome/browser/login_prompt.cc28
-rw-r--r--chrome/browser/navigation_entry_unittest.cc6
-rw-r--r--chrome/browser/ssl/ssl_blocking_page.cc1
-rw-r--r--chrome/browser/tab_contents/interstitial_page.cc2
-rw-r--r--chrome/browser/tabs/tab_strip_model_unittest.cc148
6 files changed, 397 insertions, 571 deletions
diff --git a/chrome/browser/back_forward_menu_model_unittest.cc b/chrome/browser/back_forward_menu_model_unittest.cc
index 0f3908a..36b2994 100644
--- a/chrome/browser/back_forward_menu_model_unittest.cc
+++ b/chrome/browser/back_forward_menu_model_unittest.cc
@@ -9,481 +9,398 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/browser/profile_manager.h"
+#include "chrome/browser/renderer_host/test_render_view_host.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tab_contents/tab_contents_factory.h"
#include "chrome/common/url_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
-const TabContentsType kHTTPTabContentsType =
- static_cast<TabContentsType>(TAB_CONTENTS_NUM_TYPES + 1);
-
-// Since you can't just instantiate a TabContents, and some of its methods
-// are protected, we subclass TabContents with our own testing dummy which
-// knows how to drive the base class' NavigationController as URLs are
-// loaded. Constructing one of these automatically constructs a
-// NavigationController instance which we wrap our RecentPagesModel around.
-class BackFwdMenuModelTestTabContents : public TabContents {
- public:
- BackFwdMenuModelTestTabContents() : TabContents(kHTTPTabContentsType) {
- }
-
- // We do the same thing as the TabContents one (just commit the navigation)
- // but we *don't* want to reset the title since the test looks for this.
- virtual bool NavigateToPendingEntry(bool reload) {
- controller()->CommitPendingEntry();
- return true;
- }
-
- void UpdateState(const std::wstring& title) {
- NavigationEntry* entry =
- controller()->GetEntryWithPageID(type(), NULL, GetMaxPageID());
- entry->set_title(WideToUTF16Hack(title));
- }
-};
-
-// This constructs our fake TabContents.
-class BackFwdMenuModelTestTabContentsFactory : public TabContentsFactory {
+class BackFwdMenuModelTest : public RenderViewHostTestHarness {
public:
- virtual TabContents* CreateInstance() {
- return new BackFwdMenuModelTestTabContents;
+ void ValidateModel(BackForwardMenuModel* model, int history_items,
+ int chapter_stops) {
+ int h = std::min(BackForwardMenuModel::kMaxHistoryItems, history_items);
+ int c = std::min(BackForwardMenuModel::kMaxChapterStops, chapter_stops);
+ EXPECT_EQ(h, model->GetHistoryItemCount());
+ EXPECT_EQ(c, model->GetChapterStopCount(h));
+ if (h > 0)
+ h += 2; // Separator and View History link.
+ if (c > 0)
+ ++c;
+ EXPECT_EQ(h + c, model->GetTotalItemCount());
}
- virtual bool CanHandleURL(const GURL& url) {
- return url.SchemeIs(chrome::kHttpScheme);
+ void LoadURLAndUpdateState(const char* url, const char* title) {
+ NavigateAndCommit(GURL(url));
+ controller()->GetLastCommittedEntry()->set_title(UTF8ToUTF16(title));
}
-};
-
-BackFwdMenuModelTestTabContentsFactory factory;
-
-class BackFwdMenuModelTest : public testing::Test {
- public:
-
- // Overridden from testing::Test
- virtual void SetUp() {
- TabContents::RegisterFactory(kHTTPTabContentsType, &factory);
-
- // Name a subdirectory of the temp directory.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- test_dir_ = test_dir_.Append(FILE_PATH_LITERAL("BackFwdMenuModelTest"));
-
- // Create a fresh, empty copy of this directory.
- file_util::Delete(test_dir_, true);
- file_util::CreateDirectory(test_dir_);
- profile_path_ = test_dir_;
- profile_path_ = profile_path_.Append(FILE_PATH_LITERAL("New Profile"));
-
- profile_ = ProfileManager::CreateProfile(
- profile_path_, L"New Profile", L"new-profile", L"");
- ASSERT_TRUE(profile_);
- pm_.AddProfile(profile_);
+ // Navigate back or forward the given amount and commits the entry (which
+ // will be pending after we ask to navigate there).
+ void NavigateToOffset(int offset) {
+ controller()->GoToOffset(offset);
+ const NavigationEntry* entry = controller()->GetPendingEntry();
+ rvh()->SendNavigate(entry->page_id(), entry->url());
}
- virtual void TearDown() {
- TabContents::RegisterFactory(kHTTPTabContentsType, NULL);
-
- // Removes a profile from the set of currently-loaded profiles.
- pm_.RemoveProfileByPath(profile_path_);
-
- // Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, true));
- ASSERT_FALSE(file_util::PathExists(test_dir_));
+ // Same as NavigateToOffset but goes to an absolute index.
+ void NavigateToIndex(int index) {
+ controller()->GoToIndex(index);
+ const NavigationEntry* entry = controller()->GetPendingEntry();
+ rvh()->SendNavigate(entry->page_id(), entry->url());
}
- protected:
- TabContents* CreateTabContents() {
- TabContents* contents = new BackFwdMenuModelTestTabContents;
- contents->SetupController(profile_);
- return contents;
+ // Goes back/forward and commits the load.
+ void GoBack() {
+ controller()->GoBack();
+ const NavigationEntry* entry = controller()->GetPendingEntry();
+ rvh()->SendNavigate(entry->page_id(), entry->url());
}
-
- // Forwards a URL "load" request through to our dummy TabContents
- // implementation.
- void LoadURLAndUpdateState(TabContents* contents,
- const std::string& url,
- const std::wstring& title) {
- contents->controller()->LoadURL(GURL(url), GURL(), PageTransition::LINK);
- BackFwdMenuModelTestTabContents* rsmttc =
- static_cast<BackFwdMenuModelTestTabContents*>(contents);
- rsmttc->UpdateState(title);
+ void GoForward() {
+ controller()->GoForward();
+ const NavigationEntry* entry = controller()->GetPendingEntry();
+ rvh()->SendNavigate(entry->page_id(), entry->url());
}
-
- private:
- MessageLoopForUI message_loop_;
- FilePath test_dir_;
- FilePath profile_path_;
- ProfileManager pm_;
- Profile* profile_;
};
TEST_F(BackFwdMenuModelTest, BasicCase) {
- TabContents* contents = CreateTabContents();
-
- {
- scoped_ptr<BackForwardMenuModel> back_model(BackForwardMenuModel::Create(
+ scoped_ptr<BackForwardMenuModel> back_model(BackForwardMenuModel::Create(
NULL, BackForwardMenuModel::BACKWARD_MENU_DELEGATE));
- back_model->set_test_tab_contents(contents);
+ back_model->set_test_tab_contents(contents());
- scoped_ptr<BackForwardMenuModel> forward_model(BackForwardMenuModel::Create(
+ scoped_ptr<BackForwardMenuModel> forward_model(BackForwardMenuModel::Create(
NULL, BackForwardMenuModel::FORWARD_MENU_DELEGATE));
- forward_model->set_test_tab_contents(contents);
-
- EXPECT_EQ(0, back_model->GetTotalItemCount());
- EXPECT_EQ(0, forward_model->GetTotalItemCount());
- EXPECT_FALSE(back_model->ItemHasCommand(1));
-
- // Seed the controller with a few URLs
- LoadURLAndUpdateState(contents, "http://www.a.com/1", L"A1");
- LoadURLAndUpdateState(contents, "http://www.a.com/2", L"A2");
- LoadURLAndUpdateState(contents, "http://www.a.com/3", L"A3");
- LoadURLAndUpdateState(contents, "http://www.b.com/1", L"B1");
- LoadURLAndUpdateState(contents, "http://www.b.com/2", L"B2");
- LoadURLAndUpdateState(contents, "http://www.c.com/1", L"C1");
- LoadURLAndUpdateState(contents, "http://www.c.com/2", L"C2");
- LoadURLAndUpdateState(contents, "http://www.c.com/3", L"C3");
-
- // There're two more items here: a separator and a "Show Full History".
- EXPECT_EQ(9, back_model->GetTotalItemCount());
- EXPECT_EQ(0, forward_model->GetTotalItemCount());
- EXPECT_EQ(L"C2", back_model->GetItemLabel(1));
- EXPECT_EQ(L"A1", back_model->GetItemLabel(7));
- EXPECT_EQ(back_model->GetShowFullHistoryLabel(),
- back_model->GetItemLabel(9));
-
- EXPECT_TRUE(back_model->ItemHasCommand(1));
- EXPECT_TRUE(back_model->ItemHasCommand(7));
- EXPECT_TRUE(back_model->IsSeparator(8));
- EXPECT_TRUE(back_model->ItemHasCommand(9));
- EXPECT_FALSE(back_model->ItemHasCommand(8));
- EXPECT_FALSE(back_model->ItemHasCommand(10));
-
- contents->controller()->GoToOffset(-7);
-
- EXPECT_EQ(0, back_model->GetTotalItemCount());
- EXPECT_EQ(9, forward_model->GetTotalItemCount());
- EXPECT_EQ(L"A2", forward_model->GetItemLabel(1));
- EXPECT_EQ(L"C3", forward_model->GetItemLabel(7));
- EXPECT_EQ(forward_model->GetShowFullHistoryLabel(),
- forward_model->GetItemLabel(9));
-
- EXPECT_TRUE(forward_model->ItemHasCommand(1));
- EXPECT_TRUE(forward_model->ItemHasCommand(7));
- EXPECT_TRUE(forward_model->IsSeparator(8));
- EXPECT_TRUE(forward_model->ItemHasCommand(9));
- EXPECT_FALSE(forward_model->ItemHasCommand(8));
- EXPECT_FALSE(forward_model->ItemHasCommand(10));
- contents->controller()->GoToOffset(4);
-
- EXPECT_EQ(6, back_model->GetTotalItemCount());
- EXPECT_EQ(5, forward_model->GetTotalItemCount());
- EXPECT_EQ(L"B1", back_model->GetItemLabel(1));
- EXPECT_EQ(L"A1", back_model->GetItemLabel(4));
- EXPECT_EQ(back_model->GetShowFullHistoryLabel(),
- back_model->GetItemLabel(6));
- EXPECT_EQ(L"C1", forward_model->GetItemLabel(1));
- EXPECT_EQ(L"C3", forward_model->GetItemLabel(3));
- EXPECT_EQ(forward_model->GetShowFullHistoryLabel(),
- forward_model->GetItemLabel(5));
- }
- contents->CloseContents();
+ forward_model->set_test_tab_contents(contents());
+
+ EXPECT_EQ(0, back_model->GetTotalItemCount());
+ EXPECT_EQ(0, forward_model->GetTotalItemCount());
+ EXPECT_FALSE(back_model->ItemHasCommand(1));
+
+ // Seed the controller with a few URLs
+ LoadURLAndUpdateState("http://www.a.com/1", "A1");
+ LoadURLAndUpdateState("http://www.a.com/2", "A2");
+ LoadURLAndUpdateState("http://www.a.com/3", "A3");
+ LoadURLAndUpdateState("http://www.b.com/1", "B1");
+ LoadURLAndUpdateState("http://www.b.com/2", "B2");
+ LoadURLAndUpdateState("http://www.c.com/1", "C1");
+ LoadURLAndUpdateState("http://www.c.com/2", "C2");
+ LoadURLAndUpdateState("http://www.c.com/3", "C3");
+
+ // There're two more items here: a separator and a "Show Full History".
+ EXPECT_EQ(9, back_model->GetTotalItemCount());
+ EXPECT_EQ(0, forward_model->GetTotalItemCount());
+ EXPECT_EQ(L"C2", back_model->GetItemLabel(1));
+ EXPECT_EQ(L"A1", back_model->GetItemLabel(7));
+ EXPECT_EQ(back_model->GetShowFullHistoryLabel(),
+ back_model->GetItemLabel(9));
+
+ EXPECT_TRUE(back_model->ItemHasCommand(1));
+ EXPECT_TRUE(back_model->ItemHasCommand(7));
+ EXPECT_TRUE(back_model->IsSeparator(8));
+ EXPECT_TRUE(back_model->ItemHasCommand(9));
+ EXPECT_FALSE(back_model->ItemHasCommand(8));
+ EXPECT_FALSE(back_model->ItemHasCommand(10));
+
+ NavigateToOffset(-7);
+
+ EXPECT_EQ(0, back_model->GetTotalItemCount());
+ EXPECT_EQ(9, forward_model->GetTotalItemCount());
+ EXPECT_EQ(L"A2", forward_model->GetItemLabel(1));
+ EXPECT_EQ(L"C3", forward_model->GetItemLabel(7));
+ EXPECT_EQ(forward_model->GetShowFullHistoryLabel(),
+ forward_model->GetItemLabel(9));
+
+ EXPECT_TRUE(forward_model->ItemHasCommand(1));
+ EXPECT_TRUE(forward_model->ItemHasCommand(7));
+ EXPECT_TRUE(forward_model->IsSeparator(8));
+ EXPECT_TRUE(forward_model->ItemHasCommand(9));
+ EXPECT_FALSE(forward_model->ItemHasCommand(8));
+ EXPECT_FALSE(forward_model->ItemHasCommand(10));
+ NavigateToOffset(4);
+
+ EXPECT_EQ(6, back_model->GetTotalItemCount());
+ EXPECT_EQ(5, forward_model->GetTotalItemCount());
+ EXPECT_EQ(L"B1", back_model->GetItemLabel(1));
+ EXPECT_EQ(L"A1", back_model->GetItemLabel(4));
+ EXPECT_EQ(back_model->GetShowFullHistoryLabel(),
+ back_model->GetItemLabel(6));
+ EXPECT_EQ(L"C1", forward_model->GetItemLabel(1));
+ EXPECT_EQ(L"C3", forward_model->GetItemLabel(3));
+ EXPECT_EQ(forward_model->GetShowFullHistoryLabel(),
+ forward_model->GetItemLabel(5));
}
TEST_F(BackFwdMenuModelTest, MaxItemsTest) {
- TabContents* contents = CreateTabContents();
-
- {
- scoped_ptr<BackForwardMenuModel> back_model(BackForwardMenuModel::Create(
+ scoped_ptr<BackForwardMenuModel> back_model(BackForwardMenuModel::Create(
NULL, BackForwardMenuModel::BACKWARD_MENU_DELEGATE));
- back_model->set_test_tab_contents(contents);
+ back_model->set_test_tab_contents(contents());
- scoped_ptr<BackForwardMenuModel> forward_model(BackForwardMenuModel::Create(
+ scoped_ptr<BackForwardMenuModel> forward_model(BackForwardMenuModel::Create(
NULL, BackForwardMenuModel::FORWARD_MENU_DELEGATE));
- forward_model->set_test_tab_contents(contents);
-
- // Seed the controller with 32 URLs
- LoadURLAndUpdateState(contents, "http://www.a.com/1", L"A1");
- LoadURLAndUpdateState(contents, "http://www.a.com/2", L"A2");
- LoadURLAndUpdateState(contents, "http://www.a.com/3", L"A3");
- LoadURLAndUpdateState(contents, "http://www.b.com/1", L"B1");
- LoadURLAndUpdateState(contents, "http://www.b.com/2", L"B2");
- LoadURLAndUpdateState(contents, "http://www.b.com/3", L"B3");
- LoadURLAndUpdateState(contents, "http://www.c.com/1", L"C1");
- LoadURLAndUpdateState(contents, "http://www.c.com/2", L"C2");
- LoadURLAndUpdateState(contents, "http://www.c.com/3", L"C3");
- LoadURLAndUpdateState(contents, "http://www.d.com/1", L"D1");
- LoadURLAndUpdateState(contents, "http://www.d.com/2", L"D2");
- LoadURLAndUpdateState(contents, "http://www.d.com/3", L"D3");
- LoadURLAndUpdateState(contents, "http://www.e.com/1", L"E1");
- LoadURLAndUpdateState(contents, "http://www.e.com/2", L"E2");
- LoadURLAndUpdateState(contents, "http://www.e.com/3", L"E3");
- LoadURLAndUpdateState(contents, "http://www.f.com/1", L"F1");
- LoadURLAndUpdateState(contents, "http://www.f.com/2", L"F2");
- LoadURLAndUpdateState(contents, "http://www.f.com/3", L"F3");
- LoadURLAndUpdateState(contents, "http://www.g.com/1", L"G1");
- LoadURLAndUpdateState(contents, "http://www.g.com/2", L"G2");
- LoadURLAndUpdateState(contents, "http://www.g.com/3", L"G3");
- LoadURLAndUpdateState(contents, "http://www.h.com/1", L"H1");
- LoadURLAndUpdateState(contents, "http://www.h.com/2", L"H2");
- LoadURLAndUpdateState(contents, "http://www.h.com/3", L"H3");
- LoadURLAndUpdateState(contents, "http://www.i.com/1", L"I1");
- LoadURLAndUpdateState(contents, "http://www.i.com/2", L"I2");
- LoadURLAndUpdateState(contents, "http://www.i.com/3", L"I3");
- LoadURLAndUpdateState(contents, "http://www.j.com/1", L"J1");
- LoadURLAndUpdateState(contents, "http://www.j.com/2", L"J2");
- LoadURLAndUpdateState(contents, "http://www.j.com/3", L"J3");
- LoadURLAndUpdateState(contents, "http://www.k.com/1", L"K1");
- LoadURLAndUpdateState(contents, "http://www.k.com/2", L"K2");
-
- // Also there're two more for a separator and a "Show Full History".
- int chapter_stop_offset = 6;
- EXPECT_EQ(BackForwardMenuModel::kMaxHistoryItems + 2 + chapter_stop_offset,
- back_model->GetTotalItemCount());
- EXPECT_EQ(0, forward_model->GetTotalItemCount());
- EXPECT_EQ(L"K1", back_model->GetItemLabel(1));
- EXPECT_EQ(back_model->GetShowFullHistoryLabel(),
+ forward_model->set_test_tab_contents(contents());
+
+ // Seed the controller with 32 URLs
+ LoadURLAndUpdateState("http://www.a.com/1", "A1");
+ LoadURLAndUpdateState("http://www.a.com/2", "A2");
+ LoadURLAndUpdateState("http://www.a.com/3", "A3");
+ LoadURLAndUpdateState("http://www.b.com/1", "B1");
+ LoadURLAndUpdateState("http://www.b.com/2", "B2");
+ LoadURLAndUpdateState("http://www.b.com/3", "B3");
+ LoadURLAndUpdateState("http://www.c.com/1", "C1");
+ LoadURLAndUpdateState("http://www.c.com/2", "C2");
+ LoadURLAndUpdateState("http://www.c.com/3", "C3");
+ LoadURLAndUpdateState("http://www.d.com/1", "D1");
+ LoadURLAndUpdateState("http://www.d.com/2", "D2");
+ LoadURLAndUpdateState("http://www.d.com/3", "D3");
+ LoadURLAndUpdateState("http://www.e.com/1", "E1");
+ LoadURLAndUpdateState("http://www.e.com/2", "E2");
+ LoadURLAndUpdateState("http://www.e.com/3", "E3");
+ LoadURLAndUpdateState("http://www.f.com/1", "F1");
+ LoadURLAndUpdateState("http://www.f.com/2", "F2");
+ LoadURLAndUpdateState("http://www.f.com/3", "F3");
+ LoadURLAndUpdateState("http://www.g.com/1", "G1");
+ LoadURLAndUpdateState("http://www.g.com/2", "G2");
+ LoadURLAndUpdateState("http://www.g.com/3", "G3");
+ LoadURLAndUpdateState("http://www.h.com/1", "H1");
+ LoadURLAndUpdateState("http://www.h.com/2", "H2");
+ LoadURLAndUpdateState("http://www.h.com/3", "H3");
+ LoadURLAndUpdateState("http://www.i.com/1", "I1");
+ LoadURLAndUpdateState("http://www.i.com/2", "I2");
+ LoadURLAndUpdateState("http://www.i.com/3", "I3");
+ LoadURLAndUpdateState("http://www.j.com/1", "J1");
+ LoadURLAndUpdateState("http://www.j.com/2", "J2");
+ LoadURLAndUpdateState("http://www.j.com/3", "J3");
+ LoadURLAndUpdateState("http://www.k.com/1", "K1");
+ LoadURLAndUpdateState("http://www.k.com/2", "K2");
+
+ // Also there're two more for a separator and a "Show Full History".
+ int chapter_stop_offset = 6;
+ EXPECT_EQ(BackForwardMenuModel::kMaxHistoryItems + 2 + chapter_stop_offset,
+ back_model->GetTotalItemCount());
+ EXPECT_EQ(0, forward_model->GetTotalItemCount());
+ EXPECT_EQ(L"K1", back_model->GetItemLabel(1));
+ EXPECT_EQ(back_model->GetShowFullHistoryLabel(),
back_model->GetItemLabel(BackForwardMenuModel::kMaxHistoryItems + 2 +
- chapter_stop_offset));
+ chapter_stop_offset));
- // Test for out of bounds (beyond Show Full History).
- EXPECT_FALSE(back_model->ItemHasCommand(
- BackForwardMenuModel::kMaxHistoryItems + chapter_stop_offset + 3));
+ // Test for out of bounds (beyond Show Full History).
+ EXPECT_FALSE(back_model->ItemHasCommand(
+ BackForwardMenuModel::kMaxHistoryItems + chapter_stop_offset + 3));
- EXPECT_TRUE(back_model->ItemHasCommand(
- BackForwardMenuModel::kMaxHistoryItems));
- EXPECT_TRUE(back_model->IsSeparator(
- BackForwardMenuModel::kMaxHistoryItems + 1));
+ EXPECT_TRUE(back_model->ItemHasCommand(
+ BackForwardMenuModel::kMaxHistoryItems));
+ EXPECT_TRUE(back_model->IsSeparator(
+ BackForwardMenuModel::kMaxHistoryItems + 1));
- contents->controller()->GoToIndex(0);
+ NavigateToIndex(0);
- EXPECT_EQ(BackForwardMenuModel::kMaxHistoryItems + 2 + chapter_stop_offset,
- forward_model->GetTotalItemCount());
- EXPECT_EQ(0, back_model->GetTotalItemCount());
- EXPECT_EQ(L"A2", forward_model->GetItemLabel(1));
- EXPECT_EQ(forward_model->GetShowFullHistoryLabel(),
+ EXPECT_EQ(BackForwardMenuModel::kMaxHistoryItems + 2 + chapter_stop_offset,
+ forward_model->GetTotalItemCount());
+ EXPECT_EQ(0, back_model->GetTotalItemCount());
+ EXPECT_EQ(L"A2", forward_model->GetItemLabel(1));
+ EXPECT_EQ(forward_model->GetShowFullHistoryLabel(),
forward_model->GetItemLabel(BackForwardMenuModel::kMaxHistoryItems + 2 +
- chapter_stop_offset));
-
- // Out of bounds
- EXPECT_FALSE(forward_model->ItemHasCommand(
- BackForwardMenuModel::kMaxHistoryItems + 3 + chapter_stop_offset));
+ chapter_stop_offset));
- EXPECT_TRUE(forward_model->ItemHasCommand(
- BackForwardMenuModel::kMaxHistoryItems));
- EXPECT_TRUE(forward_model->IsSeparator(
- BackForwardMenuModel::kMaxHistoryItems + 1));
- }
- contents->CloseContents();
-}
+ // Out of bounds
+ EXPECT_FALSE(forward_model->ItemHasCommand(
+ BackForwardMenuModel::kMaxHistoryItems + 3 + chapter_stop_offset));
-void ValidateModel(BackForwardMenuModel* model, int history_items,
- int chapter_stops) {
- int h = std::min(BackForwardMenuModel::kMaxHistoryItems, history_items);
- int c = std::min(BackForwardMenuModel::kMaxChapterStops, chapter_stops);
- EXPECT_EQ(h, model->GetHistoryItemCount());
- EXPECT_EQ(c, model->GetChapterStopCount(h));
- if (h > 0)
- h += 2; // separator and View History link
- if (c > 0)
- ++c;
- EXPECT_EQ(h + c, model->GetTotalItemCount());
+ EXPECT_TRUE(forward_model->ItemHasCommand(
+ BackForwardMenuModel::kMaxHistoryItems));
+ EXPECT_TRUE(forward_model->IsSeparator(
+ BackForwardMenuModel::kMaxHistoryItems + 1));
}
TEST_F(BackFwdMenuModelTest, ChapterStops) {
- TabContents* contents = CreateTabContents();
-
- {
- scoped_ptr<BackForwardMenuModel> back_model(BackForwardMenuModel::Create(
- NULL, BackForwardMenuModel::BACKWARD_MENU_DELEGATE));
- back_model->set_test_tab_contents(contents);
+ scoped_ptr<BackForwardMenuModel> back_model(BackForwardMenuModel::Create(
+ NULL, BackForwardMenuModel::BACKWARD_MENU_DELEGATE));
+ back_model->set_test_tab_contents(contents());
- scoped_ptr<BackForwardMenuModel> forward_model(BackForwardMenuModel::Create(
+ scoped_ptr<BackForwardMenuModel> forward_model(BackForwardMenuModel::Create(
NULL, BackForwardMenuModel::FORWARD_MENU_DELEGATE));
- forward_model->set_test_tab_contents(contents);
-
- // Seed the controller with 32 URLs.
- int i = 0;
- LoadURLAndUpdateState(contents, "http://www.a.com/1", L"A1"); // 0
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.a.com/2", L"A2");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.a.com/3", L"A3");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.b.com/1", L"B1");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.b.com/2", L"B2");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.b.com/3", L"B3"); // 5
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.c.com/1", L"C1");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.c.com/2", L"C2");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.c.com/3", L"C3");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.d.com/1", L"D1");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.d.com/2", L"D2"); // 10
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.d.com/3", L"D3");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.e.com/1", L"E1");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.e.com/2", L"E2");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.e.com/3", L"E3");
- ValidateModel(back_model.get(), i++, 0);
- LoadURLAndUpdateState(contents, "http://www.f.com/1", L"F1"); // 15
- ValidateModel(back_model.get(), i++, 1);
- LoadURLAndUpdateState(contents, "http://www.f.com/2", L"F2");
- ValidateModel(back_model.get(), i++, 1);
- LoadURLAndUpdateState(contents, "http://www.f.com/3", L"F3");
- ValidateModel(back_model.get(), i++, 1);
- LoadURLAndUpdateState(contents, "http://www.g.com/1", L"G1");
- ValidateModel(back_model.get(), i++, 2);
- LoadURLAndUpdateState(contents, "http://www.g.com/2", L"G2");
- ValidateModel(back_model.get(), i++, 2);
- LoadURLAndUpdateState(contents, "http://www.g.com/3", L"G3"); // 20
- ValidateModel(back_model.get(), i++, 2);
- LoadURLAndUpdateState(contents, "http://www.h.com/1", L"H1");
- ValidateModel(back_model.get(), i++, 3);
- LoadURLAndUpdateState(contents, "http://www.h.com/2", L"H2");
- ValidateModel(back_model.get(), i++, 3);
- LoadURLAndUpdateState(contents, "http://www.h.com/3", L"H3");
- ValidateModel(back_model.get(), i++, 3);
- LoadURLAndUpdateState(contents, "http://www.i.com/1", L"I1");
- ValidateModel(back_model.get(), i++, 4);
- LoadURLAndUpdateState(contents, "http://www.i.com/2", L"I2"); // 25
- ValidateModel(back_model.get(), i++, 4);
- LoadURLAndUpdateState(contents, "http://www.i.com/3", L"I3");
- ValidateModel(back_model.get(), i++, 4);
- LoadURLAndUpdateState(contents, "http://www.j.com/1", L"J1");
- ValidateModel(back_model.get(), i++, 5);
- LoadURLAndUpdateState(contents, "http://www.j.com/2", L"J2");
- ValidateModel(back_model.get(), i++, 5);
- LoadURLAndUpdateState(contents, "http://www.j.com/3", L"J3");
- ValidateModel(back_model.get(), i++, 5);
- LoadURLAndUpdateState(contents, "http://www.k.com/1", L"K1"); // 30
- ValidateModel(back_model.get(), i++, 6);
- LoadURLAndUpdateState(contents, "http://www.k.com/2", L"K2");
- ValidateModel(back_model.get(), i++, 6);
- LoadURLAndUpdateState(contents, "http://www.k.com/3", L"K3"); // 32
- ValidateModel(back_model.get(), i++, 6);
-
- // Check to see if the chapter stops have the right labels.
- int index = BackForwardMenuModel::kMaxHistoryItems + 1;
- EXPECT_EQ(L"", back_model->GetItemLabel(index++)); // separator.
- EXPECT_EQ(L"F3", back_model->GetItemLabel(index++));
- EXPECT_EQ(L"E3", back_model->GetItemLabel(index++));
- EXPECT_EQ(L"D3", back_model->GetItemLabel(index++));
- EXPECT_EQ(L"C3", back_model->GetItemLabel(index++));
- EXPECT_EQ(L"B3", back_model->GetItemLabel(index)); // max 5 chapter stops.
- EXPECT_EQ(L"", back_model->GetItemLabel(index + 1)); // separator.
- EXPECT_EQ(back_model->GetShowFullHistoryLabel(),
- back_model->GetItemLabel(index + 2));
-
- // If we go back two we should still see the same chapter stop at the end.
- contents->controller()->GoBack();
- EXPECT_EQ(L"B3", back_model->GetItemLabel(index));
- contents->controller()->GoBack();
- EXPECT_EQ(L"B3", back_model->GetItemLabel(index));
- // But if we go back again, it should change.
- contents->controller()->GoBack();
- EXPECT_EQ(L"A3", back_model->GetItemLabel(index));
- contents->controller()->GoBack();
- EXPECT_EQ(L"A3", back_model->GetItemLabel(index));
- contents->controller()->GoBack();
- EXPECT_EQ(L"A3", back_model->GetItemLabel(index));
- contents->controller()->GoBack();
- EXPECT_EQ(L"", back_model->GetItemLabel(index)); // is now a separator.
- contents->controller()->GoToOffset(6); // undo our position change.
-
- // Go back enough to make sure no chapter stops should appear.
- contents->controller()->GoToOffset(-BackForwardMenuModel::kMaxHistoryItems);
- ValidateModel(forward_model.get(), BackForwardMenuModel::kMaxHistoryItems,
- 0);
- // Go forward (still no chapter stop)
- contents->controller()->GoForward();
- ValidateModel(forward_model.get(),
- BackForwardMenuModel::kMaxHistoryItems - 1, 0);
- // Go back two (one chapter stop should show up)
- contents->controller()->GoBack();
- contents->controller()->GoBack();
- ValidateModel(forward_model.get(),
- BackForwardMenuModel::kMaxHistoryItems, 1);
-
- // Go to beginning.
- contents->controller()->GoToIndex(0);
-
- // Check to see if the chapter stops have the right labels.
- index = BackForwardMenuModel::kMaxHistoryItems + 1;
- EXPECT_EQ(L"", forward_model->GetItemLabel(index++)); // separator.
- EXPECT_EQ(L"E3", forward_model->GetItemLabel(index++));
- EXPECT_EQ(L"F3", forward_model->GetItemLabel(index++));
- EXPECT_EQ(L"G3", forward_model->GetItemLabel(index++));
- EXPECT_EQ(L"H3", forward_model->GetItemLabel(index++));
- // max 5 chapter stops.
- EXPECT_EQ(L"I3", forward_model->GetItemLabel(index));
- EXPECT_EQ(L"", forward_model->GetItemLabel(index + 1)); // separator.
- EXPECT_EQ(forward_model->GetShowFullHistoryLabel(),
+ forward_model->set_test_tab_contents(contents());
+
+ // Seed the controller with 32 URLs.
+ int i = 0;
+ LoadURLAndUpdateState("http://www.a.com/1", "A1"); // 0
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.a.com/2", "A2");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.a.com/3", "A3");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.b.com/1", "B1");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.b.com/2", "B2");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.b.com/3", "B3"); // 5
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.c.com/1", "C1");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.c.com/2", "C2");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.c.com/3", "C3");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.d.com/1", "D1");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.d.com/2", "D2"); // 10
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.d.com/3", "D3");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.e.com/1", "E1");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.e.com/2", "E2");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.e.com/3", "E3");
+ ValidateModel(back_model.get(), i++, 0);
+ LoadURLAndUpdateState("http://www.f.com/1", "F1"); // 15
+ ValidateModel(back_model.get(), i++, 1);
+ LoadURLAndUpdateState("http://www.f.com/2", "F2");
+ ValidateModel(back_model.get(), i++, 1);
+ LoadURLAndUpdateState("http://www.f.com/3", "F3");
+ ValidateModel(back_model.get(), i++, 1);
+ LoadURLAndUpdateState("http://www.g.com/1", "G1");
+ ValidateModel(back_model.get(), i++, 2);
+ LoadURLAndUpdateState("http://www.g.com/2", "G2");
+ ValidateModel(back_model.get(), i++, 2);
+ LoadURLAndUpdateState("http://www.g.com/3", "G3"); // 20
+ ValidateModel(back_model.get(), i++, 2);
+ LoadURLAndUpdateState("http://www.h.com/1", "H1");
+ ValidateModel(back_model.get(), i++, 3);
+ LoadURLAndUpdateState("http://www.h.com/2", "H2");
+ ValidateModel(back_model.get(), i++, 3);
+ LoadURLAndUpdateState("http://www.h.com/3", "H3");
+ ValidateModel(back_model.get(), i++, 3);
+ LoadURLAndUpdateState("http://www.i.com/1", "I1");
+ ValidateModel(back_model.get(), i++, 4);
+ LoadURLAndUpdateState("http://www.i.com/2", "I2"); // 25
+ ValidateModel(back_model.get(), i++, 4);
+ LoadURLAndUpdateState("http://www.i.com/3", "I3");
+ ValidateModel(back_model.get(), i++, 4);
+ LoadURLAndUpdateState("http://www.j.com/1", "J1");
+ ValidateModel(back_model.get(), i++, 5);
+ LoadURLAndUpdateState("http://www.j.com/2", "J2");
+ ValidateModel(back_model.get(), i++, 5);
+ LoadURLAndUpdateState("http://www.j.com/3", "J3");
+ ValidateModel(back_model.get(), i++, 5);
+ LoadURLAndUpdateState("http://www.k.com/1", "K1"); // 30
+ ValidateModel(back_model.get(), i++, 6);
+ LoadURLAndUpdateState("http://www.k.com/2", "K2");
+ ValidateModel(back_model.get(), i++, 6);
+ LoadURLAndUpdateState("http://www.k.com/3", "K3"); // 32
+ ValidateModel(back_model.get(), i++, 6);
+
+ // Check to see if the chapter stops have the right labels.
+ int index = BackForwardMenuModel::kMaxHistoryItems + 1;
+ EXPECT_EQ(L"", back_model->GetItemLabel(index++)); // separator.
+ EXPECT_EQ(L"F3", back_model->GetItemLabel(index++));
+ EXPECT_EQ(L"E3", back_model->GetItemLabel(index++));
+ EXPECT_EQ(L"D3", back_model->GetItemLabel(index++));
+ EXPECT_EQ(L"C3", back_model->GetItemLabel(index++));
+ EXPECT_EQ(L"B3", back_model->GetItemLabel(index)); // max 5 chapter stops.
+ EXPECT_EQ(L"", back_model->GetItemLabel(index + 1)); // separator.
+ EXPECT_EQ(back_model->GetShowFullHistoryLabel(),
+ back_model->GetItemLabel(index + 2));
+
+ // If we go back two we should still see the same chapter stop at the end.
+ GoBack();
+ EXPECT_EQ(L"B3", back_model->GetItemLabel(index));
+ GoBack();
+ EXPECT_EQ(L"B3", back_model->GetItemLabel(index));
+ // But if we go back again, it should change.
+ GoBack();
+ EXPECT_EQ(L"A3", back_model->GetItemLabel(index));
+ GoBack();
+ EXPECT_EQ(L"A3", back_model->GetItemLabel(index));
+ GoBack();
+ EXPECT_EQ(L"A3", back_model->GetItemLabel(index));
+ GoBack();
+ EXPECT_EQ(L"", back_model->GetItemLabel(index)); // It is now a separator.
+ NavigateToOffset(6); // Undo our position change.
+
+ // Go back enough to make sure no chapter stops should appear.
+ NavigateToOffset(-BackForwardMenuModel::kMaxHistoryItems);
+ ValidateModel(forward_model.get(), BackForwardMenuModel::kMaxHistoryItems, 0);
+ // Go forward (still no chapter stop)
+ GoForward();
+ ValidateModel(forward_model.get(),
+ BackForwardMenuModel::kMaxHistoryItems - 1, 0);
+ // Go back two (one chapter stop should show up)
+ GoBack();
+ GoBack();
+ ValidateModel(forward_model.get(),
+ BackForwardMenuModel::kMaxHistoryItems, 1);
+
+ // Go to beginning.
+ NavigateToIndex(0);
+
+ // Check to see if the chapter stops have the right labels.
+ index = BackForwardMenuModel::kMaxHistoryItems + 1;
+ EXPECT_EQ(L"", forward_model->GetItemLabel(index++)); // separator.
+ EXPECT_EQ(L"E3", forward_model->GetItemLabel(index++));
+ EXPECT_EQ(L"F3", forward_model->GetItemLabel(index++));
+ EXPECT_EQ(L"G3", forward_model->GetItemLabel(index++));
+ EXPECT_EQ(L"H3", forward_model->GetItemLabel(index++));
+ // max 5 chapter stops.
+ EXPECT_EQ(L"I3", forward_model->GetItemLabel(index));
+ EXPECT_EQ(L"", forward_model->GetItemLabel(index + 1)); // separator.
+ EXPECT_EQ(forward_model->GetShowFullHistoryLabel(),
forward_model->GetItemLabel(index + 2));
- // If we advance one we should still see the same chapter stop at the end.
- contents->controller()->GoForward();
- EXPECT_EQ(L"I3", forward_model->GetItemLabel(index));
- // But if we advance one again, it should change.
- contents->controller()->GoForward();
- EXPECT_EQ(L"J3", forward_model->GetItemLabel(index));
- contents->controller()->GoForward();
- EXPECT_EQ(L"J3", forward_model->GetItemLabel(index));
- contents->controller()->GoForward();
- EXPECT_EQ(L"J3", forward_model->GetItemLabel(index));
- contents->controller()->GoForward();
- EXPECT_EQ(L"K3", forward_model->GetItemLabel(index));
-
- // Now test the boundary cases by using the chapter stop function directly.
- // Out of bounds, first too far right (incrementing), then too far left.
- EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(33, false));
- EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(-1, true));
- // Test being at end and going right, then at beginning going left.
- EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(32, true));
- EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(0, false));
- // Test success: beginning going right and end going left.
- EXPECT_EQ(2, back_model->GetIndexOfNextChapterStop(0, true));
- EXPECT_EQ(29, back_model->GetIndexOfNextChapterStop(32, false));
- // Now see when the chapter stops begin to show up.
- EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(1, false));
- EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(2, false));
- EXPECT_EQ(2, back_model->GetIndexOfNextChapterStop(3, false));
- // Now see when the chapter stops end.
- EXPECT_EQ(32, back_model->GetIndexOfNextChapterStop(30, true));
- EXPECT_EQ(32, back_model->GetIndexOfNextChapterStop(31, true));
- EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(32, true));
-
- // Bug found during review (two different sites, but first wasn't considered
- // a chapter-stop).
- contents->controller()->GoToIndex(0); // Go to A1.
- LoadURLAndUpdateState(contents, "http://www.b.com/1", L"B1");
- EXPECT_EQ(0, back_model->GetIndexOfNextChapterStop(1, false));
- EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(0, true));
-
- // Now see if it counts 'www.x.com' and 'mail.x.com' as same domain, which
- // it should.
- contents->controller()->GoToIndex(0); // Go to A1.
- LoadURLAndUpdateState(contents, "http://mail.a.com/2", L"A2-mail");
- LoadURLAndUpdateState(contents, "http://www.b.com/1", L"B1");
- LoadURLAndUpdateState(contents, "http://mail.b.com/2", L"B2-mail");
- LoadURLAndUpdateState(contents, "http://new.site.com", L"new");
- EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(0, true));
- EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(1, true));
- EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(2, true));
- EXPECT_EQ(4, back_model->GetIndexOfNextChapterStop(3, true));
- // And try backwards as well.
- EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(4, false));
- EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(3, false));
- EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(2, false));
- EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(1, false));
- }
- contents->CloseContents();
+ // If we advance one we should still see the same chapter stop at the end.
+ GoForward();
+ EXPECT_EQ(L"I3", forward_model->GetItemLabel(index));
+ // But if we advance one again, it should change.
+ GoForward();
+ EXPECT_EQ(L"J3", forward_model->GetItemLabel(index));
+ GoForward();
+ EXPECT_EQ(L"J3", forward_model->GetItemLabel(index));
+ GoForward();
+ EXPECT_EQ(L"J3", forward_model->GetItemLabel(index));
+ GoForward();
+ EXPECT_EQ(L"K3", forward_model->GetItemLabel(index));
+
+ // Now test the boundary cases by using the chapter stop function directly.
+ // Out of bounds, first too far right (incrementing), then too far left.
+ EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(33, false));
+ EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(-1, true));
+ // Test being at end and going right, then at beginning going left.
+ EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(32, true));
+ EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(0, false));
+ // Test success: beginning going right and end going left.
+ EXPECT_EQ(2, back_model->GetIndexOfNextChapterStop(0, true));
+ EXPECT_EQ(29, back_model->GetIndexOfNextChapterStop(32, false));
+ // Now see when the chapter stops begin to show up.
+ EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(1, false));
+ EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(2, false));
+ EXPECT_EQ(2, back_model->GetIndexOfNextChapterStop(3, false));
+ // Now see when the chapter stops end.
+ EXPECT_EQ(32, back_model->GetIndexOfNextChapterStop(30, true));
+ EXPECT_EQ(32, back_model->GetIndexOfNextChapterStop(31, true));
+ EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(32, true));
+
+ // Bug found during review (two different sites, but first wasn't considered
+ // a chapter-stop).
+ NavigateToIndex(0); // Go to A1;
+ LoadURLAndUpdateState("http://www.b.com/1", "B1");
+ EXPECT_EQ(0, back_model->GetIndexOfNextChapterStop(1, false));
+ EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(0, true));
+
+ // Now see if it counts 'www.x.com' and 'mail.x.com' as same domain, which
+ // it should.
+ NavigateToIndex(0); // Go to A1.
+ LoadURLAndUpdateState("http://mail.a.com/2", "A2-mai");
+ LoadURLAndUpdateState("http://www.b.com/1", "B1");
+ LoadURLAndUpdateState("http://mail.b.com/2", "B2-mai");
+ LoadURLAndUpdateState("http://new.site.com", "new");
+ EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(0, true));
+ EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(1, true));
+ EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(2, true));
+ EXPECT_EQ(4, back_model->GetIndexOfNextChapterStop(3, true));
+ // And try backwards as well.
+ EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(4, false));
+ EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(3, false));
+ EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(2, false));
+ EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(1, false));
}
diff --git a/chrome/browser/login_prompt.cc b/chrome/browser/login_prompt.cc
index 6a4a59d..ae2cc4d 100644
--- a/chrome/browser/login_prompt.cc
+++ b/chrome/browser/login_prompt.cc
@@ -348,21 +348,19 @@ class LoginDialogTask : public Task {
auth_info_->host,
auth_info_->realm);
LoginView* view = new LoginView(explanation);
- // Tell the password manager to look for saved passwords. There is only
- // a password manager when dealing with a WebContents type.
- if (parent_contents->type() == TAB_CONTENTS_WEB) {
- PasswordManager* password_manager =
- parent_contents->AsWebContents()->GetPasswordManager();
- // Set the model for the login view. The model (password manager) is owned
- // by the view's parent TabContents, so natural destruction order means we
- // don't have to worry about calling SetModel(NULL), because the view will
- // be deleted before the password manager.
- view->SetModel(password_manager);
- std::vector<PasswordForm> v;
- MakeInputForPasswordManager(parent_contents->GetURL(), &v);
- password_manager->PasswordFormsSeen(v);
- handler_->set_password_manager(password_manager);
- }
+
+ // Tell the password manager to look for saved passwords.
+ PasswordManager* password_manager =
+ parent_contents->AsWebContents()->GetPasswordManager();
+ // Set the model for the login view. The model (password manager) is owned
+ // by the view's parent TabContents, so natural destruction order means we
+ // don't have to worry about calling SetModel(NULL), because the view will
+ // be deleted before the password manager.
+ view->SetModel(password_manager);
+ std::vector<PasswordForm> v;
+ MakeInputForPasswordManager(parent_contents->GetURL(), &v);
+ password_manager->PasswordFormsSeen(v);
+ handler_->set_password_manager(password_manager);
handler_->set_login_view(view);
ConstrainedWindow* dialog =
diff --git a/chrome/browser/navigation_entry_unittest.cc b/chrome/browser/navigation_entry_unittest.cc
index 2e36144..d1a64bf 100644
--- a/chrome/browser/navigation_entry_unittest.cc
+++ b/chrome/browser/navigation_entry_unittest.cc
@@ -12,7 +12,7 @@ class NavigationEntryTest : public testing::Test {
}
virtual void SetUp() {
- entry1_.reset(new NavigationEntry(TAB_CONTENTS_WEB));
+ entry1_.reset(new NavigationEntry);
instance_ = SiteInstance::CreateSiteInstance(NULL);
entry2_.reset(new NavigationEntry(TAB_CONTENTS_WEB, instance_, 3,
@@ -123,10 +123,6 @@ TEST_F(NavigationEntryTest, NavigationEntrySSLStatus) {
// Test other basic accessors
TEST_F(NavigationEntryTest, NavigationEntryAccessors) {
- // Type
- EXPECT_EQ(TAB_CONTENTS_WEB, entry1_.get()->tab_type());
- EXPECT_EQ(TAB_CONTENTS_WEB, entry2_.get()->tab_type());
-
// SiteInstance
EXPECT_TRUE(entry1_.get()->site_instance() == NULL);
EXPECT_EQ(instance_, entry2_.get()->site_instance());
diff --git a/chrome/browser/ssl/ssl_blocking_page.cc b/chrome/browser/ssl/ssl_blocking_page.cc
index 4edf04d..5abf71a 100644
--- a/chrome/browser/ssl/ssl_blocking_page.cc
+++ b/chrome/browser/ssl/ssl_blocking_page.cc
@@ -70,7 +70,6 @@ std::string SSLBlockingPage::GetHTMLContents() {
}
void SSLBlockingPage::UpdateEntry(NavigationEntry* entry) {
- DCHECK(tab()->type() == TAB_CONTENTS_WEB);
WebContents* web = tab()->AsWebContents();
const net::SSLInfo& ssl_info = error_->ssl_info();
int cert_id = CertStore::GetSharedInstance()->StoreCert(
diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc
index d1701b3..65551a6 100644
--- a/chrome/browser/tab_contents/interstitial_page.cc
+++ b/chrome/browser/tab_contents/interstitial_page.cc
@@ -161,7 +161,7 @@ void InterstitialPage::Show() {
(*tab_to_interstitial_page_)[tab_] = this;
if (new_navigation_) {
- NavigationEntry* entry = new NavigationEntry(TAB_CONTENTS_WEB);
+ NavigationEntry* entry = new NavigationEntry;
entry->set_url(url_);
entry->set_display_url(url_);
entry->set_page_type(NavigationEntry::INTERSTITIAL_PAGE);
diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc
index d44fdbc..72f9af0 100644
--- a/chrome/browser/tabs/tab_strip_model_unittest.cc
+++ b/chrome/browser/tabs/tab_strip_model_unittest.cc
@@ -8,10 +8,10 @@
#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/profile_manager.h"
+#include "chrome/browser/renderer_host/test_render_view_host.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tab_contents/tab_contents_factory.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/tabs/tab_strip_model_order_controller.h"
#include "chrome/common/pref_names.h"
@@ -19,14 +19,9 @@
#include "chrome/common/url_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
-const TabContentsType kHTTPTabContentsType =
- static_cast<TabContentsType>(TAB_CONTENTS_NUM_TYPES + 1);
-const TabContentsType kReplacementContentsType =
- static_cast<TabContentsType>(kHTTPTabContentsType + 1);
-
class TabStripDummyDelegate : public TabStripModelDelegate {
public:
- explicit TabStripDummyDelegate(TabContents* dummy)
+ explicit TabStripDummyDelegate(TabContents* dummy)
: dummy_contents_(dummy) {}
virtual ~TabStripDummyDelegate() {}
@@ -67,112 +62,33 @@ class TabStripDummyDelegate : public TabStripModelDelegate {
DISALLOW_EVIL_CONSTRUCTORS(TabStripDummyDelegate);
};
-// Since you can't just instantiate a TabContents, and some of its methods
-// are protected, we subclass TabContents with our own testing dummy which
-// knows how to drive the base class' NavigationController as URLs are
-// loaded.
-class TabStripModelTestTabContents : public TabContents {
- public:
- TabStripModelTestTabContents(const TabContentsType type)
- : TabContents(type) {
- }
-};
-
-
-// This constructs our fake TabContents.
-class TabStripModelTestTabContentsFactory : public TabContentsFactory {
+class TabStripModelTest : public RenderViewHostTestHarness {
public:
- virtual TabContents* CreateInstance() {
- return new TabStripModelTestTabContents(kHTTPTabContentsType);
- }
-
- virtual bool CanHandleURL(const GURL& url) {
- return url.SchemeIs(chrome::kHttpScheme);
- }
-};
-
-TabStripModelTestTabContentsFactory factory;
-
-class TabStripModelTest : public testing::Test {
- public:
- // Overridden from testing::Test
- virtual void SetUp() {
- TabContents::RegisterFactory(kHTTPTabContentsType, &factory);
-
- // Name a subdirectory of the temp directory.
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- file_util::AppendToPath(&test_dir_, L"TabStripModelTest");
-
- // Create a fresh, empty copy of this directory.
- file_util::Delete(test_dir_, true);
- CreateDirectory(test_dir_.c_str(), NULL);
-
- profile_path_ = test_dir_;
- file_util::AppendToPath(&profile_path_, L"New Profile");
-
- profile_ = ProfileManager::CreateProfile(
- FilePath::FromWStringHack(profile_path_),
- L"New Profile", L"new-profile", L"");
- ASSERT_TRUE(profile_);
- pm_.AddProfile(profile_);
- }
-
- virtual void TearDown() {
- TabContents::RegisterFactory(kHTTPTabContentsType, NULL);
-
- // Removes a profile from the set of currently-loaded profiles.
- pm_.RemoveProfileByPath(FilePath::FromWStringHack(profile_path_));
-
- // Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, true));
- ASSERT_FALSE(file_util::PathExists(test_dir_));
-
- // Flush the message loop to make Purify happy.
- message_loop_.RunAllPending();
- }
-
- protected:
TabContents* CreateTabContents() {
- TabStripModelTestTabContents* contents =
- new TabStripModelTestTabContents(kHTTPTabContentsType);
- contents->SetupController(profile_);
- return contents;
- }
- TabContents* CreateReplacementContents() {
- TabStripModelTestTabContents* contents =
- new TabStripModelTestTabContents(kReplacementContentsType);
- contents->SetupController(profile_);
- return contents;
- }
- TabContents* CreateNewTabTabContents() {
- TabStripModelTestTabContents* contents =
- new TabStripModelTestTabContents(TAB_CONTENTS_WEB);
- contents->SetupController(profile_);
- return contents;
+ WebContents* con = new WebContents(profile(), NULL, &rvh_factory_, 0, NULL);
+ con->SetupController(profile());
+ return con;
}
// Forwards a URL "load" request through to our dummy TabContents
// implementation.
- void LoadURL(TabContents* contents, const std::wstring& url) {
- contents->controller()->LoadURL(GURL(url), GURL(), PageTransition::LINK);
+ void LoadURL(TabContents* con, const std::wstring& url) {
+ controller()->LoadURL(GURL(url), GURL(), PageTransition::LINK);
}
void GoBack(TabContents* contents) {
- contents->controller()->GoBack();
+ controller()->GoBack();
}
void GoForward(TabContents* contents) {
- contents->controller()->GoForward();
+ controller()->GoForward();
}
void SwitchTabTo(TabContents* contents) {
- contents->DidBecomeSelected();
+ //contents()->DidBecomeSelected();
}
- Profile* profile_;
-
private:
- MessageLoopForUI message_loop_;
std::wstring test_dir_;
std::wstring profile_path_;
ProfileManager pm_;
@@ -294,12 +210,12 @@ class MockTabStripModelObserver : public TabStripModelObserver {
bool empty_;
- DISALLOW_EVIL_CONSTRUCTORS(MockTabStripModelObserver);
+ DISALLOW_COPY_AND_ASSIGN(MockTabStripModelObserver);
};
TEST_F(TabStripModelTest, TestBasicAPI) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
MockTabStripModelObserver observer;
tabstrip.AddObserver(&observer);
@@ -370,7 +286,7 @@ TEST_F(TabStripModelTest, TestBasicAPI) {
}
// Test ReplaceTabContentsAt, replacing the selected index
- TabContents* replacement_contents3 = CreateReplacementContents();
+ TabContents* replacement_contents3 = CreateTabContents();
{
tabstrip.ReplaceTabContentsAt(2, replacement_contents3);
// ReplaceTabContentsAt doesn't delete the source. It depends on
@@ -388,7 +304,7 @@ TEST_F(TabStripModelTest, TestBasicAPI) {
}
// Test ReplaceTabContentsAt, replacing NOT the selected index
- TabContents* replacement_contents2 = CreateReplacementContents();
+ TabContents* replacement_contents2 = CreateTabContents();
{
tabstrip.ReplaceTabContentsAt(1, replacement_contents2);
// ReplaceTabContentsAt doesn't delete the source. It depends on
@@ -506,7 +422,7 @@ TEST_F(TabStripModelTest, TestBasicAPI) {
TEST_F(TabStripModelTest, TestBasicOpenerAPI) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
// This is a basic test of opener functionality. opener_contents is created
@@ -581,7 +497,7 @@ static void InsertTabContentses(TabStripModel* tabstrip,
// Tests opening background tabs.
TEST_F(TabStripModelTest, TestLTRInsertionOptions) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
TabContents* opener_contents = CreateTabContents();
@@ -609,7 +525,7 @@ TEST_F(TabStripModelTest, TestLTRInsertionOptions) {
// end of the strip, not bundled to any existing context.
TEST_F(TabStripModelTest, TestInsertionIndexDetermination) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
TabContents* opener_contents = CreateTabContents();
@@ -688,7 +604,7 @@ TEST_F(TabStripModelTest, TestInsertionIndexDetermination) {
//
TEST_F(TabStripModelTest, TestSelectOnClose) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
TabContents* opener_contents = CreateTabContents();
@@ -766,7 +682,7 @@ TEST_F(TabStripModelTest, TestSelectOnClose) {
// - Close Tabs Opened By
TEST_F(TabStripModelTest, TestContextMenuCloseCommands) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
TabContents* opener_contents = CreateTabContents();
@@ -825,7 +741,7 @@ TEST_F(TabStripModelTest, TestContextMenuCloseCommands) {
// of links on the home page.
TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
@@ -889,7 +805,7 @@ TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) {
// opens a new tab is inserted correctly adjacent to the tab that spawned it.
TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
@@ -936,7 +852,7 @@ TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) {
// in the middle.
TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
@@ -986,7 +902,7 @@ TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) {
// context.
TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
@@ -1047,7 +963,7 @@ TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) {
TEST_F(TabStripModelTest, AppendContentsReselectionTest) {
TabContents* fake_destinations_tab = CreateTabContents();
TabStripDummyDelegate delegate(fake_destinations_tab);
- TabStripModel tabstrip(&delegate, profile_);
+ TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
@@ -1086,7 +1002,7 @@ TEST_F(TabStripModelTest, AppendContentsReselectionTest) {
// Added for http://b/issue?id=1027661
TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel strip(&delegate, profile_);
+ TabStripModel strip(&delegate, profile());
// Open page A
TabContents* page_a_contents = CreateTabContents();
@@ -1133,7 +1049,7 @@ TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) {
TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel strip(&delegate, profile_);
+ TabStripModel strip(&delegate, profile());
// Open page A
TabContents* page_a_contents = CreateTabContents();
@@ -1151,7 +1067,7 @@ TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) {
strip.SelectTabContentsAt(1, true);
// Open a New Tab at the end of the strip (simulate Ctrl+T)
- TabContents* new_tab_contents = CreateNewTabTabContents();
+ TabContents* new_tab_contents = CreateTabContents();
strip.AddTabContents(new_tab_contents, -1, PageTransition::TYPED, true);
EXPECT_EQ(4, strip.GetIndexOfTabContents(new_tab_contents));
@@ -1203,7 +1119,7 @@ TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) {
// not preserved.
TEST_F(TabStripModelTest, NavigationForgetsOpeners) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel strip(&delegate, profile_);
+ TabStripModel strip(&delegate, profile());
// Open page A
TabContents* page_a_contents = CreateTabContents();
@@ -1246,7 +1162,7 @@ TEST_F(TabStripModelTest, NavigationForgetsOpeners) {
// seelcted (Test 2 below).
TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) {
TabStripDummyDelegate delegate(NULL);
- TabStripModel strip(&delegate, profile_);
+ TabStripModel strip(&delegate, profile());
// Open a tab and several tabs from it, then select one of the tabs that was
// opened.
@@ -1267,7 +1183,7 @@ TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) {
// last on.
// Now simulate opening a new tab at the end of the TabStrip.
- TabContents* new_tab_contents1 = CreateNewTabTabContents();
+ TabContents* new_tab_contents1 = CreateTabContents();
strip.AddTabContents(new_tab_contents1, -1, PageTransition::TYPED, true);
// At this point, if we close this tab the last selected one should be
@@ -1280,7 +1196,7 @@ TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) {
// tab's opener relationship to be forgotten.
// Open a new tab again.
- TabContents* new_tab_contents2 = CreateNewTabTabContents();
+ TabContents* new_tab_contents2 = CreateTabContents();
strip.AddTabContents(new_tab_contents2, -1, PageTransition::TYPED, true);
// Now select the first tab.