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