OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/frame_host/cross_site_transferring_request.h" | 10 #include "content/browser/frame_host/cross_site_transferring_request.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 void set_should_create_webui(bool should_create_webui) { | 255 void set_should_create_webui(bool should_create_webui) { |
256 factory_.set_should_create_webui(should_create_webui); | 256 factory_.set_should_create_webui(should_create_webui); |
257 } | 257 } |
258 | 258 |
259 void NavigateActiveAndCommit(const GURL& url) { | 259 void NavigateActiveAndCommit(const GURL& url) { |
260 // Note: we navigate the active RenderFrameHost because previous navigations | 260 // Note: we navigate the active RenderFrameHost because previous navigations |
261 // won't have committed yet, so NavigateAndCommit does the wrong thing | 261 // won't have committed yet, so NavigateAndCommit does the wrong thing |
262 // for us. | 262 // for us. |
263 controller().LoadURL( | 263 controller().LoadURL( |
264 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 264 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 265 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
265 | 266 |
266 // Simulate the BeforeUnload_ACK that is received from the current renderer | 267 // Simulate the BeforeUnload_ACK that is received from the current renderer |
267 // for a cross-site navigation. | 268 // for a cross-site navigation. |
268 // PlzNavigate: it is necessary to call PrepareForCommit before getting the | 269 // PlzNavigate: it is necessary to call PrepareForCommit before getting the |
269 // main and the pending frame because when we are trying to navigate to a | 270 // main and the pending frame because when we are trying to navigate to a |
270 // WebUI from a new tab, a RenderFrameHost is created to display it that is | 271 // WebUI from a new tab, a RenderFrameHost is created to display it that is |
271 // committed immediately (since it is a new tab). Therefore the main frame | 272 // committed immediately (since it is a new tab). Therefore the main frame |
272 // is replaced without a pending frame being created, and we don't get the | 273 // is replaced without a pending frame being created, and we don't get the |
273 // right values for the RFH to navigate: we try to use the old one that has | 274 // right values for the RFH to navigate: we try to use the old one that has |
274 // been deleted in the meantime. | 275 // been deleted in the meantime. |
275 contents()->GetMainFrame()->PrepareForCommit(); | 276 contents()->GetMainFrame()->PrepareForCommit(); |
276 | 277 |
277 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); | 278 TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); |
278 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() | 279 TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() |
279 ? contents()->GetPendingMainFrame() | 280 ? contents()->GetPendingMainFrame() |
280 : old_rfh; | 281 : old_rfh; |
281 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); | 282 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, old_rfh->rfh_state()); |
282 | 283 |
283 // Commit the navigation with a new page ID. | 284 // Commit the navigation with a new page ID. |
284 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( | 285 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( |
285 active_rfh->GetSiteInstance()); | 286 active_rfh->GetSiteInstance()); |
286 | 287 |
287 // Use an observer to avoid accessing a deleted renderer later on when the | 288 // Use an observer to avoid accessing a deleted renderer later on when the |
288 // state is being checked. | 289 // state is being checked. |
289 RenderFrameHostDeletedObserver rfh_observer(old_rfh); | 290 RenderFrameHostDeletedObserver rfh_observer(old_rfh); |
290 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); | 291 RenderViewHostDeletedObserver rvh_observer(old_rfh->GetRenderViewHost()); |
291 active_rfh->SendNavigate(max_page_id + 1, url); | 292 active_rfh->SendNavigate(max_page_id + 1, entry_id, true, url); |
292 | 293 |
293 // Make sure that we start to run the unload handler at the time of commit. | 294 // Make sure that we start to run the unload handler at the time of commit. |
294 bool expecting_rfh_shutdown = false; | 295 bool expecting_rfh_shutdown = false; |
295 if (old_rfh != active_rfh && !rfh_observer.deleted()) { | 296 if (old_rfh != active_rfh && !rfh_observer.deleted()) { |
296 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, | 297 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, |
297 old_rfh->rfh_state()); | 298 old_rfh->rfh_state()); |
298 if (!old_rfh->GetSiteInstance()->active_frame_count()) { | 299 if (!old_rfh->GetSiteInstance()->active_frame_count()) { |
299 expecting_rfh_shutdown = true; | 300 expecting_rfh_shutdown = true; |
300 EXPECT_TRUE( | 301 EXPECT_TRUE( |
301 old_rfh->frame_tree_node()->render_manager()->IsPendingDeletion( | 302 old_rfh->frame_tree_node()->render_manager()->IsPendingDeletion( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 const GURL kChromeURL("chrome://foo"); | 345 const GURL kChromeURL("chrome://foo"); |
345 const GURL kDestUrl("http://www.google.com/"); | 346 const GURL kDestUrl("http://www.google.com/"); |
346 | 347 |
347 // Navigate our first tab to a chrome url and then to the destination. | 348 // Navigate our first tab to a chrome url and then to the destination. |
348 NavigateActiveAndCommit(kChromeURL); | 349 NavigateActiveAndCommit(kChromeURL); |
349 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 350 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
350 | 351 |
351 // Navigate to a cross-site URL. | 352 // Navigate to a cross-site URL. |
352 contents()->GetController().LoadURL( | 353 contents()->GetController().LoadURL( |
353 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 354 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 355 int entry_id = contents()->GetController().GetPendingEntry()->GetUniqueID(); |
354 contents()->GetMainFrame()->PrepareForCommit(); | 356 contents()->GetMainFrame()->PrepareForCommit(); |
355 EXPECT_TRUE(contents()->cross_navigation_pending()); | 357 EXPECT_TRUE(contents()->cross_navigation_pending()); |
356 | 358 |
357 // Manually increase the number of active frames in the | 359 // Manually increase the number of active frames in the |
358 // SiteInstance that ntp_rfh belongs to, to prevent it from being | 360 // SiteInstance that ntp_rfh belongs to, to prevent it from being |
359 // destroyed when it gets swapped out. | 361 // destroyed when it gets swapped out. |
360 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); | 362 ntp_rfh->GetSiteInstance()->increment_active_frame_count(); |
361 | 363 |
362 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); | 364 TestRenderFrameHost* dest_rfh = contents()->GetPendingMainFrame(); |
363 CHECK(dest_rfh); | 365 CHECK(dest_rfh); |
364 EXPECT_NE(ntp_rfh, dest_rfh); | 366 EXPECT_NE(ntp_rfh, dest_rfh); |
365 | 367 |
366 // BeforeUnload finishes. | 368 // BeforeUnload finishes. |
367 ntp_rfh->SendBeforeUnloadACK(true); | 369 ntp_rfh->SendBeforeUnloadACK(true); |
368 | 370 |
369 dest_rfh->SendNavigate(101, kDestUrl); | 371 dest_rfh->SendNavigate(101, entry_id, true, kDestUrl); |
370 ntp_rfh->OnSwappedOut(); | 372 ntp_rfh->OnSwappedOut(); |
371 | 373 |
372 EXPECT_TRUE(ntp_rfh->is_swapped_out()); | 374 EXPECT_TRUE(ntp_rfh->is_swapped_out()); |
373 return ntp_rfh; | 375 return ntp_rfh; |
374 } | 376 } |
375 | 377 |
376 // Returns the RenderFrameHost that should be used in the navigation to | 378 // Returns the RenderFrameHost that should be used in the navigation to |
377 // |entry|. | 379 // |entry|. |
378 RenderFrameHostImpl* GetFrameHostForNavigation( | 380 RenderFrameHostImpl* GetFrameHostForNavigation( |
379 RenderFrameHostManager* manager, | 381 RenderFrameHostManager* manager, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 | 444 |
443 // Make a second tab. | 445 // Make a second tab. |
444 scoped_ptr<TestWebContents> contents2( | 446 scoped_ptr<TestWebContents> contents2( |
445 TestWebContents::Create(browser_context(), NULL)); | 447 TestWebContents::Create(browser_context(), NULL)); |
446 | 448 |
447 // Load the two URLs in the second tab. Note that the first navigation creates | 449 // Load the two URLs in the second tab. Note that the first navigation creates |
448 // a RFH that's not pending (since there is no cross-site transition), so | 450 // a RFH that's not pending (since there is no cross-site transition), so |
449 // we use the committed one. | 451 // we use the committed one. |
450 contents2->GetController().LoadURL( | 452 contents2->GetController().LoadURL( |
451 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 453 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 454 int entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID(); |
452 contents2->GetMainFrame()->PrepareForCommit(); | 455 contents2->GetMainFrame()->PrepareForCommit(); |
453 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); | 456 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); |
454 EXPECT_FALSE(contents2->cross_navigation_pending()); | 457 EXPECT_FALSE(contents2->cross_navigation_pending()); |
455 ntp_rfh2->SendNavigate(100, kChromeUrl); | 458 ntp_rfh2->SendNavigate(100, entry_id, true, kChromeUrl); |
456 | 459 |
457 // The second one is the opposite, creating a cross-site transition and | 460 // The second one is the opposite, creating a cross-site transition and |
458 // requiring a beforeunload ack. | 461 // requiring a beforeunload ack. |
459 contents2->GetController().LoadURL( | 462 contents2->GetController().LoadURL( |
460 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 463 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 464 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID(); |
461 contents2->GetMainFrame()->PrepareForCommit(); | 465 contents2->GetMainFrame()->PrepareForCommit(); |
462 EXPECT_TRUE(contents2->cross_navigation_pending()); | 466 EXPECT_TRUE(contents2->cross_navigation_pending()); |
463 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); | 467 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); |
464 ASSERT_TRUE(dest_rfh2); | 468 ASSERT_TRUE(dest_rfh2); |
465 | 469 |
466 dest_rfh2->SendNavigate(101, kDestUrl); | 470 dest_rfh2->SendNavigate(101, entry_id, true, kDestUrl); |
467 | 471 |
468 // The two RFH's should be different in every way. | 472 // The two RFH's should be different in every way. |
469 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); | 473 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); |
470 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 474 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
471 dest_rfh2->GetSiteInstance()); | 475 dest_rfh2->GetSiteInstance()); |
472 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( | 476 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( |
473 contents()->GetMainFrame()->GetSiteInstance())); | 477 contents()->GetMainFrame()->GetSiteInstance())); |
474 | 478 |
475 // Navigate both to the new tab page, and verify that they share a | 479 // Navigate both to the new tab page, and verify that they share a |
476 // RenderProcessHost (not a SiteInstance). | 480 // RenderProcessHost (not a SiteInstance). |
477 NavigateActiveAndCommit(kChromeUrl); | 481 NavigateActiveAndCommit(kChromeUrl); |
478 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 482 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
479 | 483 |
480 contents2->GetController().LoadURL( | 484 contents2->GetController().LoadURL( |
481 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 485 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 486 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID(); |
482 contents2->GetMainFrame()->PrepareForCommit(); | 487 contents2->GetMainFrame()->PrepareForCommit(); |
483 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); | 488 contents2->GetPendingMainFrame()->SendNavigate(102, entry_id, true, |
| 489 kChromeUrl); |
484 | 490 |
485 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), | 491 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), |
486 contents2->GetMainFrame()->GetSiteInstance()); | 492 contents2->GetMainFrame()->GetSiteInstance()); |
487 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), | 493 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), |
488 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); | 494 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); |
489 } | 495 } |
490 | 496 |
491 // Ensure that the browser ignores most IPC messages that arrive from a | 497 // Ensure that the browser ignores most IPC messages that arrive from a |
492 // RenderViewHost that has been swapped out. We do not want to take | 498 // RenderViewHost that has been swapped out. We do not want to take |
493 // action on requests from a non-active renderer. The main exception is | 499 // action on requests from a non-active renderer. The main exception is |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 // navigation will reuse the SiteInstance created by Init(), and the second | 812 // navigation will reuse the SiteInstance created by Init(), and the second |
807 // one will create a new SiteInstance. Because current_instance and | 813 // one will create a new SiteInstance. Because current_instance and |
808 // new_instance will be different, a new RenderViewHost will be created for | 814 // new_instance will be different, a new RenderViewHost will be created for |
809 // the second navigation. We have to avoid this in order to exercise the | 815 // the second navigation. We have to avoid this in order to exercise the |
810 // target code patch. | 816 // target code patch. |
811 NavigateActiveAndCommit(kChromeUrl); | 817 NavigateActiveAndCommit(kChromeUrl); |
812 | 818 |
813 // Navigate. | 819 // Navigate. |
814 controller().LoadURL( | 820 controller().LoadURL( |
815 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 821 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 822 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
816 // Simulate response from RenderFrame for DispatchBeforeUnload. | 823 // Simulate response from RenderFrame for DispatchBeforeUnload. |
817 contents()->GetMainFrame()->PrepareForCommit(); | 824 contents()->GetMainFrame()->PrepareForCommit(); |
818 ASSERT_TRUE(contents()->GetPendingMainFrame()) | 825 ASSERT_TRUE(contents()->GetPendingMainFrame()) |
819 << "Expected new pending RenderFrameHost to be created."; | 826 << "Expected new pending RenderFrameHost to be created."; |
820 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); | 827 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); |
821 int32 new_id = | 828 int32 new_id = |
822 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; | 829 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; |
823 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); | 830 contents()->GetPendingMainFrame()->SendNavigate(new_id, entry_id, true, kUrl); |
824 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 831 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
825 ASSERT_TRUE(controller().GetLastCommittedEntry()); | 832 ASSERT_TRUE(controller().GetLastCommittedEntry()); |
826 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); | 833 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); |
827 EXPECT_FALSE(controller().GetPendingEntry()); | 834 EXPECT_FALSE(controller().GetPendingEntry()); |
828 // Because we're using TestWebContents and TestRenderViewHost in this | 835 // Because we're using TestWebContents and TestRenderViewHost in this |
829 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no | 836 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no |
830 // EnableViewSourceMode message, here. | 837 // EnableViewSourceMode message, here. |
831 | 838 |
832 // Clear queued messages before load. | 839 // Clear queued messages before load. |
833 process()->sink().ClearMessages(); | 840 process()->sink().ClearMessages(); |
834 // Navigate, again. | 841 // Navigate, again. |
835 controller().LoadURL( | 842 controller().LoadURL( |
836 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 843 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 844 entry_id = controller().GetPendingEntry()->GetUniqueID(); |
837 contents()->GetMainFrame()->PrepareForCommit(); | 845 contents()->GetMainFrame()->PrepareForCommit(); |
838 // The same RenderViewHost should be reused. | 846 // The same RenderViewHost should be reused. |
839 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 847 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
840 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); | 848 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); |
841 // Navigate using the returned page_id. | 849 // Navigate using the returned page_id. |
842 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); | 850 contents()->GetMainFrame()->SendNavigate(new_id, entry_id, false, kUrl); |
843 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 851 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
844 EXPECT_FALSE(controller().GetPendingEntry()); | 852 EXPECT_FALSE(controller().GetPendingEntry()); |
845 // New message should be sent out to make sure to enter view-source mode. | 853 // New message should be sent out to make sure to enter view-source mode. |
846 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( | 854 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( |
847 ViewMsg_EnableViewSourceMode::ID)); | 855 ViewMsg_EnableViewSourceMode::ID)); |
848 } | 856 } |
849 | 857 |
850 // Tests the Init function by checking the initial RenderViewHost. | 858 // Tests the Init function by checking the initial RenderViewHost. |
851 TEST_F(RenderFrameHostManagerTest, Init) { | 859 TEST_F(RenderFrameHostManagerTest, Init) { |
852 // Using TestBrowserContext. | 860 // Using TestBrowserContext. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 contents()->GetMainFrame()->PrepareForCommit(); | 1105 contents()->GetMainFrame()->PrepareForCommit(); |
1098 // We should have a new pending RFH. | 1106 // We should have a new pending RFH. |
1099 // Note that in this case, the navigation has not committed, so evil_rfh will | 1107 // Note that in this case, the navigation has not committed, so evil_rfh will |
1100 // not be deleted yet. | 1108 // not be deleted yet. |
1101 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); | 1109 EXPECT_NE(evil_rfh, contents()->GetPendingMainFrame()); |
1102 EXPECT_NE(evil_rfh->GetRenderViewHost(), | 1110 EXPECT_NE(evil_rfh->GetRenderViewHost(), |
1103 contents()->GetPendingMainFrame()->GetRenderViewHost()); | 1111 contents()->GetPendingMainFrame()->GetRenderViewHost()); |
1104 | 1112 |
1105 // Before that RFH has committed, the evil page reloads itself. | 1113 // Before that RFH has committed, the evil page reloads itself. |
1106 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1114 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1107 params.page_id = 1; | 1115 params.page_id = 0; |
| 1116 params.nav_entry_id = 0; |
| 1117 params.did_create_new_entry = false; |
1108 params.url = kUrl2; | 1118 params.url = kUrl2; |
1109 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 1119 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
1110 params.should_update_history = false; | 1120 params.should_update_history = false; |
1111 params.gesture = NavigationGestureAuto; | 1121 params.gesture = NavigationGestureAuto; |
1112 params.was_within_same_page = false; | 1122 params.was_within_same_page = false; |
1113 params.is_post = false; | 1123 params.is_post = false; |
1114 params.page_state = PageState::CreateFromURL(kUrl2); | 1124 params.page_state = PageState::CreateFromURL(kUrl2); |
1115 | 1125 |
1116 contents()->GetFrameTree()->root()->navigator()->DidNavigate(evil_rfh, | 1126 contents()->GetFrameTree()->root()->navigator()->DidNavigate(evil_rfh, |
1117 params); | 1127 params); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't | 1187 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't |
1178 // happen, but we have seen it when going back quickly across many entries | 1188 // happen, but we have seen it when going back quickly across many entries |
1179 // (http://crbug.com/93427). | 1189 // (http://crbug.com/93427). |
1180 contents()->GetController().GoBack(); | 1190 contents()->GetController().GoBack(); |
1181 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); | 1191 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); |
1182 contents()->GetMainFrame()->PrepareForCommit(); | 1192 contents()->GetMainFrame()->PrepareForCommit(); |
1183 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); | 1193 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); |
1184 | 1194 |
1185 // The back navigation commits. | 1195 // The back navigation commits. |
1186 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1196 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1187 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1197 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetUniqueID(), false, |
| 1198 entry1->GetURL()); |
1188 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); | 1199 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); |
1189 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); | 1200 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); |
1190 | 1201 |
1191 // We should be able to navigate forward. | 1202 // We should be able to navigate forward. |
1192 contents()->GetController().GoForward(); | 1203 contents()->GetController().GoForward(); |
1193 contents()->GetMainFrame()->PrepareForCommit(); | 1204 contents()->GetMainFrame()->PrepareForCommit(); |
1194 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 1205 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
1195 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 1206 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetUniqueID(), false, |
| 1207 entry2->GetURL()); |
1196 EXPECT_EQ(rfh2, main_test_rfh()); | 1208 EXPECT_EQ(rfh2, main_test_rfh()); |
1197 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1209 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1198 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1210 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1199 rfh1->OnSwappedOut(); | 1211 rfh1->OnSwappedOut(); |
1200 EXPECT_TRUE(rfh1->is_swapped_out()); | 1212 EXPECT_TRUE(rfh1->is_swapped_out()); |
1201 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); | 1213 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); |
1202 } | 1214 } |
1203 | 1215 |
1204 // Test that we create swapped out RFHs for the opener chain when navigating an | 1216 // Test that we create swapped out RFHs for the opener chain when navigating an |
1205 // opened tab cross-process. This allows us to support certain cross-process | 1217 // opened tab cross-process. This allows us to support certain cross-process |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 contents()->GetMainFrame()->PrepareForCommit(); | 1376 contents()->GetMainFrame()->PrepareForCommit(); |
1365 | 1377 |
1366 // Disown the opener from rfh2. | 1378 // Disown the opener from rfh2. |
1367 rfh2->DidDisownOpener(); | 1379 rfh2->DidDisownOpener(); |
1368 | 1380 |
1369 // Ensure the opener is cleared. | 1381 // Ensure the opener is cleared. |
1370 EXPECT_FALSE(contents()->HasOpener()); | 1382 EXPECT_FALSE(contents()->HasOpener()); |
1371 | 1383 |
1372 // The back navigation commits. | 1384 // The back navigation commits. |
1373 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1385 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1374 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1386 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetUniqueID(), false, |
| 1387 entry1->GetURL()); |
1375 | 1388 |
1376 // Ensure the opener is still cleared. | 1389 // Ensure the opener is still cleared. |
1377 EXPECT_FALSE(contents()->HasOpener()); | 1390 EXPECT_FALSE(contents()->HasOpener()); |
1378 } | 1391 } |
1379 | 1392 |
1380 // Test that a page can disown the opener just after a cross-process navigation | 1393 // Test that a page can disown the opener just after a cross-process navigation |
1381 // commits. | 1394 // commits. |
1382 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) { | 1395 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) { |
1383 const GURL kUrl1("http://www.google.com/"); | 1396 const GURL kUrl1("http://www.google.com/"); |
1384 const GURL kUrl2("http://www.chromium.org/"); | 1397 const GURL kUrl2("http://www.chromium.org/"); |
(...skipping 12 matching lines...) Expand all Loading... |
1397 // BrowsingInstance). | 1410 // BrowsingInstance). |
1398 contents()->NavigateAndCommit(kUrl2); | 1411 contents()->NavigateAndCommit(kUrl2); |
1399 TestRenderFrameHost* rfh2 = main_test_rfh(); | 1412 TestRenderFrameHost* rfh2 = main_test_rfh(); |
1400 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); | 1413 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); |
1401 | 1414 |
1402 // Commit a back navigation before the DidDisownOpener message arrives. | 1415 // Commit a back navigation before the DidDisownOpener message arrives. |
1403 // rfh1 will be kept alive because of the opener tab. | 1416 // rfh1 will be kept alive because of the opener tab. |
1404 contents()->GetController().GoBack(); | 1417 contents()->GetController().GoBack(); |
1405 contents()->GetMainFrame()->PrepareForCommit(); | 1418 contents()->GetMainFrame()->PrepareForCommit(); |
1406 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 1419 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
1407 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 1420 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetUniqueID(), false, |
| 1421 entry1->GetURL()); |
1408 | 1422 |
1409 // Disown the opener from rfh2. | 1423 // Disown the opener from rfh2. |
1410 rfh2->DidDisownOpener(); | 1424 rfh2->DidDisownOpener(); |
1411 EXPECT_FALSE(contents()->HasOpener()); | 1425 EXPECT_FALSE(contents()->HasOpener()); |
1412 } | 1426 } |
1413 | 1427 |
1414 // Test that we clean up swapped out RenderViewHosts when a process hosting | 1428 // Test that we clean up swapped out RenderViewHosts when a process hosting |
1415 // those associated RenderViews crashes. http://crbug.com/258993 | 1429 // those associated RenderViews crashes. http://crbug.com/258993 |
1416 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { | 1430 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { |
1417 const GURL kUrl1("http://www.google.com/"); | 1431 const GURL kUrl1("http://www.google.com/"); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 | 1685 |
1672 // Navigate to the first page. | 1686 // Navigate to the first page. |
1673 contents()->NavigateAndCommit(kUrl1); | 1687 contents()->NavigateAndCommit(kUrl1); |
1674 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); | 1688 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); |
1675 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1689 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1676 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1690 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1677 | 1691 |
1678 // Navigate to new site, simulating onbeforeunload approval. | 1692 // Navigate to new site, simulating onbeforeunload approval. |
1679 controller().LoadURL( | 1693 controller().LoadURL( |
1680 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1694 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1695 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
1681 contents()->GetMainFrame()->PrepareForCommit(); | 1696 contents()->GetMainFrame()->PrepareForCommit(); |
1682 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1697 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1683 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1698 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1684 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1699 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1685 | 1700 |
1686 // Simulate the swap out ack, unexpectedly early (before commit). It should | 1701 // Simulate the swap out ack, unexpectedly early (before commit). It should |
1687 // have no effect. | 1702 // have no effect. |
1688 rfh1->OnSwappedOut(); | 1703 rfh1->OnSwappedOut(); |
1689 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1704 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1690 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1705 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1691 | 1706 |
1692 // The new page commits. | 1707 // The new page commits. |
1693 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1708 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, |
| 1709 ui::PAGE_TRANSITION_TYPED); |
1694 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1710 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1695 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1711 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1696 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1712 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1697 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1713 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1698 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1714 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1699 EXPECT_TRUE( | 1715 EXPECT_TRUE( |
1700 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); | 1716 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); |
1701 | 1717 |
1702 // Simulate the swap out ack. | 1718 // Simulate the swap out ack. |
1703 rfh1->OnSwappedOut(); | 1719 rfh1->OnSwappedOut(); |
(...skipping 15 matching lines...) Expand all Loading... |
1719 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1735 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1720 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1736 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1721 | 1737 |
1722 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1738 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1723 // not deleted on swap out. | 1739 // not deleted on swap out. |
1724 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1740 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1725 | 1741 |
1726 // Navigate to new site, simulating onbeforeunload approval. | 1742 // Navigate to new site, simulating onbeforeunload approval. |
1727 controller().LoadURL( | 1743 controller().LoadURL( |
1728 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1744 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1745 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
1729 contents()->GetMainFrame()->PrepareForCommit(); | 1746 contents()->GetMainFrame()->PrepareForCommit(); |
1730 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1747 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1731 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1748 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1732 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1749 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1733 | 1750 |
1734 // The new page commits. | 1751 // The new page commits. |
1735 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1752 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, |
| 1753 ui::PAGE_TRANSITION_TYPED); |
1736 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1754 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1737 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1755 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1738 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1756 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1739 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1757 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1740 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1758 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1741 | 1759 |
1742 // Simulate the swap out ack. | 1760 // Simulate the swap out ack. |
1743 rfh1->OnSwappedOut(); | 1761 rfh1->OnSwappedOut(); |
1744 | 1762 |
1745 // rfh1 should be swapped out. | 1763 // rfh1 should be swapped out. |
(...skipping 16 matching lines...) Expand all Loading... |
1762 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); | 1780 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); |
1763 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); | 1781 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); |
1764 | 1782 |
1765 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is | 1783 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is |
1766 // not deleted on swap out. | 1784 // not deleted on swap out. |
1767 rfh1->GetSiteInstance()->increment_active_frame_count(); | 1785 rfh1->GetSiteInstance()->increment_active_frame_count(); |
1768 | 1786 |
1769 // Navigate to new site, simulating onbeforeunload approval. | 1787 // Navigate to new site, simulating onbeforeunload approval. |
1770 controller().LoadURL( | 1788 controller().LoadURL( |
1771 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1789 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1790 int entry_id = controller().GetPendingEntry()->GetUniqueID(); |
1772 rfh1->PrepareForCommit(); | 1791 rfh1->PrepareForCommit(); |
1773 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1792 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1774 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); | 1793 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); |
1775 | 1794 |
1776 // The new page commits. | 1795 // The new page commits. |
1777 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); | 1796 contents()->TestDidNavigate(rfh2, 1, entry_id, true, kUrl2, |
| 1797 ui::PAGE_TRANSITION_TYPED); |
1778 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1798 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1779 EXPECT_EQ(rfh2, contents()->GetMainFrame()); | 1799 EXPECT_EQ(rfh2, contents()->GetMainFrame()); |
1780 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1800 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1781 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); | 1801 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); |
1782 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); | 1802 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); |
1783 | 1803 |
1784 // Simulate the swap out ack. | 1804 // Simulate the swap out ack. |
1785 rfh1->OnSwappedOut(); | 1805 rfh1->OnSwappedOut(); |
1786 | 1806 |
1787 // rfh1 should be swapped out. | 1807 // rfh1 should be swapped out. |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2018 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2038 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2019 contents2->NavigateAndCommit(kUrl3); | 2039 contents2->NavigateAndCommit(kUrl3); |
2020 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2040 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2021 EXPECT_NE(nullptr, | 2041 EXPECT_NE(nullptr, |
2022 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); | 2042 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); |
2023 EXPECT_EQ(nullptr, | 2043 EXPECT_EQ(nullptr, |
2024 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); | 2044 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); |
2025 } | 2045 } |
2026 | 2046 |
2027 } // namespace content | 2047 } // namespace content |
OLD | NEW |