Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 1002803002: Classify navigations without page id in parallel to the existing classifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unit tests Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 NavigationEntry* entry = controller().GetPendingEntry();
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->GetUniqueID(), 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
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 NavigationEntry* entry = controller().GetPendingEntry();
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->GetUniqueID(), 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 TestWebContents::Create(browser_context(), NULL)); 429 TestWebContents::Create(browser_context(), NULL));
428 430
429 // Load the two URLs in the second tab. Note that the first navigation creates 431 // Load the two URLs in the second tab. Note that the first navigation creates
430 // a RFH that's not pending (since there is no cross-site transition), so 432 // a RFH that's not pending (since there is no cross-site transition), so
431 // we use the committed one. 433 // we use the committed one.
432 contents2->GetController().LoadURL( 434 contents2->GetController().LoadURL(
433 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 435 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
434 contents2->GetMainFrame()->PrepareForCommit(); 436 contents2->GetMainFrame()->PrepareForCommit();
435 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); 437 TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame();
436 EXPECT_FALSE(contents2->cross_navigation_pending()); 438 EXPECT_FALSE(contents2->cross_navigation_pending());
437 ntp_rfh2->SendNavigate(100, kChromeUrl); 439 ntp_rfh2->SendNavigate(100, 100, true, kChromeUrl);
438 440
439 // The second one is the opposite, creating a cross-site transition and 441 // The second one is the opposite, creating a cross-site transition and
440 // requiring a beforeunload ack. 442 // requiring a beforeunload ack.
441 contents2->GetController().LoadURL( 443 contents2->GetController().LoadURL(
442 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 444 kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
443 contents2->GetMainFrame()->PrepareForCommit(); 445 contents2->GetMainFrame()->PrepareForCommit();
444 EXPECT_TRUE(contents2->cross_navigation_pending()); 446 EXPECT_TRUE(contents2->cross_navigation_pending());
445 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); 447 TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame();
446 ASSERT_TRUE(dest_rfh2); 448 ASSERT_TRUE(dest_rfh2);
447 449
448 dest_rfh2->SendNavigate(101, kDestUrl); 450 dest_rfh2->SendNavigate(101, 101, true, kDestUrl);
449 451
450 // The two RFH's should be different in every way. 452 // The two RFH's should be different in every way.
451 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess()); 453 EXPECT_NE(contents()->GetMainFrame()->GetProcess(), dest_rfh2->GetProcess());
452 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), 454 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(),
453 dest_rfh2->GetSiteInstance()); 455 dest_rfh2->GetSiteInstance());
454 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance( 456 EXPECT_FALSE(dest_rfh2->GetSiteInstance()->IsRelatedSiteInstance(
455 contents()->GetMainFrame()->GetSiteInstance())); 457 contents()->GetMainFrame()->GetSiteInstance()));
456 458
457 // Navigate both to the new tab page, and verify that they share a 459 // Navigate both to the new tab page, and verify that they share a
458 // RenderProcessHost (not a SiteInstance). 460 // RenderProcessHost (not a SiteInstance).
459 NavigateActiveAndCommit(kChromeUrl); 461 NavigateActiveAndCommit(kChromeUrl);
460 EXPECT_FALSE(contents()->GetPendingMainFrame()); 462 EXPECT_FALSE(contents()->GetPendingMainFrame());
461 463
462 contents2->GetController().LoadURL( 464 contents2->GetController().LoadURL(
463 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 465 kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
464 contents2->GetMainFrame()->PrepareForCommit(); 466 contents2->GetMainFrame()->PrepareForCommit();
465 contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); 467 contents2->GetPendingMainFrame()->SendNavigate(102, 102, true, kChromeUrl);
466 468
467 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), 469 EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(),
468 contents2->GetMainFrame()->GetSiteInstance()); 470 contents2->GetMainFrame()->GetSiteInstance());
469 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(), 471 EXPECT_EQ(contents()->GetMainFrame()->GetSiteInstance()->GetProcess(),
470 contents2->GetMainFrame()->GetSiteInstance()->GetProcess()); 472 contents2->GetMainFrame()->GetSiteInstance()->GetProcess());
471 } 473 }
472 474
473 // Ensure that the browser ignores most IPC messages that arrive from a 475 // Ensure that the browser ignores most IPC messages that arrive from a
474 // RenderViewHost that has been swapped out. We do not want to take 476 // RenderViewHost that has been swapped out. We do not want to take
475 // action on requests from a non-active renderer. The main exception is 477 // action on requests from a non-active renderer. The main exception is
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 // navigation will reuse the SiteInstance created by Init(), and the second 790 // navigation will reuse the SiteInstance created by Init(), and the second
789 // one will create a new SiteInstance. Because current_instance and 791 // one will create a new SiteInstance. Because current_instance and
790 // new_instance will be different, a new RenderViewHost will be created for 792 // new_instance will be different, a new RenderViewHost will be created for
791 // the second navigation. We have to avoid this in order to exercise the 793 // the second navigation. We have to avoid this in order to exercise the
792 // target code patch. 794 // target code patch.
793 NavigateActiveAndCommit(kChromeUrl); 795 NavigateActiveAndCommit(kChromeUrl);
794 796
795 // Navigate. 797 // Navigate.
796 controller().LoadURL( 798 controller().LoadURL(
797 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 799 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
800 NavigationEntry* entry = controller().GetPendingEntry();
798 // Simulate response from RenderFrame for DispatchBeforeUnload. 801 // Simulate response from RenderFrame for DispatchBeforeUnload.
799 contents()->GetMainFrame()->PrepareForCommit(); 802 contents()->GetMainFrame()->PrepareForCommit();
800 ASSERT_TRUE(contents()->GetPendingMainFrame()) 803 ASSERT_TRUE(contents()->GetPendingMainFrame())
801 << "Expected new pending RenderFrameHost to be created."; 804 << "Expected new pending RenderFrameHost to be created.";
802 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); 805 RenderFrameHost* last_rfh = contents()->GetPendingMainFrame();
803 int32 new_id = 806 int32 new_id =
804 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1; 807 contents()->GetMaxPageIDForSiteInstance(last_rfh->GetSiteInstance()) + 1;
805 contents()->GetPendingMainFrame()->SendNavigate(new_id, kUrl); 808 contents()->GetPendingMainFrame()->SendNavigate(
809 new_id, entry->GetUniqueID(), true, kUrl);
806 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); 810 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1);
807 ASSERT_TRUE(controller().GetLastCommittedEntry()); 811 ASSERT_TRUE(controller().GetLastCommittedEntry());
808 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); 812 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL());
809 EXPECT_FALSE(controller().GetPendingEntry()); 813 EXPECT_FALSE(controller().GetPendingEntry());
810 // Because we're using TestWebContents and TestRenderViewHost in this 814 // Because we're using TestWebContents and TestRenderViewHost in this
811 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no 815 // unittest, no one calls WebContentsImpl::RenderViewCreated(). So, we see no
812 // EnableViewSourceMode message, here. 816 // EnableViewSourceMode message, here.
813 817
814 // Clear queued messages before load. 818 // Clear queued messages before load.
815 process()->sink().ClearMessages(); 819 process()->sink().ClearMessages();
816 // Navigate, again. 820 // Navigate, again.
817 controller().LoadURL( 821 controller().LoadURL(
818 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 822 kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
823 entry = controller().GetPendingEntry();
819 contents()->GetMainFrame()->PrepareForCommit(); 824 contents()->GetMainFrame()->PrepareForCommit();
820 // The same RenderViewHost should be reused. 825 // The same RenderViewHost should be reused.
821 EXPECT_FALSE(contents()->GetPendingMainFrame()); 826 EXPECT_FALSE(contents()->GetPendingMainFrame());
822 EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); 827 EXPECT_TRUE(last_rfh == contents()->GetMainFrame());
823 // Navigate using the returned page_id. 828 // Navigate using the returned page_id.
824 contents()->GetMainFrame()->SendNavigate(new_id, kUrl); 829 contents()->GetMainFrame()->SendNavigate(
830 new_id, entry->GetUniqueID(), false, kUrl);
825 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); 831 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1);
826 EXPECT_FALSE(controller().GetPendingEntry()); 832 EXPECT_FALSE(controller().GetPendingEntry());
827 // New message should be sent out to make sure to enter view-source mode. 833 // New message should be sent out to make sure to enter view-source mode.
828 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( 834 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching(
829 ViewMsg_EnableViewSourceMode::ID)); 835 ViewMsg_EnableViewSourceMode::ID));
830 } 836 }
831 837
832 // Tests the Init function by checking the initial RenderViewHost. 838 // Tests the Init function by checking the initial RenderViewHost.
833 TEST_F(RenderFrameHostManagerTest, Init) { 839 TEST_F(RenderFrameHostManagerTest, Init) {
834 // Using TestBrowserContext. 840 // Using TestBrowserContext.
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't 1165 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't
1160 // happen, but we have seen it when going back quickly across many entries 1166 // happen, but we have seen it when going back quickly across many entries
1161 // (http://crbug.com/93427). 1167 // (http://crbug.com/93427).
1162 contents()->GetController().GoBack(); 1168 contents()->GetController().GoBack();
1163 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); 1169 EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK());
1164 contents()->GetMainFrame()->PrepareForCommit(); 1170 contents()->GetMainFrame()->PrepareForCommit();
1165 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); 1171 EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK());
1166 1172
1167 // The back navigation commits. 1173 // The back navigation commits.
1168 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); 1174 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
1169 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); 1175 rfh1->SendNavigate(
1176 entry1->GetPageID(), entry1->GetUniqueID(), false, entry1->GetURL());
1170 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK()); 1177 EXPECT_TRUE(rfh2->IsWaitingForUnloadACK());
1171 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state()); 1178 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh2->rfh_state());
1172 1179
1173 // We should be able to navigate forward. 1180 // We should be able to navigate forward.
1174 contents()->GetController().GoForward(); 1181 contents()->GetController().GoForward();
1175 contents()->GetMainFrame()->PrepareForCommit(); 1182 contents()->GetMainFrame()->PrepareForCommit();
1176 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); 1183 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry();
1177 rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); 1184 rfh2->SendNavigate(
1185 entry2->GetPageID(), entry2->GetUniqueID(), false, entry2->GetURL());
1178 EXPECT_EQ(rfh2, main_test_rfh()); 1186 EXPECT_EQ(rfh2, main_test_rfh());
1179 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1187 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1180 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1188 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1181 rfh1->OnSwappedOut(); 1189 rfh1->OnSwappedOut();
1182 EXPECT_TRUE(rfh1->is_swapped_out()); 1190 EXPECT_TRUE(rfh1->is_swapped_out());
1183 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state()); 1191 EXPECT_EQ(RenderFrameHostImpl::STATE_SWAPPED_OUT, rfh1->rfh_state());
1184 } 1192 }
1185 1193
1186 // Test that we create swapped out RFHs for the opener chain when navigating an 1194 // Test that we create swapped out RFHs for the opener chain when navigating an
1187 // opened tab cross-process. This allows us to support certain cross-process 1195 // opened tab cross-process. This allows us to support certain cross-process
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 contents()->GetMainFrame()->PrepareForCommit(); 1354 contents()->GetMainFrame()->PrepareForCommit();
1347 1355
1348 // Disown the opener from rfh2. 1356 // Disown the opener from rfh2.
1349 rfh2->DidDisownOpener(); 1357 rfh2->DidDisownOpener();
1350 1358
1351 // Ensure the opener is cleared. 1359 // Ensure the opener is cleared.
1352 EXPECT_FALSE(contents()->HasOpener()); 1360 EXPECT_FALSE(contents()->HasOpener());
1353 1361
1354 // The back navigation commits. 1362 // The back navigation commits.
1355 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); 1363 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
1356 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); 1364 rfh1->SendNavigate(
1365 entry1->GetPageID(), entry1->GetUniqueID(), false, entry1->GetURL());
1357 1366
1358 // Ensure the opener is still cleared. 1367 // Ensure the opener is still cleared.
1359 EXPECT_FALSE(contents()->HasOpener()); 1368 EXPECT_FALSE(contents()->HasOpener());
1360 } 1369 }
1361 1370
1362 // Test that a page can disown the opener just after a cross-process navigation 1371 // Test that a page can disown the opener just after a cross-process navigation
1363 // commits. 1372 // commits.
1364 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) { 1373 TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) {
1365 const GURL kUrl1("http://www.google.com/"); 1374 const GURL kUrl1("http://www.google.com/");
1366 const GURL kUrl2("http://www.chromium.org/"); 1375 const GURL kUrl2("http://www.chromium.org/");
(...skipping 12 matching lines...) Expand all
1379 // BrowsingInstance). 1388 // BrowsingInstance).
1380 contents()->NavigateAndCommit(kUrl2); 1389 contents()->NavigateAndCommit(kUrl2);
1381 TestRenderFrameHost* rfh2 = main_test_rfh(); 1390 TestRenderFrameHost* rfh2 = main_test_rfh();
1382 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance()); 1391 EXPECT_NE(rfh1->GetSiteInstance(), rfh2->GetSiteInstance());
1383 1392
1384 // Commit a back navigation before the DidDisownOpener message arrives. 1393 // Commit a back navigation before the DidDisownOpener message arrives.
1385 // rfh1 will be kept alive because of the opener tab. 1394 // rfh1 will be kept alive because of the opener tab.
1386 contents()->GetController().GoBack(); 1395 contents()->GetController().GoBack();
1387 contents()->GetMainFrame()->PrepareForCommit(); 1396 contents()->GetMainFrame()->PrepareForCommit();
1388 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); 1397 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
1389 rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); 1398 rfh1->SendNavigate(
1399 entry1->GetPageID(), entry1->GetUniqueID(), false, entry1->GetURL());
1390 1400
1391 // Disown the opener from rfh2. 1401 // Disown the opener from rfh2.
1392 rfh2->DidDisownOpener(); 1402 rfh2->DidDisownOpener();
1393 EXPECT_FALSE(contents()->HasOpener()); 1403 EXPECT_FALSE(contents()->HasOpener());
1394 } 1404 }
1395 1405
1396 // Test that we clean up swapped out RenderViewHosts when a process hosting 1406 // Test that we clean up swapped out RenderViewHosts when a process hosting
1397 // those associated RenderViews crashes. http://crbug.com/258993 1407 // those associated RenderViews crashes. http://crbug.com/258993
1398 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { 1408 TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) {
1399 const GURL kUrl1("http://www.google.com/"); 1409 const GURL kUrl1("http://www.google.com/");
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 1673
1664 // Navigate to the first page. 1674 // Navigate to the first page.
1665 contents()->NavigateAndCommit(kUrl1); 1675 contents()->NavigateAndCommit(kUrl1);
1666 TestRenderFrameHost* rfh1 = contents()->GetMainFrame(); 1676 TestRenderFrameHost* rfh1 = contents()->GetMainFrame();
1667 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); 1677 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1);
1668 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1678 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1669 1679
1670 // Navigate to new site, simulating onbeforeunload approval. 1680 // Navigate to new site, simulating onbeforeunload approval.
1671 controller().LoadURL( 1681 controller().LoadURL(
1672 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1682 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1683 NavigationEntry* entry = controller().GetPendingEntry();
1673 contents()->GetMainFrame()->PrepareForCommit(); 1684 contents()->GetMainFrame()->PrepareForCommit();
1674 EXPECT_TRUE(contents()->cross_navigation_pending()); 1685 EXPECT_TRUE(contents()->cross_navigation_pending());
1675 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1686 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1676 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 1687 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
1677 1688
1678 // Simulate the swap out ack, unexpectedly early (before commit). It should 1689 // Simulate the swap out ack, unexpectedly early (before commit). It should
1679 // have no effect. 1690 // have no effect.
1680 rfh1->OnSwappedOut(); 1691 rfh1->OnSwappedOut();
1681 EXPECT_TRUE(contents()->cross_navigation_pending()); 1692 EXPECT_TRUE(contents()->cross_navigation_pending());
1682 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1693 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1683 1694
1684 // The new page commits. 1695 // The new page commits.
1685 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); 1696 contents()->TestDidNavigate(rfh2, 1, entry->GetUniqueID(), true, kUrl2,
1697 ui::PAGE_TRANSITION_TYPED);
1686 EXPECT_FALSE(contents()->cross_navigation_pending()); 1698 EXPECT_FALSE(contents()->cross_navigation_pending());
1687 EXPECT_EQ(rfh2, contents()->GetMainFrame()); 1699 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1688 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1700 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1689 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1701 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1690 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1702 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1691 EXPECT_TRUE( 1703 EXPECT_TRUE(
1692 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1)); 1704 rfh1->frame_tree_node()->render_manager()->IsPendingDeletion(rfh1));
1693 1705
1694 // Simulate the swap out ack. 1706 // Simulate the swap out ack.
1695 rfh1->OnSwappedOut(); 1707 rfh1->OnSwappedOut();
(...skipping 15 matching lines...) Expand all
1711 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); 1723 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1);
1712 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1724 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1713 1725
1714 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is 1726 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is
1715 // not deleted on swap out. 1727 // not deleted on swap out.
1716 rfh1->GetSiteInstance()->increment_active_frame_count(); 1728 rfh1->GetSiteInstance()->increment_active_frame_count();
1717 1729
1718 // Navigate to new site, simulating onbeforeunload approval. 1730 // Navigate to new site, simulating onbeforeunload approval.
1719 controller().LoadURL( 1731 controller().LoadURL(
1720 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1732 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1733 NavigationEntry* entry = controller().GetPendingEntry();
1721 contents()->GetMainFrame()->PrepareForCommit(); 1734 contents()->GetMainFrame()->PrepareForCommit();
1722 EXPECT_TRUE(contents()->cross_navigation_pending()); 1735 EXPECT_TRUE(contents()->cross_navigation_pending());
1723 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1736 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1724 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 1737 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
1725 1738
1726 // The new page commits. 1739 // The new page commits.
1727 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); 1740 contents()->TestDidNavigate(rfh2, 1, entry->GetUniqueID(), true, kUrl2,
1741 ui::PAGE_TRANSITION_TYPED);
1728 EXPECT_FALSE(contents()->cross_navigation_pending()); 1742 EXPECT_FALSE(contents()->cross_navigation_pending());
1729 EXPECT_EQ(rfh2, contents()->GetMainFrame()); 1743 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1730 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1744 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1731 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1745 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1732 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1746 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1733 1747
1734 // Simulate the swap out ack. 1748 // Simulate the swap out ack.
1735 rfh1->OnSwappedOut(); 1749 rfh1->OnSwappedOut();
1736 1750
1737 // rfh1 should be swapped out. 1751 // rfh1 should be swapped out.
(...skipping 16 matching lines...) Expand all
1754 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1); 1768 RenderFrameHostDeletedObserver rfh_deleted_observer(rfh1);
1755 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 1769 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
1756 1770
1757 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is 1771 // Increment the number of active frames in SiteInstanceImpl so that rfh1 is
1758 // not deleted on swap out. 1772 // not deleted on swap out.
1759 rfh1->GetSiteInstance()->increment_active_frame_count(); 1773 rfh1->GetSiteInstance()->increment_active_frame_count();
1760 1774
1761 // Navigate to new site, simulating onbeforeunload approval. 1775 // Navigate to new site, simulating onbeforeunload approval.
1762 controller().LoadURL( 1776 controller().LoadURL(
1763 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1777 kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1778 NavigationEntry* entry = controller().GetPendingEntry();
1764 rfh1->PrepareForCommit(); 1779 rfh1->PrepareForCommit();
1765 EXPECT_TRUE(contents()->cross_navigation_pending()); 1780 EXPECT_TRUE(contents()->cross_navigation_pending());
1766 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); 1781 TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
1767 1782
1768 // The new page commits. 1783 // The new page commits.
1769 contents()->TestDidNavigate(rfh2, 1, kUrl2, ui::PAGE_TRANSITION_TYPED); 1784 contents()->TestDidNavigate(rfh2, 1, entry->GetUniqueID(), true, kUrl2,
1785 ui::PAGE_TRANSITION_TYPED);
1770 EXPECT_FALSE(contents()->cross_navigation_pending()); 1786 EXPECT_FALSE(contents()->cross_navigation_pending());
1771 EXPECT_EQ(rfh2, contents()->GetMainFrame()); 1787 EXPECT_EQ(rfh2, contents()->GetMainFrame());
1772 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); 1788 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL);
1773 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state()); 1789 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh2->rfh_state());
1774 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state()); 1790 EXPECT_EQ(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT, rfh1->rfh_state());
1775 1791
1776 // Simulate the swap out ack. 1792 // Simulate the swap out ack.
1777 rfh1->OnSwappedOut(); 1793 rfh1->OnSwappedOut();
1778 1794
1779 // rfh1 should be swapped out. 1795 // rfh1 should be swapped out.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 #if 0 1924 #if 0
1909 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. 1925 // TODO(nick): Currently a proxy to the removed frame lingers in the parent.
1910 // Enable this assert below once the proxies to the subframe are correctly 1926 // Enable this assert below once the proxies to the subframe are correctly
1911 // cleaned up after detach. http://crbug.com/444955. 1927 // cleaned up after detach. http://crbug.com/444955.
1912 ASSERT_TRUE(site_instance->HasOneRef()) 1928 ASSERT_TRUE(site_instance->HasOneRef())
1913 << "This SiteInstance should be destroyable now."; 1929 << "This SiteInstance should be destroyable now.";
1914 #endif 1930 #endif
1915 } 1931 }
1916 1932
1917 } // namespace content 1933 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698