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

Side by Side Diff: content/browser/web_contents/navigation_controller_impl_unittest.cc

Issue 10830144: Consolidate all NavigationController::LoadURL and family functions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase onto TOT. Created 8 years, 4 months 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
OLDNEW
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 EXPECT_EQ(controller.GetEntryCount(), 2); 177 EXPECT_EQ(controller.GetEntryCount(), 2);
178 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 178 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
179 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 179 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
180 EXPECT_TRUE(controller.GetLastCommittedEntry()); 180 EXPECT_TRUE(controller.GetLastCommittedEntry());
181 EXPECT_FALSE(controller.GetPendingEntry()); 181 EXPECT_FALSE(controller.GetPendingEntry());
182 EXPECT_TRUE(controller.CanGoBack()); 182 EXPECT_TRUE(controller.CanGoBack());
183 EXPECT_FALSE(controller.CanGoForward()); 183 EXPECT_FALSE(controller.CanGoForward());
184 EXPECT_EQ(contents()->GetMaxPageID(), 1); 184 EXPECT_EQ(contents()->GetMaxPageID(), 1);
185 } 185 }
186 186
187 void CheckNavigationEntryMatchLoadParams(
188 NavigationController::LoadURLParams& load_params,
189 NavigationEntryImpl* entry) {
190 EXPECT_EQ(load_params.url, entry->GetURL());
191 EXPECT_EQ(load_params.referrer.url, entry->GetReferrer().url);
192 EXPECT_EQ(load_params.referrer.policy, entry->GetReferrer().policy);
193 EXPECT_EQ(load_params.transition_type, entry->GetTransitionType());
194 EXPECT_EQ(load_params.extra_headers, entry->extra_headers());
195
196 EXPECT_EQ(load_params.is_renderer_initiated, entry->is_renderer_initiated());
197 EXPECT_EQ(load_params.base_url_for_data_url, entry->GetBaseURLForDataURL());
198 if (!load_params.virtual_url_for_data_url.is_empty()) {
199 EXPECT_EQ(load_params.virtual_url_for_data_url, entry->GetVirtualURL());
200 }
201 if (NavigationController::UA_OVERRIDE_INHERIT !=
202 load_params.override_user_agent) {
203 bool should_override = (NavigationController::UA_OVERRIDE_TRUE ==
204 load_params.override_user_agent);
205 EXPECT_EQ(should_override, entry->GetIsOverridingUserAgent());
206 }
207 EXPECT_EQ(load_params.browser_initiated_post_data,
208 entry->GetBrowserInitiatedPostData());
209 EXPECT_EQ(load_params.transferred_global_request_id,
210 entry->transferred_global_request_id());
211 }
212
213 TEST_F(NavigationControllerTest, LoadURLWithParams) {
214 NavigationControllerImpl& controller = controller_impl();
215
216 NavigationController::LoadURLParams load_params(GURL("http://foo"));
217 load_params.referrer = content::Referrer(GURL("http://referrer"),
218 WebKit::WebReferrerPolicyDefault);
219 load_params.transition_type = content::PAGE_TRANSITION_GENERATED;
220 load_params.extra_headers = "content-type: text/plain";
221 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT;
222 load_params.is_renderer_initiated = true;
223 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE;
224 load_params.transferred_global_request_id = content::GlobalRequestID(2,3);
225
226 controller.LoadURLWithParams(load_params);
227 NavigationEntryImpl* entry =
228 NavigationEntryImpl::FromNavigationEntry(
229 controller.GetPendingEntry());
230
231 CheckNavigationEntryMatchLoadParams(load_params, entry);
232 }
233
234 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Data) {
235 NavigationControllerImpl& controller = controller_impl();
236
237 NavigationController::LoadURLParams load_params(
238 GURL("data:text/html,dataurl"));
239 load_params.load_type = NavigationController::LOAD_TYPE_DATA;
240 load_params.base_url_for_data_url = GURL("http://foo");
241 load_params.virtual_url_for_data_url = GURL("about:blank");
242 load_params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE;
243
244 controller.LoadURLWithParams(load_params);
245 NavigationEntryImpl* entry =
246 NavigationEntryImpl::FromNavigationEntry(
247 controller.GetPendingEntry());
248
249 CheckNavigationEntryMatchLoadParams(load_params, entry);
250 }
251
252 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) {
253 NavigationControllerImpl& controller = controller_impl();
254
255 NavigationController::LoadURLParams load_params(GURL("https://posturl"));
256 load_params.transition_type = content::PAGE_TRANSITION_TYPED;
257 load_params.load_type =
258 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
259 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE;
260
261
262 const unsigned char* raw_data =
263 reinterpret_cast<const unsigned char*>("d\n\0a2");
264 const int length = 5;
265 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length);
266 scoped_refptr<base::RefCountedBytes> data =
267 base::RefCountedBytes::TakeVector(&post_data_vector);
268 load_params.browser_initiated_post_data = data.get();
269
270 controller.LoadURLWithParams(load_params);
271 NavigationEntryImpl* entry =
272 NavigationEntryImpl::FromNavigationEntry(
273 controller.GetPendingEntry());
274
275 CheckNavigationEntryMatchLoadParams(load_params, entry);
276 }
277
187 // Tests what happens when the same page is loaded again. Should not create a 278 // Tests what happens when the same page is loaded again. Should not create a
188 // new session history entry. This is what happens when you press enter in the 279 // new session history entry. This is what happens when you press enter in the
189 // URL bar to reload: a pending entry is created and then it is discarded when 280 // URL bar to reload: a pending entry is created and then it is discarded when
190 // the load commits (because WebCore didn't actually make a new entry). 281 // the load commits (because WebCore didn't actually make a new entry).
191 TEST_F(NavigationControllerTest, LoadURL_SamePage) { 282 TEST_F(NavigationControllerTest, LoadURL_SamePage) {
192 NavigationControllerImpl& controller = controller_impl(); 283 NavigationControllerImpl& controller = controller_impl();
193 TestNotificationTracker notifications; 284 TestNotificationTracker notifications;
194 RegisterForAllNavNotifications(&notifications, &controller); 285 RegisterForAllNavNotifications(&notifications, &controller);
195 286
196 const GURL url1("http://foo1"); 287 const GURL url1("http://foo1");
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // Set a WebContentsDelegate to listen for state changes. 596 // Set a WebContentsDelegate to listen for state changes.
506 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); 597 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate());
507 EXPECT_FALSE(contents()->GetDelegate()); 598 EXPECT_FALSE(contents()->GetDelegate());
508 contents()->SetDelegate(delegate.get()); 599 contents()->SetDelegate(delegate.get());
509 600
510 // Without any navigations, the renderer starts at about:blank. 601 // Without any navigations, the renderer starts at about:blank.
511 const GURL kExistingURL("about:blank"); 602 const GURL kExistingURL("about:blank");
512 603
513 // Now make a pending new navigation, initiated by the renderer. 604 // Now make a pending new navigation, initiated by the renderer.
514 const GURL kNewURL("http://eh"); 605 const GURL kNewURL("http://eh");
515 controller.LoadURLFromRenderer( 606 NavigationController::LoadURLParams load_url_params(kNewURL);
516 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, 607 load_url_params.transition_type = content::PAGE_TRANSITION_TYPED;
517 std::string()); 608 load_url_params.is_renderer_initiated = true;
609 controller.LoadURLWithParams(load_url_params);
518 EXPECT_EQ(0U, notifications.size()); 610 EXPECT_EQ(0U, notifications.size());
519 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 611 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
520 EXPECT_TRUE(controller.GetPendingEntry()); 612 EXPECT_TRUE(controller.GetPendingEntry());
521 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); 613 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
522 EXPECT_EQ(1, delegate->navigation_state_change_count()); 614 EXPECT_EQ(1, delegate->navigation_state_change_count());
523 615
524 // There should be no visible entry (resulting in about:blank in the 616 // There should be no visible entry (resulting in about:blank in the
525 // omnibox), because it was renderer-initiated and there's no last committed 617 // omnibox), because it was renderer-initiated and there's no last committed
526 // entry. 618 // entry.
527 EXPECT_FALSE(controller.GetVisibleEntry()); 619 EXPECT_FALSE(controller.GetVisibleEntry());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); 651 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
560 EXPECT_EQ(1, delegate->navigation_state_change_count()); 652 EXPECT_EQ(1, delegate->navigation_state_change_count());
561 653
562 // There should be no visible entry (resulting in about:blank in the 654 // There should be no visible entry (resulting in about:blank in the
563 // omnibox), ensuring no spoof is possible. 655 // omnibox), ensuring no spoof is possible.
564 EXPECT_FALSE(controller.GetVisibleEntry()); 656 EXPECT_FALSE(controller.GetVisibleEntry());
565 657
566 contents()->SetDelegate(NULL); 658 contents()->SetDelegate(NULL);
567 } 659 }
568 660
569 // Test NavigationEntry is constructed correctly. No other logic tested.
570 TEST_F(NavigationControllerTest, PostURL) {
571 NavigationControllerImpl& controller = controller_impl();
572
573 const GURL url("http://foo1");
574
575 const int length = 5;
576 const unsigned char* raw_data =
577 reinterpret_cast<const unsigned char*>("d\n\0a2");
578 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length);
579 scoped_refptr<base::RefCountedBytes> data =
580 base::RefCountedBytes::TakeVector(&post_data_vector);
581
582 controller.PostURL(url, content::Referrer(), *data.get(), true);
583
584 NavigationEntryImpl* post_entry =
585 NavigationEntryImpl::FromNavigationEntry(
586 controller.GetPendingEntry());
587
588 EXPECT_TRUE(post_entry);
589 EXPECT_TRUE(post_entry->GetHasPostData());
590 EXPECT_EQ(data->front(),
591 post_entry->GetBrowserInitiatedPostData()->front());
592 }
593
594 TEST_F(NavigationControllerTest, Reload) { 661 TEST_F(NavigationControllerTest, Reload) {
595 NavigationControllerImpl& controller = controller_impl(); 662 NavigationControllerImpl& controller = controller_impl();
596 TestNotificationTracker notifications; 663 TestNotificationTracker notifications;
597 RegisterForAllNavNotifications(&notifications, &controller); 664 RegisterForAllNavNotifications(&notifications, &controller);
598 665
599 const GURL url1("http://foo1"); 666 const GURL url1("http://foo1");
600 667
601 controller.LoadURL( 668 controller.LoadURL(
602 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 669 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
603 EXPECT_EQ(0U, notifications.size()); 670 EXPECT_EQ(0U, notifications.size());
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after
2020 // For typed navigations (browser-initiated), both active and visible entries 2087 // For typed navigations (browser-initiated), both active and visible entries
2021 // should update before commit. 2088 // should update before commit.
2022 controller.LoadURL(url0, content::Referrer(), 2089 controller.LoadURL(url0, content::Referrer(),
2023 content::PAGE_TRANSITION_TYPED, std::string()); 2090 content::PAGE_TRANSITION_TYPED, std::string());
2024 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL()); 2091 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL());
2025 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); 2092 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL());
2026 test_rvh()->SendNavigate(0, url0); 2093 test_rvh()->SendNavigate(0, url0);
2027 2094
2028 // For link clicks (renderer-initiated navigations), the active entry should 2095 // For link clicks (renderer-initiated navigations), the active entry should
2029 // update before commit but the visible should not. 2096 // update before commit but the visible should not.
2030 controller.LoadURLFromRenderer(url1, content::Referrer(), 2097 NavigationController::LoadURLParams load_url_params(url1);
2031 content::PAGE_TRANSITION_LINK, 2098 load_url_params.is_renderer_initiated = true;
2032 std::string()); 2099 controller.LoadURLWithParams(load_url_params);
2033 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); 2100 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL());
2034 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); 2101 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL());
2035 EXPECT_TRUE( 2102 EXPECT_TRUE(
2036 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> 2103 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2037 is_renderer_initiated()); 2104 is_renderer_initiated());
2038 2105
2039 // After commit, both should be updated, and we should no longer treat the 2106 // After commit, both should be updated, and we should no longer treat the
2040 // entry as renderer-initiated. 2107 // entry as renderer-initiated.
2041 test_rvh()->SendNavigate(1, url1); 2108 test_rvh()->SendNavigate(1, url1);
2042 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); 2109 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL());
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
2751 TabNavigation nav(0, url0, GURL(), string16(), 2818 TabNavigation nav(0, url0, GURL(), string16(),
2752 webkit_glue::CreateHistoryStateForURL(url0), 2819 webkit_glue::CreateHistoryStateForURL(url0),
2753 content::PAGE_TRANSITION_LINK); 2820 content::PAGE_TRANSITION_LINK);
2754 session_helper_.AssertNavigationEquals(nav, 2821 session_helper_.AssertNavigationEquals(nav,
2755 windows_[0]->tabs[0]->navigations[0]); 2822 windows_[0]->tabs[0]->navigations[0]);
2756 nav.set_url(url2); 2823 nav.set_url(url2);
2757 session_helper_.AssertNavigationEquals(nav, 2824 session_helper_.AssertNavigationEquals(nav,
2758 windows_[0]->tabs[0]->navigations[1]); 2825 windows_[0]->tabs[0]->navigations[1]);
2759 } 2826 }
2760 */ 2827 */
OLDNEW
« no previous file with comments | « content/browser/web_contents/navigation_controller_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698