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

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

Issue 1496483002: OOPIF: Support session restore by combining/splitting frame PageStates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix remaining tests Created 5 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/bind.h" 5 #include "base/bind.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/frame_host/frame_navigation_entry.h" 8 #include "content/browser/frame_host/frame_navigation_entry.h"
9 #include "content/browser/frame_host/frame_tree.h" 9 #include "content/browser/frame_host/frame_tree.h"
10 #include "content/browser/frame_host/navigation_controller_impl.h" 10 #include "content/browser/frame_host/navigation_controller_impl.h"
(...skipping 2302 matching lines...) Expand 10 before | Expand all | Expand 10 after
2313 EXPECT_EQ(data_url, root->child_at(0)->current_url()); 2313 EXPECT_EQ(data_url, root->child_at(0)->current_url());
2314 2314
2315 EXPECT_EQ(1, controller.GetEntryCount()); 2315 EXPECT_EQ(1, controller.GetEntryCount());
2316 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 2316 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
2317 NavigationEntryImpl* entry1 = controller.GetLastCommittedEntry(); 2317 NavigationEntryImpl* entry1 = controller.GetLastCommittedEntry();
2318 2318
2319 // The entry should have a FrameNavigationEntry for the data subframe. 2319 // The entry should have a FrameNavigationEntry for the data subframe.
2320 ASSERT_EQ(1U, entry1->root_node()->children.size()); 2320 ASSERT_EQ(1U, entry1->root_node()->children.size());
2321 EXPECT_EQ(data_url, entry1->root_node()->children[0]->frame_entry->url()); 2321 EXPECT_EQ(data_url, entry1->root_node()->children[0]->frame_entry->url());
2322 2322
2323 // 2. Navigate the iframe cross-site to a page with a nested iframe. 2323 // 2. Navigate the iframe cross-site.
2324 GURL frame_url_b(embedded_test_server()->GetURL( 2324 GURL frame_url_b(embedded_test_server()->GetURL(
2325 "b.com", "/navigation_controller/simple_page_1.html")); 2325 "b.com", "/navigation_controller/simple_page_1.html"));
2326 { 2326 {
2327 FrameNavigateParamsCapturer capturer(root->child_at(0)); 2327 FrameNavigateParamsCapturer capturer(root->child_at(0));
2328 NavigateFrameToURL(root->child_at(0), frame_url_b); 2328 NavigateFrameToURL(root->child_at(0), frame_url_b);
2329 capturer.Wait(); 2329 capturer.Wait();
2330 } 2330 }
2331 ASSERT_EQ(1U, root->child_count()); 2331 ASSERT_EQ(1U, root->child_count());
2332 EXPECT_EQ(main_url_a, root->current_url()); 2332 EXPECT_EQ(main_url_a, root->current_url());
2333 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); 2333 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 2371 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
2372 EXPECT_EQ(entry2, controller.GetLastCommittedEntry()); 2372 EXPECT_EQ(entry2, controller.GetLastCommittedEntry());
2373 2373
2374 // The entry should have both the stale FrameNavigationEntry with the old 2374 // The entry should have both the stale FrameNavigationEntry with the old
2375 // name and the new FrameNavigationEntry for the fallback navigation. 2375 // name and the new FrameNavigationEntry for the fallback navigation.
2376 ASSERT_EQ(2U, entry2->root_node()->children.size()); 2376 ASSERT_EQ(2U, entry2->root_node()->children.size());
2377 EXPECT_EQ(frame_url_b, entry2->root_node()->children[0]->frame_entry->url()); 2377 EXPECT_EQ(frame_url_b, entry2->root_node()->children[0]->frame_entry->url());
2378 EXPECT_EQ(data_url, entry2->root_node()->children[1]->frame_entry->url()); 2378 EXPECT_EQ(data_url, entry2->root_node()->children[1]->frame_entry->url());
2379 } 2379 }
2380 2380
2381 // Verify that subframes can be restored in a new NavigationController using the
2382 // PageState of an existing NavigationEntry.
2383 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
2384 FrameNavigationEntry_RestoreViaPageState) {
2385 // 1. Start on a page with a data URL iframe.
2386 GURL main_url_a(embedded_test_server()->GetURL(
2387 "a.com", "/navigation_controller/page_with_data_iframe.html"));
2388 GURL data_url("data:text/html,Subframe");
2389 NavigateToURL(shell(), main_url_a);
2390 const NavigationControllerImpl& controller =
2391 static_cast<const NavigationControllerImpl&>(
2392 shell()->web_contents()->GetController());
2393 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
2394 ->GetFrameTree()
2395 ->root();
2396 ASSERT_EQ(1U, root->child_count());
2397 ASSERT_EQ(0U, root->child_at(0)->child_count());
2398 EXPECT_EQ(main_url_a, root->current_url());
2399 EXPECT_EQ(data_url, root->child_at(0)->current_url());
2400
2401 EXPECT_EQ(1, controller.GetEntryCount());
2402 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
2403 NavigationEntryImpl* entry1 = controller.GetLastCommittedEntry();
2404
2405 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2406 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2407 // The entry should have a FrameNavigationEntry for the data subframe.
2408 ASSERT_EQ(1U, entry1->root_node()->children.size());
2409 EXPECT_EQ(data_url, entry1->root_node()->children[0]->frame_entry->url());
2410 } else {
2411 // There are no subframe FrameNavigationEntries by default.
2412 EXPECT_EQ(0U, entry1->root_node()->children.size());
2413 }
2414
2415 // 2. Navigate the iframe cross-site.
2416 GURL frame_url_b(embedded_test_server()->GetURL(
2417 "b.com", "/navigation_controller/simple_page_1.html"));
2418 {
2419 FrameNavigateParamsCapturer capturer(root->child_at(0));
2420 NavigateFrameToURL(root->child_at(0), frame_url_b);
2421 capturer.Wait();
2422 }
2423 ASSERT_EQ(1U, root->child_count());
2424 EXPECT_EQ(main_url_a, root->current_url());
2425 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url());
2426
2427 EXPECT_EQ(2, controller.GetEntryCount());
2428 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
2429 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry();
2430
2431 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2432 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2433 // The entry should have a FrameNavigationEntry for the b.com subframe.
2434 ASSERT_EQ(1U, entry2->root_node()->children.size());
2435 EXPECT_EQ(frame_url_b,
2436 entry2->root_node()->children[0]->frame_entry->url());
2437 } else {
2438 // There are no subframe FrameNavigationEntries by default.
2439 EXPECT_EQ(0U, entry2->root_node()->children.size());
2440 }
2441
2442 // 3. Navigate main frame cross-site, destroying the frames.
2443 GURL main_url_c(embedded_test_server()->GetURL(
2444 "c.com", "/navigation_controller/simple_page_2.html"));
2445 NavigateToURL(shell(), main_url_c);
2446 ASSERT_EQ(0U, root->child_count());
2447 EXPECT_EQ(main_url_c, root->current_url());
2448
2449 EXPECT_EQ(3, controller.GetEntryCount());
2450 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
2451 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry();
2452 EXPECT_EQ(0U, entry3->root_node()->children.size());
2453
2454 // 4. Create a NavigationEntry with the same PageState as |entry2| and verify
2455 // it has the same FrameNavigationEntry structure.
2456 scoped_ptr<NavigationEntryImpl> restored_entry =
2457 NavigationEntryImpl::FromNavigationEntry(
2458 NavigationControllerImpl::CreateNavigationEntry(
2459 main_url_a, Referrer(), ui::PAGE_TRANSITION_RELOAD, false,
2460 std::string(), controller.GetBrowserContext()));
2461 restored_entry->SetPageID(0);
2462 EXPECT_EQ(0U, restored_entry->root_node()->children.size());
2463 restored_entry->SetPageState(entry2->GetPageState());
2464
2465 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2466 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2467 // The entry should have a FrameNavigationEntry for the b.com subframe.
2468 EXPECT_EQ(main_url_a, restored_entry->root_node()->frame_entry->url());
2469 ASSERT_EQ(1U, restored_entry->root_node()->children.size());
2470 EXPECT_EQ(frame_url_b,
2471 restored_entry->root_node()->children[0]->frame_entry->url());
2472 } else {
2473 // There are no subframe FrameNavigationEntries by default.
2474 EXPECT_EQ(0U, restored_entry->root_node()->children.size());
2475 }
2476
2477 // 5. Restore the new entry in a new tab and verify the correct URLs load.
2478 std::vector<scoped_ptr<NavigationEntry>> entries;
2479 entries.push_back(restored_entry.Pass());
2480 Shell* new_shell = Shell::CreateNewWindow(
2481 controller.GetBrowserContext(), GURL::EmptyGURL(), nullptr, gfx::Size());
2482 FrameTreeNode* new_root =
2483 static_cast<WebContentsImpl*>(new_shell->web_contents())
2484 ->GetFrameTree()
2485 ->root();
2486 NavigationControllerImpl& new_controller =
2487 static_cast<NavigationControllerImpl&>(
2488 new_shell->web_contents()->GetController());
2489 new_controller.Restore(
2490 entries.size() - 1,
2491 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries);
2492 ASSERT_EQ(0u, entries.size());
2493 {
2494 TestNavigationObserver restore_observer(new_shell->web_contents());
2495 new_controller.LoadIfNecessary();
2496 restore_observer.Wait();
2497 }
2498 ASSERT_EQ(1U, new_root->child_count());
2499 EXPECT_EQ(main_url_a, new_root->current_url());
2500 EXPECT_EQ(frame_url_b, new_root->child_at(0)->current_url());
2501
2502 EXPECT_EQ(1, new_controller.GetEntryCount());
2503 EXPECT_EQ(0, new_controller.GetLastCommittedEntryIndex());
2504 NavigationEntryImpl* new_entry = new_controller.GetLastCommittedEntry();
2505
2506 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2507 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2508 // The entry should have a FrameNavigationEntry for the b.com subframe.
2509 EXPECT_EQ(main_url_a, new_entry->root_node()->frame_entry->url());
2510 ASSERT_EQ(1U, new_entry->root_node()->children.size());
2511 EXPECT_EQ(frame_url_b,
2512 new_entry->root_node()->children[0]->frame_entry->url());
2513 } else {
2514 // There are no subframe FrameNavigationEntries by default.
2515 EXPECT_EQ(0U, new_entry->root_node()->children.size());
2516 }
2517 }
2518
2381 // Verifies that the |frame_unique_name| is set to the correct frame, so that we 2519 // Verifies that the |frame_unique_name| is set to the correct frame, so that we
2382 // can match subframe FrameNavigationEntries to newly created frames after 2520 // can match subframe FrameNavigationEntries to newly created frames after
2383 // back/forward and restore. 2521 // back/forward and restore.
2384 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 2522 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
2385 FrameNavigationEntry_FrameUniqueName) { 2523 FrameNavigationEntry_FrameUniqueName) {
2386 const NavigationControllerImpl& controller = 2524 const NavigationControllerImpl& controller =
2387 static_cast<const NavigationControllerImpl&>( 2525 static_cast<const NavigationControllerImpl&>(
2388 shell()->web_contents()->GetController()); 2526 shell()->web_contents()->GetController());
2389 2527
2390 // 1. Navigate the main frame. 2528 // 1. Navigate the main frame.
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
2943 EXPECT_EQ(original_url, capturer.all_params()[1].url); 3081 EXPECT_EQ(original_url, capturer.all_params()[1].url);
2944 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); 3082 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL());
2945 } 3083 }
2946 3084
2947 // Make sure the renderer is still alive. 3085 // Make sure the renderer is still alive.
2948 EXPECT_TRUE( 3086 EXPECT_TRUE(
2949 ExecuteScript(shell()->web_contents(), "console.log('Success');")); 3087 ExecuteScript(shell()->web_contents(), "console.log('Success');"));
2950 } 3088 }
2951 3089
2952 } // namespace content 3090 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.cc ('k') | content/browser/frame_host/navigation_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698