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" |
11 #include "content/browser/site_instance.h" | |
12 #include "content/browser/tab_contents/test_tab_contents.h" | 11 #include "content/browser/tab_contents/test_tab_contents.h" |
13 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
| 13 #include "content/public/browser/site_instance.h" |
14 #include "content/test/test_browser_thread.h" | 14 #include "content/test/test_browser_thread.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using content::BrowserThread; | 17 using content::BrowserThread; |
18 using content::NavigationController; | 18 using content::NavigationController; |
19 using content::WebContents; | 19 using content::WebContents; |
20 | 20 |
21 class WebUITest : public TabContentsWrapperTestHarness { | 21 class WebUITest : public TabContentsWrapperTestHarness { |
22 public: | 22 public: |
23 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} | 23 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 std::string()); | 148 std::string()); |
149 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 149 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); |
150 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 150 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
151 | 151 |
152 // Committing Web UI is tested above. | 152 // Committing Web UI is tested above. |
153 } | 153 } |
154 | 154 |
155 class TabContentsForFocusTest : public TestTabContents { | 155 class TabContentsForFocusTest : public TestTabContents { |
156 public: | 156 public: |
157 TabContentsForFocusTest(content::BrowserContext* browser_context, | 157 TabContentsForFocusTest(content::BrowserContext* browser_context, |
158 SiteInstance* instance) | 158 content::SiteInstance* instance) |
159 : TestTabContents(browser_context, instance), focus_called_(0) { | 159 : TestTabContents(browser_context, instance), focus_called_(0) { |
160 } | 160 } |
161 | 161 |
162 virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; } | 162 virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; } |
163 int focus_called() const { return focus_called_; } | 163 int focus_called() const { return focus_called_; } |
164 | 164 |
165 private: | 165 private: |
166 int focus_called_; | 166 int focus_called_; |
167 }; | 167 }; |
168 | 168 |
169 TEST_F(WebUITest, FocusOnNavigate) { | 169 TEST_F(WebUITest, FocusOnNavigate) { |
170 // Setup. |tc| will be used to track when we try to focus the location bar. | 170 // Setup. |tc| will be used to track when we try to focus the location bar. |
171 TabContentsForFocusTest* tc = new TabContentsForFocusTest( | 171 TabContentsForFocusTest* tc = new TabContentsForFocusTest( |
172 contents()->GetBrowserContext(), | 172 contents()->GetBrowserContext(), |
173 SiteInstance::CreateSiteInstance(contents()->GetBrowserContext())); | 173 content::SiteInstance::CreateSiteInstance( |
| 174 contents()->GetBrowserContext())); |
174 tc->GetController().CopyStateFrom(controller()); | 175 tc->GetController().CopyStateFrom(controller()); |
175 SetContents(tc); | 176 SetContents(tc); |
176 int page_id = 200; | 177 int page_id = 200; |
177 | 178 |
178 // Load the NTP. | 179 // Load the NTP. |
179 GURL new_tab_url(chrome::kChromeUINewTabURL); | 180 GURL new_tab_url(chrome::kChromeUINewTabURL); |
180 controller().LoadURL(new_tab_url, content::Referrer(), | 181 controller().LoadURL(new_tab_url, content::Referrer(), |
181 content::PAGE_TRANSITION_LINK, | 182 content::PAGE_TRANSITION_LINK, |
182 std::string()); | 183 std::string()); |
183 rvh()->SendNavigate(page_id, new_tab_url); | 184 rvh()->SendNavigate(page_id, new_tab_url); |
(...skipping 22 matching lines...) Expand all Loading... |
206 // Navigate forward. Shouldn't focus the location bar. | 207 // Navigate forward. Shouldn't focus the location bar. |
207 focus_called = tc->focus_called(); | 208 focus_called = tc->focus_called(); |
208 ASSERT_TRUE(controller().CanGoForward()); | 209 ASSERT_TRUE(controller().CanGoForward()); |
209 controller().GoForward(); | 210 controller().GoForward(); |
210 old_rvh = rvh(); | 211 old_rvh = rvh(); |
211 old_rvh->SendShouldCloseACK(true); | 212 old_rvh->SendShouldCloseACK(true); |
212 pending_rvh()->SendNavigate(next_page_id, next_url); | 213 pending_rvh()->SendNavigate(next_page_id, next_url); |
213 old_rvh->OnSwapOutACK(); | 214 old_rvh->OnSwapOutACK(); |
214 EXPECT_EQ(focus_called, tc->focus_called()); | 215 EXPECT_EQ(focus_called, tc->focus_called()); |
215 } | 216 } |
OLD | NEW |