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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 EXPECT_EQ(nullptr, frame_tree->FindByRoutingID(process_id, 37)); | 335 EXPECT_EQ(nullptr, frame_tree->FindByRoutingID(process_id, 37)); |
336 | 336 |
337 // Ensure they can be found by name, if they have one. | 337 // Ensure they can be found by name, if they have one. |
338 EXPECT_EQ(root, frame_tree->FindByName(std::string())); | 338 EXPECT_EQ(root, frame_tree->FindByName(std::string())); |
339 EXPECT_EQ(child0, frame_tree->FindByName("child0")); | 339 EXPECT_EQ(child0, frame_tree->FindByName("child0")); |
340 EXPECT_EQ(child1, frame_tree->FindByName("child1")); | 340 EXPECT_EQ(child1, frame_tree->FindByName("child1")); |
341 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); | 341 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); |
342 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); | 342 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); |
343 } | 343 } |
344 | 344 |
345 // Check that PreviousSibling() is retrieved correctly. | 345 // Check that PreviousSibling() and NextSibling() are retrieved correctly. |
346 TEST_F(FrameTreeTest, PreviousSibling) { | 346 TEST_F(FrameTreeTest, GetSibling) { |
347 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 347 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
348 | 348 |
349 // Add a few child frames to the main frame. | 349 // Add a few child frames to the main frame. |
350 FrameTree* frame_tree = contents()->GetFrameTree(); | 350 FrameTree* frame_tree = contents()->GetFrameTree(); |
351 FrameTreeNode* root = frame_tree->root(); | 351 FrameTreeNode* root = frame_tree->root(); |
352 main_test_rfh()->OnCreateChildFrame( | 352 main_test_rfh()->OnCreateChildFrame( |
353 22, blink::WebTreeScopeType::Document, "child0", "uniqueName0", | 353 22, blink::WebTreeScopeType::Document, "child0", "uniqueName0", |
354 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); | 354 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
355 main_test_rfh()->OnCreateChildFrame( | 355 main_test_rfh()->OnCreateChildFrame( |
356 23, blink::WebTreeScopeType::Document, "child1", "uniqueName1", | 356 23, blink::WebTreeScopeType::Document, "child1", "uniqueName1", |
357 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); | 357 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
358 main_test_rfh()->OnCreateChildFrame( | 358 main_test_rfh()->OnCreateChildFrame( |
359 24, blink::WebTreeScopeType::Document, "child2", "uniqueName2", | 359 24, blink::WebTreeScopeType::Document, "child2", "uniqueName2", |
360 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); | 360 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
361 FrameTreeNode* child0 = root->child_at(0); | 361 FrameTreeNode* child0 = root->child_at(0); |
362 FrameTreeNode* child1 = root->child_at(1); | 362 FrameTreeNode* child1 = root->child_at(1); |
363 FrameTreeNode* child2 = root->child_at(2); | 363 FrameTreeNode* child2 = root->child_at(2); |
364 | 364 |
365 // Add one grandchild frame. | 365 // Add one grandchild frame. |
366 child1->current_frame_host()->OnCreateChildFrame( | 366 child1->current_frame_host()->OnCreateChildFrame( |
367 33, blink::WebTreeScopeType::Document, "grandchild", "uniqueName3", | 367 33, blink::WebTreeScopeType::Document, "grandchild", "uniqueName3", |
368 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); | 368 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
369 FrameTreeNode* grandchild = child1->child_at(0); | 369 FrameTreeNode* grandchild = child1->child_at(0); |
370 | 370 |
| 371 // Test PreviousSibling(). |
371 EXPECT_EQ(nullptr, root->PreviousSibling()); | 372 EXPECT_EQ(nullptr, root->PreviousSibling()); |
372 EXPECT_EQ(nullptr, child0->PreviousSibling()); | 373 EXPECT_EQ(nullptr, child0->PreviousSibling()); |
373 EXPECT_EQ(child0, child1->PreviousSibling()); | 374 EXPECT_EQ(child0, child1->PreviousSibling()); |
374 EXPECT_EQ(child1, child2->PreviousSibling()); | 375 EXPECT_EQ(child1, child2->PreviousSibling()); |
375 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); | 376 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); |
| 377 |
| 378 // Test NextSibling(). |
| 379 EXPECT_EQ(nullptr, root->NextSibling()); |
| 380 EXPECT_EQ(child1, child0->NextSibling()); |
| 381 EXPECT_EQ(child2, child1->NextSibling()); |
| 382 EXPECT_EQ(nullptr, child2->NextSibling()); |
| 383 EXPECT_EQ(nullptr, grandchild->NextSibling()); |
376 } | 384 } |
377 | 385 |
378 // Do some simple manipulations of the frame tree, making sure that | 386 // Do some simple manipulations of the frame tree, making sure that |
379 // WebContentsObservers see a consistent view of the tree as we go. | 387 // WebContentsObservers see a consistent view of the tree as we go. |
380 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { | 388 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { |
381 TreeWalkingWebContentsLogger activity(contents()); | 389 TreeWalkingWebContentsLogger activity(contents()); |
382 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 390 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
383 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); | 391 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); |
384 | 392 |
385 FrameTree* frame_tree = contents()->GetFrameTree(); | 393 FrameTree* frame_tree = contents()->GetFrameTree(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 // Crash the renderer. | 496 // Crash the renderer. |
489 main_test_rfh()->GetProcess()->SimulateCrash(); | 497 main_test_rfh()->GetProcess()->SimulateCrash(); |
490 | 498 |
491 // Ensure they cannot be found by id after the process has crashed. | 499 // Ensure they cannot be found by id after the process has crashed. |
492 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); | 500 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
493 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); | 501 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
494 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); | 502 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
495 } | 503 } |
496 | 504 |
497 } // namespace content | 505 } // namespace content |
OLD | NEW |