| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 frame_tree->RemoveFrame(root->child_at(1)); | 222 frame_tree->RemoveFrame(root->child_at(1)); |
| 223 ASSERT_EQ("1: [14: [244: [], 245: []], " | 223 ASSERT_EQ("1: [14: [244: [], 245: []], " |
| 224 "16: [264: [], 266: [], " | 224 "16: [264: [], 266: [], " |
| 225 "267 'node with deep subtree': " | 225 "267 'node with deep subtree': " |
| 226 "[365: [455: []]], 268: []]]", | 226 "[365: [455: []]], 268: []]]", |
| 227 GetTreeState(frame_tree)); | 227 GetTreeState(frame_tree)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Ensure frames can be found by frame_tree_node_id, routing ID, or name. | 230 // Ensure frames can be found by frame_tree_node_id, routing ID, or name. |
| 231 TEST_F(FrameTreeTest, FindFrames) { | 231 TEST_F(FrameTreeTest, FindFrames) { |
| 232 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 233 |
| 232 // Add a few child frames to the main frame. | 234 // Add a few child frames to the main frame. |
| 233 FrameTree* frame_tree = contents()->GetFrameTree(); | 235 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 234 FrameTreeNode* root = frame_tree->root(); | 236 FrameTreeNode* root = frame_tree->root(); |
| 237 |
| 235 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, | 238 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 236 "child0", blink::WebSandboxFlags::None); | 239 "child0", blink::WebSandboxFlags::None); |
| 237 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | 240 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 238 "child1", blink::WebSandboxFlags::None); | 241 "child1", blink::WebSandboxFlags::None); |
| 239 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, | 242 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, |
| 240 std::string(), | 243 std::string(), |
| 241 blink::WebSandboxFlags::None); | 244 blink::WebSandboxFlags::None); |
| 242 FrameTreeNode* child0 = root->child_at(0); | 245 FrameTreeNode* child0 = root->child_at(0); |
| 243 FrameTreeNode* child1 = root->child_at(1); | 246 FrameTreeNode* child1 = root->child_at(1); |
| 244 | 247 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 271 // Ensure they can be found by name, if they have one. | 274 // Ensure they can be found by name, if they have one. |
| 272 EXPECT_EQ(root, frame_tree->FindByName(std::string())); | 275 EXPECT_EQ(root, frame_tree->FindByName(std::string())); |
| 273 EXPECT_EQ(child0, frame_tree->FindByName("child0")); | 276 EXPECT_EQ(child0, frame_tree->FindByName("child0")); |
| 274 EXPECT_EQ(child1, frame_tree->FindByName("child1")); | 277 EXPECT_EQ(child1, frame_tree->FindByName("child1")); |
| 275 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); | 278 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); |
| 276 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); | 279 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); |
| 277 } | 280 } |
| 278 | 281 |
| 279 // Check that PreviousSibling() is retrieved correctly. | 282 // Check that PreviousSibling() is retrieved correctly. |
| 280 TEST_F(FrameTreeTest, PreviousSibling) { | 283 TEST_F(FrameTreeTest, PreviousSibling) { |
| 284 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 285 |
| 281 // Add a few child frames to the main frame. | 286 // Add a few child frames to the main frame. |
| 282 FrameTree* frame_tree = contents()->GetFrameTree(); | 287 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 283 FrameTreeNode* root = frame_tree->root(); | 288 FrameTreeNode* root = frame_tree->root(); |
| 284 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, | 289 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 285 "child0", blink::WebSandboxFlags::None); | 290 "child0", blink::WebSandboxFlags::None); |
| 286 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | 291 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 287 "child1", blink::WebSandboxFlags::None); | 292 "child1", blink::WebSandboxFlags::None); |
| 288 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, | 293 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, |
| 289 "child2", blink::WebSandboxFlags::None); | 294 "child2", blink::WebSandboxFlags::None); |
| 290 FrameTreeNode* child0 = root->child_at(0); | 295 FrameTreeNode* child0 = root->child_at(0); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // Simulate attaching a frame from mismatched process id. | 385 // Simulate attaching a frame from mismatched process id. |
| 381 ASSERT_FALSE(frame_tree->AddFrame( | 386 ASSERT_FALSE(frame_tree->AddFrame( |
| 382 root, process_id + 1, 1, blink::WebTreeScopeType::Document, std::string(), | 387 root, process_id + 1, 1, blink::WebTreeScopeType::Document, std::string(), |
| 383 blink::WebSandboxFlags::None)); | 388 blink::WebSandboxFlags::None)); |
| 384 ASSERT_EQ("1: []", GetTreeState(frame_tree)); | 389 ASSERT_EQ("1: []", GetTreeState(frame_tree)); |
| 385 } | 390 } |
| 386 | 391 |
| 387 // Ensure that frames removed while a process has crashed are not preserved in | 392 // Ensure that frames removed while a process has crashed are not preserved in |
| 388 // the global map of id->frame. | 393 // the global map of id->frame. |
| 389 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { | 394 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { |
| 395 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 396 |
| 390 // Add a couple child frames to the main frame. | 397 // Add a couple child frames to the main frame. |
| 391 FrameTreeNode* root = contents()->GetFrameTree()->root(); | 398 FrameTreeNode* root = contents()->GetFrameTree()->root(); |
| 392 | 399 |
| 393 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, | 400 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 394 std::string(), | 401 std::string(), |
| 395 blink::WebSandboxFlags::None); | 402 blink::WebSandboxFlags::None); |
| 396 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | 403 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 397 std::string(), | 404 std::string(), |
| 398 blink::WebSandboxFlags::None); | 405 blink::WebSandboxFlags::None); |
| 399 | 406 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 413 // Crash the renderer. | 420 // Crash the renderer. |
| 414 main_test_rfh()->GetProcess()->SimulateCrash(); | 421 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 415 | 422 |
| 416 // Ensure they cannot be found by id after the process has crashed. | 423 // Ensure they cannot be found by id after the process has crashed. |
| 417 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); | 424 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
| 418 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); | 425 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
| 419 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); | 426 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
| 420 } | 427 } |
| 421 | 428 |
| 422 } // namespace content | 429 } // namespace content |
| OLD | NEW |