| OLD | NEW |
| 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/frame_tree.h" | 5 #include "content/browser/frame_host/frame_tree.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "content/browser/frame_host/navigator_impl.h" | 9 #include "content/browser/frame_host/navigator_impl.h" |
| 10 #include "content/browser/frame_host/render_frame_host_factory.h" | 10 #include "content/browser/frame_host/render_frame_host_factory.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 EXPECT_EQ(nullptr, frame_tree->FindByRoutingID(process_id, 37)); | 293 EXPECT_EQ(nullptr, frame_tree->FindByRoutingID(process_id, 37)); |
| 294 | 294 |
| 295 // Ensure they can be found by name, if they have one. | 295 // Ensure they can be found by name, if they have one. |
| 296 EXPECT_EQ(root, frame_tree->FindByName(std::string())); | 296 EXPECT_EQ(root, frame_tree->FindByName(std::string())); |
| 297 EXPECT_EQ(child0, frame_tree->FindByName("child0")); | 297 EXPECT_EQ(child0, frame_tree->FindByName("child0")); |
| 298 EXPECT_EQ(child1, frame_tree->FindByName("child1")); | 298 EXPECT_EQ(child1, frame_tree->FindByName("child1")); |
| 299 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); | 299 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); |
| 300 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); | 300 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); |
| 301 } | 301 } |
| 302 | 302 |
| 303 // Check that PreviousSibling() is retrieved correctly. | 303 // Check that PreviousSibling() and NextSibling() are retrieved correctly. |
| 304 TEST_F(FrameTreeTest, PreviousSibling) { | 304 TEST_F(FrameTreeTest, GetSibling) { |
| 305 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 305 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 306 | 306 |
| 307 // Add a few child frames to the main frame. | 307 // Add a few child frames to the main frame. |
| 308 FrameTree* frame_tree = contents()->GetFrameTree(); | 308 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 309 FrameTreeNode* root = frame_tree->root(); | 309 FrameTreeNode* root = frame_tree->root(); |
| 310 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, | 310 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 311 "child0", blink::WebSandboxFlags::None, | 311 "child0", blink::WebSandboxFlags::None, |
| 312 blink::WebFrameOwnerProperties()); | 312 blink::WebFrameOwnerProperties()); |
| 313 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | 313 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 314 "child1", blink::WebSandboxFlags::None, | 314 "child1", blink::WebSandboxFlags::None, |
| 315 blink::WebFrameOwnerProperties()); | 315 blink::WebFrameOwnerProperties()); |
| 316 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, | 316 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, |
| 317 "child2", blink::WebSandboxFlags::None, | 317 "child2", blink::WebSandboxFlags::None, |
| 318 blink::WebFrameOwnerProperties()); | 318 blink::WebFrameOwnerProperties()); |
| 319 FrameTreeNode* child0 = root->child_at(0); | 319 FrameTreeNode* child0 = root->child_at(0); |
| 320 FrameTreeNode* child1 = root->child_at(1); | 320 FrameTreeNode* child1 = root->child_at(1); |
| 321 FrameTreeNode* child2 = root->child_at(2); | 321 FrameTreeNode* child2 = root->child_at(2); |
| 322 | 322 |
| 323 // Add one grandchild frame. | 323 // Add one grandchild frame. |
| 324 child1->current_frame_host()->OnCreateChildFrame( | 324 child1->current_frame_host()->OnCreateChildFrame( |
| 325 33, blink::WebTreeScopeType::Document, "grandchild", | 325 33, blink::WebTreeScopeType::Document, "grandchild", |
| 326 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); | 326 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
| 327 FrameTreeNode* grandchild = child1->child_at(0); | 327 FrameTreeNode* grandchild = child1->child_at(0); |
| 328 | 328 |
| 329 // Test PreviousSibling(). |
| 329 EXPECT_EQ(nullptr, root->PreviousSibling()); | 330 EXPECT_EQ(nullptr, root->PreviousSibling()); |
| 330 EXPECT_EQ(nullptr, child0->PreviousSibling()); | 331 EXPECT_EQ(nullptr, child0->PreviousSibling()); |
| 331 EXPECT_EQ(child0, child1->PreviousSibling()); | 332 EXPECT_EQ(child0, child1->PreviousSibling()); |
| 332 EXPECT_EQ(child1, child2->PreviousSibling()); | 333 EXPECT_EQ(child1, child2->PreviousSibling()); |
| 333 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); | 334 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); |
| 335 |
| 336 // Test NextSibling(). |
| 337 EXPECT_EQ(nullptr, root->NextSibling()); |
| 338 EXPECT_EQ(child1, child0->NextSibling()); |
| 339 EXPECT_EQ(child2, child1->NextSibling()); |
| 340 EXPECT_EQ(nullptr, child2->NextSibling()); |
| 341 EXPECT_EQ(nullptr, grandchild->NextSibling()); |
| 334 } | 342 } |
| 335 | 343 |
| 336 // Do some simple manipulations of the frame tree, making sure that | 344 // Do some simple manipulations of the frame tree, making sure that |
| 337 // WebContentsObservers see a consistent view of the tree as we go. | 345 // WebContentsObservers see a consistent view of the tree as we go. |
| 338 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { | 346 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { |
| 339 TreeWalkingWebContentsLogger activity(contents()); | 347 TreeWalkingWebContentsLogger activity(contents()); |
| 340 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 348 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 341 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); | 349 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); |
| 342 | 350 |
| 343 FrameTree* frame_tree = contents()->GetFrameTree(); | 351 FrameTree* frame_tree = contents()->GetFrameTree(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 // Crash the renderer. | 459 // Crash the renderer. |
| 452 main_test_rfh()->GetProcess()->SimulateCrash(); | 460 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 453 | 461 |
| 454 // Ensure they cannot be found by id after the process has crashed. | 462 // Ensure they cannot be found by id after the process has crashed. |
| 455 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); | 463 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
| 456 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); | 464 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
| 457 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); | 465 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
| 458 } | 466 } |
| 459 | 467 |
| 460 } // namespace content | 468 } // namespace content |
| OLD | NEW |