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

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

Issue 2797813002: Replicate feature policy container policies. (Closed)
Patch Set: Addressing review comments Created 3 years, 8 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::kDocument, 159 frame_tree->AddFrame(root, process_id, 14, blink::WebTreeScopeType::kDocument,
160 std::string(), "uniqueName0", 160 std::string(), "uniqueName0",
161 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 161 blink::WebSandboxFlags::kNone,
162 ParsedFeaturePolicyHeader(), FrameOwnerProperties());
162 frame_tree->AddFrame(root, process_id, 15, blink::WebTreeScopeType::kDocument, 163 frame_tree->AddFrame(root, process_id, 15, blink::WebTreeScopeType::kDocument,
163 std::string(), "uniqueName1", 164 std::string(), "uniqueName1",
164 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 165 blink::WebSandboxFlags::kNone,
166 ParsedFeaturePolicyHeader(), FrameOwnerProperties());
165 frame_tree->AddFrame(root, process_id, 16, blink::WebTreeScopeType::kDocument, 167 frame_tree->AddFrame(root, process_id, 16, blink::WebTreeScopeType::kDocument,
166 std::string(), "uniqueName2", 168 std::string(), "uniqueName2",
167 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 169 blink::WebSandboxFlags::kNone,
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::kDocument, std::string(), 172 blink::WebTreeScopeType::kDocument, std::string(),
171 "uniqueName3", blink::WebSandboxFlags::kNone, 173 "uniqueName3", blink::WebSandboxFlags::kNone,
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::kDocument, no_children_node, 176 blink::WebTreeScopeType::kDocument, no_children_node,
175 "uniqueName4", blink::WebSandboxFlags::kNone, 177 "uniqueName4", blink::WebSandboxFlags::kNone,
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::kDocument, std::string(), 180 blink::WebTreeScopeType::kDocument, std::string(),
179 "uniqueName5", blink::WebSandboxFlags::kNone, 181 "uniqueName5", blink::WebSandboxFlags::kNone,
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::kDocument, std::string(), 192 blink::WebTreeScopeType::kDocument, std::string(),
191 "uniqueName6", blink::WebSandboxFlags::kNone, 193 "uniqueName6", blink::WebSandboxFlags::kNone,
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::kDocument, std::string(), 196 blink::WebTreeScopeType::kDocument, std::string(),
195 "uniqueName7", blink::WebSandboxFlags::kNone, 197 "uniqueName7", blink::WebSandboxFlags::kNone,
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::kDocument, std::string(), 200 blink::WebTreeScopeType::kDocument, std::string(),
199 "uniqueName8", blink::WebSandboxFlags::kNone, 201 "uniqueName8", blink::WebSandboxFlags::kNone,
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::kDocument, deep_subtree, 204 blink::WebTreeScopeType::kDocument, deep_subtree,
203 "uniqueName9", blink::WebSandboxFlags::kNone, 205 "uniqueName9", blink::WebSandboxFlags::kNone,
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::kDocument, std::string(), 208 blink::WebTreeScopeType::kDocument, std::string(),
207 "uniqueName10", blink::WebSandboxFlags::kNone, 209 "uniqueName10", blink::WebSandboxFlags::kNone,
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::kDocument, std::string(), 214 blink::WebTreeScopeType::kDocument, std::string(),
213 "uniqueName11", blink::WebSandboxFlags::kNone, 215 "uniqueName11", blink::WebSandboxFlags::kNone,
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::kDocument, std::string(), 218 blink::WebTreeScopeType::kDocument, std::string(),
217 "uniqueName12", blink::WebSandboxFlags::kNone, 219 "uniqueName12", blink::WebSandboxFlags::kNone,
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::kDocument, std::string(), 222 blink::WebTreeScopeType::kDocument, std::string(),
221 "uniqueName13", blink::WebSandboxFlags::kNone, 223 "uniqueName13", blink::WebSandboxFlags::kNone,
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::kDocument, 226 process_id, 655, blink::WebTreeScopeType::kDocument,
225 std::string(), "uniqueName14", 227 std::string(), "uniqueName14",
226 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 228 blink::WebSandboxFlags::kNone,
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
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::kDocument, "child0", "uniqueName0", 301 22, blink::WebTreeScopeType::kDocument, "child0", "uniqueName0",
299 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 302 blink::WebSandboxFlags::kNone, ParsedFeaturePolicyHeader(),
303 FrameOwnerProperties());
300 main_test_rfh()->OnCreateChildFrame( 304 main_test_rfh()->OnCreateChildFrame(
301 23, blink::WebTreeScopeType::kDocument, "child1", "uniqueName1", 305 23, blink::WebTreeScopeType::kDocument, "child1", "uniqueName1",
302 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 306 blink::WebSandboxFlags::kNone, ParsedFeaturePolicyHeader(),
307 FrameOwnerProperties());
303 main_test_rfh()->OnCreateChildFrame( 308 main_test_rfh()->OnCreateChildFrame(
304 24, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName2", 309 24, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName2",
305 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 310 blink::WebSandboxFlags::kNone, 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::kDocument, "grandchild", "uniqueName3", 319 33, blink::WebTreeScopeType::kDocument, "grandchild", "uniqueName3",
314 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 320 blink::WebSandboxFlags::kNone, 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
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::kDocument, "child0", "uniqueName0", 358 22, blink::WebTreeScopeType::kDocument, "child0", "uniqueName0",
352 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 359 blink::WebSandboxFlags::kNone, ParsedFeaturePolicyHeader(),
360 FrameOwnerProperties());
353 main_test_rfh()->OnCreateChildFrame( 361 main_test_rfh()->OnCreateChildFrame(
354 23, blink::WebTreeScopeType::kDocument, "child1", "uniqueName1", 362 23, blink::WebTreeScopeType::kDocument, "child1", "uniqueName1",
355 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 363 blink::WebSandboxFlags::kNone, ParsedFeaturePolicyHeader(),
364 FrameOwnerProperties());
356 main_test_rfh()->OnCreateChildFrame( 365 main_test_rfh()->OnCreateChildFrame(
357 24, blink::WebTreeScopeType::kDocument, "child2", "uniqueName2", 366 24, blink::WebTreeScopeType::kDocument, "child2", "uniqueName2",
358 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 367 blink::WebSandboxFlags::kNone, 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::kDocument, "grandchild", "uniqueName3", 375 33, blink::WebTreeScopeType::kDocument, "grandchild", "uniqueName3",
366 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 376 blink::WebSandboxFlags::kNone, 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
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::kDocument, std::string(), "uniqueName0", 407 14, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName0",
397 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 408 blink::WebSandboxFlags::kNone, 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::kDocument, std::string(), "uniqueName1", 415 18, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName1",
404 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 416 blink::WebSandboxFlags::kNone, 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::kDocument, std::string(), "uniqueName0", 436 22, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName0",
424 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 437 blink::WebSandboxFlags::kNone, 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::kDocument, std::string(), "uniqueName1", 444 23, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName1",
431 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 445 blink::WebSandboxFlags::kNone, 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::kDocument, 474 root, process_id + 1, 1, blink::WebTreeScopeType::kDocument,
460 std::string(), "uniqueName0", blink::WebSandboxFlags::kNone, 475 std::string(), "uniqueName0", blink::WebSandboxFlags::kNone,
461 FrameOwnerProperties())); 476 ParsedFeaturePolicyHeader(), FrameOwnerProperties()));
462 ASSERT_EQ("2: []", GetTreeState(frame_tree)); 477 ASSERT_EQ("2: []", GetTreeState(frame_tree));
463 } 478 }
464 479
465 // 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
466 // the global map of id->frame. 481 // the global map of id->frame.
467 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { 482 TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) {
468 main_test_rfh()->InitializeRenderFrameIfNeeded(); 483 main_test_rfh()->InitializeRenderFrameIfNeeded();
469 484
470 // Add a couple child frames to the main frame. 485 // Add a couple child frames to the main frame.
471 FrameTreeNode* root = contents()->GetFrameTree()->root(); 486 FrameTreeNode* root = contents()->GetFrameTree()->root();
472 487
473 main_test_rfh()->OnCreateChildFrame( 488 main_test_rfh()->OnCreateChildFrame(
474 22, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName0", 489 22, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName0",
475 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 490 blink::WebSandboxFlags::kNone, ParsedFeaturePolicyHeader(),
491 FrameOwnerProperties());
476 main_test_rfh()->OnCreateChildFrame( 492 main_test_rfh()->OnCreateChildFrame(
477 23, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName1", 493 23, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName1",
478 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 494 blink::WebSandboxFlags::kNone, ParsedFeaturePolicyHeader(),
495 FrameOwnerProperties());
479 496
480 // Add one grandchild frame. 497 // Add one grandchild frame.
481 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host(); 498 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host();
482 child1_rfh->OnCreateChildFrame( 499 child1_rfh->OnCreateChildFrame(
483 33, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName2", 500 33, blink::WebTreeScopeType::kDocument, std::string(), "uniqueName2",
484 blink::WebSandboxFlags::kNone, FrameOwnerProperties()); 501 blink::WebSandboxFlags::kNone, ParsedFeaturePolicyHeader(),
502 FrameOwnerProperties());
485 503
486 // Ensure they can be found by id. 504 // Ensure they can be found by id.
487 int id1 = root->child_at(0)->frame_tree_node_id(); 505 int id1 = root->child_at(0)->frame_tree_node_id();
488 int id2 = root->child_at(1)->frame_tree_node_id(); 506 int id2 = root->child_at(1)->frame_tree_node_id();
489 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();
490 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1)); 508 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1));
491 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2)); 509 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2));
492 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3)); 510 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3));
493 511
494 // Crash the renderer. 512 // Crash the renderer.
495 main_test_rfh()->GetProcess()->SimulateCrash(); 513 main_test_rfh()->GetProcess()->SimulateCrash();
496 514
497 // 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.
498 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); 516 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1));
499 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); 517 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2));
500 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); 518 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3));
501 } 519 }
502 520
503 } // namespace content 521 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698