OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/favicon/favicon_tab_helper.h" | 5 #include "chrome/browser/favicon/favicon_tab_helper.h" |
6 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 6 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
8 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 GURL new_tab_url(chrome::kChromeUINewTabURL); | 30 GURL new_tab_url(chrome::kChromeUINewTabURL); |
31 controller->LoadURL(new_tab_url, GURL(), PageTransition::LINK); | 31 controller->LoadURL(new_tab_url, GURL(), PageTransition::LINK); |
32 | 32 |
33 // The navigation entry should be pending with no committed entry. | 33 // The navigation entry should be pending with no committed entry. |
34 ASSERT_TRUE(controller->pending_entry()); | 34 ASSERT_TRUE(controller->pending_entry()); |
35 ASSERT_FALSE(controller->GetLastCommittedEntry()); | 35 ASSERT_FALSE(controller->GetLastCommittedEntry()); |
36 | 36 |
37 // Check the things the pending Web UI should have set. | 37 // Check the things the pending Web UI should have set. |
38 EXPECT_FALSE(contents->ShouldDisplayURL()); | 38 EXPECT_FALSE(contents->ShouldDisplayURL()); |
39 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); | 39 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); |
40 EXPECT_TRUE(wrapper->bookmark_tab_helper()->ShouldShowBookmarkBar()); | |
41 EXPECT_TRUE(contents->FocusLocationBarByDefault()); | 40 EXPECT_TRUE(contents->FocusLocationBarByDefault()); |
42 | 41 |
43 // Now commit the load. | 42 // Now commit the load. |
44 static_cast<TestRenderViewHost*>( | 43 static_cast<TestRenderViewHost*>( |
45 contents->render_view_host())->SendNavigate(page_id, new_tab_url); | 44 contents->render_view_host())->SendNavigate(page_id, new_tab_url); |
46 | 45 |
47 // The same flags should be set as before now that the load has committed. | 46 // The same flags should be set as before now that the load has committed. |
48 EXPECT_FALSE(contents->ShouldDisplayURL()); | 47 EXPECT_FALSE(contents->ShouldDisplayURL()); |
49 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); | 48 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); |
50 EXPECT_TRUE(wrapper->bookmark_tab_helper()->ShouldShowBookmarkBar()); | |
51 EXPECT_TRUE(contents->FocusLocationBarByDefault()); | 49 EXPECT_TRUE(contents->FocusLocationBarByDefault()); |
52 | 50 |
53 // Start a pending navigation to a regular page. | 51 // Start a pending navigation to a regular page. |
54 GURL next_url("http://google.com/"); | 52 GURL next_url("http://google.com/"); |
55 controller->LoadURL(next_url, GURL(), PageTransition::LINK); | 53 controller->LoadURL(next_url, GURL(), PageTransition::LINK); |
56 | 54 |
57 // Check the flags. Some should reflect the new page (URL, title), some | 55 // Check the flags. Some should reflect the new page (URL, title), some |
58 // should reflect the old one (bookmark bar) until it has committed. | 56 // should reflect the old one (bookmark bar) until it has committed. |
59 EXPECT_TRUE(contents->ShouldDisplayURL()); | 57 EXPECT_TRUE(contents->ShouldDisplayURL()); |
60 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); | 58 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); |
61 EXPECT_TRUE(wrapper->bookmark_tab_helper()->ShouldShowBookmarkBar()); | |
62 EXPECT_FALSE(contents->FocusLocationBarByDefault()); | 59 EXPECT_FALSE(contents->FocusLocationBarByDefault()); |
63 | 60 |
64 // Commit the regular page load. Note that we must send it to the "pending" | 61 // Commit the regular page load. Note that we must send it to the "pending" |
65 // RenderViewHost if there is one, since this transition will also cause a | 62 // RenderViewHost if there is one, since this transition will also cause a |
66 // process transition, and our RVH pointer will be the "committed" one. | 63 // process transition, and our RVH pointer will be the "committed" one. |
67 // In the second call to this function from WebUIToStandard, it won't | 64 // In the second call to this function from WebUIToStandard, it won't |
68 // actually be pending, which is the point of this test. | 65 // actually be pending, which is the point of this test. |
69 if (contents->render_manager()->pending_render_view_host()) { | 66 if (contents->render_manager()->pending_render_view_host()) { |
70 static_cast<TestRenderViewHost*>( | 67 static_cast<TestRenderViewHost*>( |
71 contents->render_manager()->pending_render_view_host())->SendNavigate( | 68 contents->render_manager()->pending_render_view_host())->SendNavigate( |
72 page_id + 1, next_url); | 69 page_id + 1, next_url); |
73 } else { | 70 } else { |
74 static_cast<TestRenderViewHost*>( | 71 static_cast<TestRenderViewHost*>( |
75 contents->render_view_host())->SendNavigate(page_id + 1, next_url); | 72 contents->render_view_host())->SendNavigate(page_id + 1, next_url); |
76 } | 73 } |
77 | 74 |
78 // The state should now reflect a regular page. | 75 // The state should now reflect a regular page. |
79 EXPECT_TRUE(contents->ShouldDisplayURL()); | 76 EXPECT_TRUE(contents->ShouldDisplayURL()); |
80 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); | 77 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); |
81 EXPECT_FALSE(wrapper->bookmark_tab_helper()->ShouldShowBookmarkBar()); | |
82 EXPECT_FALSE(contents->FocusLocationBarByDefault()); | 78 EXPECT_FALSE(contents->FocusLocationBarByDefault()); |
83 } | 79 } |
84 | 80 |
85 private: | 81 private: |
86 BrowserThread ui_thread_; | 82 BrowserThread ui_thread_; |
87 | 83 |
88 DISALLOW_COPY_AND_ASSIGN(WebUITest); | 84 DISALLOW_COPY_AND_ASSIGN(WebUITest); |
89 }; | 85 }; |
90 | 86 |
91 // Tests that the New Tab Page flags are correctly set and propogated by | 87 // Tests that the New Tab Page flags are correctly set and propogated by |
(...skipping 19 matching lines...) Expand all Loading... |
111 rvh()->SendNavigate(1, new_tab_url); | 107 rvh()->SendNavigate(1, new_tab_url); |
112 | 108 |
113 // Start another pending load of the new tab page. | 109 // Start another pending load of the new tab page. |
114 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); | 110 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); |
115 rvh()->SendNavigate(2, new_tab_url); | 111 rvh()->SendNavigate(2, new_tab_url); |
116 | 112 |
117 // The flags should be the same as the non-pending state. | 113 // The flags should be the same as the non-pending state. |
118 EXPECT_FALSE(contents()->ShouldDisplayURL()); | 114 EXPECT_FALSE(contents()->ShouldDisplayURL()); |
119 EXPECT_FALSE( | 115 EXPECT_FALSE( |
120 contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 116 contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); |
121 EXPECT_TRUE( | |
122 contents_wrapper()->bookmark_tab_helper()->ShouldShowBookmarkBar()); | |
123 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 117 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
124 } | 118 } |
125 | 119 |
126 TEST_F(WebUITest, StandardToWebUI) { | 120 TEST_F(WebUITest, StandardToWebUI) { |
127 // Start a pending navigation to a regular page. | 121 // Start a pending navigation to a regular page. |
128 GURL std_url("http://google.com/"); | 122 GURL std_url("http://google.com/"); |
129 | 123 |
130 controller().LoadURL(std_url, GURL(), PageTransition::LINK); | 124 controller().LoadURL(std_url, GURL(), PageTransition::LINK); |
131 | 125 |
132 // The state should now reflect the default. | 126 // The state should now reflect the default. |
133 EXPECT_TRUE(contents()->ShouldDisplayURL()); | 127 EXPECT_TRUE(contents()->ShouldDisplayURL()); |
134 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 128 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); |
135 EXPECT_FALSE( | |
136 contents_wrapper()->bookmark_tab_helper()->ShouldShowBookmarkBar()); | |
137 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | 129 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); |
138 | 130 |
139 // Commit the load, the state should be the same. | 131 // Commit the load, the state should be the same. |
140 rvh()->SendNavigate(1, std_url); | 132 rvh()->SendNavigate(1, std_url); |
141 EXPECT_TRUE(contents()->ShouldDisplayURL()); | 133 EXPECT_TRUE(contents()->ShouldDisplayURL()); |
142 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 134 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); |
143 EXPECT_FALSE( | |
144 contents_wrapper()->bookmark_tab_helper()->ShouldShowBookmarkBar()); | |
145 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | 135 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); |
146 | 136 |
147 // Start a pending load for a WebUI. | 137 // Start a pending load for a WebUI. |
148 GURL new_tab_url(chrome::kChromeUINewTabURL); | 138 GURL new_tab_url(chrome::kChromeUINewTabURL); |
149 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); | 139 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); |
150 EXPECT_FALSE(contents()->ShouldDisplayURL()); | 140 EXPECT_FALSE(contents()->ShouldDisplayURL()); |
151 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 141 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); |
152 EXPECT_FALSE( | |
153 contents_wrapper()->bookmark_tab_helper()->ShouldShowBookmarkBar()); | |
154 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 142 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
155 | 143 |
156 // Committing Web UI is tested above. | 144 // Committing Web UI is tested above. |
157 } | 145 } |
158 | 146 |
159 class TabContentsForFocusTest : public TestTabContents { | 147 class TabContentsForFocusTest : public TestTabContents { |
160 public: | 148 public: |
161 TabContentsForFocusTest(content::BrowserContext* browser_context, | 149 TabContentsForFocusTest(content::BrowserContext* browser_context, |
162 SiteInstance* instance) | 150 SiteInstance* instance) |
163 : TestTabContents(browser_context, instance), focus_called_(0) { | 151 : TestTabContents(browser_context, instance), focus_called_(0) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // Navigate forward. Shouldn't focus the location bar. | 194 // Navigate forward. Shouldn't focus the location bar. |
207 focus_called = tc->focus_called(); | 195 focus_called = tc->focus_called(); |
208 ASSERT_TRUE(controller().CanGoForward()); | 196 ASSERT_TRUE(controller().CanGoForward()); |
209 controller().GoForward(); | 197 controller().GoForward(); |
210 old_rvh = rvh(); | 198 old_rvh = rvh(); |
211 old_rvh->SendShouldCloseACK(true); | 199 old_rvh->SendShouldCloseACK(true); |
212 pending_rvh()->SendNavigate(next_page_id, next_url); | 200 pending_rvh()->SendNavigate(next_page_id, next_url); |
213 old_rvh->OnSwapOutACK(); | 201 old_rvh->OnSwapOutACK(); |
214 EXPECT_EQ(focus_called, tc->focus_called()); | 202 EXPECT_EQ(focus_called, tc->focus_called()); |
215 } | 203 } |
OLD | NEW |