OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/toolbar/back_forward_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" |
6 | 6 |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "content/browser/tab_contents/test_tab_contents.h" | |
18 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
19 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
20 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
21 #include "content/test/test_browser_thread.h" | 20 #include "content/test/test_browser_thread.h" |
| 21 #include "content/test/web_contents_tester.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
24 #include "ui/gfx/codec/png_codec.h" | 24 #include "ui/gfx/codec/png_codec.h" |
25 | 25 |
26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 using content::WebContentsTester; |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // Creates a bitmap of the specified color. | 31 // Creates a bitmap of the specified color. |
31 SkBitmap CreateBitmap(SkColor color) { | 32 SkBitmap CreateBitmap(SkColor color) { |
32 SkBitmap bitmap; | 33 SkBitmap bitmap; |
33 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 34 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
34 bitmap.allocPixels(); | 35 bitmap.allocPixels(); |
35 bitmap.eraseColor(color); | 36 bitmap.eraseColor(color); |
36 return bitmap; | 37 return bitmap; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 77 |
77 void LoadURLAndUpdateState(const char* url, const char* title) { | 78 void LoadURLAndUpdateState(const char* url, const char* title) { |
78 NavigateAndCommit(GURL(url)); | 79 NavigateAndCommit(GURL(url)); |
79 controller().GetLastCommittedEntry()->SetTitle(UTF8ToUTF16(title)); | 80 controller().GetLastCommittedEntry()->SetTitle(UTF8ToUTF16(title)); |
80 } | 81 } |
81 | 82 |
82 // Navigate back or forward the given amount and commits the entry (which | 83 // Navigate back or forward the given amount and commits the entry (which |
83 // will be pending after we ask to navigate there). | 84 // will be pending after we ask to navigate there). |
84 void NavigateToOffset(int offset) { | 85 void NavigateToOffset(int offset) { |
85 controller().GoToOffset(offset); | 86 controller().GoToOffset(offset); |
86 contents()->CommitPendingNavigation(); | 87 WebContentsTester::For(contents())->CommitPendingNavigation(); |
87 } | 88 } |
88 | 89 |
89 // Same as NavigateToOffset but goes to an absolute index. | 90 // Same as NavigateToOffset but goes to an absolute index. |
90 void NavigateToIndex(int index) { | 91 void NavigateToIndex(int index) { |
91 controller().GoToIndex(index); | 92 controller().GoToIndex(index); |
92 contents()->CommitPendingNavigation(); | 93 WebContentsTester::For(contents())->CommitPendingNavigation(); |
93 } | 94 } |
94 | 95 |
95 // Goes back/forward and commits the load. | 96 // Goes back/forward and commits the load. |
96 void GoBack() { | 97 void GoBack() { |
97 controller().GoBack(); | 98 controller().GoBack(); |
98 contents()->CommitPendingNavigation(); | 99 WebContentsTester::For(contents())->CommitPendingNavigation(); |
99 } | 100 } |
100 void GoForward() { | 101 void GoForward() { |
101 controller().GoForward(); | 102 controller().GoForward(); |
102 contents()->CommitPendingNavigation(); | 103 WebContentsTester::For(contents())->CommitPendingNavigation(); |
103 } | 104 } |
104 | 105 |
105 content::TestBrowserThread ui_thread_; | 106 content::TestBrowserThread ui_thread_; |
106 }; | 107 }; |
107 | 108 |
108 TEST_F(BackFwdMenuModelTest, BasicCase) { | 109 TEST_F(BackFwdMenuModelTest, BasicCase) { |
109 scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel( | 110 scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel( |
110 NULL, BackForwardMenuModel::BACKWARD_MENU)); | 111 NULL, BackForwardMenuModel::BACKWARD_MENU)); |
111 back_model->set_test_web_contents(contents()); | 112 back_model->set_test_web_contents(contents()); |
112 | 113 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // Verify we did get the expected favicon. | 552 // Verify we did get the expected favicon. |
552 EXPECT_EQ(0, memcmp(new_icon.getPixels(), valid_icon.getPixels(), | 553 EXPECT_EQ(0, memcmp(new_icon.getPixels(), valid_icon.getPixels(), |
553 new_icon.getSize())); | 554 new_icon.getSize())); |
554 | 555 |
555 // Make sure the browser deconstructor doesn't have problems. | 556 // Make sure the browser deconstructor doesn't have problems. |
556 browser.CloseAllTabs(); | 557 browser.CloseAllTabs(); |
557 // This is required to prevent the message loop from hanging. | 558 // This is required to prevent the message loop from hanging. |
558 profile()->DestroyHistoryService(); | 559 profile()->DestroyHistoryService(); |
559 } | 560 } |
560 | 561 |
OLD | NEW |