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" |
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 // TODO(avi): Kill this when TabContents goes away. |
| 30 class WebUITestContentsCreator { |
| 31 public: |
| 32 static TabContents* CreateTabContents(content::WebContents* contents) { |
| 33 return TabContents::Factory::CreateTabContents(contents); |
| 34 } |
| 35 }; |
| 36 |
29 class WebUITest : public TabContentsTestHarness { | 37 class WebUITest : public TabContentsTestHarness { |
30 public: | 38 public: |
31 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} | 39 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} |
32 | 40 |
33 // 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) |
34 // state, through pending, committed, then another navigation. The first page | 42 // 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 | 43 // 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. | 44 // values. This must be increasing for the life of the tests. |
37 static void DoNavigationTest(TabContents* tab_contents, int page_id) { | 45 static void DoNavigationTest(TabContents* tab_contents, int page_id) { |
38 WebContents* contents = tab_contents->web_contents(); | 46 WebContents* contents = tab_contents->web_contents(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // non-DOM-UI page. | 110 // non-DOM-UI page. |
103 TEST_F(WebUITest, WebUIToStandard) { | 111 TEST_F(WebUITest, WebUIToStandard) { |
104 DoNavigationTest(tab_contents(), 1); | 112 DoNavigationTest(tab_contents(), 1); |
105 | 113 |
106 // Test the case where we're not doing the initial navigation. This is | 114 // Test the case where we're not doing the initial navigation. This is |
107 // slightly different than the very-first-navigation case since the | 115 // slightly different than the very-first-navigation case since the |
108 // SiteInstance will be the same (the original WebContents must still be | 116 // SiteInstance will be the same (the original WebContents must still be |
109 // alive), which will trigger different behavior in RenderViewHostManager. | 117 // alive), which will trigger different behavior in RenderViewHostManager. |
110 WebContents* contents2 = | 118 WebContents* contents2 = |
111 WebContentsTester::CreateTestWebContents(profile(), NULL); | 119 WebContentsTester::CreateTestWebContents(profile(), NULL); |
112 TabContents tab_contents2(contents2); | 120 scoped_ptr<TabContents> tab_contents2( |
| 121 WebUITestContentsCreator::CreateTabContents(contents2)); |
113 | 122 |
114 DoNavigationTest(&tab_contents2, 101); | 123 DoNavigationTest(tab_contents2.get(), 101); |
115 } | 124 } |
116 | 125 |
117 TEST_F(WebUITest, WebUIToWebUI) { | 126 TEST_F(WebUITest, WebUIToWebUI) { |
118 // Do a load (this state is tested above). | 127 // Do a load (this state is tested above). |
119 GURL new_tab_url(chrome::kChromeUINewTabURL); | 128 GURL new_tab_url(chrome::kChromeUINewTabURL); |
120 controller().LoadURL(new_tab_url, content::Referrer(), | 129 controller().LoadURL(new_tab_url, content::Referrer(), |
121 content::PAGE_TRANSITION_LINK, | 130 content::PAGE_TRANSITION_LINK, |
122 std::string()); | 131 std::string()); |
123 rvh_tester()->SendNavigate(1, new_tab_url); | 132 rvh_tester()->SendNavigate(1, new_tab_url); |
124 | 133 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 focus_called = wct->GetNumberOfFocusCalls(); | 214 focus_called = wct->GetNumberOfFocusCalls(); |
206 ASSERT_TRUE(controller().CanGoForward()); | 215 ASSERT_TRUE(controller().CanGoForward()); |
207 controller().GoForward(); | 216 controller().GoForward(); |
208 old_rvh = rvh(); | 217 old_rvh = rvh(); |
209 RenderViewHostTester::For(old_rvh)->SendShouldCloseACK(true); | 218 RenderViewHostTester::For(old_rvh)->SendShouldCloseACK(true); |
210 RenderViewHostTester::For( | 219 RenderViewHostTester::For( |
211 pending_rvh())->SendNavigate(next_page_id, next_url); | 220 pending_rvh())->SendNavigate(next_page_id, next_url); |
212 RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK(); | 221 RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK(); |
213 EXPECT_EQ(focus_called, wct->GetNumberOfFocusCalls()); | 222 EXPECT_EQ(focus_called, wct->GetNumberOfFocusCalls()); |
214 } | 223 } |
OLD | NEW |