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 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 // Create another NavigationController. | 1937 // Create another NavigationController. |
1938 GURL url3("http://foo2"); | 1938 GURL url3("http://foo2"); |
1939 scoped_ptr<TestWebContents> other_contents( | 1939 scoped_ptr<TestWebContents> other_contents( |
1940 static_cast<TestWebContents*>(CreateTestWebContents())); | 1940 static_cast<TestWebContents*>(CreateTestWebContents())); |
1941 NavigationControllerImpl& other_controller = other_contents->GetController(); | 1941 NavigationControllerImpl& other_controller = other_contents->GetController(); |
1942 other_contents->NavigateAndCommit(url3); | 1942 other_contents->NavigateAndCommit(url3); |
1943 other_contents->ExpectSetHistoryLengthAndPrune( | 1943 other_contents->ExpectSetHistoryLengthAndPrune( |
1944 NavigationEntryImpl::FromNavigationEntry( | 1944 NavigationEntryImpl::FromNavigationEntry( |
1945 other_controller.GetEntryAtIndex(0))->site_instance(), 1, | 1945 other_controller.GetEntryAtIndex(0))->site_instance(), 1, |
1946 other_controller.GetEntryAtIndex(0)->GetPageID()); | 1946 other_controller.GetEntryAtIndex(0)->GetPageID()); |
1947 other_controller.CopyStateFromAndPrune(&controller()); | 1947 EXPECT_TRUE(other_controller.CopyStateFromAndPrune(&controller())); |
1948 | 1948 |
1949 // The merged controller should only have two entries: url1 and url2. | 1949 // The merged controller should only have two entries: url1 and url2. |
1950 ASSERT_EQ(2, other_controller.GetEntryCount()); | 1950 ASSERT_EQ(2, other_controller.GetEntryCount()); |
1951 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); | 1951 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); |
1952 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 1952 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
1953 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); | 1953 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); |
1954 | 1954 |
1955 // And the merged controller shouldn't be showing an interstitial. | 1955 // And the merged controller shouldn't be showing an interstitial. |
1956 EXPECT_FALSE(other_contents->ShowingInterstitialPage()); | 1956 EXPECT_FALSE(other_contents->ShowingInterstitialPage()); |
1957 } | 1957 } |
1958 | 1958 |
1959 // Makes sure that CopyStateFromAndPrune does the right thing if the object | 1959 // Makes sure that CopyStateFromAndPrune cannot be called if the target is |
1960 // CopyStateFromAndPrune is invoked on is showing an interstitial. | 1960 // showing an interstitial. |
1961 TEST_F(WebContentsImplTest, CopyStateFromAndPruneTargetInterstitial) { | 1961 TEST_F(WebContentsImplTest, CopyStateFromAndPruneTargetInterstitial) { |
1962 // Navigate to a page. | 1962 // Navigate to a page. |
1963 GURL url1("http://www.google.com"); | 1963 GURL url1("http://www.google.com"); |
1964 contents()->NavigateAndCommit(url1); | 1964 contents()->NavigateAndCommit(url1); |
1965 | 1965 |
1966 // Create another NavigationController. | 1966 // Create another NavigationController. |
1967 scoped_ptr<TestWebContents> other_contents( | 1967 scoped_ptr<TestWebContents> other_contents( |
1968 static_cast<TestWebContents*>(CreateTestWebContents())); | 1968 static_cast<TestWebContents*>(CreateTestWebContents())); |
1969 NavigationControllerImpl& other_controller = other_contents->GetController(); | 1969 NavigationControllerImpl& other_controller = other_contents->GetController(); |
1970 | 1970 |
1971 // Navigate it to url2. | 1971 // Navigate it to url2. |
1972 GURL url2("http://foo2"); | 1972 GURL url2("http://foo2"); |
1973 other_contents->NavigateAndCommit(url2); | 1973 other_contents->NavigateAndCommit(url2); |
1974 | 1974 |
1975 // Show an interstitial. | 1975 // Show an interstitial. |
1976 TestInterstitialPage::InterstitialState state = | 1976 TestInterstitialPage::InterstitialState state = |
1977 TestInterstitialPage::INVALID; | 1977 TestInterstitialPage::INVALID; |
1978 bool deleted = false; | 1978 bool deleted = false; |
1979 GURL url3("http://interstitial"); | 1979 GURL url3("http://interstitial"); |
1980 TestInterstitialPage* interstitial = | 1980 TestInterstitialPage* interstitial = |
1981 new TestInterstitialPage(other_contents.get(), true, url3, &state, | 1981 new TestInterstitialPage(other_contents.get(), true, url3, &state, |
1982 &deleted); | 1982 &deleted); |
1983 TestInterstitialPageStateGuard state_guard(interstitial); | 1983 TestInterstitialPageStateGuard state_guard(interstitial); |
1984 interstitial->Show(); | 1984 interstitial->Show(); |
1985 interstitial->TestDidNavigate(1, url3); | 1985 interstitial->TestDidNavigate(1, url3); |
1986 EXPECT_TRUE(interstitial->is_showing()); | 1986 EXPECT_TRUE(interstitial->is_showing()); |
1987 EXPECT_EQ(2, other_controller.GetEntryCount()); | 1987 EXPECT_EQ(2, other_controller.GetEntryCount()); |
1988 other_contents->ExpectSetHistoryLengthAndPrune( | |
1989 NavigationEntryImpl::FromNavigationEntry( | |
1990 other_controller.GetEntryAtIndex(0))->site_instance(), 1, | |
1991 other_controller.GetEntryAtIndex(0)->GetPageID()); | |
1992 other_controller.CopyStateFromAndPrune(&controller()); | |
1993 | 1988 |
1994 // The merged controller should only have two entries: url1 and url2. | 1989 // Ensure that we do not allow calling CopyStateFromAndPrune when an |
1995 ASSERT_EQ(2, other_controller.GetEntryCount()); | 1990 // interstitial is showing in the target. |
1996 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); | 1991 EXPECT_FALSE(other_controller.CanPruneAllButVisible()); |
1997 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | |
1998 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); | |
1999 | |
2000 // It should have a transient entry. | |
2001 EXPECT_TRUE(other_controller.GetTransientEntry()); | |
2002 | |
2003 // And the interstitial should be showing. | |
2004 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); | |
2005 | |
2006 // And the interstitial should do a reload on don't proceed. | |
2007 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( | |
2008 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); | |
2009 } | 1992 } |
2010 | 1993 |
2011 // Regression test for http://crbug.com/168611 - the URLs passed by the | 1994 // Regression test for http://crbug.com/168611 - the URLs passed by the |
2012 // DidFinishLoad and DidFailLoadWithError IPCs should get filtered. | 1995 // DidFinishLoad and DidFailLoadWithError IPCs should get filtered. |
2013 TEST_F(WebContentsImplTest, FilterURLs) { | 1996 TEST_F(WebContentsImplTest, FilterURLs) { |
2014 TestWebContentsObserver observer(contents()); | 1997 TestWebContentsObserver observer(contents()); |
2015 | 1998 |
2016 // A navigation to about:whatever should always look like a navigation to | 1999 // A navigation to about:whatever should always look like a navigation to |
2017 // about:blank | 2000 // about:blank |
2018 GURL url_normalized("about:blank"); | 2001 GURL url_normalized("about:blank"); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count()); | 2106 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count()); |
2124 | 2107 |
2125 contents()->OnFrameDetached(16, 265); | 2108 contents()->OnFrameDetached(16, 265); |
2126 EXPECT_EQ(4UL, root->child_at(2)->child_count()); | 2109 EXPECT_EQ(4UL, root->child_at(2)->child_count()); |
2127 | 2110 |
2128 contents()->OnFrameDetached(5, 15); | 2111 contents()->OnFrameDetached(5, 15); |
2129 EXPECT_EQ(2UL, root->child_count()); | 2112 EXPECT_EQ(2UL, root->child_count()); |
2130 } | 2113 } |
2131 | 2114 |
2132 } // namespace content | 2115 } // namespace content |
OLD | NEW |