| OLD | NEW |
| 1 // Copyright (c) 2012 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/favicon/favicon_tab_helper.h" | 5 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 6 #include "chrome/browser/prefs/pref_service.h" | 6 #include "chrome/browser/prefs/pref_service.h" |
| 7 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 7 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 9 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" | 9 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" |
| 10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 public: | 38 public: |
| 39 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} | 39 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} |
| 40 | 40 |
| 41 // Tests navigating with a Web UI from a fresh (nothing pending or committed) | 41 // Tests navigating with a Web UI from a fresh (nothing pending or committed) |
| 42 // state, through pending, committed, then another navigation. The first page | 42 // state, through pending, committed, then another navigation. The first page |
| 43 // ID that we should use is passed as a parameter. We'll use the next two | 43 // ID that we should use is passed as a parameter. We'll use the next two |
| 44 // values. This must be increasing for the life of the tests. | 44 // values. This must be increasing for the life of the tests. |
| 45 static void DoNavigationTest(TabContents* tab_contents, int page_id) { | 45 static void DoNavigationTest(TabContents* tab_contents, int page_id) { |
| 46 WebContents* contents = tab_contents->web_contents(); | 46 WebContents* contents = tab_contents->web_contents(); |
| 47 NavigationController* controller = &contents->GetController(); | 47 NavigationController* controller = &contents->GetController(); |
| 48 FaviconTabHelper* favicon_tab_helper = |
| 49 FaviconTabHelper::FromWebContents(contents); |
| 48 | 50 |
| 49 // Start a pending load. | 51 // Start a pending load. |
| 50 GURL new_tab_url(chrome::kChromeUINewTabURL); | 52 GURL new_tab_url(chrome::kChromeUINewTabURL); |
| 51 controller->LoadURL(new_tab_url, content::Referrer(), | 53 controller->LoadURL(new_tab_url, content::Referrer(), |
| 52 content::PAGE_TRANSITION_LINK, | 54 content::PAGE_TRANSITION_LINK, |
| 53 std::string()); | 55 std::string()); |
| 54 | 56 |
| 55 // The navigation entry should be pending with no committed entry. | 57 // The navigation entry should be pending with no committed entry. |
| 56 ASSERT_TRUE(controller->GetPendingEntry()); | 58 ASSERT_TRUE(controller->GetPendingEntry()); |
| 57 ASSERT_FALSE(controller->GetLastCommittedEntry()); | 59 ASSERT_FALSE(controller->GetLastCommittedEntry()); |
| 58 | 60 |
| 59 // Check the things the pending Web UI should have set. | 61 // Check the things the pending Web UI should have set. |
| 60 EXPECT_FALSE(tab_contents->favicon_tab_helper()->ShouldDisplayFavicon()); | 62 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 61 EXPECT_TRUE(contents->FocusLocationBarByDefault()); | 63 EXPECT_TRUE(contents->FocusLocationBarByDefault()); |
| 62 | 64 |
| 63 // Now commit the load. | 65 // Now commit the load. |
| 64 RenderViewHostTester::For( | 66 RenderViewHostTester::For( |
| 65 contents->GetRenderViewHost())->SendNavigate(page_id, new_tab_url); | 67 contents->GetRenderViewHost())->SendNavigate(page_id, new_tab_url); |
| 66 | 68 |
| 67 // The same flags should be set as before now that the load has committed. | 69 // The same flags should be set as before now that the load has committed. |
| 68 EXPECT_FALSE(tab_contents->favicon_tab_helper()->ShouldDisplayFavicon()); | 70 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 69 EXPECT_TRUE(contents->FocusLocationBarByDefault()); | 71 EXPECT_TRUE(contents->FocusLocationBarByDefault()); |
| 70 | 72 |
| 71 // Start a pending navigation to a regular page. | 73 // Start a pending navigation to a regular page. |
| 72 GURL next_url("http://google.com/"); | 74 GURL next_url("http://google.com/"); |
| 73 controller->LoadURL(next_url, content::Referrer(), | 75 controller->LoadURL(next_url, content::Referrer(), |
| 74 content::PAGE_TRANSITION_LINK, | 76 content::PAGE_TRANSITION_LINK, |
| 75 std::string()); | 77 std::string()); |
| 76 | 78 |
| 77 // Check the flags. Some should reflect the new page (URL, title), some | 79 // Check the flags. Some should reflect the new page (URL, title), some |
| 78 // should reflect the old one (bookmark bar) until it has committed. | 80 // should reflect the old one (bookmark bar) until it has committed. |
| 79 EXPECT_TRUE(tab_contents->favicon_tab_helper()->ShouldDisplayFavicon()); | 81 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 80 EXPECT_FALSE(contents->FocusLocationBarByDefault()); | 82 EXPECT_FALSE(contents->FocusLocationBarByDefault()); |
| 81 | 83 |
| 82 // Commit the regular page load. Note that we must send it to the "pending" | 84 // Commit the regular page load. Note that we must send it to the "pending" |
| 83 // RenderViewHost if there is one, since this transition will also cause a | 85 // RenderViewHost if there is one, since this transition will also cause a |
| 84 // process transition, and our RVH pointer will be the "committed" one. | 86 // process transition, and our RVH pointer will be the "committed" one. |
| 85 // In the second call to this function from WebUIToStandard, it won't | 87 // In the second call to this function from WebUIToStandard, it won't |
| 86 // actually be pending, which is the point of this test. | 88 // actually be pending, which is the point of this test. |
| 87 RenderViewHost* pending_rvh = | 89 RenderViewHost* pending_rvh = |
| 88 RenderViewHostTester::GetPendingForController(controller); | 90 RenderViewHostTester::GetPendingForController(controller); |
| 89 if (pending_rvh) { | 91 if (pending_rvh) { |
| 90 RenderViewHostTester::For( | 92 RenderViewHostTester::For( |
| 91 pending_rvh)->SendNavigate(page_id + 1, next_url); | 93 pending_rvh)->SendNavigate(page_id + 1, next_url); |
| 92 } else { | 94 } else { |
| 93 RenderViewHostTester::For( | 95 RenderViewHostTester::For( |
| 94 contents->GetRenderViewHost())->SendNavigate(page_id + 1, next_url); | 96 contents->GetRenderViewHost())->SendNavigate(page_id + 1, next_url); |
| 95 } | 97 } |
| 96 | 98 |
| 97 // The state should now reflect a regular page. | 99 // The state should now reflect a regular page. |
| 98 EXPECT_TRUE(tab_contents->favicon_tab_helper()->ShouldDisplayFavicon()); | 100 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 99 EXPECT_FALSE(contents->FocusLocationBarByDefault()); | 101 EXPECT_FALSE(contents->FocusLocationBarByDefault()); |
| 100 } | 102 } |
| 101 | 103 |
| 102 private: | 104 private: |
| 103 content::TestBrowserThread ui_thread_; | 105 content::TestBrowserThread ui_thread_; |
| 104 | 106 |
| 105 DISALLOW_COPY_AND_ASSIGN(WebUITest); | 107 DISALLOW_COPY_AND_ASSIGN(WebUITest); |
| 106 }; | 108 }; |
| 107 | 109 |
| 108 // Tests that the New Tab Page flags are correctly set and propogated by | 110 // Tests that the New Tab Page flags are correctly set and propogated by |
| (...skipping 22 matching lines...) Expand all Loading... |
| 131 std::string()); | 133 std::string()); |
| 132 rvh_tester()->SendNavigate(1, new_tab_url); | 134 rvh_tester()->SendNavigate(1, new_tab_url); |
| 133 | 135 |
| 134 // Start another pending load of the new tab page. | 136 // Start another pending load of the new tab page. |
| 135 controller().LoadURL(new_tab_url, content::Referrer(), | 137 controller().LoadURL(new_tab_url, content::Referrer(), |
| 136 content::PAGE_TRANSITION_LINK, | 138 content::PAGE_TRANSITION_LINK, |
| 137 std::string()); | 139 std::string()); |
| 138 rvh_tester()->SendNavigate(2, new_tab_url); | 140 rvh_tester()->SendNavigate(2, new_tab_url); |
| 139 | 141 |
| 140 // The flags should be the same as the non-pending state. | 142 // The flags should be the same as the non-pending state. |
| 141 EXPECT_FALSE(tab_contents()->favicon_tab_helper()->ShouldDisplayFavicon()); | 143 FaviconTabHelper* favicon_tab_helper = |
| 144 FaviconTabHelper::FromWebContents(contents()); |
| 145 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 142 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 146 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
| 143 } | 147 } |
| 144 | 148 |
| 145 TEST_F(WebUITest, StandardToWebUI) { | 149 TEST_F(WebUITest, StandardToWebUI) { |
| 146 // Start a pending navigation to a regular page. | 150 // Start a pending navigation to a regular page. |
| 147 GURL std_url("http://google.com/"); | 151 GURL std_url("http://google.com/"); |
| 148 | 152 |
| 149 controller().LoadURL(std_url, content::Referrer(), | 153 controller().LoadURL(std_url, content::Referrer(), |
| 150 content::PAGE_TRANSITION_LINK, | 154 content::PAGE_TRANSITION_LINK, |
| 151 std::string()); | 155 std::string()); |
| 152 | 156 |
| 157 FaviconTabHelper* favicon_tab_helper = |
| 158 FaviconTabHelper::FromWebContents(contents()); |
| 153 // The state should now reflect the default. | 159 // The state should now reflect the default. |
| 154 EXPECT_TRUE(tab_contents()->favicon_tab_helper()->ShouldDisplayFavicon()); | 160 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 155 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | 161 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); |
| 156 | 162 |
| 157 // Commit the load, the state should be the same. | 163 // Commit the load, the state should be the same. |
| 158 rvh_tester()->SendNavigate(1, std_url); | 164 rvh_tester()->SendNavigate(1, std_url); |
| 159 EXPECT_TRUE(tab_contents()->favicon_tab_helper()->ShouldDisplayFavicon()); | 165 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 160 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | 166 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); |
| 161 | 167 |
| 162 // Start a pending load for a WebUI. | 168 // Start a pending load for a WebUI. |
| 163 GURL new_tab_url(chrome::kChromeUINewTabURL); | 169 GURL new_tab_url(chrome::kChromeUINewTabURL); |
| 164 controller().LoadURL(new_tab_url, content::Referrer(), | 170 controller().LoadURL(new_tab_url, content::Referrer(), |
| 165 content::PAGE_TRANSITION_LINK, | 171 content::PAGE_TRANSITION_LINK, |
| 166 std::string()); | 172 std::string()); |
| 167 EXPECT_TRUE(tab_contents()->favicon_tab_helper()->ShouldDisplayFavicon()); | 173 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); |
| 168 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 174 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
| 169 | 175 |
| 170 // Committing Web UI is tested above. | 176 // Committing Web UI is tested above. |
| 171 } | 177 } |
| 172 | 178 |
| 173 TEST_F(WebUITest, FocusOnNavigate) { | 179 TEST_F(WebUITest, FocusOnNavigate) { |
| 174 // Setup. |wc| will be used to track when we try to focus the location bar. | 180 // Setup. |wc| will be used to track when we try to focus the location bar. |
| 175 WebContents* wc = | 181 WebContents* wc = |
| 176 WebContentsTester::CreateTestWebContentsCountSetFocusToLocationBar( | 182 WebContentsTester::CreateTestWebContentsCountSetFocusToLocationBar( |
| 177 contents()->GetBrowserContext(), | 183 contents()->GetBrowserContext(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 focus_called = wct->GetNumberOfFocusCalls(); | 220 focus_called = wct->GetNumberOfFocusCalls(); |
| 215 ASSERT_TRUE(controller().CanGoForward()); | 221 ASSERT_TRUE(controller().CanGoForward()); |
| 216 controller().GoForward(); | 222 controller().GoForward(); |
| 217 old_rvh = rvh(); | 223 old_rvh = rvh(); |
| 218 RenderViewHostTester::For(old_rvh)->SendShouldCloseACK(true); | 224 RenderViewHostTester::For(old_rvh)->SendShouldCloseACK(true); |
| 219 RenderViewHostTester::For( | 225 RenderViewHostTester::For( |
| 220 pending_rvh())->SendNavigate(next_page_id, next_url); | 226 pending_rvh())->SendNavigate(next_page_id, next_url); |
| 221 RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK(); | 227 RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK(); |
| 222 EXPECT_EQ(focus_called, wct->GetNumberOfFocusCalls()); | 228 EXPECT_EQ(focus_called, wct->GetNumberOfFocusCalls()); |
| 223 } | 229 } |
| OLD | NEW |