Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: content/browser/frame_host/frame_tree_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698