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

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

Issue 2309583002: Fix for the NavigationControllerTest.BackSubframe test failures with PlzNavigate (Closed)
Patch Set: Set document_sequence_number correctly and use the same strategy like Blink to generate these numbe… Created 4 years, 3 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
« no previous file with comments | « no previous file | content/public/common/page_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (message_loop_runner_.get()) 126 if (message_loop_runner_.get())
127 message_loop_runner_->Quit(); 127 message_loop_runner_->Quit();
128 } 128 }
129 129
130 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 130 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
131 bool encoding_screenshot_in_progress_; 131 bool encoding_screenshot_in_progress_;
132 132
133 DISALLOW_COPY_AND_ASSIGN(MockScreenshotManager); 133 DISALLOW_COPY_AND_ASSIGN(MockScreenshotManager);
134 }; 134 };
135 135
136 int64_t GenerateSequenceNumber() {
137 // Based on how Blink generates sequence numbers.
138 static int64_t next_number = base::Time::Now().ToDoubleT() * 1000000;
139 return ++next_number;
140 }
141
136 } // namespace 142 } // namespace
137 143
138 namespace content { 144 namespace content {
139 145
140 // TimeSmoother tests ---------------------------------------------------------- 146 // TimeSmoother tests ----------------------------------------------------------
141 147
142 // With no duplicates, GetSmoothedTime should be the identity 148 // With no duplicates, GetSmoothedTime should be the identity
143 // function. 149 // function.
144 TEST(TimeSmoother, Basic) { 150 TEST(TimeSmoother, Basic) {
145 NavigationControllerImpl::TimeSmoother smoother; 151 NavigationControllerImpl::TimeSmoother smoother;
(...skipping 2306 matching lines...) Expand 10 before | Expand all | Expand 10 after
2452 std::string unique_name("uniqueName0"); 2458 std::string unique_name("uniqueName0");
2453 main_test_rfh()->OnCreateChildFrame( 2459 main_test_rfh()->OnCreateChildFrame(
2454 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document, 2460 process()->GetNextRoutingID(), blink::WebTreeScopeType::Document,
2455 std::string(), unique_name, blink::WebSandboxFlags::None, 2461 std::string(), unique_name, blink::WebSandboxFlags::None,
2456 FrameOwnerProperties()); 2462 FrameOwnerProperties());
2457 TestRenderFrameHost* subframe = static_cast<TestRenderFrameHost*>( 2463 TestRenderFrameHost* subframe = static_cast<TestRenderFrameHost*>(
2458 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host()); 2464 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host());
2459 const GURL subframe_url("http://foo1/subframe"); 2465 const GURL subframe_url("http://foo1/subframe");
2460 2466
2461 // Compute the sequence number assigned by Blink. 2467 // Compute the sequence number assigned by Blink.
2462 int64_t item_sequence_number1 = base::Time::Now().ToDoubleT() * 1000000; 2468 int64_t item_sequence_number1 = GenerateSequenceNumber();
2469 int64_t document_sequence_number1 = GenerateSequenceNumber();
2463 2470
2464 { 2471 {
2465 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2472 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2466 params.page_id = 1; 2473 params.page_id = 1;
2467 params.nav_entry_id = 0; 2474 params.nav_entry_id = 0;
2468 params.frame_unique_name = unique_name; 2475 params.frame_unique_name = unique_name;
2469 params.did_create_new_entry = false; 2476 params.did_create_new_entry = false;
2470 params.url = subframe_url; 2477 params.url = subframe_url;
2471 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2478 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2472 params.should_update_history = false; 2479 params.should_update_history = false;
2473 params.gesture = NavigationGestureUser; 2480 params.gesture = NavigationGestureUser;
2474 params.method = "GET"; 2481 params.method = "GET";
2475 params.page_state = PageState::CreateFromURL(subframe_url); 2482 params.page_state = PageState::CreateForTestingWithSequenceNumbers(
2483 subframe_url, item_sequence_number1, document_sequence_number1);
2476 params.item_sequence_number = item_sequence_number1; 2484 params.item_sequence_number = item_sequence_number1;
2485 params.document_sequence_number = document_sequence_number1;
2477 2486
2478 // Navigating should do nothing. 2487 // Navigating should do nothing.
2479 subframe->SendRendererInitiatedNavigationRequest(subframe_url, false); 2488 subframe->SendRendererInitiatedNavigationRequest(subframe_url, false);
2480 subframe->PrepareForCommit(); 2489 subframe->PrepareForCommit();
2481 subframe->SendNavigateWithParams(&params); 2490 subframe->SendNavigateWithParams(&params);
2482 2491
2483 // In UseSubframeNavigationEntries mode, we notify of a PageState update to 2492 // In UseSubframeNavigationEntries mode, we notify of a PageState update to
2484 // the entry here rather than during UpdateState. 2493 // the entry here rather than during UpdateState.
2485 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) 2494 if (SiteIsolationPolicy::UseSubframeNavigationEntries())
2486 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_CHANGED)); 2495 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_ENTRY_CHANGED));
2487 else 2496 else
2488 EXPECT_EQ(0U, notifications.size()); 2497 EXPECT_EQ(0U, notifications.size());
2489 } 2498 }
2490 2499
2491 // First manual subframe navigation. 2500 // First manual subframe navigation.
2492 const GURL url2("http://foo2"); 2501 const GURL url2("http://foo2");
2493 int64_t item_sequence_number2 = base::Time::Now().ToDoubleT() * 1000000; 2502 int64_t item_sequence_number2 = GenerateSequenceNumber();
2503 int64_t document_sequence_number2 = GenerateSequenceNumber();
2494 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2504 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2495 params.page_id = 2; 2505 params.page_id = 2;
2496 params.nav_entry_id = 0; 2506 params.nav_entry_id = 0;
2497 params.frame_unique_name = unique_name; 2507 params.frame_unique_name = unique_name;
2498 params.did_create_new_entry = true; 2508 params.did_create_new_entry = true;
2499 params.url = url2; 2509 params.url = url2;
2500 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2510 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2501 params.should_update_history = false; 2511 params.should_update_history = false;
2502 params.gesture = NavigationGestureUser; 2512 params.gesture = NavigationGestureUser;
2503 params.method = "GET"; 2513 params.method = "GET";
2504 params.page_state = PageState::CreateFromURL(url2); 2514 params.page_state = PageState::CreateForTestingWithSequenceNumbers(
2515 url2, item_sequence_number2, document_sequence_number2);
2505 params.item_sequence_number = item_sequence_number2; 2516 params.item_sequence_number = item_sequence_number2;
2517 params.document_sequence_number = document_sequence_number2;
2506 2518
2507 // This should generate a new entry. 2519 // This should generate a new entry.
2508 subframe->SendRendererInitiatedNavigationRequest(url2, false); 2520 subframe->SendRendererInitiatedNavigationRequest(url2, false);
2509 subframe->PrepareForCommit(); 2521 subframe->PrepareForCommit();
2510 subframe->SendNavigateWithParams(&params); 2522 subframe->SendNavigateWithParams(&params);
2511 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); 2523 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry();
2512 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2524 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2513 navigation_entry_committed_counter_ = 0; 2525 navigation_entry_committed_counter_ = 0;
2514 EXPECT_EQ(2, controller.GetEntryCount()); 2526 EXPECT_EQ(2, controller.GetEntryCount());
2515 2527
2516 // Verify subframe entries if they're enabled (e.g. in --site-per-process). 2528 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2517 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 2529 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2518 // The entry should have a subframe FrameNavigationEntry. 2530 // The entry should have a subframe FrameNavigationEntry.
2519 ASSERT_EQ(1U, entry2->root_node()->children.size()); 2531 ASSERT_EQ(1U, entry2->root_node()->children.size());
2520 EXPECT_EQ(url2, entry2->root_node()->children[0]->frame_entry->url()); 2532 EXPECT_EQ(url2, entry2->root_node()->children[0]->frame_entry->url());
2521 } else { 2533 } else {
2522 // There are no subframe FrameNavigationEntries by default. 2534 // There are no subframe FrameNavigationEntries by default.
2523 EXPECT_EQ(0U, entry2->root_node()->children.size()); 2535 EXPECT_EQ(0U, entry2->root_node()->children.size());
2524 } 2536 }
2525 2537
2526 2538
2527 // Second manual subframe navigation should also make a new entry. 2539 // Second manual subframe navigation should also make a new entry.
2528 const GURL url3("http://foo3"); 2540 const GURL url3("http://foo3");
2541 int64_t item_sequence_number3 = GenerateSequenceNumber();
2542 int64_t document_sequence_number3 = GenerateSequenceNumber();
2529 params.page_id = 3; 2543 params.page_id = 3;
2530 params.nav_entry_id = 0; 2544 params.nav_entry_id = 0;
2531 params.frame_unique_name = unique_name; 2545 params.frame_unique_name = unique_name;
2532 params.did_create_new_entry = true; 2546 params.did_create_new_entry = true;
2533 params.url = url3; 2547 params.url = url3;
2534 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2548 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2535 params.page_state = PageState::CreateFromURL(url3); 2549 params.item_sequence_number = item_sequence_number3;
2536 params.item_sequence_number = base::Time::Now().ToDoubleT() * 1000000; 2550 params.document_sequence_number = document_sequence_number3;
2551 params.page_state = PageState::CreateForTestingWithSequenceNumbers(
2552 url3, item_sequence_number3, document_sequence_number3);
2537 subframe->SendRendererInitiatedNavigationRequest(url3, false); 2553 subframe->SendRendererInitiatedNavigationRequest(url3, false);
2538 subframe->PrepareForCommit(); 2554 subframe->PrepareForCommit();
2539 subframe->SendNavigateWithParams(&params); 2555 subframe->SendNavigateWithParams(&params);
2540 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2556 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2541 navigation_entry_committed_counter_ = 0; 2557 navigation_entry_committed_counter_ = 0;
2542 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry(); 2558 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry();
2543 EXPECT_EQ(3, controller.GetEntryCount()); 2559 EXPECT_EQ(3, controller.GetEntryCount());
2544 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2560 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2545 2561
2546 // Verify subframe entries if they're enabled (e.g. in --site-per-process). 2562 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2547 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 2563 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2548 // The entry should have a subframe FrameNavigationEntry. 2564 // The entry should have a subframe FrameNavigationEntry.
2549 ASSERT_EQ(1U, entry3->root_node()->children.size()); 2565 ASSERT_EQ(1U, entry3->root_node()->children.size());
2550 EXPECT_EQ(url3, entry3->root_node()->children[0]->frame_entry->url()); 2566 EXPECT_EQ(url3, entry3->root_node()->children[0]->frame_entry->url());
2551 } else { 2567 } else {
2552 // There are no subframe FrameNavigationEntries by default. 2568 // There are no subframe FrameNavigationEntries by default.
2553 EXPECT_EQ(0U, entry3->root_node()->children.size()); 2569 EXPECT_EQ(0U, entry3->root_node()->children.size());
2554 } 2570 }
2555 2571
2556 // Go back one. 2572 // Go back one.
2557 controller.GoBack(); 2573 controller.GoBack();
2558 params.page_id = 2; 2574 params.page_id = 2;
2559 params.nav_entry_id = entry2->GetUniqueID(); 2575 params.nav_entry_id = entry2->GetUniqueID();
2560 params.frame_unique_name = unique_name; 2576 params.frame_unique_name = unique_name;
2561 params.did_create_new_entry = false; 2577 params.did_create_new_entry = false;
2562 params.url = url2; 2578 params.url = url2;
2563 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2579 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2564 params.page_state = PageState::CreateFromURL(url2); 2580 params.page_state = PageState::CreateForTestingWithSequenceNumbers(
2581 url2, item_sequence_number2, document_sequence_number2);
2565 params.item_sequence_number = item_sequence_number2; 2582 params.item_sequence_number = item_sequence_number2;
2583 params.document_sequence_number = document_sequence_number2;
2566 subframe->PrepareForCommit(); 2584 subframe->PrepareForCommit();
2567 subframe->SendNavigateWithParams(&params); 2585 subframe->SendNavigateWithParams(&params);
2568 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2586 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2569 navigation_entry_committed_counter_ = 0; 2587 navigation_entry_committed_counter_ = 0;
2570 EXPECT_EQ(entry2, controller.GetLastCommittedEntry()); 2588 EXPECT_EQ(entry2, controller.GetLastCommittedEntry());
2571 EXPECT_EQ(3, controller.GetEntryCount()); 2589 EXPECT_EQ(3, controller.GetEntryCount());
2572 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2590 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2573 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2591 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2574 EXPECT_FALSE(controller.GetPendingEntry()); 2592 EXPECT_FALSE(controller.GetPendingEntry());
2575 2593
2576 // Go back one more. 2594 // Go back one more.
2577 controller.GoBack(); 2595 controller.GoBack();
2578 params.page_id = 1; 2596 params.page_id = 1;
2579 params.nav_entry_id = entry1->GetUniqueID(); 2597 params.nav_entry_id = entry1->GetUniqueID();
2580 params.frame_unique_name = unique_name; 2598 params.frame_unique_name = unique_name;
2581 params.did_create_new_entry = false; 2599 params.did_create_new_entry = false;
2582 params.url = subframe_url; 2600 params.url = subframe_url;
2583 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2601 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2584 params.page_state = PageState::CreateFromURL(subframe_url); 2602 params.page_state = PageState::CreateForTestingWithSequenceNumbers(
2603 subframe_url, item_sequence_number1, document_sequence_number1);
2585 params.item_sequence_number = item_sequence_number1; 2604 params.item_sequence_number = item_sequence_number1;
2605 params.document_sequence_number = document_sequence_number1;
2586 subframe->PrepareForCommit(); 2606 subframe->PrepareForCommit();
2587 subframe->SendNavigateWithParams(&params); 2607 subframe->SendNavigateWithParams(&params);
2588 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2608 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2589 navigation_entry_committed_counter_ = 0; 2609 navigation_entry_committed_counter_ = 0;
2590 EXPECT_EQ(entry1, controller.GetLastCommittedEntry()); 2610 EXPECT_EQ(entry1, controller.GetLastCommittedEntry());
2591 EXPECT_EQ(3, controller.GetEntryCount()); 2611 EXPECT_EQ(3, controller.GetEntryCount());
2592 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2612 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2593 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2613 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2594 EXPECT_FALSE(controller.GetPendingEntry()); 2614 EXPECT_FALSE(controller.GetPendingEntry());
2595 } 2615 }
(...skipping 2722 matching lines...) Expand 10 before | Expand all | Expand 10 after
5318 // means that occasionally a navigation conflict will end up with one entry 5338 // means that occasionally a navigation conflict will end up with one entry
5319 // bubbling to the end of the entry list, but that's the least-bad option. 5339 // bubbling to the end of the entry list, but that's the least-bad option.
5320 EXPECT_EQ(3, controller.GetEntryCount()); 5340 EXPECT_EQ(3, controller.GetEntryCount());
5321 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 5341 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
5322 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); 5342 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL());
5323 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); 5343 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL());
5324 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); 5344 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL());
5325 } 5345 }
5326 5346
5327 } // namespace content 5347 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/public/common/page_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698