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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 EXPECT_EQ(nullptr, frame_tree->FindByRoutingID(process_id, 37)); | 237 EXPECT_EQ(nullptr, frame_tree->FindByRoutingID(process_id, 37)); |
238 | 238 |
239 // Ensure they can be found by name, if they have one. | 239 // Ensure they can be found by name, if they have one. |
240 EXPECT_EQ(root, frame_tree->FindByName(std::string())); | 240 EXPECT_EQ(root, frame_tree->FindByName(std::string())); |
241 EXPECT_EQ(child0, frame_tree->FindByName("child0")); | 241 EXPECT_EQ(child0, frame_tree->FindByName("child0")); |
242 EXPECT_EQ(child1, frame_tree->FindByName("child1")); | 242 EXPECT_EQ(child1, frame_tree->FindByName("child1")); |
243 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); | 243 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); |
244 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); | 244 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); |
245 } | 245 } |
246 | 246 |
247 // Check that PreviousSibling() is retrieved correctly. | |
248 TEST_F(FrameTreeTest, PreviousSibling) { | |
249 // Add a few child frames to the main frame. | |
250 FrameTree* frame_tree = contents()->GetFrameTree(); | |
251 FrameTreeNode* root = frame_tree->root(); | |
252 main_test_rfh()->OnCreateChildFrame(22, "child0", SandboxFlags::NONE); | |
253 main_test_rfh()->OnCreateChildFrame(23, "child1", SandboxFlags::NONE); | |
254 main_test_rfh()->OnCreateChildFrame(24, "child2", SandboxFlags::NONE); | |
255 FrameTreeNode* child0 = root->child_at(0); | |
256 FrameTreeNode* child1 = root->child_at(1); | |
257 FrameTreeNode* child2 = root->child_at(2); | |
258 | |
259 // Add one grandchild frame. | |
260 child1->current_frame_host()->OnCreateChildFrame(33, "grandchild", | |
261 SandboxFlags::NONE); | |
262 FrameTreeNode* grandchild = child1->child_at(0); | |
263 | |
264 EXPECT_EQ(nullptr, root->PreviousSibling()); | |
265 EXPECT_EQ(nullptr, child0->PreviousSibling()); | |
266 EXPECT_EQ(child0, child1->PreviousSibling()); | |
267 EXPECT_EQ(child1, child2->PreviousSibling()); | |
268 EXPECT_EQ(nullptr, grandchild->PreviousSibling()); | |
269 } | |
270 | |
271 // Do some simple manipulations of the frame tree, making sure that | 247 // Do some simple manipulations of the frame tree, making sure that |
272 // WebContentsObservers see a consistent view of the tree as we go. | 248 // WebContentsObservers see a consistent view of the tree as we go. |
273 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { | 249 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { |
274 TreeWalkingWebContentsLogger activity(contents()); | 250 TreeWalkingWebContentsLogger activity(contents()); |
275 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 251 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
276 EXPECT_EQ("", activity.GetLog()); | 252 EXPECT_EQ("", activity.GetLog()); |
277 | 253 |
278 FrameTree* frame_tree = contents()->GetFrameTree(); | 254 FrameTree* frame_tree = contents()->GetFrameTree(); |
279 FrameTreeNode* root = frame_tree->root(); | 255 FrameTreeNode* root = frame_tree->root(); |
280 | 256 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // Crash the renderer. | 338 // Crash the renderer. |
363 main_test_rfh()->GetProcess()->SimulateCrash(); | 339 main_test_rfh()->GetProcess()->SimulateCrash(); |
364 | 340 |
365 // Ensure they cannot be found by id after the process has crashed. | 341 // Ensure they cannot be found by id after the process has crashed. |
366 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); | 342 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
367 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); | 343 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
368 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); | 344 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
369 } | 345 } |
370 | 346 |
371 } // namespace content | 347 } // namespace content |
OLD | NEW |