OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/profile_manager.h" | 10 #include "chrome/browser/profile_manager.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 void LoadURLAndUpdateState(const char* url, const char* title) { | 34 void LoadURLAndUpdateState(const char* url, const char* title) { |
35 NavigateAndCommit(GURL(url)); | 35 NavigateAndCommit(GURL(url)); |
36 controller().GetLastCommittedEntry()->set_title(UTF8ToUTF16(title)); | 36 controller().GetLastCommittedEntry()->set_title(UTF8ToUTF16(title)); |
37 } | 37 } |
38 | 38 |
39 // Navigate back or forward the given amount and commits the entry (which | 39 // Navigate back or forward the given amount and commits the entry (which |
40 // will be pending after we ask to navigate there). | 40 // will be pending after we ask to navigate there). |
41 void NavigateToOffset(int offset) { | 41 void NavigateToOffset(int offset) { |
42 controller().GoToOffset(offset); | 42 controller().GoToOffset(offset); |
43 contents()->CommitPendingNavigation(); | 43 const NavigationEntry* entry = controller().pending_entry(); |
| 44 rvh()->SendNavigate(entry->page_id(), entry->url()); |
44 } | 45 } |
45 | 46 |
46 // Same as NavigateToOffset but goes to an absolute index. | 47 // Same as NavigateToOffset but goes to an absolute index. |
47 void NavigateToIndex(int index) { | 48 void NavigateToIndex(int index) { |
48 controller().GoToIndex(index); | 49 controller().GoToIndex(index); |
49 contents()->CommitPendingNavigation(); | 50 const NavigationEntry* entry = controller().pending_entry(); |
| 51 rvh()->SendNavigate(entry->page_id(), entry->url()); |
50 } | 52 } |
51 | 53 |
52 // Goes back/forward and commits the load. | 54 // Goes back/forward and commits the load. |
53 void GoBack() { | 55 void GoBack() { |
54 controller().GoBack(); | 56 controller().GoBack(); |
55 contents()->CommitPendingNavigation(); | 57 const NavigationEntry* entry = controller().pending_entry(); |
| 58 rvh()->SendNavigate(entry->page_id(), entry->url()); |
56 } | 59 } |
57 void GoForward() { | 60 void GoForward() { |
58 controller().GoForward(); | 61 controller().GoForward(); |
59 contents()->CommitPendingNavigation(); | 62 const NavigationEntry* entry = controller().pending_entry(); |
| 63 rvh()->SendNavigate(entry->page_id(), entry->url()); |
60 } | 64 } |
61 }; | 65 }; |
62 | 66 |
63 TEST_F(BackFwdMenuModelTest, BasicCase) { | 67 TEST_F(BackFwdMenuModelTest, BasicCase) { |
64 scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel( | 68 scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel( |
65 NULL, BackForwardMenuModel::BACKWARD_MENU)); | 69 NULL, BackForwardMenuModel::BACKWARD_MENU)); |
66 back_model->set_test_tab_contents(contents()); | 70 back_model->set_test_tab_contents(contents()); |
67 | 71 |
68 scoped_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel( | 72 scoped_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel( |
69 NULL, BackForwardMenuModel::FORWARD_MENU)); | 73 NULL, BackForwardMenuModel::FORWARD_MENU)); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(0, true)); | 417 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(0, true)); |
414 EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(1, true)); | 418 EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(1, true)); |
415 EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(2, true)); | 419 EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(2, true)); |
416 EXPECT_EQ(4, back_model->GetIndexOfNextChapterStop(3, true)); | 420 EXPECT_EQ(4, back_model->GetIndexOfNextChapterStop(3, true)); |
417 // And try backwards as well. | 421 // And try backwards as well. |
418 EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(4, false)); | 422 EXPECT_EQ(3, back_model->GetIndexOfNextChapterStop(4, false)); |
419 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(3, false)); | 423 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(3, false)); |
420 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(2, false)); | 424 EXPECT_EQ(1, back_model->GetIndexOfNextChapterStop(2, false)); |
421 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(1, false)); | 425 EXPECT_EQ(-1, back_model->GetIndexOfNextChapterStop(1, false)); |
422 } | 426 } |
OLD | NEW |