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_for_data_url.is_empty()) { | |
196 EXPECT_EQ(load_params.virtual_url_for_data_url, entry->GetVirtualURL()); | |
197 } | |
198 if (NavigationController::UA_OVERRIDE_INHERIT != | |
199 load_params.override_user_agent) { | |
200 EXPECT_EQ( | |
201 NavigationController::UA_OVERRIDE_TRUE == | |
202 load_params.override_user_agent ? true : false, | |
Charlie Reis
2012/08/03 23:12:48
This is a bit awkward to read (three types of equa
boliu
2012/08/03 23:31:39
Done.
| |
203 entry->GetIsOverridingUserAgent()); | |
204 } | |
205 EXPECT_EQ(load_params.browser_initiated_post_data, | |
206 entry->GetBrowserInitiatedPostData()); | |
207 EXPECT_EQ(load_params.transferred_global_request_id, | |
208 entry->transferred_global_request_id()); | |
209 } | |
210 | |
211 TEST_F(NavigationControllerTest, LoadURLWithParams) { | |
212 NavigationControllerImpl& controller = controller_impl(); | |
213 | |
214 NavigationController::LoadURLParams load_params(GURL("http://foo")); | |
215 load_params.referrer = content::Referrer(GURL("http://referrer"), | |
216 WebKit::WebReferrerPolicyDefault); | |
217 load_params.transition_type = content::PAGE_TRANSITION_GENERATED; | |
218 load_params.extra_headers = "content-type: text/plain"; | |
219 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; | |
220 load_params.is_renderer_initiated = true; | |
221 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; | |
222 load_params.transferred_global_request_id = content::GlobalRequestID(2,3); | |
223 | |
224 controller.LoadURLWithParams(load_params); | |
225 NavigationEntryImpl* entry = | |
226 NavigationEntryImpl::FromNavigationEntry( | |
227 controller.GetPendingEntry()); | |
228 | |
229 CheckNavigationEntryMatchLoadParams(load_params, entry); | |
230 } | |
231 | |
232 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Data) { | |
233 NavigationControllerImpl& controller = controller_impl(); | |
234 | |
235 NavigationController::LoadURLParams load_params( | |
236 GURL("data:text/html,dataurl")); | |
237 load_params.load_type = NavigationController::LOAD_TYPE_DATA; | |
238 load_params.base_url_for_data_url = GURL("http://foo"); | |
239 load_params.virtual_url_for_data_url = GURL("about:blank"); | |
240 load_params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE; | |
241 | |
242 controller.LoadURLWithParams(load_params); | |
243 NavigationEntryImpl* entry = | |
244 NavigationEntryImpl::FromNavigationEntry( | |
245 controller.GetPendingEntry()); | |
246 | |
247 CheckNavigationEntryMatchLoadParams(load_params, entry); | |
248 } | |
249 | |
250 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) { | |
251 NavigationControllerImpl& controller = controller_impl(); | |
252 | |
253 NavigationController::LoadURLParams load_params(GURL("https://posturl")); | |
254 load_params.transition_type = content::PAGE_TRANSITION_TYPED; | |
255 load_params.load_type = | |
256 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | |
257 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; | |
258 | |
259 | |
260 const unsigned char* raw_data = | |
261 reinterpret_cast<const unsigned char*>("d\n\0a2"); | |
262 const int length = 5; | |
263 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | |
264 scoped_refptr<base::RefCountedBytes> data = | |
265 base::RefCountedBytes::TakeVector(&post_data_vector); | |
266 load_params.browser_initiated_post_data = data.get(); | |
267 | |
268 controller.LoadURLWithParams(load_params); | |
269 NavigationEntryImpl* entry = | |
270 NavigationEntryImpl::FromNavigationEntry( | |
271 controller.GetPendingEntry()); | |
272 | |
273 CheckNavigationEntryMatchLoadParams(load_params, entry); | |
274 } | |
275 | |
184 // Tests what happens when the same page is loaded again. Should not create a | 276 // 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 | 277 // 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 | 278 // 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). | 279 // the load commits (because WebCore didn't actually make a new entry). |
188 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 280 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
189 NavigationControllerImpl& controller = controller_impl(); | 281 NavigationControllerImpl& controller = controller_impl(); |
190 TestNotificationTracker notifications; | 282 TestNotificationTracker notifications; |
191 RegisterForAllNavNotifications(¬ifications, &controller); | 283 RegisterForAllNavNotifications(¬ifications, &controller); |
192 | 284 |
193 const GURL url1("http://foo1"); | 285 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. | 594 // Set a WebContentsDelegate to listen for state changes. |
503 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 595 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
504 EXPECT_FALSE(contents()->GetDelegate()); | 596 EXPECT_FALSE(contents()->GetDelegate()); |
505 contents()->SetDelegate(delegate.get()); | 597 contents()->SetDelegate(delegate.get()); |
506 | 598 |
507 // Without any navigations, the renderer starts at about:blank. | 599 // Without any navigations, the renderer starts at about:blank. |
508 const GURL kExistingURL("about:blank"); | 600 const GURL kExistingURL("about:blank"); |
509 | 601 |
510 // Now make a pending new navigation, initiated by the renderer. | 602 // Now make a pending new navigation, initiated by the renderer. |
511 const GURL kNewURL("http://eh"); | 603 const GURL kNewURL("http://eh"); |
512 controller.LoadURLFromRenderer( | 604 NavigationController::LoadURLParams load_url_params(kNewURL); |
513 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 605 load_url_params.transition_type = content::PAGE_TRANSITION_TYPED; |
514 std::string()); | 606 load_url_params.is_renderer_initiated = true; |
607 controller.LoadURLWithParams(load_url_params); | |
515 EXPECT_EQ(0U, notifications.size()); | 608 EXPECT_EQ(0U, notifications.size()); |
516 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 609 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
517 EXPECT_TRUE(controller.GetPendingEntry()); | 610 EXPECT_TRUE(controller.GetPendingEntry()); |
518 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 611 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
519 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 612 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
520 | 613 |
521 // There should be no visible entry (resulting in about:blank in the | 614 // 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 | 615 // omnibox), because it was renderer-initiated and there's no last committed |
523 // entry. | 616 // entry. |
524 EXPECT_FALSE(controller.GetVisibleEntry()); | 617 EXPECT_FALSE(controller.GetVisibleEntry()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 649 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
557 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 650 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
558 | 651 |
559 // There should be no visible entry (resulting in about:blank in the | 652 // There should be no visible entry (resulting in about:blank in the |
560 // omnibox), ensuring no spoof is possible. | 653 // omnibox), ensuring no spoof is possible. |
561 EXPECT_FALSE(controller.GetVisibleEntry()); | 654 EXPECT_FALSE(controller.GetVisibleEntry()); |
562 | 655 |
563 contents()->SetDelegate(NULL); | 656 contents()->SetDelegate(NULL); |
564 } | 657 } |
565 | 658 |
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) { | 659 TEST_F(NavigationControllerTest, Reload) { |
592 NavigationControllerImpl& controller = controller_impl(); | 660 NavigationControllerImpl& controller = controller_impl(); |
593 TestNotificationTracker notifications; | 661 TestNotificationTracker notifications; |
594 RegisterForAllNavNotifications(¬ifications, &controller); | 662 RegisterForAllNavNotifications(¬ifications, &controller); |
595 | 663 |
596 const GURL url1("http://foo1"); | 664 const GURL url1("http://foo1"); |
597 | 665 |
598 controller.LoadURL( | 666 controller.LoadURL( |
599 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 667 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
600 EXPECT_EQ(0U, notifications.size()); | 668 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 | 2007 // For typed navigations (browser-initiated), both active and visible entries |
1940 // should update before commit. | 2008 // should update before commit. |
1941 controller.LoadURL(url0, content::Referrer(), | 2009 controller.LoadURL(url0, content::Referrer(), |
1942 content::PAGE_TRANSITION_TYPED, std::string()); | 2010 content::PAGE_TRANSITION_TYPED, std::string()); |
1943 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL()); | 2011 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL()); |
1944 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2012 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
1945 test_rvh()->SendNavigate(0, url0); | 2013 test_rvh()->SendNavigate(0, url0); |
1946 | 2014 |
1947 // For link clicks (renderer-initiated navigations), the active entry should | 2015 // For link clicks (renderer-initiated navigations), the active entry should |
1948 // update before commit but the visible should not. | 2016 // update before commit but the visible should not. |
1949 controller.LoadURLFromRenderer(url1, content::Referrer(), | 2017 NavigationController::LoadURLParams load_url_params(url1); |
1950 content::PAGE_TRANSITION_LINK, | 2018 load_url_params.is_renderer_initiated = true; |
1951 std::string()); | 2019 controller.LoadURLWithParams(load_url_params); |
1952 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 2020 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); |
1953 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2021 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
1954 EXPECT_TRUE( | 2022 EXPECT_TRUE( |
1955 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2023 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
1956 is_renderer_initiated()); | 2024 is_renderer_initiated()); |
1957 | 2025 |
1958 // After commit, both should be updated, and we should no longer treat the | 2026 // After commit, both should be updated, and we should no longer treat the |
1959 // entry as renderer-initiated. | 2027 // entry as renderer-initiated. |
1960 test_rvh()->SendNavigate(1, url1); | 2028 test_rvh()->SendNavigate(1, url1); |
1961 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); | 2029 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(), | 2723 TabNavigation nav(0, url0, GURL(), string16(), |
2656 webkit_glue::CreateHistoryStateForURL(url0), | 2724 webkit_glue::CreateHistoryStateForURL(url0), |
2657 content::PAGE_TRANSITION_LINK); | 2725 content::PAGE_TRANSITION_LINK); |
2658 session_helper_.AssertNavigationEquals(nav, | 2726 session_helper_.AssertNavigationEquals(nav, |
2659 windows_[0]->tabs[0]->navigations[0]); | 2727 windows_[0]->tabs[0]->navigations[0]); |
2660 nav.set_url(url2); | 2728 nav.set_url(url2); |
2661 session_helper_.AssertNavigationEquals(nav, | 2729 session_helper_.AssertNavigationEquals(nav, |
2662 windows_[0]->tabs[0]->navigations[1]); | 2730 windows_[0]->tabs[0]->navigations[1]); |
2663 } | 2731 } |
2664 */ | 2732 */ |
OLD | NEW |