| 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/ui/webui/new_tab_ui.h" | 5 #include "chrome/browser/ui/webui/new_tab_ui.h" |
| 6 #include "chrome/common/url_constants.h" | 6 #include "chrome/common/url_constants.h" |
| 7 #include "chrome/test/testing_profile.h" | 7 #include "chrome/test/testing_profile.h" |
| 8 #include "content/browser/browser_thread.h" | 8 #include "content/browser/browser_thread.h" |
| 9 #include "content/browser/renderer_host/test_render_view_host.h" | 9 #include "content/browser/renderer_host/test_render_view_host.h" |
| 10 #include "content/browser/site_instance.h" | 10 #include "content/browser/site_instance.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 private: | 159 private: |
| 160 int focus_called_; | 160 int focus_called_; |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 TEST_F(WebUITest, FocusOnNavigate) { | 163 TEST_F(WebUITest, FocusOnNavigate) { |
| 164 // Setup. |tc| will be used to track when we try to focus the location bar. | 164 // Setup. |tc| will be used to track when we try to focus the location bar. |
| 165 TabContentsForFocusTest* tc = new TabContentsForFocusTest( | 165 TabContentsForFocusTest* tc = new TabContentsForFocusTest( |
| 166 contents()->profile(), | 166 contents()->profile(), |
| 167 SiteInstance::CreateSiteInstance(contents()->profile())); | 167 SiteInstance::CreateSiteInstance(contents()->profile())); |
| 168 tc->controller().CopyStateFrom(controller()); | 168 tc->controller().CopyStateFrom(controller()); |
| 169 scoped_ptr<TestTabContents> tc_scoped_ptr(tc); | 169 SetContents(tc); |
| 170 contents_.swap(tc_scoped_ptr); | |
| 171 int page_id = 200; | 170 int page_id = 200; |
| 172 | 171 |
| 173 // Load the NTP. | 172 // Load the NTP. |
| 174 GURL new_tab_url(chrome::kChromeUINewTabURL); | 173 GURL new_tab_url(chrome::kChromeUINewTabURL); |
| 175 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); | 174 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); |
| 176 rvh()->SendNavigate(page_id, new_tab_url); | 175 rvh()->SendNavigate(page_id, new_tab_url); |
| 177 | 176 |
| 178 // Navigate to another page. | 177 // Navigate to another page. |
| 179 GURL next_url("http://google.com/"); | 178 GURL next_url("http://google.com/"); |
| 180 int next_page_id = page_id + 1; | 179 int next_page_id = page_id + 1; |
| 181 controller().LoadURL(next_url, GURL(), PageTransition::LINK); | 180 controller().LoadURL(next_url, GURL(), PageTransition::LINK); |
| 182 pending_rvh()->SendNavigate(next_page_id, next_url); | 181 pending_rvh()->SendNavigate(next_page_id, next_url); |
| 183 | 182 |
| 184 // Navigate back. Should focus the location bar. | 183 // Navigate back. Should focus the location bar. |
| 185 int focus_called = tc->focus_called(); | 184 int focus_called = tc->focus_called(); |
| 186 ASSERT_TRUE(controller().CanGoBack()); | 185 ASSERT_TRUE(controller().CanGoBack()); |
| 187 controller().GoBack(); | 186 controller().GoBack(); |
| 188 pending_rvh()->SendNavigate(page_id, new_tab_url); | 187 pending_rvh()->SendNavigate(page_id, new_tab_url); |
| 189 EXPECT_LT(focus_called, tc->focus_called()); | 188 EXPECT_LT(focus_called, tc->focus_called()); |
| 190 | 189 |
| 191 // Navigate forward. Shouldn't focus the location bar. | 190 // Navigate forward. Shouldn't focus the location bar. |
| 192 focus_called = tc->focus_called(); | 191 focus_called = tc->focus_called(); |
| 193 ASSERT_TRUE(controller().CanGoForward()); | 192 ASSERT_TRUE(controller().CanGoForward()); |
| 194 controller().GoForward(); | 193 controller().GoForward(); |
| 195 pending_rvh()->SendNavigate(next_page_id, next_url); | 194 pending_rvh()->SendNavigate(next_page_id, next_url); |
| 196 EXPECT_EQ(focus_called, tc->focus_called()); | 195 EXPECT_EQ(focus_called, tc->focus_called()); |
| 197 | |
| 198 contents_.swap(tc_scoped_ptr); | |
| 199 } | 196 } |
| OLD | NEW |