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 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 // longer swapped out. | 1009 // longer swapped out. |
1011 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 1010 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
1012 SiteInstance* instance2 = contents()->GetSiteInstance(); | 1011 SiteInstance* instance2 = contents()->GetSiteInstance(); |
1013 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1012 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1014 EXPECT_EQ(orig_rvh, rvh()); | 1013 EXPECT_EQ(orig_rvh, rvh()); |
1015 EXPECT_FALSE(orig_rvh->is_swapped_out()); | 1014 EXPECT_FALSE(orig_rvh->is_swapped_out()); |
1016 EXPECT_EQ(instance1, instance2); | 1015 EXPECT_EQ(instance1, instance2); |
1017 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 1016 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
1018 } | 1017 } |
1019 | 1018 |
1020 // Test that NavigationEntries have the correct content state after going | 1019 // Test that NavigationEntries have the correct page state after going |
1021 // forward and back. Prevents regression for bug 1116137. | 1020 // forward and back. Prevents regression for bug 1116137. |
1022 TEST_F(WebContentsImplTest, NavigationEntryContentState) { | 1021 TEST_F(WebContentsImplTest, NavigationEntryContentState) { |
1023 TestRenderViewHost* orig_rvh = test_rvh(); | 1022 TestRenderViewHost* orig_rvh = test_rvh(); |
1024 | 1023 |
1025 // Navigate to URL. There should be no committed entry yet. | 1024 // Navigate to URL. There should be no committed entry yet. |
1026 const GURL url("http://www.google.com"); | 1025 const GURL url("http://www.google.com"); |
1027 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1026 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1028 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 1027 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
1029 EXPECT_TRUE(entry == NULL); | 1028 EXPECT_TRUE(entry == NULL); |
1030 | 1029 |
1031 // Committed entry should have content state after DidNavigate. | 1030 // Committed entry should have page state after DidNavigate. |
1032 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1031 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1033 entry = controller().GetLastCommittedEntry(); | 1032 entry = controller().GetLastCommittedEntry(); |
1034 EXPECT_FALSE(entry->GetContentState().empty()); | 1033 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1035 | 1034 |
1036 // Navigate to same site. | 1035 // Navigate to same site. |
1037 const GURL url2("http://images.google.com"); | 1036 const GURL url2("http://images.google.com"); |
1038 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1037 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1039 entry = controller().GetLastCommittedEntry(); | 1038 entry = controller().GetLastCommittedEntry(); |
1040 EXPECT_FALSE(entry->GetContentState().empty()); | 1039 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1041 | 1040 |
1042 // Committed entry should have content state after DidNavigate. | 1041 // Committed entry should have page state after DidNavigate. |
1043 contents()->TestDidNavigate(orig_rvh, 2, url2, PAGE_TRANSITION_TYPED); | 1042 contents()->TestDidNavigate(orig_rvh, 2, url2, PAGE_TRANSITION_TYPED); |
1044 entry = controller().GetLastCommittedEntry(); | 1043 entry = controller().GetLastCommittedEntry(); |
1045 EXPECT_FALSE(entry->GetContentState().empty()); | 1044 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1046 | 1045 |
1047 // Now go back. Committed entry should still have content state. | 1046 // Now go back. Committed entry should still have page state. |
1048 controller().GoBack(); | 1047 controller().GoBack(); |
1049 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1048 contents()->TestDidNavigate(orig_rvh, 1, url, 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 | 1052 |
1054 // Test that NavigationEntries have the correct content state and SiteInstance | 1053 // Test that NavigationEntries have the correct page state and SiteInstance |
1055 // state after opening a new window to about:blank. Prevents regression for | 1054 // state after opening a new window to about:blank. Prevents regression for |
1056 // bugs b/1116137 and http://crbug.com/111975. | 1055 // bugs b/1116137 and http://crbug.com/111975. |
1057 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { | 1056 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { |
1058 TestRenderViewHost* orig_rvh = test_rvh(); | 1057 TestRenderViewHost* orig_rvh = test_rvh(); |
1059 | 1058 |
1060 // When opening a new window, it is navigated to about:blank internally. | 1059 // When opening a new window, it is navigated to about:blank internally. |
1061 // Currently, this results in two DidNavigate events. | 1060 // Currently, this results in two DidNavigate events. |
1062 const GURL url(kAboutBlankURL); | 1061 const GURL url(kAboutBlankURL); |
1063 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1062 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1064 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); | 1063 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1065 | 1064 |
1066 // Should have a content state here. | 1065 // Should have a page state here. |
1067 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 1066 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
1068 EXPECT_FALSE(entry->GetContentState().empty()); | 1067 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1069 | 1068 |
1070 // The SiteInstance should be available for other navigations to use. | 1069 // The SiteInstance should be available for other navigations to use. |
1071 NavigationEntryImpl* entry_impl = | 1070 NavigationEntryImpl* entry_impl = |
1072 NavigationEntryImpl::FromNavigationEntry(entry); | 1071 NavigationEntryImpl::FromNavigationEntry(entry); |
1073 EXPECT_FALSE(entry_impl->site_instance()->HasSite()); | 1072 EXPECT_FALSE(entry_impl->site_instance()->HasSite()); |
1074 int32 site_instance_id = entry_impl->site_instance()->GetId(); | 1073 int32 site_instance_id = entry_impl->site_instance()->GetId(); |
1075 | 1074 |
1076 // Navigating to a normal page should not cause a process swap. | 1075 // Navigating to a normal page should not cause a process swap. |
1077 const GURL new_url("http://www.google.com"); | 1076 const GURL new_url("http://www.google.com"); |
1078 controller().LoadURL(new_url, Referrer(), | 1077 controller().LoadURL(new_url, Referrer(), |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2122 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count()); | 2121 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count()); |
2123 | 2122 |
2124 contents()->OnFrameDetached(16, 265); | 2123 contents()->OnFrameDetached(16, 265); |
2125 EXPECT_EQ(4UL, root->child_at(2)->child_count()); | 2124 EXPECT_EQ(4UL, root->child_at(2)->child_count()); |
2126 | 2125 |
2127 contents()->OnFrameDetached(5, 15); | 2126 contents()->OnFrameDetached(5, 15); |
2128 EXPECT_EQ(2UL, root->child_count()); | 2127 EXPECT_EQ(2UL, root->child_count()); |
2129 } | 2128 } |
2130 | 2129 |
2131 } // namespace content | 2130 } // namespace content |
OLD | NEW |