OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/back_forward_menu_model.h" | 5 #include "chrome/browser/back_forward_menu_model.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "chrome/browser/navigation_controller.h" | 9 #include "chrome/browser/navigation_controller.h" |
10 #include "chrome/browser/navigation_entry.h" | 10 #include "chrome/browser/navigation_entry.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // loaded. Constructing one of these automatically constructs a | 22 // loaded. Constructing one of these automatically constructs a |
23 // NavigationController instance which we wrap our RecentPagesModel around. | 23 // NavigationController instance which we wrap our RecentPagesModel around. |
24 class BackFwdMenuModelTestTabContents : public TabContents { | 24 class BackFwdMenuModelTestTabContents : public TabContents { |
25 public: | 25 public: |
26 BEGIN_MSG_MAP(BackFwdMenuModelTestTabContents) | 26 BEGIN_MSG_MAP(BackFwdMenuModelTestTabContents) |
27 END_MSG_MAP() | 27 END_MSG_MAP() |
28 | 28 |
29 BackFwdMenuModelTestTabContents() : TabContents(kHTTPTabContentsType) { | 29 BackFwdMenuModelTestTabContents() : TabContents(kHTTPTabContentsType) { |
30 } | 30 } |
31 | 31 |
32 bool Navigate(const NavigationEntry& entry, bool reload) { | 32 // We do the same thing as the TabContents one (just commit the navigation) |
33 NavigationEntry* pending_entry = new NavigationEntry(entry); | 33 // but we *don't* want to reset the title since the test looks for this. |
34 if (pending_entry->page_id() == -1) { | 34 virtual bool NavigateToPendingEntry(bool reload) { |
35 pending_entry->set_page_id(g_page_id_++); | 35 controller()->CommitPendingEntry(); |
36 } | |
37 NavigationController::LoadCommittedDetails details; | |
38 DidNavigateToEntry(pending_entry, &details); | |
39 return true; | 36 return true; |
40 } | 37 } |
41 | 38 |
42 void UpdateState(const std::wstring& title) { | 39 void UpdateState(const std::wstring& title) { |
43 NavigationEntry* entry = | 40 NavigationEntry* entry = |
44 controller()->GetEntryWithPageID(type(), NULL, g_page_id_ - 1); | 41 controller()->GetEntryWithPageID(type(), NULL, GetMaxPageID()); |
45 entry->set_title(title); | 42 entry->set_title(title); |
46 } | 43 } |
47 | |
48 private: | |
49 // We need to use valid, incrementing page ids otherwise the TabContents | |
50 // and NavController will not play nice when we try to go back and forward. | |
51 static int g_page_id_; | |
52 }; | 44 }; |
53 | 45 |
54 int BackFwdMenuModelTestTabContents::g_page_id_ = 0; | |
55 | |
56 // This constructs our fake TabContents. | 46 // This constructs our fake TabContents. |
57 class BackFwdMenuModelTestTabContentsFactory : public TabContentsFactory { | 47 class BackFwdMenuModelTestTabContentsFactory : public TabContentsFactory { |
58 public: | 48 public: |
59 virtual TabContents* CreateInstance() { | 49 virtual TabContents* CreateInstance() { |
60 return new BackFwdMenuModelTestTabContents; | 50 return new BackFwdMenuModelTestTabContents; |
61 } | 51 } |
62 | 52 |
63 virtual bool CanHandleURL(const GURL& url) { | 53 virtual bool CanHandleURL(const GURL& url) { |
64 return url.scheme() == "http"; | 54 return url.scheme() == "http"; |
65 } | 55 } |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 EXPECT_EQ(4, back_model.GetIndexOfNextChapterStop(3, true)); | 498 EXPECT_EQ(4, back_model.GetIndexOfNextChapterStop(3, true)); |
509 // And try backwards as well. | 499 // And try backwards as well. |
510 EXPECT_EQ(3, back_model.GetIndexOfNextChapterStop(4, false)); | 500 EXPECT_EQ(3, back_model.GetIndexOfNextChapterStop(4, false)); |
511 EXPECT_EQ(1, back_model.GetIndexOfNextChapterStop(3, false)); | 501 EXPECT_EQ(1, back_model.GetIndexOfNextChapterStop(3, false)); |
512 EXPECT_EQ(1, back_model.GetIndexOfNextChapterStop(2, false)); | 502 EXPECT_EQ(1, back_model.GetIndexOfNextChapterStop(2, false)); |
513 EXPECT_EQ(-1, back_model.GetIndexOfNextChapterStop(1, false)); | 503 EXPECT_EQ(-1, back_model.GetIndexOfNextChapterStop(1, false)); |
514 } | 504 } |
515 contents->CloseContents(); | 505 contents->CloseContents(); |
516 } | 506 } |
517 | 507 |
OLD | NEW |