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

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

Issue 2191543003: Remove existing FrameNavigationEntry when new named frame is added. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New implementation of FNE clearing. More work needed. Created 4 years, 4 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 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 "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 5379 matching lines...) Expand 10 before | Expand all | Expand 10 after
5390 // the body of the page. 5390 // the body of the page.
5391 std::string body; 5391 std::string body;
5392 EXPECT_TRUE(ExecuteScriptAndExtractString( 5392 EXPECT_TRUE(ExecuteScriptAndExtractString(
5393 shell()->web_contents(), 5393 shell()->web_contents(),
5394 "window.domAutomationController.send(" 5394 "window.domAutomationController.send("
5395 "document.getElementsByTagName('pre')[0].innerText);", 5395 "document.getElementsByTagName('pre')[0].innerText);",
5396 &body)); 5396 &body));
5397 EXPECT_EQ("text=value\n", body); 5397 EXPECT_EQ("text=value\n", body);
5398 } 5398 }
5399 5399
5400 // Tests that sending a PageState update from a named subframe does not get
5401 // incorrectly set on previously existing FrameNavigationEntry for the same
5402 // name. See https://crbug.com/628677.
5403 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, PageStateMismatch) {
5404 WebContentsImpl* web_contents =
5405 static_cast<WebContentsImpl*>(shell()->web_contents());
5406 FrameTreeNode* root = web_contents->GetFrameTree()->root();
5407
5408 GURL start_url(embedded_test_server()->GetURL("/title1.html"));
5409 EXPECT_TRUE(NavigateToURL(shell(), start_url));
5410
5411 std::string add_named_frame_script =
5412 "var f = document.createElement('iframe');"
5413 "f.name = 'foo';"
5414 "document.body.appendChild(f);";
5415 EXPECT_TRUE(ExecuteScript(root, add_named_frame_script));
5416 EXPECT_EQ(1U, root->child_count());
5417 EXPECT_EQ("foo", root->child_at(0)->frame_name());
5418
5419 std::string remove_frame_script =
5420 "var f = document.querySelector('iframe');"
5421 "f.parentNode.removeChild(f);";
5422 EXPECT_TRUE(ExecuteScript(root, remove_frame_script));
5423 EXPECT_EQ(0U, root->child_count());
5424
5425 std::string add_frame_script =
5426 "var f = document.createElement('iframe');"
5427 "document.body.appendChild(f);";
5428 EXPECT_TRUE(ExecuteScript(root, add_frame_script));
5429 EXPECT_EQ(1U, root->child_count());
5430 EXPECT_NE("foo", root->child_at(0)->frame_name());
5431
5432 // Add a nested frame with the previously used name.
5433 EXPECT_TRUE(ExecuteScript(root->child_at(0), add_named_frame_script));
5434 EXPECT_EQ(1U, root->child_at(0)->child_count());
5435 EXPECT_EQ("foo", root->child_at(0)->child_at(0)->frame_name());
5436
5437 EXPECT_TRUE(ExecuteScript(root->child_at(0), remove_frame_script));
5438 EXPECT_EQ(0U, root->child_at(0)->child_count());
5439 }
5440
5441 // Tests that inserting a named subframe into the FrameTree clears any
5442 // previously existing FrameNavigationEntry objects for the same name.
5443 // See https://crbug.com/628677.
5444 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
5445 EnsureFrameNavigationEntriesClearedOnNameConflict) {
5446 WebContentsImpl* web_contents =
5447 static_cast<WebContentsImpl*>(shell()->web_contents());
5448 NavigationControllerImpl& controller = web_contents->GetController();
5449 FrameTreeNode* root = web_contents->GetFrameTree()->root();
5450
5451 // Start by navigating to a page with complex frame hierarchy.
5452 GURL start_url(embedded_test_server()->GetURL("/frame_tree/top.html"));
5453 EXPECT_TRUE(NavigateToURL(shell(), start_url));
5454 EXPECT_EQ(3U, root->child_count());
5455 EXPECT_EQ(2U, root->child_at(0)->child_count());
5456
5457 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
5458
5459 // Verify only the parts of the NavigationEntry affected by this test.
5460 {
5461 // * Main frame has 3 subframes.
5462 FrameNavigationEntry* root_entry = entry->GetFrameEntry(root);
5463 EXPECT_NE(nullptr, root_entry);
5464 EXPECT_EQ("", root_entry->frame_unique_name());
5465 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
5466 EXPECT_EQ(3U, entry->root_node()->children.size());
5467
5468 // * The first child of the main frame is named and has two more children.
5469 FrameTreeNode* frame = root->child_at(0);
5470 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame);
5471 EXPECT_NE(nullptr, frame_entry);
5472 EXPECT_EQ("1-1-name", frame_entry->frame_unique_name());
5473 EXPECT_EQ(2U, entry->root_node()->children[0]->children.size());
5474 }
5475 }
5476
5477 // Removing the first child of the main frame should remove the corresponding
5478 // FrameTreeNode.
5479 std::string remove_frame_script =
5480 "var f = document.getElementById('1-1-id');"
5481 "f.parentNode.removeChild(f);";
5482 EXPECT_TRUE(ExecuteScript(root, remove_frame_script));
5483 EXPECT_EQ(2U, root->child_count());
5484
5485 // However, the FrameNavigationEntry objects for the frame that was removed
5486 // should still be around.
5487 {
5488 FrameNavigationEntry* root_entry = entry->GetFrameEntry(root);
5489 EXPECT_NE(nullptr, root_entry);
5490 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
5491 EXPECT_EQ(3U, entry->root_node()->children.size());
5492 EXPECT_EQ(2U, entry->root_node()->children[0]->children.size());
5493 }
5494 }
5495
5496 // Now, insert a frame with the same name as the previously removed one
5497 // at a different layer of the frame tree.
5498 FrameTreeNode* subframe = root->child_at(1)->child_at(1)->child_at(0);
5499 EXPECT_EQ(2U, root->child_at(1)->child_count());
5500 EXPECT_EQ(0U, subframe->child_count());
5501 std::string add_named_frame_script =
5502 "var f = document.createElement('iframe');"
5503 "f.name = '1-1-name';"
5504 "document.body.appendChild(f);";
5505 EXPECT_TRUE(ExecuteScript(subframe, add_named_frame_script));
5506 EXPECT_EQ(1U, subframe->child_count());
5507
5508 // Verify that the FrameNavigationEntry for the original frame is now gone.
5509 {
5510 FrameNavigationEntry* root_entry = entry->GetFrameEntry(root);
5511 EXPECT_NE(nullptr, root_entry);
5512 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
5513 EXPECT_EQ(2U, entry->root_node()->children.size());
5514 }
5515 }
5516 }
5517
5400 } // namespace content 5518 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698