| 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_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 9 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.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" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
| 13 #include "content/public/browser/site_instance.h" | 13 #include "content/public/browser/site_instance.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/common/referrer.h" | 15 #include "content/public/common/referrer.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "content/public/test/test_renderer_host.h" | 17 #include "content/public/test/test_renderer_host.h" |
| 18 #include "content/public/test/web_contents_tester.h" | 18 #include "content/public/test/web_contents_tester.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using content::BrowserThread; | 21 using content::BrowserThread; |
| 22 using content::NavigationController; | 22 using content::NavigationController; |
| 23 using content::RenderViewHost; | 23 using content::RenderViewHost; |
| 24 using content::RenderViewHostTester; | 24 using content::RenderViewHostTester; |
| 25 using content::SiteInstance; | 25 using content::SiteInstance; |
| 26 using content::WebContents; | 26 using content::WebContents; |
| 27 using content::WebContentsTester; | 27 using content::WebContentsTester; |
| 28 | 28 |
| 29 class WebUITest : public TabContentsWrapperTestHarness { | 29 class WebUITest : public TabContentsTestHarness { |
| 30 public: | 30 public: |
| 31 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} | 31 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} |
| 32 | 32 |
| 33 // Tests navigating with a Web UI from a fresh (nothing pending or committed) | 33 // Tests navigating with a Web UI from a fresh (nothing pending or committed) |
| 34 // state, through pending, committed, then another navigation. The first page | 34 // state, through pending, committed, then another navigation. The first page |
| 35 // ID that we should use is passed as a parameter. We'll use the next two | 35 // ID that we should use is passed as a parameter. We'll use the next two |
| 36 // values. This must be increasing for the life of the tests. | 36 // values. This must be increasing for the life of the tests. |
| 37 static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) { | 37 static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) { |
| 38 WebContents* contents = wrapper->web_contents(); | 38 WebContents* contents = wrapper->web_contents(); |
| 39 NavigationController* controller = &contents->GetController(); | 39 NavigationController* controller = &contents->GetController(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 private: | 94 private: |
| 95 content::TestBrowserThread ui_thread_; | 95 content::TestBrowserThread ui_thread_; |
| 96 | 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(WebUITest); | 97 DISALLOW_COPY_AND_ASSIGN(WebUITest); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 // Tests that the New Tab Page flags are correctly set and propogated by | 100 // Tests that the New Tab Page flags are correctly set and propogated by |
| 101 // WebContents when we first navigate to a Web UI page, then to a standard | 101 // WebContents when we first navigate to a Web UI page, then to a standard |
| 102 // non-DOM-UI page. | 102 // non-DOM-UI page. |
| 103 TEST_F(WebUITest, WebUIToStandard) { | 103 TEST_F(WebUITest, WebUIToStandard) { |
| 104 DoNavigationTest(contents_wrapper(), 1); | 104 DoNavigationTest(tab_contents(), 1); |
| 105 | 105 |
| 106 // Test the case where we're not doing the initial navigation. This is | 106 // Test the case where we're not doing the initial navigation. This is |
| 107 // slightly different than the very-first-navigation case since the | 107 // slightly different than the very-first-navigation case since the |
| 108 // SiteInstance will be the same (the original WebContents must still be | 108 // SiteInstance will be the same (the original WebContents must still be |
| 109 // alive), which will trigger different behavior in RenderViewHostManager. | 109 // alive), which will trigger different behavior in RenderViewHostManager. |
| 110 WebContents* contents2 = | 110 WebContents* contents2 = |
| 111 WebContentsTester::CreateTestWebContents(profile(), NULL); | 111 WebContentsTester::CreateTestWebContents(profile(), NULL); |
| 112 TabContentsWrapper wrapper2(contents2); | 112 TabContentsWrapper wrapper2(contents2); |
| 113 | 113 |
| 114 DoNavigationTest(&wrapper2, 101); | 114 DoNavigationTest(&wrapper2, 101); |
| 115 } | 115 } |
| 116 | 116 |
| 117 TEST_F(WebUITest, WebUIToWebUI) { | 117 TEST_F(WebUITest, WebUIToWebUI) { |
| 118 // Do a load (this state is tested above). | 118 // Do a load (this state is tested above). |
| 119 GURL new_tab_url(chrome::kChromeUINewTabURL); | 119 GURL new_tab_url(chrome::kChromeUINewTabURL); |
| 120 controller().LoadURL(new_tab_url, content::Referrer(), | 120 controller().LoadURL(new_tab_url, content::Referrer(), |
| 121 content::PAGE_TRANSITION_LINK, | 121 content::PAGE_TRANSITION_LINK, |
| 122 std::string()); | 122 std::string()); |
| 123 rvh_tester()->SendNavigate(1, new_tab_url); | 123 rvh_tester()->SendNavigate(1, new_tab_url); |
| 124 | 124 |
| 125 // Start another pending load of the new tab page. | 125 // Start another pending load of the new tab page. |
| 126 controller().LoadURL(new_tab_url, content::Referrer(), | 126 controller().LoadURL(new_tab_url, content::Referrer(), |
| 127 content::PAGE_TRANSITION_LINK, | 127 content::PAGE_TRANSITION_LINK, |
| 128 std::string()); | 128 std::string()); |
| 129 rvh_tester()->SendNavigate(2, new_tab_url); | 129 rvh_tester()->SendNavigate(2, new_tab_url); |
| 130 | 130 |
| 131 // The flags should be the same as the non-pending state. | 131 // The flags should be the same as the non-pending state. |
| 132 EXPECT_FALSE( | 132 EXPECT_FALSE(tab_contents()->favicon_tab_helper()->ShouldDisplayFavicon()); |
| 133 contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | |
| 134 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 133 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
| 135 } | 134 } |
| 136 | 135 |
| 137 TEST_F(WebUITest, StandardToWebUI) { | 136 TEST_F(WebUITest, StandardToWebUI) { |
| 138 // Start a pending navigation to a regular page. | 137 // Start a pending navigation to a regular page. |
| 139 GURL std_url("http://google.com/"); | 138 GURL std_url("http://google.com/"); |
| 140 | 139 |
| 141 controller().LoadURL(std_url, content::Referrer(), | 140 controller().LoadURL(std_url, content::Referrer(), |
| 142 content::PAGE_TRANSITION_LINK, | 141 content::PAGE_TRANSITION_LINK, |
| 143 std::string()); | 142 std::string()); |
| 144 | 143 |
| 145 // The state should now reflect the default. | 144 // The state should now reflect the default. |
| 146 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 145 EXPECT_TRUE(tab_contents()->favicon_tab_helper()->ShouldDisplayFavicon()); |
| 147 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | 146 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); |
| 148 | 147 |
| 149 // Commit the load, the state should be the same. | 148 // Commit the load, the state should be the same. |
| 150 rvh_tester()->SendNavigate(1, std_url); | 149 rvh_tester()->SendNavigate(1, std_url); |
| 151 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 150 EXPECT_TRUE(tab_contents()->favicon_tab_helper()->ShouldDisplayFavicon()); |
| 152 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | 151 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); |
| 153 | 152 |
| 154 // Start a pending load for a WebUI. | 153 // Start a pending load for a WebUI. |
| 155 GURL new_tab_url(chrome::kChromeUINewTabURL); | 154 GURL new_tab_url(chrome::kChromeUINewTabURL); |
| 156 controller().LoadURL(new_tab_url, content::Referrer(), | 155 controller().LoadURL(new_tab_url, content::Referrer(), |
| 157 content::PAGE_TRANSITION_LINK, | 156 content::PAGE_TRANSITION_LINK, |
| 158 std::string()); | 157 std::string()); |
| 159 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); | 158 EXPECT_TRUE(tab_contents()->favicon_tab_helper()->ShouldDisplayFavicon()); |
| 160 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 159 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
| 161 | 160 |
| 162 // Committing Web UI is tested above. | 161 // Committing Web UI is tested above. |
| 163 } | 162 } |
| 164 | 163 |
| 165 TEST_F(WebUITest, FocusOnNavigate) { | 164 TEST_F(WebUITest, FocusOnNavigate) { |
| 166 // Setup. |wc| will be used to track when we try to focus the location bar. | 165 // Setup. |wc| will be used to track when we try to focus the location bar. |
| 167 WebContents* wc = | 166 WebContents* wc = |
| 168 WebContentsTester::CreateTestWebContentsCountSetFocusToLocationBar( | 167 WebContentsTester::CreateTestWebContentsCountSetFocusToLocationBar( |
| 169 contents()->GetBrowserContext(), | 168 contents()->GetBrowserContext(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 focus_called = wct->GetNumberOfFocusCalls(); | 205 focus_called = wct->GetNumberOfFocusCalls(); |
| 207 ASSERT_TRUE(controller().CanGoForward()); | 206 ASSERT_TRUE(controller().CanGoForward()); |
| 208 controller().GoForward(); | 207 controller().GoForward(); |
| 209 old_rvh = rvh(); | 208 old_rvh = rvh(); |
| 210 RenderViewHostTester::For(old_rvh)->SendShouldCloseACK(true); | 209 RenderViewHostTester::For(old_rvh)->SendShouldCloseACK(true); |
| 211 RenderViewHostTester::For( | 210 RenderViewHostTester::For( |
| 212 pending_rvh())->SendNavigate(next_page_id, next_url); | 211 pending_rvh())->SendNavigate(next_page_id, next_url); |
| 213 RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK(); | 212 RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK(); |
| 214 EXPECT_EQ(focus_called, wct->GetNumberOfFocusCalls()); | 213 EXPECT_EQ(focus_called, wct->GetNumberOfFocusCalls()); |
| 215 } | 214 } |
| OLD | NEW |