| 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 EXPECT_EQ(child0, child1->PreviousSibling()); | 302 EXPECT_EQ(child0, child1->PreviousSibling()); |
| 303 EXPECT_EQ(child1, child2->PreviousSibling()); | 303 EXPECT_EQ(child1, child2->PreviousSibling()); |
| 304 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); | 304 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); |
| 305 } | 305 } |
| 306 | 306 |
| 307 // Do some simple manipulations of the frame tree, making sure that | 307 // Do some simple manipulations of the frame tree, making sure that |
| 308 // WebContentsObservers see a consistent view of the tree as we go. | 308 // WebContentsObservers see a consistent view of the tree as we go. |
| 309 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { | 309 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { |
| 310 TreeWalkingWebContentsLogger activity(contents()); | 310 TreeWalkingWebContentsLogger activity(contents()); |
| 311 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 311 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 312 EXPECT_EQ("", activity.GetLog()); | 312 EXPECT_EQ("RenderFrameCreated(1) -> 1: []", activity.GetLog()); |
| 313 | 313 |
| 314 FrameTree* frame_tree = contents()->GetFrameTree(); | 314 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 315 FrameTreeNode* root = frame_tree->root(); | 315 FrameTreeNode* root = frame_tree->root(); |
| 316 | 316 |
| 317 // Simulate attaching a series of frames to build the frame tree. | 317 // Simulate attaching a series of frames to build the frame tree. |
| 318 main_test_rfh()->OnCreateChildFrame(14, blink::WebTreeScopeType::Document, | 318 main_test_rfh()->OnCreateChildFrame(14, blink::WebTreeScopeType::Document, |
| 319 std::string(), | 319 std::string(), |
| 320 blink::WebSandboxFlags::None); | 320 blink::WebSandboxFlags::None); |
| 321 EXPECT_EQ( | 321 EXPECT_EQ( |
| 322 "RenderFrameHostChanged(new)(14) -> 1: []\n" | 322 "RenderFrameHostChanged(new)(14) -> 1: []\n" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 333 EXPECT_EQ("RenderFrameDeleted(14) -> 1: [18: []]", activity.GetLog()); | 333 EXPECT_EQ("RenderFrameDeleted(14) -> 1: [18: []]", activity.GetLog()); |
| 334 frame_tree->RemoveFrame(root->child_at(0)); | 334 frame_tree->RemoveFrame(root->child_at(0)); |
| 335 EXPECT_EQ("RenderFrameDeleted(18) -> 1: []", activity.GetLog()); | 335 EXPECT_EQ("RenderFrameDeleted(18) -> 1: []", activity.GetLog()); |
| 336 } | 336 } |
| 337 | 337 |
| 338 // Make sure that WebContentsObservers see a consistent view of the tree after | 338 // Make sure that WebContentsObservers see a consistent view of the tree after |
| 339 // recovery from a render process crash. | 339 // recovery from a render process crash. |
| 340 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { | 340 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { |
| 341 TreeWalkingWebContentsLogger activity(contents()); | 341 TreeWalkingWebContentsLogger activity(contents()); |
| 342 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 342 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 343 EXPECT_EQ("", activity.GetLog()); | 343 EXPECT_EQ("RenderFrameCreated(1) -> 1: []", activity.GetLog()); |
| 344 | 344 |
| 345 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, | 345 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 346 std::string(), | 346 std::string(), |
| 347 blink::WebSandboxFlags::None); | 347 blink::WebSandboxFlags::None); |
| 348 EXPECT_EQ( | 348 EXPECT_EQ( |
| 349 "RenderFrameHostChanged(new)(22) -> 1: []\n" | 349 "RenderFrameHostChanged(new)(22) -> 1: []\n" |
| 350 "RenderFrameCreated(22) -> 1: [22: []]", | 350 "RenderFrameCreated(22) -> 1: [22: []]", |
| 351 activity.GetLog()); | 351 activity.GetLog()); |
| 352 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | 352 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 353 std::string(), | 353 std::string(), |
| 354 blink::WebSandboxFlags::None); | 354 blink::WebSandboxFlags::None); |
| 355 EXPECT_EQ( | 355 EXPECT_EQ( |
| 356 "RenderFrameHostChanged(new)(23) -> 1: [22: []]\n" | 356 "RenderFrameHostChanged(new)(23) -> 1: [22: []]\n" |
| 357 "RenderFrameCreated(23) -> 1: [22: [], 23: []]", | 357 "RenderFrameCreated(23) -> 1: [22: [], 23: []]", |
| 358 activity.GetLog()); | 358 activity.GetLog()); |
| 359 | 359 |
| 360 // Crash the renderer | 360 // Crash the renderer |
| 361 main_test_rfh()->GetProcess()->SimulateCrash(); | 361 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 362 EXPECT_EQ( | 362 EXPECT_EQ( |
| 363 "RenderFrameDeleted(23) -> 1: [22: [], 23*: []]\n" | 363 "RenderFrameDeleted(23) -> 1: [22: [], 23*: []]\n" |
| 364 "RenderFrameDeleted(22) -> 1: [22*: [], 23*: []]\n" | 364 "RenderFrameDeleted(22) -> 1: [22*: [], 23*: []]\n" |
| 365 "RenderFrameDeleted(1) -> 1: []\n" // TODO(nick): Should be "1*:" | 365 "RenderFrameDeleted(1) -> 1*: []\n" |
| 366 "RenderProcessGone -> 1*: []", | 366 "RenderProcessGone -> 1*: []", |
| 367 activity.GetLog()); | 367 activity.GetLog()); |
| 368 } | 368 } |
| 369 | 369 |
| 370 // Ensure that frames are not added to the tree, if the process passed in | 370 // Ensure that frames are not added to the tree, if the process passed in |
| 371 // is different than the process of the parent node. | 371 // is different than the process of the parent node. |
| 372 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { | 372 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { |
| 373 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 373 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 374 FrameTree* frame_tree = contents()->GetFrameTree(); | 374 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 375 FrameTreeNode* root = frame_tree->root(); | 375 FrameTreeNode* root = frame_tree->root(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // Crash the renderer. | 413 // Crash the renderer. |
| 414 main_test_rfh()->GetProcess()->SimulateCrash(); | 414 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 415 | 415 |
| 416 // Ensure they cannot be found by id after the process has crashed. | 416 // Ensure they cannot be found by id after the process has crashed. |
| 417 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); | 417 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
| 418 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); | 418 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
| 419 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); | 419 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace content | 422 } // namespace content |
| OLD | NEW |