| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/render_view_host.h" | 6 #include "chrome/browser/renderer_host/render_view_host.h" |
| 7 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 8 #include "chrome/browser/renderer_host/test_render_view_host.h" | 8 #include "chrome/browser/renderer_host/test_render_view_host.h" |
| 9 #include "chrome/browser/tab_contents/interstitial_page.h" | 9 #include "chrome/browser/tab_contents/interstitial_page.h" |
| 10 #include "chrome/browser/tab_contents/navigation_controller.h" | 10 #include "chrome/browser/tab_contents/navigation_controller.h" |
| (...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 | 984 |
| 985 EXPECT_TRUE(deleted2); | 985 EXPECT_TRUE(deleted2); |
| 986 EXPECT_FALSE(contents()->showing_interstitial_page()); | 986 EXPECT_FALSE(contents()->showing_interstitial_page()); |
| 987 EXPECT_TRUE(contents()->interstitial_page() == NULL); | 987 EXPECT_TRUE(contents()->interstitial_page() == NULL); |
| 988 NavigationEntry* entry = controller()->GetActiveEntry(); | 988 NavigationEntry* entry = controller()->GetActiveEntry(); |
| 989 ASSERT_TRUE(entry != NULL); | 989 ASSERT_TRUE(entry != NULL); |
| 990 EXPECT_TRUE(entry->url() == landing_url); | 990 EXPECT_TRUE(entry->url() == landing_url); |
| 991 EXPECT_EQ(2, controller()->GetEntryCount()); | 991 EXPECT_EQ(2, controller()->GetEntryCount()); |
| 992 } | 992 } |
| 993 | 993 |
| 994 // Test showing an interstitial, proceeding and then navigating to another |
| 995 // interstitial. |
| 996 TEST_F(WebContentsTest, ShowInterstitialProceedShowInterstitial) { |
| 997 // Navigate to a page so we have a navigation entry in the controller. |
| 998 GURL start_url("http://www.google.com"); |
| 999 rvh()->SendNavigate(1, start_url); |
| 1000 EXPECT_EQ(1, controller()->GetEntryCount()); |
| 1001 |
| 1002 // Show an interstitial. |
| 1003 TestInterstitialPage::InterstitialState state1 = |
| 1004 TestInterstitialPage::UNDECIDED; |
| 1005 bool deleted1 = false; |
| 1006 GURL url1("http://interstitial1"); |
| 1007 TestInterstitialPage* interstitial1 = |
| 1008 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1); |
| 1009 TestInterstitialPageStateGuard state_guard1(interstitial1); |
| 1010 interstitial1->Show(); |
| 1011 interstitial1->TestDidNavigate(1, url1); |
| 1012 |
| 1013 // Take action. The interstitial won't be hidden until the navigation is |
| 1014 // committed. |
| 1015 interstitial1->Proceed(); |
| 1016 EXPECT_EQ(TestInterstitialPage::OKED, state1); |
| 1017 |
| 1018 // Now show another interstitial (simulating the navigation causing another |
| 1019 // interstitial). |
| 1020 TestInterstitialPage::InterstitialState state2 = |
| 1021 TestInterstitialPage::UNDECIDED; |
| 1022 bool deleted2 = false; |
| 1023 GURL url2("http://interstitial2"); |
| 1024 TestInterstitialPage* interstitial2 = |
| 1025 new TestInterstitialPage(contents(), true, url2, &state2, &deleted2); |
| 1026 TestInterstitialPageStateGuard state_guard2(interstitial2); |
| 1027 interstitial2->Show(); |
| 1028 interstitial2->TestDidNavigate(1, url2); |
| 1029 |
| 1030 // Showing interstitial2 should have caused interstitial1 to go away. |
| 1031 EXPECT_TRUE(deleted1); |
| 1032 |
| 1033 // Let's make sure interstitial2 is working as intended. |
| 1034 ASSERT_FALSE(deleted2); |
| 1035 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); |
| 1036 interstitial2->Proceed(); |
| 1037 GURL landing_url("http://www.thepage.com"); |
| 1038 rvh()->SendNavigate(2, landing_url); |
| 1039 |
| 1040 EXPECT_TRUE(deleted2); |
| 1041 EXPECT_FALSE(contents()->showing_interstitial_page()); |
| 1042 EXPECT_TRUE(contents()->interstitial_page() == NULL); |
| 1043 NavigationEntry* entry = controller()->GetActiveEntry(); |
| 1044 ASSERT_TRUE(entry != NULL); |
| 1045 EXPECT_TRUE(entry->url() == landing_url); |
| 1046 EXPECT_EQ(2, controller()->GetEntryCount()); |
| 1047 } |
| 1048 |
| 994 // Test that navigating away from an interstitial while it's loading cause it | 1049 // Test that navigating away from an interstitial while it's loading cause it |
| 995 // not to show. | 1050 // not to show. |
| 996 TEST_F(WebContentsTest, NavigateBeforeInterstitialShows) { | 1051 TEST_F(WebContentsTest, NavigateBeforeInterstitialShows) { |
| 997 // Show an interstitial. | 1052 // Show an interstitial. |
| 998 TestInterstitialPage::InterstitialState state = | 1053 TestInterstitialPage::InterstitialState state = |
| 999 TestInterstitialPage::UNDECIDED; | 1054 TestInterstitialPage::UNDECIDED; |
| 1000 bool deleted = false; | 1055 bool deleted = false; |
| 1001 GURL interstitial_url("http://interstitial"); | 1056 GURL interstitial_url("http://interstitial"); |
| 1002 TestInterstitialPage* interstitial = | 1057 TestInterstitialPage* interstitial = |
| 1003 new TestInterstitialPage(contents(), true, interstitial_url, | 1058 new TestInterstitialPage(contents(), true, interstitial_url, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 interstitial = | 1096 interstitial = |
| 1042 new TestInterstitialPage(contents(), true, url, &state, &deleted); | 1097 new TestInterstitialPage(contents(), true, url, &state, &deleted); |
| 1043 interstitial->Show(); | 1098 interstitial->Show(); |
| 1044 interstitial->TestDidNavigate(1, url); | 1099 interstitial->TestDidNavigate(1, url); |
| 1045 // Simulate a renderer crash. | 1100 // Simulate a renderer crash. |
| 1046 interstitial->TestRenderViewGone(); | 1101 interstitial->TestRenderViewGone(); |
| 1047 // The interstitial should have been dismissed. | 1102 // The interstitial should have been dismissed. |
| 1048 EXPECT_TRUE(deleted); | 1103 EXPECT_TRUE(deleted); |
| 1049 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1104 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1050 } | 1105 } |
| OLD | NEW |