Chromium Code Reviews| 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 FrameTree* frame_tree = contents()->GetFrameTree(); | 133 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 134 FrameTreeNode* root = frame_tree->root(); | 134 FrameTreeNode* root = frame_tree->root(); |
| 135 | 135 |
| 136 std::string no_children_node("no children node"); | 136 std::string no_children_node("no children node"); |
| 137 std::string deep_subtree("node with deep subtree"); | 137 std::string deep_subtree("node with deep subtree"); |
| 138 int process_id = root->current_frame_host()->GetProcess()->GetID(); | 138 int process_id = root->current_frame_host()->GetProcess()->GetID(); |
| 139 | 139 |
| 140 ASSERT_EQ("1: []", GetTreeState(frame_tree)); | 140 ASSERT_EQ("1: []", GetTreeState(frame_tree)); |
| 141 | 141 |
| 142 // Simulate attaching a series of frames to build the frame tree. | 142 // Simulate attaching a series of frames to build the frame tree. |
| 143 frame_tree->AddFrame(root, process_id, 14, std::string(), | 143 frame_tree->AddFrame(root, process_id, 14, blink::WebTreeScopeType::Document, |
|
Charlie Reis
2015/05/19 23:17:10
I agree that these changes are a bit unwieldy for
dcheng
2015/05/20 00:09:29
That doesn't really help us a lot in tests though,
Charlie Reis
2015/05/20 21:38:40
That's why I said "pass in a default one." Almost
dcheng
2015/05/21 18:16:16
Sure, but AddFrame() doesn't need the origin, whic
Charlie Reis
2015/05/21 23:18:17
Ah. Yes, it would be unfortunate to have to pass
| |
| 144 std::string(), SandboxFlags::NONE); | |
| 145 frame_tree->AddFrame(root, process_id, 15, blink::WebTreeScopeType::Document, | |
| 146 std::string(), SandboxFlags::NONE); | |
| 147 frame_tree->AddFrame(root, process_id, 16, blink::WebTreeScopeType::Document, | |
| 148 std::string(), SandboxFlags::NONE); | |
| 149 | |
| 150 frame_tree->AddFrame(root->child_at(0), process_id, 244, | |
| 151 blink::WebTreeScopeType::Document, std::string(), | |
| 144 SandboxFlags::NONE); | 152 SandboxFlags::NONE); |
| 145 frame_tree->AddFrame(root, process_id, 15, std::string(), | 153 frame_tree->AddFrame(root->child_at(1), process_id, 255, |
| 154 blink::WebTreeScopeType::Document, no_children_node, | |
| 146 SandboxFlags::NONE); | 155 SandboxFlags::NONE); |
| 147 frame_tree->AddFrame(root, process_id, 16, std::string(), | 156 frame_tree->AddFrame(root->child_at(0), process_id, 245, |
| 148 SandboxFlags::NONE); | 157 blink::WebTreeScopeType::Document, std::string(), |
| 149 | |
| 150 frame_tree->AddFrame(root->child_at(0), process_id, 244, std::string(), | |
| 151 SandboxFlags::NONE); | |
| 152 frame_tree->AddFrame(root->child_at(1), process_id, 255, no_children_node, | |
| 153 SandboxFlags::NONE); | |
| 154 frame_tree->AddFrame(root->child_at(0), process_id, 245, std::string(), | |
| 155 SandboxFlags::NONE); | 158 SandboxFlags::NONE); |
| 156 | 159 |
| 157 ASSERT_EQ("1: [14: [244: [], 245: []], " | 160 ASSERT_EQ("1: [14: [244: [], 245: []], " |
| 158 "15: [255 'no children node': []], " | 161 "15: [255 'no children node': []], " |
| 159 "16: []]", | 162 "16: []]", |
| 160 GetTreeState(frame_tree)); | 163 GetTreeState(frame_tree)); |
| 161 | 164 |
| 162 FrameTreeNode* child_16 = root->child_at(2); | 165 FrameTreeNode* child_16 = root->child_at(2); |
| 163 frame_tree->AddFrame(child_16, process_id, 264, std::string(), | 166 frame_tree->AddFrame(child_16, process_id, 264, |
| 167 blink::WebTreeScopeType::Document, std::string(), | |
| 164 SandboxFlags::NONE); | 168 SandboxFlags::NONE); |
| 165 frame_tree->AddFrame(child_16, process_id, 265, std::string(), | 169 frame_tree->AddFrame(child_16, process_id, 265, |
| 170 blink::WebTreeScopeType::Document, std::string(), | |
| 166 SandboxFlags::NONE); | 171 SandboxFlags::NONE); |
| 167 frame_tree->AddFrame(child_16, process_id, 266, std::string(), | 172 frame_tree->AddFrame(child_16, process_id, 266, |
| 173 blink::WebTreeScopeType::Document, std::string(), | |
| 168 SandboxFlags::NONE); | 174 SandboxFlags::NONE); |
| 169 frame_tree->AddFrame(child_16, process_id, 267, deep_subtree, | 175 frame_tree->AddFrame(child_16, process_id, 267, |
| 176 blink::WebTreeScopeType::Document, deep_subtree, | |
| 170 SandboxFlags::NONE); | 177 SandboxFlags::NONE); |
| 171 frame_tree->AddFrame(child_16, process_id, 268, std::string(), | 178 frame_tree->AddFrame(child_16, process_id, 268, |
| 179 blink::WebTreeScopeType::Document, std::string(), | |
| 172 SandboxFlags::NONE); | 180 SandboxFlags::NONE); |
| 173 | 181 |
| 174 FrameTreeNode* child_267 = child_16->child_at(3); | 182 FrameTreeNode* child_267 = child_16->child_at(3); |
| 175 frame_tree->AddFrame(child_267, process_id, 365, std::string(), | 183 frame_tree->AddFrame(child_267, process_id, 365, |
| 184 blink::WebTreeScopeType::Document, std::string(), | |
| 176 SandboxFlags::NONE); | 185 SandboxFlags::NONE); |
| 177 frame_tree->AddFrame(child_267->child_at(0), process_id, 455, std::string(), | 186 frame_tree->AddFrame(child_267->child_at(0), process_id, 455, |
| 187 blink::WebTreeScopeType::Document, std::string(), | |
| 178 SandboxFlags::NONE); | 188 SandboxFlags::NONE); |
| 179 frame_tree->AddFrame(child_267->child_at(0)->child_at(0), process_id, 555, | 189 frame_tree->AddFrame(child_267->child_at(0)->child_at(0), process_id, 555, |
| 190 blink::WebTreeScopeType::Document, std::string(), | |
| 191 SandboxFlags::NONE); | |
| 192 frame_tree->AddFrame(child_267->child_at(0)->child_at(0)->child_at(0), | |
| 193 process_id, 655, blink::WebTreeScopeType::Document, | |
| 180 std::string(), SandboxFlags::NONE); | 194 std::string(), SandboxFlags::NONE); |
| 181 frame_tree->AddFrame(child_267->child_at(0)->child_at(0)->child_at(0), | |
| 182 process_id, 655, std::string(), SandboxFlags::NONE); | |
| 183 | 195 |
| 184 // Now that's it's fully built, verify the tree structure is as expected. | 196 // Now that's it's fully built, verify the tree structure is as expected. |
| 185 ASSERT_EQ("1: [14: [244: [], 245: []], " | 197 ASSERT_EQ("1: [14: [244: [], 245: []], " |
| 186 "15: [255 'no children node': []], " | 198 "15: [255 'no children node': []], " |
| 187 "16: [264: [], 265: [], 266: [], " | 199 "16: [264: [], 265: [], 266: [], " |
| 188 "267 'node with deep subtree': " | 200 "267 'node with deep subtree': " |
| 189 "[365: [455: [555: [655: []]]]], 268: []]]", | 201 "[365: [455: [555: [655: []]]]], 268: []]]", |
| 190 GetTreeState(frame_tree)); | 202 GetTreeState(frame_tree)); |
| 191 | 203 |
| 192 FrameTreeNode* child_555 = child_267->child_at(0)->child_at(0)->child_at(0); | 204 FrameTreeNode* child_555 = child_267->child_at(0)->child_at(0)->child_at(0); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 212 "267 'node with deep subtree': " | 224 "267 'node with deep subtree': " |
| 213 "[365: [455: []]], 268: []]]", | 225 "[365: [455: []]], 268: []]]", |
| 214 GetTreeState(frame_tree)); | 226 GetTreeState(frame_tree)); |
| 215 } | 227 } |
| 216 | 228 |
| 217 // Ensure frames can be found by frame_tree_node_id, routing ID, or name. | 229 // Ensure frames can be found by frame_tree_node_id, routing ID, or name. |
| 218 TEST_F(FrameTreeTest, FindFrames) { | 230 TEST_F(FrameTreeTest, FindFrames) { |
| 219 // Add a few child frames to the main frame. | 231 // Add a few child frames to the main frame. |
| 220 FrameTree* frame_tree = contents()->GetFrameTree(); | 232 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 221 FrameTreeNode* root = frame_tree->root(); | 233 FrameTreeNode* root = frame_tree->root(); |
| 222 main_test_rfh()->OnCreateChildFrame(22, "child0", SandboxFlags::NONE); | 234 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 223 main_test_rfh()->OnCreateChildFrame(23, "child1", SandboxFlags::NONE); | 235 "child0", SandboxFlags::NONE); |
| 224 main_test_rfh()->OnCreateChildFrame(24, std::string(), SandboxFlags::NONE); | 236 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 237 "child1", SandboxFlags::NONE); | |
| 238 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, | |
| 239 std::string(), SandboxFlags::NONE); | |
| 225 FrameTreeNode* child0 = root->child_at(0); | 240 FrameTreeNode* child0 = root->child_at(0); |
| 226 FrameTreeNode* child1 = root->child_at(1); | 241 FrameTreeNode* child1 = root->child_at(1); |
| 242 | |
| 227 FrameTreeNode* child2 = root->child_at(2); | 243 FrameTreeNode* child2 = root->child_at(2); |
| 228 | 244 |
| 229 // Add one grandchild frame. | 245 // Add one grandchild frame. |
| 230 child1->current_frame_host()->OnCreateChildFrame(33, "grandchild", | 246 child1->current_frame_host()->OnCreateChildFrame( |
| 231 SandboxFlags::NONE); | 247 33, blink::WebTreeScopeType::Document, "grandchild", SandboxFlags::NONE); |
| 232 FrameTreeNode* grandchild = child1->child_at(0); | 248 FrameTreeNode* grandchild = child1->child_at(0); |
| 233 | 249 |
| 234 // Ensure they can be found by FTN id. | 250 // Ensure they can be found by FTN id. |
| 235 EXPECT_EQ(root, frame_tree->FindByID(root->frame_tree_node_id())); | 251 EXPECT_EQ(root, frame_tree->FindByID(root->frame_tree_node_id())); |
| 236 EXPECT_EQ(child0, frame_tree->FindByID(child0->frame_tree_node_id())); | 252 EXPECT_EQ(child0, frame_tree->FindByID(child0->frame_tree_node_id())); |
| 237 EXPECT_EQ(child1, frame_tree->FindByID(child1->frame_tree_node_id())); | 253 EXPECT_EQ(child1, frame_tree->FindByID(child1->frame_tree_node_id())); |
| 238 EXPECT_EQ(child2, frame_tree->FindByID(child2->frame_tree_node_id())); | 254 EXPECT_EQ(child2, frame_tree->FindByID(child2->frame_tree_node_id())); |
| 239 EXPECT_EQ(grandchild, frame_tree->FindByID(grandchild->frame_tree_node_id())); | 255 EXPECT_EQ(grandchild, frame_tree->FindByID(grandchild->frame_tree_node_id())); |
| 240 EXPECT_EQ(nullptr, frame_tree->FindByID(-1)); | 256 EXPECT_EQ(nullptr, frame_tree->FindByID(-1)); |
| 241 | 257 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 255 EXPECT_EQ(child1, frame_tree->FindByName("child1")); | 271 EXPECT_EQ(child1, frame_tree->FindByName("child1")); |
| 256 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); | 272 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); |
| 257 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); | 273 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); |
| 258 } | 274 } |
| 259 | 275 |
| 260 // Check that PreviousSibling() is retrieved correctly. | 276 // Check that PreviousSibling() is retrieved correctly. |
| 261 TEST_F(FrameTreeTest, PreviousSibling) { | 277 TEST_F(FrameTreeTest, PreviousSibling) { |
| 262 // Add a few child frames to the main frame. | 278 // Add a few child frames to the main frame. |
| 263 FrameTree* frame_tree = contents()->GetFrameTree(); | 279 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 264 FrameTreeNode* root = frame_tree->root(); | 280 FrameTreeNode* root = frame_tree->root(); |
| 265 main_test_rfh()->OnCreateChildFrame(22, "child0", SandboxFlags::NONE); | 281 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 266 main_test_rfh()->OnCreateChildFrame(23, "child1", SandboxFlags::NONE); | 282 "child0", SandboxFlags::NONE); |
| 267 main_test_rfh()->OnCreateChildFrame(24, "child2", SandboxFlags::NONE); | 283 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 284 "child1", SandboxFlags::NONE); | |
| 285 main_test_rfh()->OnCreateChildFrame(24, blink::WebTreeScopeType::Document, | |
| 286 "child2", SandboxFlags::NONE); | |
| 268 FrameTreeNode* child0 = root->child_at(0); | 287 FrameTreeNode* child0 = root->child_at(0); |
| 269 FrameTreeNode* child1 = root->child_at(1); | 288 FrameTreeNode* child1 = root->child_at(1); |
| 270 FrameTreeNode* child2 = root->child_at(2); | 289 FrameTreeNode* child2 = root->child_at(2); |
| 271 | 290 |
| 272 // Add one grandchild frame. | 291 // Add one grandchild frame. |
| 273 child1->current_frame_host()->OnCreateChildFrame(33, "grandchild", | 292 child1->current_frame_host()->OnCreateChildFrame( |
| 274 SandboxFlags::NONE); | 293 33, blink::WebTreeScopeType::Document, "grandchild", SandboxFlags::NONE); |
| 275 FrameTreeNode* grandchild = child1->child_at(0); | 294 FrameTreeNode* grandchild = child1->child_at(0); |
| 276 | 295 |
| 277 EXPECT_EQ(nullptr, root->PreviousSibling()); | 296 EXPECT_EQ(nullptr, root->PreviousSibling()); |
| 278 EXPECT_EQ(nullptr, child0->PreviousSibling()); | 297 EXPECT_EQ(nullptr, child0->PreviousSibling()); |
| 279 EXPECT_EQ(child0, child1->PreviousSibling()); | 298 EXPECT_EQ(child0, child1->PreviousSibling()); |
| 280 EXPECT_EQ(child1, child2->PreviousSibling()); | 299 EXPECT_EQ(child1, child2->PreviousSibling()); |
| 281 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); | 300 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); |
| 282 } | 301 } |
| 283 | 302 |
| 284 // Do some simple manipulations of the frame tree, making sure that | 303 // Do some simple manipulations of the frame tree, making sure that |
| 285 // WebContentsObservers see a consistent view of the tree as we go. | 304 // WebContentsObservers see a consistent view of the tree as we go. |
| 286 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { | 305 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { |
| 287 TreeWalkingWebContentsLogger activity(contents()); | 306 TreeWalkingWebContentsLogger activity(contents()); |
| 288 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 307 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 289 EXPECT_EQ("", activity.GetLog()); | 308 EXPECT_EQ("", activity.GetLog()); |
| 290 | 309 |
| 291 FrameTree* frame_tree = contents()->GetFrameTree(); | 310 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 292 FrameTreeNode* root = frame_tree->root(); | 311 FrameTreeNode* root = frame_tree->root(); |
| 293 | 312 |
| 294 // Simulate attaching a series of frames to build the frame tree. | 313 // Simulate attaching a series of frames to build the frame tree. |
| 295 main_test_rfh()->OnCreateChildFrame(14, std::string(), SandboxFlags::NONE); | 314 main_test_rfh()->OnCreateChildFrame(14, blink::WebTreeScopeType::Document, |
| 315 std::string(), SandboxFlags::NONE); | |
| 296 EXPECT_EQ( | 316 EXPECT_EQ( |
| 297 "RenderFrameHostChanged(new)(14) -> 1: []\n" | 317 "RenderFrameHostChanged(new)(14) -> 1: []\n" |
| 298 "RenderFrameCreated(14) -> 1: [14: []]", | 318 "RenderFrameCreated(14) -> 1: [14: []]", |
| 299 activity.GetLog()); | 319 activity.GetLog()); |
| 300 main_test_rfh()->OnCreateChildFrame(18, std::string(), SandboxFlags::NONE); | 320 main_test_rfh()->OnCreateChildFrame(18, blink::WebTreeScopeType::Document, |
| 321 std::string(), SandboxFlags::NONE); | |
| 301 EXPECT_EQ( | 322 EXPECT_EQ( |
| 302 "RenderFrameHostChanged(new)(18) -> 1: [14: []]\n" | 323 "RenderFrameHostChanged(new)(18) -> 1: [14: []]\n" |
| 303 "RenderFrameCreated(18) -> 1: [14: [], 18: []]", | 324 "RenderFrameCreated(18) -> 1: [14: [], 18: []]", |
| 304 activity.GetLog()); | 325 activity.GetLog()); |
| 305 frame_tree->RemoveFrame(root->child_at(0)); | 326 frame_tree->RemoveFrame(root->child_at(0)); |
| 306 EXPECT_EQ("RenderFrameDeleted(14) -> 1: [18: []]", activity.GetLog()); | 327 EXPECT_EQ("RenderFrameDeleted(14) -> 1: [18: []]", activity.GetLog()); |
| 307 frame_tree->RemoveFrame(root->child_at(0)); | 328 frame_tree->RemoveFrame(root->child_at(0)); |
| 308 EXPECT_EQ("RenderFrameDeleted(18) -> 1: []", activity.GetLog()); | 329 EXPECT_EQ("RenderFrameDeleted(18) -> 1: []", activity.GetLog()); |
| 309 } | 330 } |
| 310 | 331 |
| 311 // Make sure that WebContentsObservers see a consistent view of the tree after | 332 // Make sure that WebContentsObservers see a consistent view of the tree after |
| 312 // recovery from a render process crash. | 333 // recovery from a render process crash. |
| 313 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { | 334 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { |
| 314 TreeWalkingWebContentsLogger activity(contents()); | 335 TreeWalkingWebContentsLogger activity(contents()); |
| 315 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 336 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 316 EXPECT_EQ("", activity.GetLog()); | 337 EXPECT_EQ("", activity.GetLog()); |
| 317 | 338 |
| 318 main_test_rfh()->OnCreateChildFrame(22, std::string(), SandboxFlags::NONE); | 339 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 340 std::string(), SandboxFlags::NONE); | |
| 319 EXPECT_EQ( | 341 EXPECT_EQ( |
| 320 "RenderFrameHostChanged(new)(22) -> 1: []\n" | 342 "RenderFrameHostChanged(new)(22) -> 1: []\n" |
| 321 "RenderFrameCreated(22) -> 1: [22: []]", | 343 "RenderFrameCreated(22) -> 1: [22: []]", |
| 322 activity.GetLog()); | 344 activity.GetLog()); |
| 323 main_test_rfh()->OnCreateChildFrame(23, std::string(), SandboxFlags::NONE); | 345 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, |
| 346 std::string(), SandboxFlags::NONE); | |
| 324 EXPECT_EQ( | 347 EXPECT_EQ( |
| 325 "RenderFrameHostChanged(new)(23) -> 1: [22: []]\n" | 348 "RenderFrameHostChanged(new)(23) -> 1: [22: []]\n" |
| 326 "RenderFrameCreated(23) -> 1: [22: [], 23: []]", | 349 "RenderFrameCreated(23) -> 1: [22: [], 23: []]", |
| 327 activity.GetLog()); | 350 activity.GetLog()); |
| 328 | 351 |
| 329 // Crash the renderer | 352 // Crash the renderer |
| 330 main_test_rfh()->GetProcess()->SimulateCrash(); | 353 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 331 EXPECT_EQ( | 354 EXPECT_EQ( |
| 332 "RenderFrameDeleted(23) -> 1: [22: [], 23*: []]\n" | 355 "RenderFrameDeleted(23) -> 1: [22: [], 23*: []]\n" |
| 333 "RenderFrameDeleted(22) -> 1: [22*: [], 23*: []]\n" | 356 "RenderFrameDeleted(22) -> 1: [22*: [], 23*: []]\n" |
| 334 "RenderFrameDeleted(1) -> 1: []\n" // TODO(nick): Should be "1*:" | 357 "RenderFrameDeleted(1) -> 1: []\n" // TODO(nick): Should be "1*:" |
| 335 "RenderProcessGone -> 1*: []", | 358 "RenderProcessGone -> 1*: []", |
| 336 activity.GetLog()); | 359 activity.GetLog()); |
| 337 } | 360 } |
| 338 | 361 |
| 339 // Ensure that frames are not added to the tree, if the process passed in | 362 // Ensure that frames are not added to the tree, if the process passed in |
| 340 // is different than the process of the parent node. | 363 // is different than the process of the parent node. |
| 341 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { | 364 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { |
| 342 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 365 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 343 FrameTree* frame_tree = contents()->GetFrameTree(); | 366 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 344 FrameTreeNode* root = frame_tree->root(); | 367 FrameTreeNode* root = frame_tree->root(); |
| 345 int process_id = root->current_frame_host()->GetProcess()->GetID(); | 368 int process_id = root->current_frame_host()->GetProcess()->GetID(); |
| 346 | 369 |
| 347 ASSERT_EQ("1: []", GetTreeState(frame_tree)); | 370 ASSERT_EQ("1: []", GetTreeState(frame_tree)); |
| 348 | 371 |
| 349 // Simulate attaching a frame from mismatched process id. | 372 // Simulate attaching a frame from mismatched process id. |
| 350 ASSERT_FALSE(frame_tree->AddFrame(root, process_id + 1, 1, std::string(), | 373 ASSERT_FALSE(frame_tree->AddFrame(root, process_id + 1, 1, |
| 351 SandboxFlags::NONE)); | 374 blink::WebTreeScopeType::Document, |
| 375 std::string(), SandboxFlags::NONE)); | |
| 352 ASSERT_EQ("1: []", GetTreeState(frame_tree)); | 376 ASSERT_EQ("1: []", GetTreeState(frame_tree)); |
| 353 } | 377 } |
| 354 | 378 |
| 355 // Ensure that frames removed while a process has crashed are not preserved in | 379 // Ensure that frames removed while a process has crashed are not preserved in |
| 356 // the global map of id->frame. | 380 // the global map of id->frame. |
| 357 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { | 381 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { |
| 358 // Add a couple child frames to the main frame. | 382 // Add a couple child frames to the main frame. |
| 359 FrameTreeNode* root = contents()->GetFrameTree()->root(); | 383 FrameTreeNode* root = contents()->GetFrameTree()->root(); |
| 360 | 384 |
| 361 main_test_rfh()->OnCreateChildFrame(22, std::string(), SandboxFlags::NONE); | 385 main_test_rfh()->OnCreateChildFrame(22, blink::WebTreeScopeType::Document, |
| 362 main_test_rfh()->OnCreateChildFrame(23, std::string(), SandboxFlags::NONE); | 386 std::string(), SandboxFlags::NONE); |
| 387 main_test_rfh()->OnCreateChildFrame(23, blink::WebTreeScopeType::Document, | |
| 388 std::string(), SandboxFlags::NONE); | |
| 363 | 389 |
| 364 // Add one grandchild frame. | 390 // Add one grandchild frame. |
| 365 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host(); | 391 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host(); |
| 366 child1_rfh->OnCreateChildFrame(33, std::string(), SandboxFlags::NONE); | 392 child1_rfh->OnCreateChildFrame(33, blink::WebTreeScopeType::Document, |
| 393 std::string(), SandboxFlags::NONE); | |
| 367 | 394 |
| 368 // Ensure they can be found by id. | 395 // Ensure they can be found by id. |
| 369 int id1 = root->child_at(0)->frame_tree_node_id(); | 396 int id1 = root->child_at(0)->frame_tree_node_id(); |
| 370 int id2 = root->child_at(1)->frame_tree_node_id(); | 397 int id2 = root->child_at(1)->frame_tree_node_id(); |
| 371 int id3 = root->child_at(0)->child_at(0)->frame_tree_node_id(); | 398 int id3 = root->child_at(0)->child_at(0)->frame_tree_node_id(); |
| 372 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1)); | 399 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1)); |
| 373 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2)); | 400 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2)); |
| 374 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3)); | 401 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3)); |
| 375 | 402 |
| 376 // Crash the renderer. | 403 // Crash the renderer. |
| 377 main_test_rfh()->GetProcess()->SimulateCrash(); | 404 main_test_rfh()->GetProcess()->SimulateCrash(); |
| 378 | 405 |
| 379 // Ensure they cannot be found by id after the process has crashed. | 406 // Ensure they cannot be found by id after the process has crashed. |
| 380 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); | 407 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
| 381 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); | 408 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
| 382 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); | 409 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
| 383 } | 410 } |
| 384 | 411 |
| 385 } // namespace content | 412 } // namespace content |
| OLD | NEW |