Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: chrome/browser/ui/webui/web_ui_unittest.cc

Issue 8785004: Change NavigationController::LoadURL to take a Referrer class instead of a GURL as referrer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 12 matching lines...) Expand all
23 // Tests navigating with a Web UI from a fresh (nothing pending or committed) 23 // Tests navigating with a Web UI from a fresh (nothing pending or committed)
24 // state, through pending, committed, then another navigation. The first page 24 // state, through pending, committed, then another navigation. The first page
25 // ID that we should use is passed as a parameter. We'll use the next two 25 // ID that we should use is passed as a parameter. We'll use the next two
26 // values. This must be increasing for the life of the tests. 26 // values. This must be increasing for the life of the tests.
27 static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) { 27 static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) {
28 TabContents* contents = wrapper->tab_contents(); 28 TabContents* contents = wrapper->tab_contents();
29 NavigationController* controller = &contents->controller(); 29 NavigationController* controller = &contents->controller();
30 30
31 // Start a pending load. 31 // Start a pending load.
32 GURL new_tab_url(chrome::kChromeUINewTabURL); 32 GURL new_tab_url(chrome::kChromeUINewTabURL);
33 controller->LoadURL(new_tab_url, GURL(), content::PAGE_TRANSITION_LINK, 33 controller->LoadURL(new_tab_url, content::Referrer(),
34 content::PAGE_TRANSITION_LINK,
34 std::string()); 35 std::string());
35 36
36 // The navigation entry should be pending with no committed entry. 37 // The navigation entry should be pending with no committed entry.
37 ASSERT_TRUE(controller->pending_entry()); 38 ASSERT_TRUE(controller->pending_entry());
38 ASSERT_FALSE(controller->GetLastCommittedEntry()); 39 ASSERT_FALSE(controller->GetLastCommittedEntry());
39 40
40 // Check the things the pending Web UI should have set. 41 // Check the things the pending Web UI should have set.
41 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); 42 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
42 EXPECT_TRUE(contents->FocusLocationBarByDefault()); 43 EXPECT_TRUE(contents->FocusLocationBarByDefault());
43 44
44 // Now commit the load. 45 // Now commit the load.
45 static_cast<TestRenderViewHost*>( 46 static_cast<TestRenderViewHost*>(
46 contents->render_view_host())->SendNavigate(page_id, new_tab_url); 47 contents->render_view_host())->SendNavigate(page_id, new_tab_url);
47 48
48 // The same flags should be set as before now that the load has committed. 49 // The same flags should be set as before now that the load has committed.
49 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); 50 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
50 EXPECT_TRUE(contents->FocusLocationBarByDefault()); 51 EXPECT_TRUE(contents->FocusLocationBarByDefault());
51 52
52 // Start a pending navigation to a regular page. 53 // Start a pending navigation to a regular page.
53 GURL next_url("http://google.com/"); 54 GURL next_url("http://google.com/");
54 controller->LoadURL(next_url, GURL(), content::PAGE_TRANSITION_LINK, 55 controller->LoadURL(next_url, content::Referrer(),
56 content::PAGE_TRANSITION_LINK,
55 std::string()); 57 std::string());
56 58
57 // Check the flags. Some should reflect the new page (URL, title), some 59 // Check the flags. Some should reflect the new page (URL, title), some
58 // should reflect the old one (bookmark bar) until it has committed. 60 // should reflect the old one (bookmark bar) until it has committed.
59 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); 61 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon());
60 EXPECT_FALSE(contents->FocusLocationBarByDefault()); 62 EXPECT_FALSE(contents->FocusLocationBarByDefault());
61 63
62 // Commit the regular page load. Note that we must send it to the "pending" 64 // Commit the regular page load. Note that we must send it to the "pending"
63 // RenderViewHost if there is one, since this transition will also cause a 65 // RenderViewHost if there is one, since this transition will also cause a
64 // process transition, and our RVH pointer will be the "committed" one. 66 // process transition, and our RVH pointer will be the "committed" one.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // alive), which will trigger different behavior in RenderViewHostManager. 98 // alive), which will trigger different behavior in RenderViewHostManager.
97 TestTabContents* contents2 = new TestTabContents(profile(), NULL); 99 TestTabContents* contents2 = new TestTabContents(profile(), NULL);
98 TabContentsWrapper wrapper2(contents2); 100 TabContentsWrapper wrapper2(contents2);
99 101
100 DoNavigationTest(&wrapper2, 101); 102 DoNavigationTest(&wrapper2, 101);
101 } 103 }
102 104
103 TEST_F(WebUITest, WebUIToWebUI) { 105 TEST_F(WebUITest, WebUIToWebUI) {
104 // Do a load (this state is tested above). 106 // Do a load (this state is tested above).
105 GURL new_tab_url(chrome::kChromeUINewTabURL); 107 GURL new_tab_url(chrome::kChromeUINewTabURL);
106 controller().LoadURL(new_tab_url, GURL(), content::PAGE_TRANSITION_LINK, 108 controller().LoadURL(new_tab_url, content::Referrer(),
109 content::PAGE_TRANSITION_LINK,
107 std::string()); 110 std::string());
108 rvh()->SendNavigate(1, new_tab_url); 111 rvh()->SendNavigate(1, new_tab_url);
109 112
110 // Start another pending load of the new tab page. 113 // Start another pending load of the new tab page.
111 controller().LoadURL(new_tab_url, GURL(), content::PAGE_TRANSITION_LINK, 114 controller().LoadURL(new_tab_url, content::Referrer(),
115 content::PAGE_TRANSITION_LINK,
112 std::string()); 116 std::string());
113 rvh()->SendNavigate(2, new_tab_url); 117 rvh()->SendNavigate(2, new_tab_url);
114 118
115 // The flags should be the same as the non-pending state. 119 // The flags should be the same as the non-pending state.
116 EXPECT_FALSE( 120 EXPECT_FALSE(
117 contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); 121 contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
118 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); 122 EXPECT_TRUE(contents()->FocusLocationBarByDefault());
119 } 123 }
120 124
121 TEST_F(WebUITest, StandardToWebUI) { 125 TEST_F(WebUITest, StandardToWebUI) {
122 // Start a pending navigation to a regular page. 126 // Start a pending navigation to a regular page.
123 GURL std_url("http://google.com/"); 127 GURL std_url("http://google.com/");
124 128
125 controller().LoadURL(std_url, GURL(), content::PAGE_TRANSITION_LINK, 129 controller().LoadURL(std_url, content::Referrer(),
130 content::PAGE_TRANSITION_LINK,
126 std::string()); 131 std::string());
127 132
128 // The state should now reflect the default. 133 // The state should now reflect the default.
129 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); 134 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
130 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); 135 EXPECT_FALSE(contents()->FocusLocationBarByDefault());
131 136
132 // Commit the load, the state should be the same. 137 // Commit the load, the state should be the same.
133 rvh()->SendNavigate(1, std_url); 138 rvh()->SendNavigate(1, std_url);
134 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); 139 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
135 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); 140 EXPECT_FALSE(contents()->FocusLocationBarByDefault());
136 141
137 // Start a pending load for a WebUI. 142 // Start a pending load for a WebUI.
138 GURL new_tab_url(chrome::kChromeUINewTabURL); 143 GURL new_tab_url(chrome::kChromeUINewTabURL);
139 controller().LoadURL(new_tab_url, GURL(), content::PAGE_TRANSITION_LINK, 144 controller().LoadURL(new_tab_url, content::Referrer(),
145 content::PAGE_TRANSITION_LINK,
140 std::string()); 146 std::string());
141 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); 147 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
142 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); 148 EXPECT_TRUE(contents()->FocusLocationBarByDefault());
143 149
144 // Committing Web UI is tested above. 150 // Committing Web UI is tested above.
145 } 151 }
146 152
147 class TabContentsForFocusTest : public TestTabContents { 153 class TabContentsForFocusTest : public TestTabContents {
148 public: 154 public:
149 TabContentsForFocusTest(content::BrowserContext* browser_context, 155 TabContentsForFocusTest(content::BrowserContext* browser_context,
(...skipping 12 matching lines...) Expand all
162 // Setup. |tc| will be used to track when we try to focus the location bar. 168 // Setup. |tc| will be used to track when we try to focus the location bar.
163 TabContentsForFocusTest* tc = new TabContentsForFocusTest( 169 TabContentsForFocusTest* tc = new TabContentsForFocusTest(
164 contents()->browser_context(), 170 contents()->browser_context(),
165 SiteInstance::CreateSiteInstance(contents()->browser_context())); 171 SiteInstance::CreateSiteInstance(contents()->browser_context()));
166 tc->controller().CopyStateFrom(controller()); 172 tc->controller().CopyStateFrom(controller());
167 SetContents(tc); 173 SetContents(tc);
168 int page_id = 200; 174 int page_id = 200;
169 175
170 // Load the NTP. 176 // Load the NTP.
171 GURL new_tab_url(chrome::kChromeUINewTabURL); 177 GURL new_tab_url(chrome::kChromeUINewTabURL);
172 controller().LoadURL(new_tab_url, GURL(), content::PAGE_TRANSITION_LINK, 178 controller().LoadURL(new_tab_url, content::Referrer(),
179 content::PAGE_TRANSITION_LINK,
173 std::string()); 180 std::string());
174 rvh()->SendNavigate(page_id, new_tab_url); 181 rvh()->SendNavigate(page_id, new_tab_url);
175 182
176 // Navigate to another page. 183 // Navigate to another page.
177 GURL next_url("http://google.com/"); 184 GURL next_url("http://google.com/");
178 int next_page_id = page_id + 1; 185 int next_page_id = page_id + 1;
179 controller().LoadURL(next_url, GURL(), content::PAGE_TRANSITION_LINK, 186 controller().LoadURL(next_url, content::Referrer(),
187 content::PAGE_TRANSITION_LINK,
180 std::string()); 188 std::string());
181 TestRenderViewHost* old_rvh = rvh(); 189 TestRenderViewHost* old_rvh = rvh();
182 old_rvh->SendShouldCloseACK(true); 190 old_rvh->SendShouldCloseACK(true);
183 pending_rvh()->SendNavigate(next_page_id, next_url); 191 pending_rvh()->SendNavigate(next_page_id, next_url);
184 old_rvh->OnSwapOutACK(); 192 old_rvh->OnSwapOutACK();
185 193
186 // Navigate back. Should focus the location bar. 194 // Navigate back. Should focus the location bar.
187 int focus_called = tc->focus_called(); 195 int focus_called = tc->focus_called();
188 ASSERT_TRUE(controller().CanGoBack()); 196 ASSERT_TRUE(controller().CanGoBack());
189 controller().GoBack(); 197 controller().GoBack();
190 old_rvh = rvh(); 198 old_rvh = rvh();
191 old_rvh->SendShouldCloseACK(true); 199 old_rvh->SendShouldCloseACK(true);
192 pending_rvh()->SendNavigate(page_id, new_tab_url); 200 pending_rvh()->SendNavigate(page_id, new_tab_url);
193 old_rvh->OnSwapOutACK(); 201 old_rvh->OnSwapOutACK();
194 EXPECT_LT(focus_called, tc->focus_called()); 202 EXPECT_LT(focus_called, tc->focus_called());
195 203
196 // Navigate forward. Shouldn't focus the location bar. 204 // Navigate forward. Shouldn't focus the location bar.
197 focus_called = tc->focus_called(); 205 focus_called = tc->focus_called();
198 ASSERT_TRUE(controller().CanGoForward()); 206 ASSERT_TRUE(controller().CanGoForward());
199 controller().GoForward(); 207 controller().GoForward();
200 old_rvh = rvh(); 208 old_rvh = rvh();
201 old_rvh->SendShouldCloseACK(true); 209 old_rvh->SendShouldCloseACK(true);
202 pending_rvh()->SendNavigate(next_page_id, next_url); 210 pending_rvh()->SendNavigate(next_page_id, next_url);
203 old_rvh->OnSwapOutACK(); 211 old_rvh->OnSwapOutACK();
204 EXPECT_EQ(focus_called, tc->focus_called()); 212 EXPECT_EQ(focus_called, tc->focus_called());
205 } 213 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/notifications/balloon_view.cc ('k') | chrome/test/base/browser_with_test_window_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698