| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 int process_id = root->current_frame_host()->GetProcess()->GetID(); | 133 int process_id = root->current_frame_host()->GetProcess()->GetID(); |
| 134 | 134 |
| 135 // Do not navigate each frame separately, since that will clutter the test | 135 // Do not navigate each frame separately, since that will clutter the test |
| 136 // itself. Instead, leave them in "not live" state, which is indicated by the | 136 // itself. Instead, leave them in "not live" state, which is indicated by the |
| 137 // * after the frame id, since this test cares about the shape, not the | 137 // * after the frame id, since this test cares about the shape, not the |
| 138 // frame liveliness. | 138 // frame liveliness. |
| 139 EXPECT_EQ("2*: []", GetTreeState(frame_tree)); | 139 EXPECT_EQ("2*: []", GetTreeState(frame_tree)); |
| 140 | 140 |
| 141 // Simulate attaching a series of frames to build the frame tree. | 141 // Simulate attaching a series of frames to build the frame tree. |
| 142 frame_tree->AddFrame(root, process_id, 14, blink::WebTreeScopeType::Document, | 142 frame_tree->AddFrame(root, process_id, 14, blink::WebTreeScopeType::Document, |
| 143 std::string(), blink::WebSandboxFlags::None); | 143 std::string(), blink::WebSandboxFlags::None, |
| 144 blink::WebFrameOwnerProperties()); |
| 144 frame_tree->AddFrame(root, process_id, 15, blink::WebTreeScopeType::Document, | 145 frame_tree->AddFrame(root, process_id, 15, blink::WebTreeScopeType::Document, |
| 145 std::string(), blink::WebSandboxFlags::None); | 146 std::string(), blink::WebSandboxFlags::None, |
| 147 blink::WebFrameOwnerProperties()); |
| 146 frame_tree->AddFrame(root, process_id, 16, blink::WebTreeScopeType::Document, | 148 frame_tree->AddFrame(root, process_id, 16, blink::WebTreeScopeType::Document, |
| 147 std::string(), blink::WebSandboxFlags::None); | 149 std::string(), blink::WebSandboxFlags::None, |
| 150 blink::WebFrameOwnerProperties()); |
| 148 | 151 |
| 149 frame_tree->AddFrame(root->child_at(0), process_id, 244, | 152 frame_tree->AddFrame(root->child_at(0), process_id, 244, |
| 150 blink::WebTreeScopeType::Document, std::string(), | 153 blink::WebTreeScopeType::Document, std::string(), |
| 151 blink::WebSandboxFlags::None); | 154 blink::WebSandboxFlags::None, |
| 155 blink::WebFrameOwnerProperties()); |
| 152 frame_tree->AddFrame(root->child_at(1), process_id, 255, | 156 frame_tree->AddFrame(root->child_at(1), process_id, 255, |
| 153 blink::WebTreeScopeType::Document, no_children_node, | 157 blink::WebTreeScopeType::Document, no_children_node, |
| 154 blink::WebSandboxFlags::None); | 158 blink::WebSandboxFlags::None, |
| 159 blink::WebFrameOwnerProperties()); |
| 155 frame_tree->AddFrame(root->child_at(0), process_id, 245, | 160 frame_tree->AddFrame(root->child_at(0), process_id, 245, |
| 156 blink::WebTreeScopeType::Document, std::string(), | 161 blink::WebTreeScopeType::Document, std::string(), |
| 157 blink::WebSandboxFlags::None); | 162 blink::WebSandboxFlags::None, |
| 163 blink::WebFrameOwnerProperties()); |
| 158 | 164 |
| 159 EXPECT_EQ( | 165 EXPECT_EQ( |
| 160 "2*: [14*: [244*: [], 245*: []], " | 166 "2*: [14*: [244*: [], 245*: []], " |
| 161 "15*: [255* 'no children node': []], " | 167 "15*: [255* 'no children node': []], " |
| 162 "16*: []]", | 168 "16*: []]", |
| 163 GetTreeState(frame_tree)); | 169 GetTreeState(frame_tree)); |
| 164 | 170 |
| 165 FrameTreeNode* child_16 = root->child_at(2); | 171 FrameTreeNode* child_16 = root->child_at(2); |
| 166 frame_tree->AddFrame(child_16, process_id, 264, | 172 frame_tree->AddFrame(child_16, process_id, 264, |
| 167 blink::WebTreeScopeType::Document, std::string(), | 173 blink::WebTreeScopeType::Document, std::string(), |
| 168 blink::WebSandboxFlags::None); | 174 blink::WebSandboxFlags::None, |
| 175 blink::WebFrameOwnerProperties()); |
| 169 frame_tree->AddFrame(child_16, process_id, 265, | 176 frame_tree->AddFrame(child_16, process_id, 265, |
| 170 blink::WebTreeScopeType::Document, std::string(), | 177 blink::WebTreeScopeType::Document, std::string(), |
| 171 blink::WebSandboxFlags::None); | 178 blink::WebSandboxFlags::None, |
| 179 blink::WebFrameOwnerProperties()); |
| 172 frame_tree->AddFrame(child_16, process_id, 266, | 180 frame_tree->AddFrame(child_16, process_id, 266, |
| 173 blink::WebTreeScopeType::Document, std::string(), | 181 blink::WebTreeScopeType::Document, std::string(), |
| 174 blink::WebSandboxFlags::None); | 182 blink::WebSandboxFlags::None, |
| 183 blink::WebFrameOwnerProperties()); |
| 175 frame_tree->AddFrame(child_16, process_id, 267, | 184 frame_tree->AddFrame(child_16, process_id, 267, |
| 176 blink::WebTreeScopeType::Document, deep_subtree, | 185 blink::WebTreeScopeType::Document, deep_subtree, |
| 177 blink::WebSandboxFlags::None); | 186 blink::WebSandboxFlags::None, |
| 187 blink::WebFrameOwnerProperties()); |
| 178 frame_tree->AddFrame(child_16, process_id, 268, | 188 frame_tree->AddFrame(child_16, process_id, 268, |
| 179 blink::WebTreeScopeType::Document, std::string(), | 189 blink::WebTreeScopeType::Document, std::string(), |
| 180 blink::WebSandboxFlags::None); | 190 blink::WebSandboxFlags::None, |
| 191 blink::WebFrameOwnerProperties()); |
| 181 | 192 |
| 182 FrameTreeNode* child_267 = child_16->child_at(3); | 193 FrameTreeNode* child_267 = child_16->child_at(3); |
| 183 frame_tree->AddFrame(child_267, process_id, 365, | 194 frame_tree->AddFrame(child_267, process_id, 365, |
| 184 blink::WebTreeScopeType::Document, std::string(), | 195 blink::WebTreeScopeType::Document, std::string(), |
| 185 blink::WebSandboxFlags::None); | 196 blink::WebSandboxFlags::None, |
| 197 blink::WebFrameOwnerProperties()); |
| 186 frame_tree->AddFrame(child_267->child_at(0), process_id, 455, | 198 frame_tree->AddFrame(child_267->child_at(0), process_id, 455, |
| 187 blink::WebTreeScopeType::Document, std::string(), | 199 blink::WebTreeScopeType::Document, std::string(), |
| 188 blink::WebSandboxFlags::None); | 200 blink::WebSandboxFlags::None, |
| 201 blink::WebFrameOwnerProperties()); |
| 189 frame_tree->AddFrame(child_267->child_at(0)->child_at(0), process_id, 555, | 202 frame_tree->AddFrame(child_267->child_at(0)->child_at(0), process_id, 555, |
| 190 blink::WebTreeScopeType::Document, std::string(), | 203 blink::WebTreeScopeType::Document, std::string(), |
| 191 blink::WebSandboxFlags::None); | 204 blink::WebSandboxFlags::None, |
| 205 blink::WebFrameOwnerProperties()); |
| 192 frame_tree->AddFrame(child_267->child_at(0)->child_at(0)->child_at(0), | 206 frame_tree->AddFrame(child_267->child_at(0)->child_at(0)->child_at(0), |
| 193 process_id, 655, blink::WebTreeScopeType::Document, | 207 process_id, 655, blink::WebTreeScopeType::Document, |
| 194 std::string(), blink::WebSandboxFlags::None); | 208 std::string(), blink::WebSandboxFlags::None, |
| 209 blink::WebFrameOwnerProperties()); |
| 195 | 210 |
| 196 // Now that's it's fully built, verify the tree structure is as expected. | 211 // Now that's it's fully built, verify the tree structure is as expected. |
| 197 EXPECT_EQ( | 212 EXPECT_EQ( |
| 198 "2*: [14*: [244*: [], 245*: []], " | 213 "2*: [14*: [244*: [], 245*: []], " |
| 199 "15*: [255* 'no children node': []], " | 214 "15*: [255* 'no children node': []], " |
| 200 "16*: [264*: [], 265*: [], 266*: [], " | 215 "16*: [264*: [], 265*: [], 266*: [], " |
| 201 "267* 'node with deep subtree': " | 216 "267* 'node with deep subtree': " |
| 202 "[365*: [455*: [555*: [655*: []]]]], 268*: []]]", | 217 "[365*: [455*: [555*: [655*: []]]]], 268*: []]]", |
| 203 GetTreeState(frame_tree)); | 218 GetTreeState(frame_tree)); |
| 204 | 219 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 232 | 247 |
| 233 // Ensure frames can be found by frame_tree_node_id, routing ID, or name. | 248 // Ensure frames can be found by frame_tree_node_id, routing ID, or name. |
| 234 TEST_F(FrameTreeTest, FindFrames) { | 249 TEST_F(FrameTreeTest, FindFrames) { |
| 235 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 250 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 236 | 251 |
| 237 // Add a few child frames to the main frame. | 252 // Add a few child frames to the main frame. |
| 238 FrameTree* frame_tree = contents()->GetFrameTree(); | 253 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 239 FrameTreeNode* root = frame_tree->root(); | 254 FrameTreeNode* root = frame_tree->root(); |
| 240 | 255 |
| 241 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, | 256 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 242 "child0", blink::WebSandboxFlags::None); | 257 "child0", blink::WebSandboxFlags::None, |
| 258 blink::WebFrameOwnerProperties()); |
| 243 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | 259 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 244 "child1", blink::WebSandboxFlags::None); | 260 "child1", blink::WebSandboxFlags::None, |
| 261 blink::WebFrameOwnerProperties()); |
| 245 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, | 262 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, |
| 246 std::string(), | 263 std::string(), |
| 247 blink::WebSandboxFlags::None); | 264 blink::WebSandboxFlags::None, |
| 265 blink::WebFrameOwnerProperties()); |
| 248 FrameTreeNode* child0 = root->child_at(0); | 266 FrameTreeNode* child0 = root->child_at(0); |
| 249 FrameTreeNode* child1 = root->child_at(1); | 267 FrameTreeNode* child1 = root->child_at(1); |
| 250 | 268 |
| 251 FrameTreeNode* child2 = root->child_at(2); | 269 FrameTreeNode* child2 = root->child_at(2); |
| 252 | 270 |
| 253 // Add one grandchild frame. | 271 // Add one grandchild frame. |
| 254 child1->current_frame_host()->OnCreateChildFrame( | 272 child1->current_frame_host()->OnCreateChildFrame( |
| 255 33, blink::WebTreeScopeType::Document, "grandchild", | 273 33, blink::WebTreeScopeType::Document, "grandchild", |
| 256 blink::WebSandboxFlags::None); | 274 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
| 257 FrameTreeNode* grandchild = child1->child_at(0); | 275 FrameTreeNode* grandchild = child1->child_at(0); |
| 258 | 276 |
| 259 // Ensure they can be found by FTN id. | 277 // Ensure they can be found by FTN id. |
| 260 EXPECT_EQ(root, frame_tree->FindByID(root->frame_tree_node_id())); | 278 EXPECT_EQ(root, frame_tree->FindByID(root->frame_tree_node_id())); |
| 261 EXPECT_EQ(child0, frame_tree->FindByID(child0->frame_tree_node_id())); | 279 EXPECT_EQ(child0, frame_tree->FindByID(child0->frame_tree_node_id())); |
| 262 EXPECT_EQ(child1, frame_tree->FindByID(child1->frame_tree_node_id())); | 280 EXPECT_EQ(child1, frame_tree->FindByID(child1->frame_tree_node_id())); |
| 263 EXPECT_EQ(child2, frame_tree->FindByID(child2->frame_tree_node_id())); | 281 EXPECT_EQ(child2, frame_tree->FindByID(child2->frame_tree_node_id())); |
| 264 EXPECT_EQ(grandchild, frame_tree->FindByID(grandchild->frame_tree_node_id())); | 282 EXPECT_EQ(grandchild, frame_tree->FindByID(grandchild->frame_tree_node_id())); |
| 265 EXPECT_EQ(nullptr, frame_tree->FindByID(-1)); | 283 EXPECT_EQ(nullptr, frame_tree->FindByID(-1)); |
| 266 | 284 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 283 } | 301 } |
| 284 | 302 |
| 285 // Check that PreviousSibling() is retrieved correctly. | 303 // Check that PreviousSibling() is retrieved correctly. |
| 286 TEST_F(FrameTreeTest, PreviousSibling) { | 304 TEST_F(FrameTreeTest, PreviousSibling) { |
| 287 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 305 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 288 | 306 |
| 289 // Add a few child frames to the main frame. | 307 // Add a few child frames to the main frame. |
| 290 FrameTree* frame_tree = contents()->GetFrameTree(); | 308 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 291 FrameTreeNode* root = frame_tree->root(); | 309 FrameTreeNode* root = frame_tree->root(); |
| 292 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, | 310 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 293 "child0", blink::WebSandboxFlags::None); | 311 "child0", blink::WebSandboxFlags::None, |
| 312 blink::WebFrameOwnerProperties()); |
| 294 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | 313 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 295 "child1", blink::WebSandboxFlags::None); | 314 "child1", blink::WebSandboxFlags::None, |
| 315 blink::WebFrameOwnerProperties()); |
| 296 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, | 316 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, |
| 297 "child2", blink::WebSandboxFlags::None); | 317 "child2", blink::WebSandboxFlags::None, |
| 318 blink::WebFrameOwnerProperties()); |
| 298 FrameTreeNode* child0 = root->child_at(0); | 319 FrameTreeNode* child0 = root->child_at(0); |
| 299 FrameTreeNode* child1 = root->child_at(1); | 320 FrameTreeNode* child1 = root->child_at(1); |
| 300 FrameTreeNode* child2 = root->child_at(2); | 321 FrameTreeNode* child2 = root->child_at(2); |
| 301 | 322 |
| 302 // Add one grandchild frame. | 323 // Add one grandchild frame. |
| 303 child1->current_frame_host()->OnCreateChildFrame( | 324 child1->current_frame_host()->OnCreateChildFrame( |
| 304 33, blink::WebTreeScopeType::Document, "grandchild", | 325 33, blink::WebTreeScopeType::Document, "grandchild", |
| 305 blink::WebSandboxFlags::None); | 326 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
| 306 FrameTreeNode* grandchild = child1->child_at(0); | 327 FrameTreeNode* grandchild = child1->child_at(0); |
| 307 | 328 |
| 308 EXPECT_EQ(nullptr, root->PreviousSibling()); | 329 EXPECT_EQ(nullptr, root->PreviousSibling()); |
| 309 EXPECT_EQ(nullptr, child0->PreviousSibling()); | 330 EXPECT_EQ(nullptr, child0->PreviousSibling()); |
| 310 EXPECT_EQ(child0, child1->PreviousSibling()); | 331 EXPECT_EQ(child0, child1->PreviousSibling()); |
| 311 EXPECT_EQ(child1, child2->PreviousSibling()); | 332 EXPECT_EQ(child1, child2->PreviousSibling()); |
| 312 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); | 333 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); |
| 313 } | 334 } |
| 314 | 335 |
| 315 // Do some simple manipulations of the frame tree, making sure that | 336 // Do some simple manipulations of the frame tree, making sure that |
| 316 // WebContentsObservers see a consistent view of the tree as we go. | 337 // WebContentsObservers see a consistent view of the tree as we go. |
| 317 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { | 338 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { |
| 318 TreeWalkingWebContentsLogger activity(contents()); | 339 TreeWalkingWebContentsLogger activity(contents()); |
| 319 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 340 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 320 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); | 341 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); |
| 321 | 342 |
| 322 FrameTree* frame_tree = contents()->GetFrameTree(); | 343 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 323 FrameTreeNode* root = frame_tree->root(); | 344 FrameTreeNode* root = frame_tree->root(); |
| 324 | 345 |
| 325 // Simulate attaching a series of frames to build the frame tree. | 346 // Simulate attaching a series of frames to build the frame tree. |
| 326 main_test_rfh()->OnCreateChildFrame(14, blink::WebTreeScopeType::Document, | 347 main_test_rfh()->OnCreateChildFrame(14, blink::WebTreeScopeType::Document, |
| 327 std::string(), | 348 std::string(), |
| 328 blink::WebSandboxFlags::None); | 349 blink::WebSandboxFlags::None, |
| 350 blink::WebFrameOwnerProperties()); |
| 329 EXPECT_EQ( | 351 EXPECT_EQ( |
| 330 "RenderFrameHostChanged(new)(14) -> 2: []\n" | 352 "RenderFrameHostChanged(new)(14) -> 2: []\n" |
| 331 "RenderFrameCreated(14) -> 2: [14: []]", | 353 "RenderFrameCreated(14) -> 2: [14: []]", |
| 332 activity.GetLog()); | 354 activity.GetLog()); |
| 333 main_test_rfh()->OnCreateChildFrame(18, blink::WebTreeScopeType::Document, | 355 main_test_rfh()->OnCreateChildFrame(18, blink::WebTreeScopeType::Document, |
| 334 std::string(), | 356 std::string(), |
| 335 blink::WebSandboxFlags::None); | 357 blink::WebSandboxFlags::None, |
| 358 blink::WebFrameOwnerProperties()); |
| 336 EXPECT_EQ( | 359 EXPECT_EQ( |
| 337 "RenderFrameHostChanged(new)(18) -> 2: [14: []]\n" | 360 "RenderFrameHostChanged(new)(18) -> 2: [14: []]\n" |
| 338 "RenderFrameCreated(18) -> 2: [14: [], 18: []]", | 361 "RenderFrameCreated(18) -> 2: [14: [], 18: []]", |
| 339 activity.GetLog()); | 362 activity.GetLog()); |
| 340 frame_tree->RemoveFrame(root->child_at(0)); | 363 frame_tree->RemoveFrame(root->child_at(0)); |
| 341 EXPECT_EQ("RenderFrameDeleted(14) -> 2: [18: []]", activity.GetLog()); | 364 EXPECT_EQ("RenderFrameDeleted(14) -> 2: [18: []]", activity.GetLog()); |
| 342 frame_tree->RemoveFrame(root->child_at(0)); | 365 frame_tree->RemoveFrame(root->child_at(0)); |
| 343 EXPECT_EQ("RenderFrameDeleted(18) -> 2: []", activity.GetLog()); | 366 EXPECT_EQ("RenderFrameDeleted(18) -> 2: []", activity.GetLog()); |
| 344 } | 367 } |
| 345 | 368 |
| 346 // Make sure that WebContentsObservers see a consistent view of the tree after | 369 // Make sure that WebContentsObservers see a consistent view of the tree after |
| 347 // recovery from a render process crash. | 370 // recovery from a render process crash. |
| 348 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { | 371 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { |
| 349 TreeWalkingWebContentsLogger activity(contents()); | 372 TreeWalkingWebContentsLogger activity(contents()); |
| 350 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 373 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 351 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); | 374 EXPECT_EQ("RenderFrameCreated(2) -> 2: []", activity.GetLog()); |
| 352 | 375 |
| 353 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, | 376 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 354 std::string(), | 377 std::string(), |
| 355 blink::WebSandboxFlags::None); | 378 blink::WebSandboxFlags::None, |
| 379 blink::WebFrameOwnerProperties()); |
| 356 EXPECT_EQ( | 380 EXPECT_EQ( |
| 357 "RenderFrameHostChanged(new)(22) -> 2: []\n" | 381 "RenderFrameHostChanged(new)(22) -> 2: []\n" |
| 358 "RenderFrameCreated(22) -> 2: [22: []]", | 382 "RenderFrameCreated(22) -> 2: [22: []]", |
| 359 activity.GetLog()); | 383 activity.GetLog()); |
| 360 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | 384 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 361 std::string(), | 385 std::string(), |
| 362 blink::WebSandboxFlags::None); | 386 blink::WebSandboxFlags::None, |
| 387 blink::WebFrameOwnerProperties()); |
| 363 EXPECT_EQ( | 388 EXPECT_EQ( |
| 364 "RenderFrameHostChanged(new)(23) -> 2: [22: []]\n" | 389 "RenderFrameHostChanged(new)(23) -> 2: [22: []]\n" |
| 365 "RenderFrameCreated(23) -> 2: [22: [], 23: []]", | 390 "RenderFrameCreated(23) -> 2: [22: [], 23: []]", |
| 366 activity.GetLog()); | 391 activity.GetLog()); |
| 367 | 392 |
| 368 // Crash the renderer | 393 // Crash the renderer |
| 369 main_test_rfh()->GetProcess()->SimulateCrash(); | 394 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 370 EXPECT_EQ( | 395 EXPECT_EQ( |
| 371 "RenderProcessGone -> 2*: [22*: [], 23*: []]\n" | 396 "RenderProcessGone -> 2*: [22*: [], 23*: []]\n" |
| 372 "RenderFrameDeleted(23) -> 2*: [22*: [], 23*: []]\n" | 397 "RenderFrameDeleted(23) -> 2*: [22*: [], 23*: []]\n" |
| 373 "RenderFrameDeleted(22) -> 2*: [22*: [], 23*: []]\n" | 398 "RenderFrameDeleted(22) -> 2*: [22*: [], 23*: []]\n" |
| 374 "RenderFrameDeleted(2) -> 2*: []", | 399 "RenderFrameDeleted(2) -> 2*: []", |
| 375 activity.GetLog()); | 400 activity.GetLog()); |
| 376 } | 401 } |
| 377 | 402 |
| 378 // Ensure that frames are not added to the tree, if the process passed in | 403 // Ensure that frames are not added to the tree, if the process passed in |
| 379 // is different than the process of the parent node. | 404 // is different than the process of the parent node. |
| 380 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { | 405 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { |
| 381 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 406 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 382 FrameTree* frame_tree = contents()->GetFrameTree(); | 407 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 383 FrameTreeNode* root = frame_tree->root(); | 408 FrameTreeNode* root = frame_tree->root(); |
| 384 int process_id = root->current_frame_host()->GetProcess()->GetID(); | 409 int process_id = root->current_frame_host()->GetProcess()->GetID(); |
| 385 | 410 |
| 386 ASSERT_EQ("2: []", GetTreeState(frame_tree)); | 411 ASSERT_EQ("2: []", GetTreeState(frame_tree)); |
| 387 | 412 |
| 388 // Simulate attaching a frame from mismatched process id. | 413 // Simulate attaching a frame from mismatched process id. |
| 389 ASSERT_FALSE(frame_tree->AddFrame( | 414 ASSERT_FALSE(frame_tree->AddFrame( |
| 390 root, process_id + 1, 1, blink::WebTreeScopeType::Document, std::string(), | 415 root, process_id + 1, 1, blink::WebTreeScopeType::Document, std::string(), |
| 391 blink::WebSandboxFlags::None)); | 416 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties())); |
| 392 ASSERT_EQ("2: []", GetTreeState(frame_tree)); | 417 ASSERT_EQ("2: []", GetTreeState(frame_tree)); |
| 393 } | 418 } |
| 394 | 419 |
| 395 // Ensure that frames removed while a process has crashed are not preserved in | 420 // Ensure that frames removed while a process has crashed are not preserved in |
| 396 // the global map of id->frame. | 421 // the global map of id->frame. |
| 397 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { | 422 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { |
| 398 main_test_rfh()->InitializeRenderFrameIfNeeded(); | 423 main_test_rfh()->InitializeRenderFrameIfNeeded(); |
| 399 | 424 |
| 400 // Add a couple child frames to the main frame. | 425 // Add a couple child frames to the main frame. |
| 401 FrameTreeNode* root = contents()->GetFrameTree()->root(); | 426 FrameTreeNode* root = contents()->GetFrameTree()->root(); |
| 402 | 427 |
| 403 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, | 428 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 404 std::string(), | 429 std::string(), |
| 405 blink::WebSandboxFlags::None); | 430 blink::WebSandboxFlags::None, |
| 431 blink::WebFrameOwnerProperties()); |
| 406 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | 432 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 407 std::string(), | 433 std::string(), |
| 408 blink::WebSandboxFlags::None); | 434 blink::WebSandboxFlags::None, |
| 435 blink::WebFrameOwnerProperties()); |
| 409 | 436 |
| 410 // Add one grandchild frame. | 437 // Add one grandchild frame. |
| 411 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host(); | 438 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host(); |
| 412 child1_rfh->OnCreateChildFrame(33, blink::WebTreeScopeType::Document, | 439 child1_rfh->OnCreateChildFrame(33, blink::WebTreeScopeType::Document, |
| 413 std::string(), blink::WebSandboxFlags::None); | 440 std::string(), blink::WebSandboxFlags::None, |
| 441 blink::WebFrameOwnerProperties()); |
| 414 | 442 |
| 415 // Ensure they can be found by id. | 443 // Ensure they can be found by id. |
| 416 int id1 = root->child_at(0)->frame_tree_node_id(); | 444 int id1 = root->child_at(0)->frame_tree_node_id(); |
| 417 int id2 = root->child_at(1)->frame_tree_node_id(); | 445 int id2 = root->child_at(1)->frame_tree_node_id(); |
| 418 int id3 = root->child_at(0)->child_at(0)->frame_tree_node_id(); | 446 int id3 = root->child_at(0)->child_at(0)->frame_tree_node_id(); |
| 419 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1)); | 447 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1)); |
| 420 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2)); | 448 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2)); |
| 421 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3)); | 449 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3)); |
| 422 | 450 |
| 423 // Crash the renderer. | 451 // Crash the renderer. |
| 424 main_test_rfh()->GetProcess()->SimulateCrash(); | 452 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 425 | 453 |
| 426 // Ensure they cannot be found by id after the process has crashed. | 454 // Ensure they cannot be found by id after the process has crashed. |
| 427 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); | 455 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
| 428 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); | 456 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
| 429 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); | 457 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
| 430 } | 458 } |
| 431 | 459 |
| 432 } // namespace content | 460 } // namespace content |
| OLD | NEW |