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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/browser/web_contents/web_contents_screenshot_manager.h" | 27 #include "content/browser/web_contents/web_contents_screenshot_manager.h" |
28 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
29 #include "content/public/browser/navigation_details.h" | 29 #include "content/public/browser/navigation_details.h" |
30 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
31 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
33 #include "content/public/browser/render_view_host_observer.h" | 33 #include "content/public/browser/render_view_host_observer.h" |
34 #include "content/public/browser/web_contents_delegate.h" | 34 #include "content/public/browser/web_contents_delegate.h" |
35 #include "content/public/browser/web_contents_observer.h" | 35 #include "content/public/browser/web_contents_observer.h" |
36 #include "content/public/common/page_state.h" | 36 #include "content/public/common/page_state.h" |
| 37 #include "content/public/common/url_constants.h" |
37 #include "content/public/test/mock_render_process_host.h" | 38 #include "content/public/test/mock_render_process_host.h" |
38 #include "content/public/test/test_notification_tracker.h" | 39 #include "content/public/test/test_notification_tracker.h" |
39 #include "content/public/test/test_utils.h" | 40 #include "content/public/test/test_utils.h" |
40 #include "content/test/test_web_contents.h" | 41 #include "content/test/test_web_contents.h" |
41 #include "net/base/net_util.h" | 42 #include "net/base/net_util.h" |
42 #include "skia/ext/platform_canvas.h" | 43 #include "skia/ext/platform_canvas.h" |
43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
44 | 45 |
45 using base::Time; | 46 using base::Time; |
46 | 47 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 NavigationControllerImpl& controller = controller_impl(); | 500 NavigationControllerImpl& controller = controller_impl(); |
500 | 501 |
501 NavigationController::LoadURLParams load_params(GURL("http://foo")); | 502 NavigationController::LoadURLParams load_params(GURL("http://foo")); |
502 load_params.referrer = | 503 load_params.referrer = |
503 Referrer(GURL("http://referrer"), WebKit::WebReferrerPolicyDefault); | 504 Referrer(GURL("http://referrer"), WebKit::WebReferrerPolicyDefault); |
504 load_params.transition_type = PAGE_TRANSITION_GENERATED; | 505 load_params.transition_type = PAGE_TRANSITION_GENERATED; |
505 load_params.extra_headers = "content-type: text/plain"; | 506 load_params.extra_headers = "content-type: text/plain"; |
506 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; | 507 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; |
507 load_params.is_renderer_initiated = true; | 508 load_params.is_renderer_initiated = true; |
508 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; | 509 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; |
509 load_params.transferred_global_request_id = GlobalRequestID(2,3); | 510 load_params.transferred_global_request_id = GlobalRequestID(2, 3); |
510 | 511 |
511 controller.LoadURLWithParams(load_params); | 512 controller.LoadURLWithParams(load_params); |
512 NavigationEntryImpl* entry = | 513 NavigationEntryImpl* entry = |
513 NavigationEntryImpl::FromNavigationEntry( | 514 NavigationEntryImpl::FromNavigationEntry( |
514 controller.GetPendingEntry()); | 515 controller.GetPendingEntry()); |
515 | 516 |
516 // The timestamp should not have been set yet. | 517 // The timestamp should not have been set yet. |
517 ASSERT_TRUE(entry); | 518 ASSERT_TRUE(entry); |
518 EXPECT_TRUE(entry->GetTimestamp().is_null()); | 519 EXPECT_TRUE(entry->GetTimestamp().is_null()); |
519 | 520 |
520 CheckNavigationEntryMatchLoadParams(load_params, entry); | 521 CheckNavigationEntryMatchLoadParams(load_params, entry); |
521 } | 522 } |
522 | 523 |
523 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Data) { | 524 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Data) { |
524 NavigationControllerImpl& controller = controller_impl(); | 525 NavigationControllerImpl& controller = controller_impl(); |
525 | 526 |
526 NavigationController::LoadURLParams load_params( | 527 NavigationController::LoadURLParams load_params( |
527 GURL("data:text/html,dataurl")); | 528 GURL("data:text/html,dataurl")); |
528 load_params.load_type = NavigationController::LOAD_TYPE_DATA; | 529 load_params.load_type = NavigationController::LOAD_TYPE_DATA; |
529 load_params.base_url_for_data_url = GURL("http://foo"); | 530 load_params.base_url_for_data_url = GURL("http://foo"); |
530 load_params.virtual_url_for_data_url = GURL("about:blank"); | 531 load_params.virtual_url_for_data_url = GURL(kAboutBlankURL); |
531 load_params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE; | 532 load_params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE; |
532 | 533 |
533 controller.LoadURLWithParams(load_params); | 534 controller.LoadURLWithParams(load_params); |
534 NavigationEntryImpl* entry = | 535 NavigationEntryImpl* entry = |
535 NavigationEntryImpl::FromNavigationEntry( | 536 NavigationEntryImpl::FromNavigationEntry( |
536 controller.GetPendingEntry()); | 537 controller.GetPendingEntry()); |
537 | 538 |
538 CheckNavigationEntryMatchLoadParams(load_params, entry); | 539 CheckNavigationEntryMatchLoadParams(load_params, entry); |
539 } | 540 } |
540 | 541 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 NavigationControllerImpl& controller = controller_impl(); | 861 NavigationControllerImpl& controller = controller_impl(); |
861 TestNotificationTracker notifications; | 862 TestNotificationTracker notifications; |
862 RegisterForAllNavNotifications(¬ifications, &controller); | 863 RegisterForAllNavNotifications(¬ifications, &controller); |
863 | 864 |
864 // Set a WebContentsDelegate to listen for state changes. | 865 // Set a WebContentsDelegate to listen for state changes. |
865 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 866 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
866 EXPECT_FALSE(contents()->GetDelegate()); | 867 EXPECT_FALSE(contents()->GetDelegate()); |
867 contents()->SetDelegate(delegate.get()); | 868 contents()->SetDelegate(delegate.get()); |
868 | 869 |
869 // Without any navigations, the renderer starts at about:blank. | 870 // Without any navigations, the renderer starts at about:blank. |
870 const GURL kExistingURL("about:blank"); | 871 const GURL kExistingURL(kAboutBlankURL); |
871 | 872 |
872 // Now make a pending new navigation. | 873 // Now make a pending new navigation. |
873 const GURL kNewURL("http://eh"); | 874 const GURL kNewURL("http://eh"); |
874 controller.LoadURL( | 875 controller.LoadURL( |
875 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 876 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
876 EXPECT_EQ(0U, notifications.size()); | 877 EXPECT_EQ(0U, notifications.size()); |
877 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 878 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
878 EXPECT_TRUE(controller.GetPendingEntry()); | 879 EXPECT_TRUE(controller.GetPendingEntry()); |
879 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 880 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
880 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 881 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1154 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1154 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1155 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1155 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1156 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1156 EXPECT_FALSE(controller.GetPendingEntry()); | 1157 EXPECT_FALSE(controller.GetPendingEntry()); |
1157 EXPECT_TRUE(controller.CanGoBack()); | 1158 EXPECT_TRUE(controller.CanGoBack()); |
1158 EXPECT_FALSE(controller.CanGoForward()); | 1159 EXPECT_FALSE(controller.CanGoForward()); |
1159 } | 1160 } |
1160 | 1161 |
1161 class TestNavigationObserver : public RenderViewHostObserver { | 1162 class TestNavigationObserver : public RenderViewHostObserver { |
1162 public: | 1163 public: |
1163 TestNavigationObserver(RenderViewHost* render_view_host) | 1164 explicit TestNavigationObserver(RenderViewHost* render_view_host) |
1164 : RenderViewHostObserver(render_view_host) { | 1165 : RenderViewHostObserver(render_view_host) { |
1165 } | 1166 } |
1166 | 1167 |
1167 const GURL& navigated_url() const { | 1168 const GURL& navigated_url() const { |
1168 return navigated_url_; | 1169 return navigated_url_; |
1169 } | 1170 } |
1170 | 1171 |
1171 protected: | 1172 protected: |
1172 virtual void Navigate(const GURL& url) OVERRIDE { | 1173 virtual void Navigate(const GURL& url) OVERRIDE { |
1173 navigated_url_ = url; | 1174 navigated_url_ = url; |
(...skipping 2343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3517 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); | 3518 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); |
3518 | 3519 |
3519 // Simulate Chromium having set the favicon for |kPageWithFavicon|. | 3520 // Simulate Chromium having set the favicon for |kPageWithFavicon|. |
3520 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 3521 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
3521 favicon_status.image = CreateImage(SK_ColorWHITE); | 3522 favicon_status.image = CreateImage(SK_ColorWHITE); |
3522 favicon_status.url = kIconURL; | 3523 favicon_status.url = kIconURL; |
3523 favicon_status.valid = true; | 3524 favicon_status.valid = true; |
3524 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 3525 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
3525 | 3526 |
3526 test_rvh()->SendNavigateWithTransition( | 3527 test_rvh()->SendNavigateWithTransition( |
3527 0, // same page ID. | 3528 0, // same page ID. |
3528 kPageWithoutFavicon, | 3529 kPageWithoutFavicon, |
3529 PAGE_TRANSITION_CLIENT_REDIRECT); | 3530 PAGE_TRANSITION_CLIENT_REDIRECT); |
3530 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 3531 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
3531 navigation_entry_committed_counter_ = 0; | 3532 navigation_entry_committed_counter_ = 0; |
3532 | 3533 |
3533 entry = controller.GetLastCommittedEntry(); | 3534 entry = controller.GetLastCommittedEntry(); |
3534 EXPECT_TRUE(entry); | 3535 EXPECT_TRUE(entry); |
3535 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); | 3536 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); |
3536 | 3537 |
3537 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 3538 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3896 PAGE_TRANSITION_LINK); | 3897 PAGE_TRANSITION_LINK); |
3897 session_helper_.AssertNavigationEquals(nav, | 3898 session_helper_.AssertNavigationEquals(nav, |
3898 windows_[0]->tabs[0]->navigations[0]); | 3899 windows_[0]->tabs[0]->navigations[0]); |
3899 nav.set_url(url2); | 3900 nav.set_url(url2); |
3900 session_helper_.AssertNavigationEquals(nav, | 3901 session_helper_.AssertNavigationEquals(nav, |
3901 windows_[0]->tabs[0]->navigations[1]); | 3902 windows_[0]->tabs[0]->navigations[1]); |
3902 } | 3903 } |
3903 */ | 3904 */ |
3904 | 3905 |
3905 } // namespace content | 3906 } // namespace content |
OLD | NEW |