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