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 <stdint.h> | 5 #include <stdint.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2208 interstitial_rfh, url2, std::vector<GURL>(), base::TimeTicks::Now()); | 2208 interstitial_rfh, url2, std::vector<GURL>(), base::TimeTicks::Now()); |
2209 EXPECT_FALSE(deleted); | 2209 EXPECT_FALSE(deleted); |
2210 | 2210 |
2211 // Simulate a commit in the interstitial page, which should also not crash. | 2211 // Simulate a commit in the interstitial page, which should also not crash. |
2212 interstitial_rfh->SimulateNavigationCommit(url2); | 2212 interstitial_rfh->SimulateNavigationCommit(url2); |
2213 | 2213 |
2214 RunAllPendingInMessageLoop(); | 2214 RunAllPendingInMessageLoop(); |
2215 EXPECT_TRUE(deleted); | 2215 EXPECT_TRUE(deleted); |
2216 } | 2216 } |
2217 | 2217 |
| 2218 // Test for https://crbug.com/703655, where navigating a tab and showing an |
| 2219 // interstitial could race. |
| 2220 TEST_F(WebContentsImplTest, TabNavigationDoesntRaceInterstitial) { |
| 2221 // Navigate to a page. |
| 2222 GURL url1("http://www.google.com"); |
| 2223 main_test_rfh()->NavigateAndCommitRendererInitiated(true, url1); |
| 2224 EXPECT_EQ(1, controller().GetEntryCount()); |
| 2225 |
| 2226 // Initiate a browser navigation that will trigger an interstitial. |
| 2227 GURL evil_url("http://www.evil.com"); |
| 2228 controller().LoadURL(evil_url, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 2229 std::string()); |
| 2230 NavigationEntry* entry = contents()->GetController().GetPendingEntry(); |
| 2231 ASSERT_TRUE(entry); |
| 2232 EXPECT_EQ(evil_url, entry->GetURL()); |
| 2233 |
| 2234 // Show an interstitial. |
| 2235 TestInterstitialPage::InterstitialState state = TestInterstitialPage::INVALID; |
| 2236 bool deleted = false; |
| 2237 GURL url2("http://interstitial"); |
| 2238 TestInterstitialPage* interstitial = |
| 2239 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
| 2240 TestInterstitialPageStateGuard state_guard(interstitial); |
| 2241 interstitial->Show(); |
| 2242 // The interstitial should not show until its navigation has committed. |
| 2243 EXPECT_FALSE(interstitial->is_showing()); |
| 2244 EXPECT_FALSE(contents()->ShowingInterstitialPage()); |
| 2245 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); |
| 2246 |
| 2247 // At this point, there is an interstitial that has been instructed to show |
| 2248 // but has not yet committed its own navigation. This is a window; navigate |
| 2249 // back one page within this window. |
| 2250 // |
| 2251 // Because the page with the interstitial did not commit, this invokes an |
| 2252 // early return in NavigationControllerImpl::NavigateToPendingEntry which just |
| 2253 // drops the pending entry, so no committing is required. |
| 2254 controller().GoBack(); |
| 2255 entry = contents()->GetController().GetPendingEntry(); |
| 2256 ASSERT_FALSE(entry); |
| 2257 |
| 2258 // The interstitial should be gone. |
| 2259 RunAllPendingInMessageLoop(); |
| 2260 EXPECT_TRUE(deleted); |
| 2261 } |
| 2262 |
2218 // Test that after Proceed is called and an interstitial is still shown, no more | 2263 // Test that after Proceed is called and an interstitial is still shown, no more |
2219 // commands get executed. | 2264 // commands get executed. |
2220 TEST_F(WebContentsImplTest, ShowInterstitialProceedMultipleCommands) { | 2265 TEST_F(WebContentsImplTest, ShowInterstitialProceedMultipleCommands) { |
2221 // Navigate to a page so we have a navigation entry in the controller. | 2266 // Navigate to a page so we have a navigation entry in the controller. |
2222 GURL url1("http://www.google.com"); | 2267 GURL url1("http://www.google.com"); |
2223 main_test_rfh()->NavigateAndCommitRendererInitiated(true, url1); | 2268 main_test_rfh()->NavigateAndCommitRendererInitiated(true, url1); |
2224 EXPECT_EQ(1, controller().GetEntryCount()); | 2269 EXPECT_EQ(1, controller().GetEntryCount()); |
2225 | 2270 |
2226 // Show an interstitial. | 2271 // Show an interstitial. |
2227 TestInterstitialPage::InterstitialState state = | 2272 TestInterstitialPage::InterstitialState state = |
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3490 // An automatic navigation. | 3535 // An automatic navigation. |
3491 main_test_rfh()->SendNavigateWithModificationCallback( | 3536 main_test_rfh()->SendNavigateWithModificationCallback( |
3492 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); | 3537 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); |
3493 | 3538 |
3494 EXPECT_EQ(1u, dialog_manager.reset_count()); | 3539 EXPECT_EQ(1u, dialog_manager.reset_count()); |
3495 | 3540 |
3496 contents()->SetJavaScriptDialogManagerForTesting(nullptr); | 3541 contents()->SetJavaScriptDialogManagerForTesting(nullptr); |
3497 } | 3542 } |
3498 | 3543 |
3499 } // namespace content | 3544 } // namespace content |
OLD | NEW |