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 "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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 EXPECT_EQ(controller.GetEntryCount(), 2); | 174 EXPECT_EQ(controller.GetEntryCount(), 2); |
175 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 175 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
176 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 176 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
177 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 177 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
178 EXPECT_FALSE(controller.GetPendingEntry()); | 178 EXPECT_FALSE(controller.GetPendingEntry()); |
179 EXPECT_TRUE(controller.CanGoBack()); | 179 EXPECT_TRUE(controller.CanGoBack()); |
180 EXPECT_FALSE(controller.CanGoForward()); | 180 EXPECT_FALSE(controller.CanGoForward()); |
181 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 181 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
182 } | 182 } |
183 | 183 |
184 void CheckNavigationEntryMatchLoadParams( | |
185 NavigationController::LoadURLParams& load_params, | |
186 NavigationEntryImpl* entry) { | |
187 EXPECT_EQ(load_params.url, entry->GetURL()); | |
188 EXPECT_EQ(load_params.referrer.url, entry->GetReferrer().url); | |
189 EXPECT_EQ(load_params.referrer.policy, entry->GetReferrer().policy); | |
190 EXPECT_EQ(load_params.transition_type, entry->GetTransitionType()); | |
191 EXPECT_EQ(load_params.extra_headers, entry->extra_headers()); | |
192 | |
193 EXPECT_EQ(load_params.is_renderer_initiated, entry->is_renderer_initiated()); | |
194 EXPECT_EQ(load_params.base_url_for_data_url, entry->GetBaseURLForDataURL()); | |
195 if (!load_params.virtual_url.is_empty()) { | |
196 EXPECT_EQ(load_params.virtual_url, entry->GetVirtualURL()); | |
197 } | |
198 if (load_params.should_inherit_user_agent_override) { | |
199 EXPECT_EQ(load_params.is_overriding_user_agent, | |
200 entry->GetIsOverridingUserAgent()); | |
201 } | |
202 EXPECT_EQ(load_params.browser_initiated_post_data, | |
203 entry->GetBrowserInitiatedPostData()); | |
204 EXPECT_EQ(load_params.transferred_global_request_id, | |
205 entry->transferred_global_request_id()); | |
206 } | |
207 | |
208 TEST_F(NavigationControllerTest, LoadURLWithParams) { | |
209 NavigationControllerImpl& controller = controller_impl(); | |
210 | |
211 NavigationController::LoadURLParams load_params(GURL("http://foo")); | |
212 load_params.referrer = content::Referrer(GURL("http://referrer"), | |
213 WebKit::WebReferrerPolicyDefault); | |
214 load_params.transition_type = content::PAGE_TRANSITION_GENERATED; | |
215 load_params.extra_headers = "content-type: text/plain"; | |
216 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; | |
217 load_params.is_renderer_initiated = true; | |
218 load_params.should_inherit_user_agent_override = false; | |
219 load_params.is_overriding_user_agent = true; | |
220 load_params.transferred_global_request_id = content::GlobalRequestID(2,3); | |
221 | |
222 controller.LoadURLWithParams(load_params); | |
223 NavigationEntryImpl* entry = | |
224 NavigationEntryImpl::FromNavigationEntry( | |
225 controller.GetPendingEntry()); | |
226 | |
227 CheckNavigationEntryMatchLoadParams(load_params, entry); | |
228 } | |
229 | |
230 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Data) { | |
231 NavigationControllerImpl& controller = controller_impl(); | |
232 | |
233 NavigationController::LoadURLParams load_params(GURL("data://dataurl")); | |
Charlie Reis
2012/08/03 21:28:36
nit: "data:text/html,dataurl"
(There's no :// in d
boliu
2012/08/03 22:42:08
Done.
| |
234 load_params.load_type = NavigationController::LOAD_TYPE_DATA; | |
235 load_params.base_url_for_data_url = GURL("http://foo"); | |
236 load_params.virtual_url = GURL("about:blank"); | |
237 load_params.should_inherit_user_agent_override = false; | |
238 load_params.is_overriding_user_agent = false; | |
239 | |
240 controller.LoadURLWithParams(load_params); | |
241 NavigationEntryImpl* entry = | |
242 NavigationEntryImpl::FromNavigationEntry( | |
243 controller.GetPendingEntry()); | |
244 | |
245 CheckNavigationEntryMatchLoadParams(load_params, entry); | |
246 } | |
247 | |
248 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) { | |
249 NavigationControllerImpl& controller = controller_impl(); | |
250 | |
251 NavigationController::LoadURLParams load_params(GURL("https://posturl")); | |
252 load_params.transition_type = content::PAGE_TRANSITION_TYPED; | |
253 load_params.load_type = | |
254 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | |
255 load_params.should_inherit_user_agent_override = false; | |
256 load_params.is_overriding_user_agent = true; | |
257 | |
258 const unsigned char* raw_data = | |
259 reinterpret_cast<const unsigned char*>("d\n\0a2"); | |
260 const int length = 5; | |
261 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | |
262 scoped_refptr<base::RefCountedBytes> data = | |
263 base::RefCountedBytes::TakeVector(&post_data_vector); | |
264 load_params.browser_initiated_post_data = data.get(); | |
265 | |
266 controller.LoadURLWithParams(load_params); | |
267 NavigationEntryImpl* entry = | |
268 NavigationEntryImpl::FromNavigationEntry( | |
269 controller.GetPendingEntry()); | |
270 | |
271 CheckNavigationEntryMatchLoadParams(load_params, entry); | |
272 } | |
273 | |
184 // Tests what happens when the same page is loaded again. Should not create a | 274 // Tests what happens when the same page is loaded again. Should not create a |
185 // new session history entry. This is what happens when you press enter in the | 275 // new session history entry. This is what happens when you press enter in the |
186 // URL bar to reload: a pending entry is created and then it is discarded when | 276 // URL bar to reload: a pending entry is created and then it is discarded when |
187 // the load commits (because WebCore didn't actually make a new entry). | 277 // the load commits (because WebCore didn't actually make a new entry). |
188 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 278 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
189 NavigationControllerImpl& controller = controller_impl(); | 279 NavigationControllerImpl& controller = controller_impl(); |
190 TestNotificationTracker notifications; | 280 TestNotificationTracker notifications; |
191 RegisterForAllNavNotifications(¬ifications, &controller); | 281 RegisterForAllNavNotifications(¬ifications, &controller); |
192 | 282 |
193 const GURL url1("http://foo1"); | 283 const GURL url1("http://foo1"); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 // Set a WebContentsDelegate to listen for state changes. | 592 // Set a WebContentsDelegate to listen for state changes. |
503 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 593 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
504 EXPECT_FALSE(contents()->GetDelegate()); | 594 EXPECT_FALSE(contents()->GetDelegate()); |
505 contents()->SetDelegate(delegate.get()); | 595 contents()->SetDelegate(delegate.get()); |
506 | 596 |
507 // Without any navigations, the renderer starts at about:blank. | 597 // Without any navigations, the renderer starts at about:blank. |
508 const GURL kExistingURL("about:blank"); | 598 const GURL kExistingURL("about:blank"); |
509 | 599 |
510 // Now make a pending new navigation, initiated by the renderer. | 600 // Now make a pending new navigation, initiated by the renderer. |
511 const GURL kNewURL("http://eh"); | 601 const GURL kNewURL("http://eh"); |
512 controller.LoadURLFromRenderer( | 602 NavigationController::LoadURLParams load_url_params(kNewURL); |
513 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 603 load_url_params.transition_type = content::PAGE_TRANSITION_TYPED; |
514 std::string()); | 604 load_url_params.is_renderer_initiated = true; |
605 controller.LoadURLWithParams(load_url_params); | |
515 EXPECT_EQ(0U, notifications.size()); | 606 EXPECT_EQ(0U, notifications.size()); |
516 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 607 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
517 EXPECT_TRUE(controller.GetPendingEntry()); | 608 EXPECT_TRUE(controller.GetPendingEntry()); |
518 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 609 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
519 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 610 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
520 | 611 |
521 // There should be no visible entry (resulting in about:blank in the | 612 // There should be no visible entry (resulting in about:blank in the |
522 // omnibox), because it was renderer-initiated and there's no last committed | 613 // omnibox), because it was renderer-initiated and there's no last committed |
523 // entry. | 614 // entry. |
524 EXPECT_FALSE(controller.GetVisibleEntry()); | 615 EXPECT_FALSE(controller.GetVisibleEntry()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 647 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
557 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 648 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
558 | 649 |
559 // There should be no visible entry (resulting in about:blank in the | 650 // There should be no visible entry (resulting in about:blank in the |
560 // omnibox), ensuring no spoof is possible. | 651 // omnibox), ensuring no spoof is possible. |
561 EXPECT_FALSE(controller.GetVisibleEntry()); | 652 EXPECT_FALSE(controller.GetVisibleEntry()); |
562 | 653 |
563 contents()->SetDelegate(NULL); | 654 contents()->SetDelegate(NULL); |
564 } | 655 } |
565 | 656 |
566 // Test NavigationEntry is constructed correctly. No other logic tested. | |
567 TEST_F(NavigationControllerTest, PostURL) { | |
568 NavigationControllerImpl& controller = controller_impl(); | |
569 | |
570 const GURL url("http://foo1"); | |
571 | |
572 const int length = 5; | |
573 const unsigned char* raw_data = | |
574 reinterpret_cast<const unsigned char*>("d\n\0a2"); | |
575 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | |
576 scoped_refptr<base::RefCountedBytes> data = | |
577 base::RefCountedBytes::TakeVector(&post_data_vector); | |
578 | |
579 controller.PostURL(url, content::Referrer(), *data.get(), true); | |
580 | |
581 NavigationEntryImpl* post_entry = | |
582 NavigationEntryImpl::FromNavigationEntry( | |
583 controller.GetPendingEntry()); | |
584 | |
585 EXPECT_TRUE(post_entry); | |
586 EXPECT_TRUE(post_entry->GetHasPostData()); | |
587 EXPECT_EQ(data->front(), | |
588 post_entry->GetBrowserInitiatedPostData()->front()); | |
589 } | |
590 | |
591 TEST_F(NavigationControllerTest, Reload) { | 657 TEST_F(NavigationControllerTest, Reload) { |
592 NavigationControllerImpl& controller = controller_impl(); | 658 NavigationControllerImpl& controller = controller_impl(); |
593 TestNotificationTracker notifications; | 659 TestNotificationTracker notifications; |
594 RegisterForAllNavNotifications(¬ifications, &controller); | 660 RegisterForAllNavNotifications(¬ifications, &controller); |
595 | 661 |
596 const GURL url1("http://foo1"); | 662 const GURL url1("http://foo1"); |
597 | 663 |
598 controller.LoadURL( | 664 controller.LoadURL( |
599 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 665 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
600 EXPECT_EQ(0U, notifications.size()); | 666 EXPECT_EQ(0U, notifications.size()); |
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1939 // For typed navigations (browser-initiated), both active and visible entries | 2005 // For typed navigations (browser-initiated), both active and visible entries |
1940 // should update before commit. | 2006 // should update before commit. |
1941 controller.LoadURL(url0, content::Referrer(), | 2007 controller.LoadURL(url0, content::Referrer(), |
1942 content::PAGE_TRANSITION_TYPED, std::string()); | 2008 content::PAGE_TRANSITION_TYPED, std::string()); |
1943 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL()); | 2009 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL()); |
1944 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2010 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
1945 test_rvh()->SendNavigate(0, url0); | 2011 test_rvh()->SendNavigate(0, url0); |
1946 | 2012 |
1947 // For link clicks (renderer-initiated navigations), the active entry should | 2013 // For link clicks (renderer-initiated navigations), the active entry should |
1948 // update before commit but the visible should not. | 2014 // update before commit but the visible should not. |
1949 controller.LoadURLFromRenderer(url1, content::Referrer(), | 2015 NavigationController::LoadURLParams load_url_params(url1); |
1950 content::PAGE_TRANSITION_LINK, | 2016 load_url_params.is_renderer_initiated = true; |
1951 std::string()); | 2017 controller.LoadURLWithParams(load_url_params); |
1952 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 2018 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); |
1953 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2019 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
1954 EXPECT_TRUE( | 2020 EXPECT_TRUE( |
1955 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2021 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
1956 is_renderer_initiated()); | 2022 is_renderer_initiated()); |
1957 | 2023 |
1958 // After commit, both should be updated, and we should no longer treat the | 2024 // After commit, both should be updated, and we should no longer treat the |
1959 // entry as renderer-initiated. | 2025 // entry as renderer-initiated. |
1960 test_rvh()->SendNavigate(1, url1); | 2026 test_rvh()->SendNavigate(1, url1); |
1961 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 2027 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2655 TabNavigation nav(0, url0, GURL(), string16(), | 2721 TabNavigation nav(0, url0, GURL(), string16(), |
2656 webkit_glue::CreateHistoryStateForURL(url0), | 2722 webkit_glue::CreateHistoryStateForURL(url0), |
2657 content::PAGE_TRANSITION_LINK); | 2723 content::PAGE_TRANSITION_LINK); |
2658 session_helper_.AssertNavigationEquals(nav, | 2724 session_helper_.AssertNavigationEquals(nav, |
2659 windows_[0]->tabs[0]->navigations[0]); | 2725 windows_[0]->tabs[0]->navigations[0]); |
2660 nav.set_url(url2); | 2726 nav.set_url(url2); |
2661 session_helper_.AssertNavigationEquals(nav, | 2727 session_helper_.AssertNavigationEquals(nav, |
2662 windows_[0]->tabs[0]->navigations[1]); | 2728 windows_[0]->tabs[0]->navigations[1]); |
2663 } | 2729 } |
2664 */ | 2730 */ |
OLD | NEW |