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

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

Issue 1104603002: Pick frame to navigate in the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit test Created 5 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 "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
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
228 // Ensure they can be found by routing id.
229 int process_id = main_test_rfh()->GetProcess()->GetID();
230 EXPECT_EQ(root, frame_tree->FindByRoutingID(process_id,
231 main_test_rfh()->GetRoutingID()));
232 EXPECT_EQ(child0, frame_tree->FindByRoutingID(process_id, 22));
233 EXPECT_EQ(child1, frame_tree->FindByRoutingID(process_id, 23));
234 EXPECT_EQ(child2, frame_tree->FindByRoutingID(process_id, 24));
235 EXPECT_EQ(grandchild, frame_tree->FindByRoutingID(process_id, 33));
236
237 // Ensure they can be found by name, if they have one.
238 EXPECT_EQ(root, frame_tree->FindByName(std::string()));
239 EXPECT_EQ(child0, frame_tree->FindByName("child0"));
240 EXPECT_EQ(child1, frame_tree->FindByName("child1"));
241 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild"));
alexmos 2015/04/23 23:32:54 Would it be worth also checking that lookups for n
Charlie Reis 2015/04/24 18:30:54 Good point. Done.
242 }
243
204 // Do some simple manipulations of the frame tree, making sure that 244 // Do some simple manipulations of the frame tree, making sure that
205 // WebContentsObservers see a consistent view of the tree as we go. 245 // WebContentsObservers see a consistent view of the tree as we go.
206 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { 246 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) {
207 TreeWalkingWebContentsLogger activity(contents()); 247 TreeWalkingWebContentsLogger activity(contents());
208 contents()->NavigateAndCommit(GURL("http://www.google.com")); 248 contents()->NavigateAndCommit(GURL("http://www.google.com"));
209 EXPECT_EQ("", activity.GetLog()); 249 EXPECT_EQ("", activity.GetLog());
210 250
211 FrameTree* frame_tree = contents()->GetFrameTree(); 251 FrameTree* frame_tree = contents()->GetFrameTree();
212 FrameTreeNode* root = frame_tree->root(); 252 FrameTreeNode* root = frame_tree->root();
213 253
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Crash the renderer. 335 // Crash the renderer.
296 main_test_rfh()->GetProcess()->SimulateCrash(); 336 main_test_rfh()->GetProcess()->SimulateCrash();
297 337
298 // Ensure they cannot be found by id after the process has crashed. 338 // Ensure they cannot be found by id after the process has crashed.
299 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); 339 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1));
300 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); 340 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2));
301 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); 341 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3));
302 } 342 }
303 343
304 } // namespace content 344 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698