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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 GetTreeState(frame_tree)); | 194 GetTreeState(frame_tree)); |
195 | 195 |
196 frame_tree->RemoveFrame(root->child_at(1)); | 196 frame_tree->RemoveFrame(root->child_at(1)); |
197 ASSERT_EQ("1: [14: [244: [], 245: []], " | 197 ASSERT_EQ("1: [14: [244: [], 245: []], " |
198 "16: [264: [], 266: [], " | 198 "16: [264: [], 266: [], " |
199 "267 'node with deep subtree': " | 199 "267 'node with deep subtree': " |
200 "[365: [455: []]], 268: []]]", | 200 "[365: [455: []]], 268: []]]", |
201 GetTreeState(frame_tree)); | 201 GetTreeState(frame_tree)); |
202 } | 202 } |
203 | 203 |
| 204 // Ensure frames can be found by frame_tree_node_id, routing ID, or name. |
| 205 TEST_F(FrameTreeTest, FindFrames) { |
| 206 // Add a few child frames to the main frame. |
| 207 FrameTree* frame_tree = contents()->GetFrameTree(); |
| 208 FrameTreeNode* root = frame_tree->root(); |
| 209 main_test_rfh()->OnCreateChildFrame(22, "child0", SandboxFlags::NONE); |
| 210 main_test_rfh()->OnCreateChildFrame(23, "child1", SandboxFlags::NONE); |
| 211 main_test_rfh()->OnCreateChildFrame(24, std::string(), SandboxFlags::NONE); |
| 212 FrameTreeNode* child0 = root->child_at(0); |
| 213 FrameTreeNode* child1 = root->child_at(1); |
| 214 FrameTreeNode* child2 = root->child_at(2); |
| 215 |
| 216 // Add one grandchild frame. |
| 217 child1->current_frame_host()->OnCreateChildFrame(33, "grandchild", |
| 218 SandboxFlags::NONE); |
| 219 FrameTreeNode* grandchild = child1->child_at(0); |
| 220 |
| 221 // Ensure they can be found by FTN id. |
| 222 EXPECT_EQ(root, frame_tree->FindByID(root->frame_tree_node_id())); |
| 223 EXPECT_EQ(child0, frame_tree->FindByID(child0->frame_tree_node_id())); |
| 224 EXPECT_EQ(child1, frame_tree->FindByID(child1->frame_tree_node_id())); |
| 225 EXPECT_EQ(child2, frame_tree->FindByID(child2->frame_tree_node_id())); |
| 226 EXPECT_EQ(grandchild, frame_tree->FindByID(grandchild->frame_tree_node_id())); |
| 227 EXPECT_EQ(nullptr, frame_tree->FindByID(-1)); |
| 228 |
| 229 // Ensure they can be found by routing id. |
| 230 int process_id = main_test_rfh()->GetProcess()->GetID(); |
| 231 EXPECT_EQ(root, frame_tree->FindByRoutingID(process_id, |
| 232 main_test_rfh()->GetRoutingID())); |
| 233 EXPECT_EQ(child0, frame_tree->FindByRoutingID(process_id, 22)); |
| 234 EXPECT_EQ(child1, frame_tree->FindByRoutingID(process_id, 23)); |
| 235 EXPECT_EQ(child2, frame_tree->FindByRoutingID(process_id, 24)); |
| 236 EXPECT_EQ(grandchild, frame_tree->FindByRoutingID(process_id, 33)); |
| 237 EXPECT_EQ(nullptr, frame_tree->FindByRoutingID(process_id, 37)); |
| 238 |
| 239 // Ensure they can be found by name, if they have one. |
| 240 EXPECT_EQ(root, frame_tree->FindByName(std::string())); |
| 241 EXPECT_EQ(child0, frame_tree->FindByName("child0")); |
| 242 EXPECT_EQ(child1, frame_tree->FindByName("child1")); |
| 243 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild")); |
| 244 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame")); |
| 245 } |
| 246 |
204 // Do some simple manipulations of the frame tree, making sure that | 247 // Do some simple manipulations of the frame tree, making sure that |
205 // WebContentsObservers see a consistent view of the tree as we go. | 248 // WebContentsObservers see a consistent view of the tree as we go. |
206 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { | 249 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { |
207 TreeWalkingWebContentsLogger activity(contents()); | 250 TreeWalkingWebContentsLogger activity(contents()); |
208 contents()->NavigateAndCommit(GURL("http://www.google.com")); | 251 contents()->NavigateAndCommit(GURL("http://www.google.com")); |
209 EXPECT_EQ("", activity.GetLog()); | 252 EXPECT_EQ("", activity.GetLog()); |
210 | 253 |
211 FrameTree* frame_tree = contents()->GetFrameTree(); | 254 FrameTree* frame_tree = contents()->GetFrameTree(); |
212 FrameTreeNode* root = frame_tree->root(); | 255 FrameTreeNode* root = frame_tree->root(); |
213 | 256 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 // Crash the renderer. | 338 // Crash the renderer. |
296 main_test_rfh()->GetProcess()->SimulateCrash(); | 339 main_test_rfh()->GetProcess()->SimulateCrash(); |
297 | 340 |
298 // 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. |
299 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); | 342 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
300 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); | 343 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
301 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); | 344 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
302 } | 345 } |
303 | 346 |
304 } // namespace content | 347 } // namespace content |
OLD | NEW |