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

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: 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 // TODO(nasko): Move this to NavigationControllerBrowserTest once the default
5404 // for UseSubframeNavigationEntries is set to true.
Charlie Reis 2016/07/27 22:48:27 Interesting. I've just been making them normal te
nasko 2016/07/29 15:52:21 Sure. Makes sense. I was trying to ensure they run
5405 IN_PROC_BROWSER_TEST_F(NavigationControllerOopifBrowserTest,
5406 PageStateMismatch) {
5407 WebContentsImpl* web_contents =
5408 static_cast<WebContentsImpl*>(shell()->web_contents());
5409 FrameTreeNode* root = web_contents->GetFrameTree()->root();
5410
5411 GURL start_url(embedded_test_server()->GetURL("/title1.html"));
5412 EXPECT_TRUE(NavigateToURL(shell(), start_url));
5413
5414 std::string add_named_frame_script =
5415 "var f = document.createElement('iframe');"
5416 "f.name = 'foo';"
5417 "document.body.appendChild(f);";
5418 EXPECT_TRUE(ExecuteScript(root, add_named_frame_script));
5419 EXPECT_EQ(1U, root->child_count());
5420 EXPECT_EQ("foo", root->child_at(0)->frame_name());
5421
5422 std::string remove_frame_script =
5423 "var f = document.querySelector('iframe');"
5424 "f.parentNode.removeChild(f);";
5425 EXPECT_TRUE(ExecuteScript(root, remove_frame_script));
5426 EXPECT_EQ(0U, root->child_count());
Charlie Reis 2016/07/27 22:48:27 Can you add an expectation after this that we stil
nasko 2016/07/29 15:52:21 Done.
5427
5428 std::string add_frame_script =
5429 "var f = document.createElement('iframe');"
5430 "document.body.appendChild(f);";
5431 EXPECT_TRUE(ExecuteScript(root, add_frame_script));
5432 EXPECT_EQ(1U, root->child_count());
5433 EXPECT_NE("foo", root->child_at(0)->frame_name());
5434
5435 EXPECT_TRUE(ExecuteScript(root->child_at(0), add_named_frame_script));
Charlie Reis 2016/07/27 22:48:27 // Add a nested frame with the previously used nam
nasko 2016/07/29 15:52:19 Done.
5436 EXPECT_EQ(1U, root->child_at(0)->child_count());
5437 EXPECT_EQ("foo", root->child_at(0)->child_at(0)->frame_name());
Charlie Reis 2016/07/27 22:48:27 Let's verify the tree of FrameNavigationEntries he
nasko 2016/07/29 15:52:21 Done.
5438
5439 EXPECT_TRUE(ExecuteScript(root->child_at(0), remove_frame_script));
5440 EXPECT_EQ(0U, root->child_at(0)->child_count());
Charlie Reis 2016/07/27 22:48:27 I assume this crashed due to your NOTREACHED?
nasko 2016/07/29 15:52:19 Indeed!
5441 }
5442
5443 // Tests that inserting a named subframe into the FrameTree clears any
5444 // previously existing FrameNavigationEntry objects for the same name.
5445 // See https://crbug.com/628677.
5446 // TODO(nasko): Move this to NavigationControllerBrowserTest once the default
5447 // for UseSubframeNavigationEntries is set to true.
5448 IN_PROC_BROWSER_TEST_F(NavigationControllerOopifBrowserTest,
5449 EnsureFrameNavigationEntriesClearedOnNameConflict) {
Charlie Reis 2016/07/27 22:48:27 This seems better documented than the one above, a
nasko 2016/07/29 15:52:20 This one actually navigates the iframes to real UR
Charlie Reis 2016/07/29 17:21:35 Ah, that didn't come across from the comments or t
nasko 2016/08/01 20:42:15 Reordered and renamed to match a bit better.
Charlie Reis 2016/08/01 21:04:25 Yes. I'm curious how that works out, since I'd lo
5450 WebContentsImpl* web_contents =
5451 static_cast<WebContentsImpl*>(shell()->web_contents());
5452 NavigationControllerImpl& controller = web_contents->GetController();
5453 FrameTreeNode* root = web_contents->GetFrameTree()->root();
5454
5455 // Start by navigating to a page with complex frame hierarchy.
5456 GURL start_url(embedded_test_server()->GetURL("/frame_tree/top.html"));
5457 EXPECT_TRUE(NavigateToURL(shell(), start_url));
5458 EXPECT_EQ(3U, root->child_count());
5459 EXPECT_EQ(2U, root->child_at(0)->child_count());
5460
5461 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
5462
5463 // Verify only the parts of the NavigationEntry affected by this test.
5464 {
5465 // * Main frame has 3 subframes.
5466 FrameNavigationEntry* root_entry = entry->GetFrameEntry(root);
5467 EXPECT_NE(nullptr, root_entry);
5468 EXPECT_EQ("", root_entry->frame_unique_name());
5469 EXPECT_EQ(3U, entry->root_node()->children.size());
5470
5471 // * The first child of the main frame is named and has two more children.
5472 FrameTreeNode* frame = root->child_at(0);
5473 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame);
5474 EXPECT_NE(nullptr, frame_entry);
5475 EXPECT_EQ("1-1-name", frame_entry->frame_unique_name());
5476 EXPECT_EQ(2U, entry->root_node()->children[0]->children.size());
5477 }
5478
5479 // Removing the first child of the main frame should remove the corresponding
5480 // FrameTreeNode.
5481 std::string remove_frame_script =
5482 "var f = document.getElementById('1-1-id');"
5483 "f.parentNode.removeChild(f);";
5484 EXPECT_TRUE(ExecuteScript(root, remove_frame_script));
5485 EXPECT_EQ(2U, root->child_count());
5486
5487 // However, the FrameNavigationEntry objects for the frame that was removed
5488 // should still be around.
5489 {
5490 FrameNavigationEntry* root_entry = entry->GetFrameEntry(root);
5491 EXPECT_NE(nullptr, root_entry);
5492 EXPECT_EQ(3U, entry->root_node()->children.size());
5493 EXPECT_EQ(2U, entry->root_node()->children[0]->children.size());
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 EXPECT_EQ(2U, entry->root_node()->children.size());
5513 }
5514 }
5515
5400 } // namespace content 5516 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698