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 10 matching lines...) Expand all Loading... |
21 // Tests navigating with a Web UI from a fresh (nothing pending or committed) | 21 // Tests navigating with a Web UI from a fresh (nothing pending or committed) |
22 // state, through pending, committed, then another navigation. The first page | 22 // state, through pending, committed, then another navigation. The first page |
23 // ID that we should use is passed as a parameter. We'll use the next two | 23 // ID that we should use is passed as a parameter. We'll use the next two |
24 // values. This must be increasing for the life of the tests. | 24 // values. This must be increasing for the life of the tests. |
25 static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) { | 25 static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) { |
26 TabContents* contents = wrapper->tab_contents(); | 26 TabContents* contents = wrapper->tab_contents(); |
27 NavigationController* controller = &contents->controller(); | 27 NavigationController* controller = &contents->controller(); |
28 | 28 |
29 // Start a pending load. | 29 // Start a pending load. |
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(), content::PAGE_TRANSITION_LINK, |
32 std::string()); | 32 std::string()); |
33 | 33 |
34 // The navigation entry should be pending with no committed entry. | 34 // The navigation entry should be pending with no committed entry. |
35 ASSERT_TRUE(controller->pending_entry()); | 35 ASSERT_TRUE(controller->pending_entry()); |
36 ASSERT_FALSE(controller->GetLastCommittedEntry()); | 36 ASSERT_FALSE(controller->GetLastCommittedEntry()); |
37 | 37 |
38 // Check the things the pending Web UI should have set. | 38 // Check the things the pending Web UI should have set. |
39 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); | 39 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); |
40 EXPECT_TRUE(contents->FocusLocationBarByDefault()); | 40 EXPECT_TRUE(contents->FocusLocationBarByDefault()); |
41 | 41 |
42 // Now commit the load. | 42 // Now commit the load. |
43 static_cast<TestRenderViewHost*>( | 43 static_cast<TestRenderViewHost*>( |
44 contents->render_view_host())->SendNavigate(page_id, new_tab_url); | 44 contents->render_view_host())->SendNavigate(page_id, new_tab_url); |
45 | 45 |
46 // 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. |
47 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); | 47 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); |
48 EXPECT_TRUE(contents->FocusLocationBarByDefault()); | 48 EXPECT_TRUE(contents->FocusLocationBarByDefault()); |
49 | 49 |
50 // Start a pending navigation to a regular page. | 50 // Start a pending navigation to a regular page. |
51 GURL next_url("http://google.com/"); | 51 GURL next_url("http://google.com/"); |
52 controller->LoadURL(next_url, GURL(), PageTransition::LINK, std::string()); | 52 controller->LoadURL(next_url, GURL(), content::PAGE_TRANSITION_LINK, |
| 53 std::string()); |
53 | 54 |
54 // 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 |
55 // should reflect the old one (bookmark bar) until it has committed. | 56 // should reflect the old one (bookmark bar) until it has committed. |
56 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); | 57 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); |
57 EXPECT_FALSE(contents->FocusLocationBarByDefault()); | 58 EXPECT_FALSE(contents->FocusLocationBarByDefault()); |
58 | 59 |
59 // Commit the regular page load. Note that we must send it to the "pending" | 60 // Commit the regular page load. Note that we must send it to the "pending" |
60 // RenderViewHost if there is one, since this transition will also cause a | 61 // RenderViewHost if there is one, since this transition will also cause a |
61 // process transition, and our RVH pointer will be the "committed" one. | 62 // process transition, and our RVH pointer will be the "committed" one. |
62 // In the second call to this function from WebUIToStandard, it won't | 63 // In the second call to this function from WebUIToStandard, it won't |
(...skipping 30 matching lines...) Expand all Loading... |
93 // alive), which will trigger different behavior in RenderViewHostManager. | 94 // alive), which will trigger different behavior in RenderViewHostManager. |
94 TestTabContents* contents2 = new TestTabContents(profile(), NULL); | 95 TestTabContents* contents2 = new TestTabContents(profile(), NULL); |
95 TabContentsWrapper wrapper2(contents2); | 96 TabContentsWrapper wrapper2(contents2); |
96 | 97 |
97 DoNavigationTest(&wrapper2, 101); | 98 DoNavigationTest(&wrapper2, 101); |
98 } | 99 } |
99 | 100 |
100 TEST_F(WebUITest, WebUIToWebUI) { | 101 TEST_F(WebUITest, WebUIToWebUI) { |
101 // Do a load (this state is tested above). | 102 // Do a load (this state is tested above). |
102 GURL new_tab_url(chrome::kChromeUINewTabURL); | 103 GURL new_tab_url(chrome::kChromeUINewTabURL); |
103 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK, | 104 controller().LoadURL(new_tab_url, GURL(), content::PAGE_TRANSITION_LINK, |
104 std::string()); | 105 std::string()); |
105 rvh()->SendNavigate(1, new_tab_url); | 106 rvh()->SendNavigate(1, new_tab_url); |
106 | 107 |
107 // Start another pending load of the new tab page. | 108 // Start another pending load of the new tab page. |
108 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK, | 109 controller().LoadURL(new_tab_url, GURL(), content::PAGE_TRANSITION_LINK, |
109 std::string()); | 110 std::string()); |
110 rvh()->SendNavigate(2, new_tab_url); | 111 rvh()->SendNavigate(2, new_tab_url); |
111 | 112 |
112 // The flags should be the same as the non-pending state. | 113 // The flags should be the same as the non-pending state. |
113 EXPECT_FALSE( | 114 EXPECT_FALSE( |
114 contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 115 contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); |
115 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 116 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
116 } | 117 } |
117 | 118 |
118 TEST_F(WebUITest, StandardToWebUI) { | 119 TEST_F(WebUITest, StandardToWebUI) { |
119 // Start a pending navigation to a regular page. | 120 // Start a pending navigation to a regular page. |
120 GURL std_url("http://google.com/"); | 121 GURL std_url("http://google.com/"); |
121 | 122 |
122 controller().LoadURL(std_url, GURL(), PageTransition::LINK, std::string()); | 123 controller().LoadURL(std_url, GURL(), content::PAGE_TRANSITION_LINK, |
| 124 std::string()); |
123 | 125 |
124 // The state should now reflect the default. | 126 // The state should now reflect the default. |
125 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 127 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); |
126 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | 128 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); |
127 | 129 |
128 // Commit the load, the state should be the same. | 130 // Commit the load, the state should be the same. |
129 rvh()->SendNavigate(1, std_url); | 131 rvh()->SendNavigate(1, std_url); |
130 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 132 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); |
131 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | 133 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); |
132 | 134 |
133 // Start a pending load for a WebUI. | 135 // Start a pending load for a WebUI. |
134 GURL new_tab_url(chrome::kChromeUINewTabURL); | 136 GURL new_tab_url(chrome::kChromeUINewTabURL); |
135 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK, | 137 controller().LoadURL(new_tab_url, GURL(), content::PAGE_TRANSITION_LINK, |
136 std::string()); | 138 std::string()); |
137 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 139 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); |
138 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 140 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
139 | 141 |
140 // Committing Web UI is tested above. | 142 // Committing Web UI is tested above. |
141 } | 143 } |
142 | 144 |
143 class TabContentsForFocusTest : public TestTabContents { | 145 class TabContentsForFocusTest : public TestTabContents { |
144 public: | 146 public: |
145 TabContentsForFocusTest(content::BrowserContext* browser_context, | 147 TabContentsForFocusTest(content::BrowserContext* browser_context, |
(...skipping 12 matching lines...) Expand all Loading... |
158 // Setup. |tc| will be used to track when we try to focus the location bar. | 160 // Setup. |tc| will be used to track when we try to focus the location bar. |
159 TabContentsForFocusTest* tc = new TabContentsForFocusTest( | 161 TabContentsForFocusTest* tc = new TabContentsForFocusTest( |
160 contents()->browser_context(), | 162 contents()->browser_context(), |
161 SiteInstance::CreateSiteInstance(contents()->browser_context())); | 163 SiteInstance::CreateSiteInstance(contents()->browser_context())); |
162 tc->controller().CopyStateFrom(controller()); | 164 tc->controller().CopyStateFrom(controller()); |
163 SetContents(tc); | 165 SetContents(tc); |
164 int page_id = 200; | 166 int page_id = 200; |
165 | 167 |
166 // Load the NTP. | 168 // Load the NTP. |
167 GURL new_tab_url(chrome::kChromeUINewTabURL); | 169 GURL new_tab_url(chrome::kChromeUINewTabURL); |
168 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK, | 170 controller().LoadURL(new_tab_url, GURL(), content::PAGE_TRANSITION_LINK, |
169 std::string()); | 171 std::string()); |
170 rvh()->SendNavigate(page_id, new_tab_url); | 172 rvh()->SendNavigate(page_id, new_tab_url); |
171 | 173 |
172 // Navigate to another page. | 174 // Navigate to another page. |
173 GURL next_url("http://google.com/"); | 175 GURL next_url("http://google.com/"); |
174 int next_page_id = page_id + 1; | 176 int next_page_id = page_id + 1; |
175 controller().LoadURL(next_url, GURL(), PageTransition::LINK, std::string()); | 177 controller().LoadURL(next_url, GURL(), content::PAGE_TRANSITION_LINK, |
| 178 std::string()); |
176 TestRenderViewHost* old_rvh = rvh(); | 179 TestRenderViewHost* old_rvh = rvh(); |
177 old_rvh->SendShouldCloseACK(true); | 180 old_rvh->SendShouldCloseACK(true); |
178 pending_rvh()->SendNavigate(next_page_id, next_url); | 181 pending_rvh()->SendNavigate(next_page_id, next_url); |
179 old_rvh->OnSwapOutACK(); | 182 old_rvh->OnSwapOutACK(); |
180 | 183 |
181 // Navigate back. Should focus the location bar. | 184 // Navigate back. Should focus the location bar. |
182 int focus_called = tc->focus_called(); | 185 int focus_called = tc->focus_called(); |
183 ASSERT_TRUE(controller().CanGoBack()); | 186 ASSERT_TRUE(controller().CanGoBack()); |
184 controller().GoBack(); | 187 controller().GoBack(); |
185 old_rvh = rvh(); | 188 old_rvh = rvh(); |
186 old_rvh->SendShouldCloseACK(true); | 189 old_rvh->SendShouldCloseACK(true); |
187 pending_rvh()->SendNavigate(page_id, new_tab_url); | 190 pending_rvh()->SendNavigate(page_id, new_tab_url); |
188 old_rvh->OnSwapOutACK(); | 191 old_rvh->OnSwapOutACK(); |
189 EXPECT_LT(focus_called, tc->focus_called()); | 192 EXPECT_LT(focus_called, tc->focus_called()); |
190 | 193 |
191 // Navigate forward. Shouldn't focus the location bar. | 194 // Navigate forward. Shouldn't focus the location bar. |
192 focus_called = tc->focus_called(); | 195 focus_called = tc->focus_called(); |
193 ASSERT_TRUE(controller().CanGoForward()); | 196 ASSERT_TRUE(controller().CanGoForward()); |
194 controller().GoForward(); | 197 controller().GoForward(); |
195 old_rvh = rvh(); | 198 old_rvh = rvh(); |
196 old_rvh->SendShouldCloseACK(true); | 199 old_rvh->SendShouldCloseACK(true); |
197 pending_rvh()->SendNavigate(next_page_id, next_url); | 200 pending_rvh()->SendNavigate(next_page_id, next_url); |
198 old_rvh->OnSwapOutACK(); | 201 old_rvh->OnSwapOutACK(); |
199 EXPECT_EQ(focus_called, tc->focus_called()); | 202 EXPECT_EQ(focus_called, tc->focus_called()); |
200 } | 203 } |
OLD | NEW |