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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "content/browser/renderer_host/frame_tree_node.h" | 7 #include "content/browser/renderer_host/frame_tree_node.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/browser/renderer_host/test_render_view_host.h" | 9 #include "content/browser/renderer_host/test_render_view_host.h" |
10 #include "content/browser/site_instance_impl.h" | 10 #include "content/browser/site_instance_impl.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/public/common/bindings_policy.h" | 23 #include "content/public/common/bindings_policy.h" |
24 #include "content/public/common/content_constants.h" | 24 #include "content/public/common/content_constants.h" |
25 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
26 #include "content/public/test/mock_render_process_host.h" | 26 #include "content/public/test/mock_render_process_host.h" |
27 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
28 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
29 #include "content/test/test_content_browser_client.h" | 29 #include "content/test/test_content_browser_client.h" |
30 #include "content/test/test_content_client.h" | 30 #include "content/test/test_content_client.h" |
31 #include "content/test/test_web_contents.h" | 31 #include "content/test/test_web_contents.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "webkit/glue/webkit_glue.h" | |
34 | 33 |
35 namespace content { | 34 namespace content { |
36 namespace { | 35 namespace { |
37 | 36 |
38 const char kTestWebUIUrl[] = "chrome://blah"; | 37 const char kTestWebUIUrl[] = "chrome://blah"; |
39 | 38 |
40 class WebContentsImplTestWebUIControllerFactory | 39 class WebContentsImplTestWebUIControllerFactory |
41 : public WebUIControllerFactory { | 40 : public WebUIControllerFactory { |
42 public: | 41 public: |
43 virtual WebUIController* CreateWebUIControllerForURL( | 42 virtual WebUIController* CreateWebUIControllerForURL( |
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 // longer swapped out. | 1015 // longer swapped out. |
1017 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 1016 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
1018 SiteInstance* instance2 = contents()->GetSiteInstance(); | 1017 SiteInstance* instance2 = contents()->GetSiteInstance(); |
1019 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1018 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1020 EXPECT_EQ(orig_rvh, rvh()); | 1019 EXPECT_EQ(orig_rvh, rvh()); |
1021 EXPECT_FALSE(orig_rvh->is_swapped_out()); | 1020 EXPECT_FALSE(orig_rvh->is_swapped_out()); |
1022 EXPECT_EQ(instance1, instance2); | 1021 EXPECT_EQ(instance1, instance2); |
1023 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 1022 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
1024 } | 1023 } |
1025 | 1024 |
1026 // Test that NavigationEntries have the correct content state after going | 1025 // Test that NavigationEntries have the correct page state after going |
1027 // forward and back. Prevents regression for bug 1116137. | 1026 // forward and back. Prevents regression for bug 1116137. |
1028 TEST_F(WebContentsImplTest, NavigationEntryContentState) { | 1027 TEST_F(WebContentsImplTest, NavigationEntryContentState) { |
1029 TestRenderViewHost* orig_rvh = test_rvh(); | 1028 TestRenderViewHost* orig_rvh = test_rvh(); |
1030 | 1029 |
1031 // Navigate to URL. There should be no committed entry yet. | 1030 // Navigate to URL. There should be no committed entry yet. |
1032 const GURL url("http://www.google.com"); | 1031 const GURL url("http://www.google.com"); |
1033 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1032 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1034 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 1033 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
1035 EXPECT_TRUE(entry == NULL); | 1034 EXPECT_TRUE(entry == NULL); |
1036 | 1035 |
1037 // Committed entry should have content state after DidNavigate. | 1036 // Committed entry should have page state after DidNavigate. |
1038 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1037 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1039 entry = controller().GetLastCommittedEntry(); | 1038 entry = controller().GetLastCommittedEntry(); |
1040 EXPECT_FALSE(entry->GetContentState().empty()); | 1039 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1041 | 1040 |
1042 // Navigate to same site. | 1041 // Navigate to same site. |
1043 const GURL url2("http://images.google.com"); | 1042 const GURL url2("http://images.google.com"); |
1044 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1043 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1045 entry = controller().GetLastCommittedEntry(); | 1044 entry = controller().GetLastCommittedEntry(); |
1046 EXPECT_FALSE(entry->GetContentState().empty()); | 1045 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1047 | 1046 |
1048 // Committed entry should have content state after DidNavigate. | 1047 // Committed entry should have page state after DidNavigate. |
1049 contents()->TestDidNavigate(orig_rvh, 2, url2, PAGE_TRANSITION_TYPED); | 1048 contents()->TestDidNavigate(orig_rvh, 2, url2, PAGE_TRANSITION_TYPED); |
1050 entry = controller().GetLastCommittedEntry(); | 1049 entry = controller().GetLastCommittedEntry(); |
1051 EXPECT_FALSE(entry->GetContentState().empty()); | 1050 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1052 | 1051 |
1053 // Now go back. Committed entry should still have content state. | 1052 // Now go back. Committed entry should still have page state. |
1054 controller().GoBack(); | 1053 controller().GoBack(); |
1055 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1054 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1056 entry = controller().GetLastCommittedEntry(); | 1055 entry = controller().GetLastCommittedEntry(); |
1057 EXPECT_FALSE(entry->GetContentState().empty()); | 1056 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1058 } | 1057 } |
1059 | 1058 |
1060 // Test that NavigationEntries have the correct content state and SiteInstance | 1059 // Test that NavigationEntries have the correct page state and SiteInstance |
1061 // state after opening a new window to about:blank. Prevents regression for | 1060 // state after opening a new window to about:blank. Prevents regression for |
1062 // bugs b/1116137 and http://crbug.com/111975. | 1061 // bugs b/1116137 and http://crbug.com/111975. |
1063 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { | 1062 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { |
1064 TestRenderViewHost* orig_rvh = test_rvh(); | 1063 TestRenderViewHost* orig_rvh = test_rvh(); |
1065 | 1064 |
1066 // When opening a new window, it is navigated to about:blank internally. | 1065 // When opening a new window, it is navigated to about:blank internally. |
1067 // Currently, this results in two DidNavigate events. | 1066 // Currently, this results in two DidNavigate events. |
1068 const GURL url(kAboutBlankURL); | 1067 const GURL url(kAboutBlankURL); |
1069 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1068 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1070 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1069 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1071 | 1070 |
1072 // Should have a content state here. | 1071 // Should have a page state here. |
1073 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 1072 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
1074 EXPECT_FALSE(entry->GetContentState().empty()); | 1073 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1075 | 1074 |
1076 // The SiteInstance should be available for other navigations to use. | 1075 // The SiteInstance should be available for other navigations to use. |
1077 NavigationEntryImpl* entry_impl = | 1076 NavigationEntryImpl* entry_impl = |
1078 NavigationEntryImpl::FromNavigationEntry(entry); | 1077 NavigationEntryImpl::FromNavigationEntry(entry); |
1079 EXPECT_FALSE(entry_impl->site_instance()->HasSite()); | 1078 EXPECT_FALSE(entry_impl->site_instance()->HasSite()); |
1080 int32 site_instance_id = entry_impl->site_instance()->GetId(); | 1079 int32 site_instance_id = entry_impl->site_instance()->GetId(); |
1081 | 1080 |
1082 // Navigating to a normal page should not cause a process swap. | 1081 // Navigating to a normal page should not cause a process swap. |
1083 const GURL new_url("http://www.google.com"); | 1082 const GURL new_url("http://www.google.com"); |
1084 controller().LoadURL(new_url, Referrer(), | 1083 controller().LoadURL(new_url, Referrer(), |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count()); | 2127 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count()); |
2129 | 2128 |
2130 contents()->OnFrameDetached(16, 265); | 2129 contents()->OnFrameDetached(16, 265); |
2131 EXPECT_EQ(4UL, root->child_at(2)->child_count()); | 2130 EXPECT_EQ(4UL, root->child_at(2)->child_count()); |
2132 | 2131 |
2133 contents()->OnFrameDetached(5, 15); | 2132 contents()->OnFrameDetached(5, 15); |
2134 EXPECT_EQ(2UL, root->child_count()); | 2133 EXPECT_EQ(2UL, root->child_count()); |
2135 } | 2134 } |
2136 | 2135 |
2137 } // namespace content | 2136 } // namespace content |
OLD | NEW |