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