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

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

Issue 1086613003: Revert of Set frame liveness before calling RenderFrameCreated/RenderFrameDeleted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b444955
Patch Set: 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
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11 matching lines...) Expand all
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 namespace content { 24 namespace content {
25 25
26 namespace { 26 namespace {
27 27
28 // Appends a description of the structure of the frame tree to |result|. 28 // Appends a description of the structure of the frame tree to |result|.
29 void AppendTreeNodeState(FrameTreeNode* node, std::string* result) { 29 void AppendTreeNodeState(FrameTreeNode* node, std::string* result) {
30 result->append( 30 result->append(
31 base::Int64ToString(node->current_frame_host()->GetRoutingID())); 31 base::Int64ToString(node->current_frame_host()->GetRoutingID()));
32 if (!node->current_frame_host()->IsRenderFrameLive())
33 result->append("*"); // Asterisk next to dead frames.
34
35 if (!node->frame_name().empty()) { 32 if (!node->frame_name().empty()) {
36 result->append(" '"); 33 result->append(" '");
37 result->append(node->frame_name()); 34 result->append(node->frame_name());
38 result->append("'"); 35 result->append("'");
39 } 36 }
40 result->append(": ["); 37 result->append(": [");
41 const char* separator = ""; 38 const char* separator = "";
42 for (size_t i = 0; i < node->child_count(); i++) { 39 for (size_t i = 0; i < node->child_count(); i++) {
43 result->append(separator); 40 result->append(separator);
44 AppendTreeNodeState(node->child_at(i), result); 41 AppendTreeNodeState(node->child_at(i), result);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 "16: [264: [], 266: [], " 195 "16: [264: [], 266: [], "
199 "267 'node with deep subtree': " 196 "267 'node with deep subtree': "
200 "[365: [455: []]], 268: []]]", 197 "[365: [455: []]], 268: []]]",
201 GetTreeState(frame_tree)); 198 GetTreeState(frame_tree));
202 } 199 }
203 200
204 // Do some simple manipulations of the frame tree, making sure that 201 // Do some simple manipulations of the frame tree, making sure that
205 // WebContentsObservers see a consistent view of the tree as we go. 202 // WebContentsObservers see a consistent view of the tree as we go.
206 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { 203 TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) {
207 TreeWalkingWebContentsLogger activity(contents()); 204 TreeWalkingWebContentsLogger activity(contents());
208 contents()->NavigateAndCommit(GURL("http://www.google.com"));
209 EXPECT_EQ("", activity.GetLog());
210
211 FrameTree* frame_tree = contents()->GetFrameTree(); 205 FrameTree* frame_tree = contents()->GetFrameTree();
212 FrameTreeNode* root = frame_tree->root(); 206 FrameTreeNode* root = frame_tree->root();
213 207
208 EXPECT_EQ("", activity.GetLog());
209
214 // Simulate attaching a series of frames to build the frame tree. 210 // Simulate attaching a series of frames to build the frame tree.
215 main_test_rfh()->OnCreateChildFrame(14, std::string(), SandboxFlags::NONE); 211 main_test_rfh()->OnCreateChildFrame(14, std::string(), SandboxFlags::NONE);
216 EXPECT_EQ( 212 EXPECT_EQ(
217 "RenderFrameHostChanged(new)(14) -> 1: []\n" 213 "RenderFrameHostChanged(new)(14) -> 1: []\n"
218 "RenderFrameCreated(14) -> 1: [14: []]", 214 "RenderFrameCreated(14) -> 1: [14: []]",
219 activity.GetLog()); 215 activity.GetLog());
220 main_test_rfh()->OnCreateChildFrame(18, std::string(), SandboxFlags::NONE); 216 main_test_rfh()->OnCreateChildFrame(18, std::string(), SandboxFlags::NONE);
221 EXPECT_EQ( 217 EXPECT_EQ(
222 "RenderFrameHostChanged(new)(18) -> 1: [14: []]\n" 218 "RenderFrameHostChanged(new)(18) -> 1: [14: []]\n"
223 "RenderFrameCreated(18) -> 1: [14: [], 18: []]", 219 "RenderFrameCreated(18) -> 1: [14: [], 18: []]",
224 activity.GetLog()); 220 activity.GetLog());
225 frame_tree->RemoveFrame(root->child_at(0)); 221 frame_tree->RemoveFrame(root->child_at(0));
226 EXPECT_EQ("RenderFrameDeleted(14) -> 1: [18: []]", activity.GetLog()); 222 EXPECT_EQ("RenderFrameDeleted(14) -> 1: [18: []]", activity.GetLog());
227 frame_tree->RemoveFrame(root->child_at(0)); 223 frame_tree->RemoveFrame(root->child_at(0));
228 EXPECT_EQ("RenderFrameDeleted(18) -> 1: []", activity.GetLog()); 224 EXPECT_EQ("RenderFrameDeleted(18) -> 1: []", activity.GetLog());
229 } 225 }
230 226
231 // Make sure that WebContentsObservers see a consistent view of the tree after 227 // Make sure that WebContentsObservers see a consistent view of the tree after
232 // recovery from a render process crash. 228 // recovery from a render process crash.
233 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { 229 TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) {
234 TreeWalkingWebContentsLogger activity(contents()); 230 TreeWalkingWebContentsLogger activity(contents());
235 contents()->NavigateAndCommit(GURL("http://www.google.com"));
236 EXPECT_EQ("", activity.GetLog());
237 231
238 main_test_rfh()->OnCreateChildFrame(22, std::string(), SandboxFlags::NONE); 232 main_test_rfh()->OnCreateChildFrame(22, std::string(), SandboxFlags::NONE);
239 EXPECT_EQ( 233 EXPECT_EQ(
240 "RenderFrameHostChanged(new)(22) -> 1: []\n" 234 "RenderFrameHostChanged(new)(22) -> 1: []\n"
241 "RenderFrameCreated(22) -> 1: [22: []]", 235 "RenderFrameCreated(22) -> 1: [22: []]",
242 activity.GetLog()); 236 activity.GetLog());
243 main_test_rfh()->OnCreateChildFrame(23, std::string(), SandboxFlags::NONE); 237 main_test_rfh()->OnCreateChildFrame(23, std::string(), SandboxFlags::NONE);
244 EXPECT_EQ( 238 EXPECT_EQ(
245 "RenderFrameHostChanged(new)(23) -> 1: [22: []]\n" 239 "RenderFrameHostChanged(new)(23) -> 1: [22: []]\n"
246 "RenderFrameCreated(23) -> 1: [22: [], 23: []]", 240 "RenderFrameCreated(23) -> 1: [22: [], 23: []]",
247 activity.GetLog()); 241 activity.GetLog());
248 242
249 // Crash the renderer 243 // Crash the renderer
250 main_test_rfh()->OnMessageReceived(FrameHostMsg_RenderProcessGone( 244 main_test_rfh()->OnMessageReceived(FrameHostMsg_RenderProcessGone(
251 main_test_rfh()->GetRoutingID(), base::TERMINATION_STATUS_PROCESS_CRASHED, 245 main_test_rfh()->GetRoutingID(), base::TERMINATION_STATUS_PROCESS_CRASHED,
252 -1)); 246 -1));
253 EXPECT_EQ( 247 EXPECT_EQ(
254 "RenderFrameDeleted(22) -> 1: []\n" 248 "RenderFrameDeleted(22) -> 1: []\n"
255 "RenderFrameDeleted(23) -> 1: []\n" 249 "RenderFrameDeleted(23) -> 1: []\n"
256 "RenderFrameDeleted(1) -> 1: []\n" 250 "RenderFrameDeleted(1) -> 1: []\n"
257 "RenderProcessGone -> 1: []", 251 "RenderProcessGone -> 1: []",
258 activity.GetLog()); 252 activity.GetLog());
259 } 253 }
260 254
261 // Ensure that frames are not added to the tree, if the process passed in 255 // Ensure that frames are not added to the tree, if the process passed in
262 // is different than the process of the parent node. 256 // is different than the process of the parent node.
263 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { 257 TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) {
264 contents()->NavigateAndCommit(GURL("http://www.google.com"));
265 FrameTree* frame_tree = contents()->GetFrameTree(); 258 FrameTree* frame_tree = contents()->GetFrameTree();
266 FrameTreeNode* root = frame_tree->root(); 259 FrameTreeNode* root = frame_tree->root();
267 int process_id = root->current_frame_host()->GetProcess()->GetID(); 260 int process_id = root->current_frame_host()->GetProcess()->GetID();
268 261
269 ASSERT_EQ("1: []", GetTreeState(frame_tree)); 262 ASSERT_EQ("1: []", GetTreeState(frame_tree));
270 263
271 // Simulate attaching a frame from mismatched process id. 264 // Simulate attaching a frame from mismatched process id.
272 ASSERT_FALSE(frame_tree->AddFrame(root, process_id + 1, 1, std::string())); 265 ASSERT_FALSE(frame_tree->AddFrame(root, process_id + 1, 1, std::string()));
273 ASSERT_EQ("1: []", GetTreeState(frame_tree)); 266 ASSERT_EQ("1: []", GetTreeState(frame_tree));
274 } 267 }
(...skipping 23 matching lines...) Expand all
298 main_test_rfh()->OnMessageReceived(FrameHostMsg_RenderProcessGone( 291 main_test_rfh()->OnMessageReceived(FrameHostMsg_RenderProcessGone(
299 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); 292 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1));
300 293
301 // Ensure they cannot be found by id after the process has crashed. 294 // Ensure they cannot be found by id after the process has crashed.
302 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); 295 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1));
303 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); 296 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2));
304 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); 297 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3));
305 } 298 }
306 299
307 } // namespace content 300 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698