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

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

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