| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 // Do not navigate each frame separately, since that will clutter the test | 152 // Do not navigate each frame separately, since that will clutter the test |
| 153 // itself. Instead, leave them in "not live" state, which is indicated by the | 153 // itself. Instead, leave them in "not live" state, which is indicated by the |
| 154 // * after the frame id, since this test cares about the shape, not the | 154 // * after the frame id, since this test cares about the shape, not the |
| 155 // frame liveness. | 155 // frame liveness. |
| 156 EXPECT_EQ("2: []", GetTreeState(frame_tree)); | 156 EXPECT_EQ("2: []", GetTreeState(frame_tree)); |
| 157 | 157 |
| 158 // Simulate attaching a series of frames to build the frame tree. | 158 // Simulate attaching a series of frames to build the frame tree. |
| 159 frame_tree->AddFrame(root, process_id, 14, blink::WebTreeScopeType::Document, | 159 frame_tree->AddFrame(root, process_id, 14, blink::WebTreeScopeType::Document, |
| 160 std::string(), "uniqueName0", | 160 std::string(), "uniqueName0", |
| 161 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 161 blink::WebSandboxFlags::None, |
| 162 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 162 frame_tree->AddFrame(root, process_id, 15, blink::WebTreeScopeType::Document, | 163 frame_tree->AddFrame(root, process_id, 15, blink::WebTreeScopeType::Document, |
| 163 std::string(), "uniqueName1", | 164 std::string(), "uniqueName1", |
| 164 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 165 blink::WebSandboxFlags::None, |
| 166 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 165 frame_tree->AddFrame(root, process_id, 16, blink::WebTreeScopeType::Document, | 167 frame_tree->AddFrame(root, process_id, 16, blink::WebTreeScopeType::Document, |
| 166 std::string(), "uniqueName2", | 168 std::string(), "uniqueName2", |
| 167 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 169 blink::WebSandboxFlags::None, |
| 168 | 170 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 169 frame_tree->AddFrame(root->child_at(0), process_id, 244, | 171 frame_tree->AddFrame(root->child_at(0), process_id, 244, |
| 170 blink::WebTreeScopeType::Document, std::string(), | 172 blink::WebTreeScopeType::Document, std::string(), |
| 171 "uniqueName3", blink::WebSandboxFlags::None, | 173 "uniqueName3", blink::WebSandboxFlags::None, |
| 172 FrameOwnerProperties()); | 174 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 173 frame_tree->AddFrame(root->child_at(1), process_id, 255, | 175 frame_tree->AddFrame(root->child_at(1), process_id, 255, |
| 174 blink::WebTreeScopeType::Document, no_children_node, | 176 blink::WebTreeScopeType::Document, no_children_node, |
| 175 "uniqueName4", blink::WebSandboxFlags::None, | 177 "uniqueName4", blink::WebSandboxFlags::None, |
| 176 FrameOwnerProperties()); | 178 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 177 frame_tree->AddFrame(root->child_at(0), process_id, 245, | 179 frame_tree->AddFrame(root->child_at(0), process_id, 245, |
| 178 blink::WebTreeScopeType::Document, std::string(), | 180 blink::WebTreeScopeType::Document, std::string(), |
| 179 "uniqueName5", blink::WebSandboxFlags::None, | 181 "uniqueName5", blink::WebSandboxFlags::None, |
| 180 FrameOwnerProperties()); | 182 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 181 | 183 |
| 182 EXPECT_EQ( | 184 EXPECT_EQ( |
| 183 "2: [14: [244: [], 245: []], " | 185 "2: [14: [244: [], 245: []], " |
| 184 "15: [255 'no children node': []], " | 186 "15: [255 'no children node': []], " |
| 185 "16: []]", | 187 "16: []]", |
| 186 GetTreeState(frame_tree)); | 188 GetTreeState(frame_tree)); |
| 187 | 189 |
| 188 FrameTreeNode* child_16 = root->child_at(2); | 190 FrameTreeNode* child_16 = root->child_at(2); |
| 189 frame_tree->AddFrame(child_16, process_id, 264, | 191 frame_tree->AddFrame(child_16, process_id, 264, |
| 190 blink::WebTreeScopeType::Document, std::string(), | 192 blink::WebTreeScopeType::Document, std::string(), |
| 191 "uniqueName6", blink::WebSandboxFlags::None, | 193 "uniqueName6", blink::WebSandboxFlags::None, |
| 192 FrameOwnerProperties()); | 194 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 193 frame_tree->AddFrame(child_16, process_id, 265, | 195 frame_tree->AddFrame(child_16, process_id, 265, |
| 194 blink::WebTreeScopeType::Document, std::string(), | 196 blink::WebTreeScopeType::Document, std::string(), |
| 195 "uniqueName7", blink::WebSandboxFlags::None, | 197 "uniqueName7", blink::WebSandboxFlags::None, |
| 196 FrameOwnerProperties()); | 198 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 197 frame_tree->AddFrame(child_16, process_id, 266, | 199 frame_tree->AddFrame(child_16, process_id, 266, |
| 198 blink::WebTreeScopeType::Document, std::string(), | 200 blink::WebTreeScopeType::Document, std::string(), |
| 199 "uniqueName8", blink::WebSandboxFlags::None, | 201 "uniqueName8", blink::WebSandboxFlags::None, |
| 200 FrameOwnerProperties()); | 202 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 201 frame_tree->AddFrame(child_16, process_id, 267, | 203 frame_tree->AddFrame(child_16, process_id, 267, |
| 202 blink::WebTreeScopeType::Document, deep_subtree, | 204 blink::WebTreeScopeType::Document, deep_subtree, |
| 203 "uniqueName9", blink::WebSandboxFlags::None, | 205 "uniqueName9", blink::WebSandboxFlags::None, |
| 204 FrameOwnerProperties()); | 206 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 205 frame_tree->AddFrame(child_16, process_id, 268, | 207 frame_tree->AddFrame(child_16, process_id, 268, |
| 206 blink::WebTreeScopeType::Document, std::string(), | 208 blink::WebTreeScopeType::Document, std::string(), |
| 207 "uniqueName10", blink::WebSandboxFlags::None, | 209 "uniqueName10", blink::WebSandboxFlags::None, |
| 208 FrameOwnerProperties()); | 210 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 209 | 211 |
| 210 FrameTreeNode* child_267 = child_16->child_at(3); | 212 FrameTreeNode* child_267 = child_16->child_at(3); |
| 211 frame_tree->AddFrame(child_267, process_id, 365, | 213 frame_tree->AddFrame(child_267, process_id, 365, |
| 212 blink::WebTreeScopeType::Document, std::string(), | 214 blink::WebTreeScopeType::Document, std::string(), |
| 213 "uniqueName11", blink::WebSandboxFlags::None, | 215 "uniqueName11", blink::WebSandboxFlags::None, |
| 214 FrameOwnerProperties()); | 216 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 215 frame_tree->AddFrame(child_267->child_at(0), process_id, 455, | 217 frame_tree->AddFrame(child_267->child_at(0), process_id, 455, |
| 216 blink::WebTreeScopeType::Document, std::string(), | 218 blink::WebTreeScopeType::Document, std::string(), |
| 217 "uniqueName12", blink::WebSandboxFlags::None, | 219 "uniqueName12", blink::WebSandboxFlags::None, |
| 218 FrameOwnerProperties()); | 220 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 219 frame_tree->AddFrame(child_267->child_at(0)->child_at(0), process_id, 555, | 221 frame_tree->AddFrame(child_267->child_at(0)->child_at(0), process_id, 555, |
| 220 blink::WebTreeScopeType::Document, std::string(), | 222 blink::WebTreeScopeType::Document, std::string(), |
| 221 "uniqueName13", blink::WebSandboxFlags::None, | 223 "uniqueName13", blink::WebSandboxFlags::None, |
| 222 FrameOwnerProperties()); | 224 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 223 frame_tree->AddFrame(child_267->child_at(0)->child_at(0)->child_at(0), | 225 frame_tree->AddFrame(child_267->child_at(0)->child_at(0)->child_at(0), |
| 224 process_id, 655, blink::WebTreeScopeType::Document, | 226 process_id, 655, blink::WebTreeScopeType::Document, |
| 225 std::string(), "uniqueName14", | 227 std::string(), "uniqueName14", |
| 226 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 228 blink::WebSandboxFlags::None, |
| 229 ParsedFeaturePolicyHeader(), FrameOwnerProperties()); |
| 227 | 230 |
| 228 // Now that's it's fully built, verify the tree structure is as expected. | 231 // Now that's it's fully built, verify the tree structure is as expected. |
| 229 EXPECT_EQ( | 232 EXPECT_EQ( |
| 230 "2: [14: [244: [], 245: []], " | 233 "2: [14: [244: [], 245: []], " |
| 231 "15: [255 'no children node': []], " | 234 "15: [255 'no children node': []], " |
| 232 "16: [264: [], 265: [], 266: [], " | 235 "16: [264: [], 265: [], 266: [], " |
| 233 "267 'node with deep subtree': " | 236 "267 'node with deep subtree': " |
| 234 "[365: [455: [555: [655: []]]]], 268: []]]", | 237 "[365: [455: [555: [655: []]]]], 268: []]]", |
| 235 GetTreeState(frame_tree)); | 238 GetTreeState(frame_tree)); |
| 236 | 239 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 // Ensure frames can be found by frame_tree_node_id, routing ID, or name. | 292 // Ensure frames can be found by frame_tree_node_id, routing ID, or name. |
| 290 TEST_F(FrameTreeTest, FindFrames) { | 293 TEST_F(FrameTreeTest, FindFrames) { |
| 291 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 294 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 292 | 295 |
| 293 // Add a few child frames to the main frame. | 296 // Add a few child frames to the main frame. |
| 294 FrameTree* frame_tree = contents()->GetFrameTree(); | 297 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 295 FrameTreeNode* root = frame_tree->root(); | 298 FrameTreeNode* root = frame_tree->root(); |
| 296 | 299 |
| 297 main_test_rfh()->OnCreateChildFrame( | 300 main_test_rfh()->OnCreateChildFrame( |
| 298 22, blink::WebTreeScopeType::Document, "child0", "uniqueName0", | 301 22, blink::WebTreeScopeType::Document, "child0", "uniqueName0", |
| 299 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 302 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 303 FrameOwnerProperties()); |
| 300 main_test_rfh()->OnCreateChildFrame( | 304 main_test_rfh()->OnCreateChildFrame( |
| 301 23, blink::WebTreeScopeType::Document, "child1", "uniqueName1", | 305 23, blink::WebTreeScopeType::Document, "child1", "uniqueName1", |
| 302 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 306 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 307 FrameOwnerProperties()); |
| 303 main_test_rfh()->OnCreateChildFrame( | 308 main_test_rfh()->OnCreateChildFrame( |
| 304 24, blink::WebTreeScopeType::Document, std::string(), "uniqueName2", | 309 24, blink::WebTreeScopeType::Document, std::string(), "uniqueName2", |
| 305 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 310 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 311 FrameOwnerProperties()); |
| 306 FrameTreeNode* child0 = root->child_at(0); | 312 FrameTreeNode* child0 = root->child_at(0); |
| 307 FrameTreeNode* child1 = root->child_at(1); | 313 FrameTreeNode* child1 = root->child_at(1); |
| 308 | 314 |
| 309 FrameTreeNode* child2 = root->child_at(2); | 315 FrameTreeNode* child2 = root->child_at(2); |
| 310 | 316 |
| 311 // Add one grandchild frame. | 317 // Add one grandchild frame. |
| 312 child1->current_frame_host()->OnCreateChildFrame( | 318 child1->current_frame_host()->OnCreateChildFrame( |
| 313 33, blink::WebTreeScopeType::Document, "grandchild", "uniqueName3", | 319 33, blink::WebTreeScopeType::Document, "grandchild", "uniqueName3", |
| 314 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 320 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 321 FrameOwnerProperties()); |
| 315 FrameTreeNode* grandchild = child1->child_at(0); | 322 FrameTreeNode* grandchild = child1->child_at(0); |
| 316 | 323 |
| 317 // Ensure they can be found by FTN id. | 324 // Ensure they can be found by FTN id. |
| 318 EXPECT_EQ(root, frame_tree->FindByID(root->frame_tree_node_id())); | 325 EXPECT_EQ(root, frame_tree->FindByID(root->frame_tree_node_id())); |
| 319 EXPECT_EQ(child0, frame_tree->FindByID(child0->frame_tree_node_id())); | 326 EXPECT_EQ(child0, frame_tree->FindByID(child0->frame_tree_node_id())); |
| 320 EXPECT_EQ(child1, frame_tree->FindByID(child1->frame_tree_node_id())); | 327 EXPECT_EQ(child1, frame_tree->FindByID(child1->frame_tree_node_id())); |
| 321 EXPECT_EQ(child2, frame_tree->FindByID(child2->frame_tree_node_id())); | 328 EXPECT_EQ(child2, frame_tree->FindByID(child2->frame_tree_node_id())); |
| 322 EXPECT_EQ(grandchild, frame_tree->FindByID(grandchild->frame_tree_node_id())); | 329 EXPECT_EQ(grandchild, frame_tree->FindByID(grandchild->frame_tree_node_id())); |
| 323 EXPECT_EQ(nullptr, frame_tree->FindByID(-1)); | 330 EXPECT_EQ(nullptr, frame_tree->FindByID(-1)); |
| 324 | 331 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 342 | 349 |
| 343 // Check that PreviousSibling() and NextSibling() are retrieved correctly. | 350 // Check that PreviousSibling() and NextSibling() are retrieved correctly. |
| 344 TEST_F(FrameTreeTest, GetSibling) { | 351 TEST_F(FrameTreeTest, GetSibling) { |
| 345 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 352 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 346 | 353 |
| 347 // Add a few child frames to the main frame. | 354 // Add a few child frames to the main frame. |
| 348 FrameTree* frame_tree = contents()->GetFrameTree(); | 355 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 349 FrameTreeNode* root = frame_tree->root(); | 356 FrameTreeNode* root = frame_tree->root(); |
| 350 main_test_rfh()->OnCreateChildFrame( | 357 main_test_rfh()->OnCreateChildFrame( |
| 351 22, blink::WebTreeScopeType::Document, "child0", "uniqueName0", | 358 22, blink::WebTreeScopeType::Document, "child0", "uniqueName0", |
| 352 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 359 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 360 FrameOwnerProperties()); |
| 353 main_test_rfh()->OnCreateChildFrame( | 361 main_test_rfh()->OnCreateChildFrame( |
| 354 23, blink::WebTreeScopeType::Document, "child1", "uniqueName1", | 362 23, blink::WebTreeScopeType::Document, "child1", "uniqueName1", |
| 355 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 363 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 364 FrameOwnerProperties()); |
| 356 main_test_rfh()->OnCreateChildFrame( | 365 main_test_rfh()->OnCreateChildFrame( |
| 357 24, blink::WebTreeScopeType::Document, "child2", "uniqueName2", | 366 24, blink::WebTreeScopeType::Document, "child2", "uniqueName2", |
| 358 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 367 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 368 FrameOwnerProperties()); |
| 359 FrameTreeNode* child0 = root->child_at(0); | 369 FrameTreeNode* child0 = root->child_at(0); |
| 360 FrameTreeNode* child1 = root->child_at(1); | 370 FrameTreeNode* child1 = root->child_at(1); |
| 361 FrameTreeNode* child2 = root->child_at(2); | 371 FrameTreeNode* child2 = root->child_at(2); |
| 362 | 372 |
| 363 // Add one grandchild frame. | 373 // Add one grandchild frame. |
| 364 child1->current_frame_host()->OnCreateChildFrame( | 374 child1->current_frame_host()->OnCreateChildFrame( |
| 365 33, blink::WebTreeScopeType::Document, "grandchild", "uniqueName3", | 375 33, blink::WebTreeScopeType::Document, "grandchild", "uniqueName3", |
| 366 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 376 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 377 FrameOwnerProperties()); |
| 367 FrameTreeNode* grandchild = child1->child_at(0); | 378 FrameTreeNode* grandchild = child1->child_at(0); |
| 368 | 379 |
| 369 // Test PreviousSibling(). | 380 // Test PreviousSibling(). |
| 370 EXPECT_EQ(nullptr, root->PreviousSibling()); | 381 EXPECT_EQ(nullptr, root->PreviousSibling()); |
| 371 EXPECT_EQ(nullptr, child0->PreviousSibling()); | 382 EXPECT_EQ(nullptr, child0->PreviousSibling()); |
| 372 EXPECT_EQ(child0, child1->PreviousSibling()); | 383 EXPECT_EQ(child0, child1->PreviousSibling()); |
| 373 EXPECT_EQ(child1, child2->PreviousSibling()); | 384 EXPECT_EQ(child1, child2->PreviousSibling()); |
| 374 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); | 385 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); |
| 375 | 386 |
| 376 // Test NextSibling(). | 387 // Test NextSibling(). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 387 TreeWalkingWebContentsLogger activity(contents()); | 398 TreeWalkingWebContentsLogger activity(contents()); |
| 388 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 399 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 389 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); | 400 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); |
| 390 | 401 |
| 391 FrameTree* frame_tree = contents()->GetFrameTree(); | 402 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 392 FrameTreeNode* root = frame_tree->root(); | 403 FrameTreeNode* root = frame_tree->root(); |
| 393 | 404 |
| 394 // Simulate attaching a series of frames to build the frame tree. | 405 // Simulate attaching a series of frames to build the frame tree. |
| 395 main_test_rfh()->OnCreateChildFrame( | 406 main_test_rfh()->OnCreateChildFrame( |
| 396 14, blink::WebTreeScopeType::Document, std::string(), "uniqueName0", | 407 14, blink::WebTreeScopeType::Document, std::string(), "uniqueName0", |
| 397 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 408 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 409 FrameOwnerProperties()); |
| 398 EXPECT_EQ( | 410 EXPECT_EQ( |
| 399 "RenderFrameHostChanged(new)(14) -> 2: []\n" | 411 "RenderFrameHostChanged(new)(14) -> 2: []\n" |
| 400 "RenderFrameCreated(14) -> 2: [14: []]", | 412 "RenderFrameCreated(14) -> 2: [14: []]", |
| 401 activity.GetLog()); | 413 activity.GetLog()); |
| 402 main_test_rfh()->OnCreateChildFrame( | 414 main_test_rfh()->OnCreateChildFrame( |
| 403 18, blink::WebTreeScopeType::Document, std::string(), "uniqueName1", | 415 18, blink::WebTreeScopeType::Document, std::string(), "uniqueName1", |
| 404 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 416 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 417 FrameOwnerProperties()); |
| 405 EXPECT_EQ( | 418 EXPECT_EQ( |
| 406 "RenderFrameHostChanged(new)(18) -> 2: [14: []]\n" | 419 "RenderFrameHostChanged(new)(18) -> 2: [14: []]\n" |
| 407 "RenderFrameCreated(18) -> 2: [14: [], 18: []]", | 420 "RenderFrameCreated(18) -> 2: [14: [], 18: []]", |
| 408 activity.GetLog()); | 421 activity.GetLog()); |
| 409 frame_tree->RemoveFrame(root->child_at(0)); | 422 frame_tree->RemoveFrame(root->child_at(0)); |
| 410 EXPECT_EQ("RenderFrameDeleted(14) -> 2: [18: []]", activity.GetLog()); | 423 EXPECT_EQ("RenderFrameDeleted(14) -> 2: [18: []]", activity.GetLog()); |
| 411 frame_tree->RemoveFrame(root->child_at(0)); | 424 frame_tree->RemoveFrame(root->child_at(0)); |
| 412 EXPECT_EQ("RenderFrameDeleted(18) -> 2: []", activity.GetLog()); | 425 EXPECT_EQ("RenderFrameDeleted(18) -> 2: []", activity.GetLog()); |
| 413 } | 426 } |
| 414 | 427 |
| 415 // Make sure that WebContentsObservers see a consistent view of the tree after | 428 // Make sure that WebContentsObservers see a consistent view of the tree after |
| 416 // recovery from a render process crash. | 429 // recovery from a render process crash. |
| 417 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { | 430 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { |
| 418 TreeWalkingWebContentsLogger activity(contents()); | 431 TreeWalkingWebContentsLogger activity(contents()); |
| 419 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 432 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 420 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); | 433 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); |
| 421 | 434 |
| 422 main_test_rfh()->OnCreateChildFrame( | 435 main_test_rfh()->OnCreateChildFrame( |
| 423 22, blink::WebTreeScopeType::Document, std::string(), "uniqueName0", | 436 22, blink::WebTreeScopeType::Document, std::string(), "uniqueName0", |
| 424 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 437 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 438 FrameOwnerProperties()); |
| 425 EXPECT_EQ( | 439 EXPECT_EQ( |
| 426 "RenderFrameHostChanged(new)(22) -> 2: []\n" | 440 "RenderFrameHostChanged(new)(22) -> 2: []\n" |
| 427 "RenderFrameCreated(22) -> 2: [22: []]", | 441 "RenderFrameCreated(22) -> 2: [22: []]", |
| 428 activity.GetLog()); | 442 activity.GetLog()); |
| 429 main_test_rfh()->OnCreateChildFrame( | 443 main_test_rfh()->OnCreateChildFrame( |
| 430 23, blink::WebTreeScopeType::Document, std::string(), "uniqueName1", | 444 23, blink::WebTreeScopeType::Document, std::string(), "uniqueName1", |
| 431 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 445 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 446 FrameOwnerProperties()); |
| 432 EXPECT_EQ( | 447 EXPECT_EQ( |
| 433 "RenderFrameHostChanged(new)(23) -> 2: [22: []]\n" | 448 "RenderFrameHostChanged(new)(23) -> 2: [22: []]\n" |
| 434 "RenderFrameCreated(23) -> 2: [22: [], 23: []]", | 449 "RenderFrameCreated(23) -> 2: [22: [], 23: []]", |
| 435 activity.GetLog()); | 450 activity.GetLog()); |
| 436 | 451 |
| 437 // Crash the renderer | 452 // Crash the renderer |
| 438 main_test_rfh()->GetProcess()->SimulateCrash(); | 453 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 439 EXPECT_EQ( | 454 EXPECT_EQ( |
| 440 "RenderProcessGone -> 2*: [22*: [], 23*: []]\n" | 455 "RenderProcessGone -> 2*: [22*: [], 23*: []]\n" |
| 441 "RenderFrameDeleted(23) -> 2*: [22*: [], 23*: []]\n" | 456 "RenderFrameDeleted(23) -> 2*: [22*: [], 23*: []]\n" |
| 442 "RenderFrameDeleted(22) -> 2*: [22*: [], 23*: []]\n" | 457 "RenderFrameDeleted(22) -> 2*: [22*: [], 23*: []]\n" |
| 443 "RenderFrameDeleted(2) -> 2*: []", | 458 "RenderFrameDeleted(2) -> 2*: []", |
| 444 activity.GetLog()); | 459 activity.GetLog()); |
| 445 } | 460 } |
| 446 | 461 |
| 447 // Ensure that frames are not added to the tree, if the process passed in | 462 // Ensure that frames are not added to the tree, if the process passed in |
| 448 // is different than the process of the parent node. | 463 // is different than the process of the parent node. |
| 449 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { | 464 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { |
| 450 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 465 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 451 FrameTree* frame_tree = contents()->GetFrameTree(); | 466 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 452 FrameTreeNode* root = frame_tree->root(); | 467 FrameTreeNode* root = frame_tree->root(); |
| 453 int process_id = root->current_frame_host()->GetProcess()->GetID(); | 468 int process_id = root->current_frame_host()->GetProcess()->GetID(); |
| 454 | 469 |
| 455 ASSERT_EQ("2: []", GetTreeState(frame_tree)); | 470 ASSERT_EQ("2: []", GetTreeState(frame_tree)); |
| 456 | 471 |
| 457 // Simulate attaching a frame from mismatched process id. | 472 // Simulate attaching a frame from mismatched process id. |
| 458 ASSERT_FALSE(frame_tree->AddFrame( | 473 ASSERT_FALSE(frame_tree->AddFrame( |
| 459 root, process_id + 1, 1, blink::WebTreeScopeType::Document, std::string(), | 474 root, process_id + 1, 1, blink::WebTreeScopeType::Document, std::string(), |
| 460 "uniqueName0", blink::WebSandboxFlags::None, FrameOwnerProperties())); | 475 "uniqueName0", blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 476 FrameOwnerProperties())); |
| 461 ASSERT_EQ("2: []", GetTreeState(frame_tree)); | 477 ASSERT_EQ("2: []", GetTreeState(frame_tree)); |
| 462 } | 478 } |
| 463 | 479 |
| 464 // Ensure that frames removed while a process has crashed are not preserved in | 480 // Ensure that frames removed while a process has crashed are not preserved in |
| 465 // the global map of id->frame. | 481 // the global map of id->frame. |
| 466 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { | 482 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { |
| 467 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 483 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 468 | 484 |
| 469 // Add a couple child frames to the main frame. | 485 // Add a couple child frames to the main frame. |
| 470 FrameTreeNode* root = contents()->GetFrameTree()->root(); | 486 FrameTreeNode* root = contents()->GetFrameTree()->root(); |
| 471 | 487 |
| 472 main_test_rfh()->OnCreateChildFrame( | 488 main_test_rfh()->OnCreateChildFrame( |
| 473 22, blink::WebTreeScopeType::Document, std::string(), "uniqueName0", | 489 22, blink::WebTreeScopeType::Document, std::string(), "uniqueName0", |
| 474 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 490 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 491 FrameOwnerProperties()); |
| 475 main_test_rfh()->OnCreateChildFrame( | 492 main_test_rfh()->OnCreateChildFrame( |
| 476 23, blink::WebTreeScopeType::Document, std::string(), "uniqueName1", | 493 23, blink::WebTreeScopeType::Document, std::string(), "uniqueName1", |
| 477 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 494 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 495 FrameOwnerProperties()); |
| 478 | 496 |
| 479 // Add one grandchild frame. | 497 // Add one grandchild frame. |
| 480 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host(); | 498 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host(); |
| 481 child1_rfh->OnCreateChildFrame( | 499 child1_rfh->OnCreateChildFrame( |
| 482 33, blink::WebTreeScopeType::Document, std::string(), "uniqueName2", | 500 33, blink::WebTreeScopeType::Document, std::string(), "uniqueName2", |
| 483 blink::WebSandboxFlags::None, FrameOwnerProperties()); | 501 blink::WebSandboxFlags::None, ParsedFeaturePolicyHeader(), |
| 502 FrameOwnerProperties()); |
| 484 | 503 |
| 485 // Ensure they can be found by id. | 504 // Ensure they can be found by id. |
| 486 int id1 = root->child_at(0)->frame_tree_node_id(); | 505 int id1 = root->child_at(0)->frame_tree_node_id(); |
| 487 int id2 = root->child_at(1)->frame_tree_node_id(); | 506 int id2 = root->child_at(1)->frame_tree_node_id(); |
| 488 int id3 = root->child_at(0)->child_at(0)->frame_tree_node_id(); | 507 int id3 = root->child_at(0)->child_at(0)->frame_tree_node_id(); |
| 489 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1)); | 508 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1)); |
| 490 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2)); | 509 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2)); |
| 491 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3)); | 510 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3)); |
| 492 | 511 |
| 493 // Crash the renderer. | 512 // Crash the renderer. |
| 494 main_test_rfh()->GetProcess()->SimulateCrash(); | 513 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 495 | 514 |
| 496 // Ensure they cannot be found by id after the process has crashed. | 515 // Ensure they cannot be found by id after the process has crashed. |
| 497 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); | 516 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
| 498 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); | 517 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
| 499 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); | 518 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
| 500 } | 519 } |
| 501 | 520 |
| 502 } // namespace content | 521 } // namespace content |
| OLD | NEW |