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

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

Issue 106963004: Make RenderFrameHostManager swap RenderFrameHosts, not RenderViewHosts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years 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 | Annotate | Revision Log
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 29 matching lines...) Expand all
40 const char* separator = ""; 40 const char* separator = "";
41 for (size_t i = 0; i < node->child_count(); i++) { 41 for (size_t i = 0; i < node->child_count(); i++) {
42 result->append(separator); 42 result->append(separator);
43 AppendTreeNodeState(node->child_at(i), result); 43 AppendTreeNodeState(node->child_at(i), result);
44 separator = ", "; 44 separator = ", ";
45 } 45 }
46 result->append("]"); 46 result->append("]");
47 } 47 }
48 }; 48 };
49 49
50 // The root node never changes during navigation even though its
51 // RenderFrameHost does.
52 // - Swapping main frame doesn't change root node.
53 // - Swapping back to NULL doesn't crash (easier tear-down for interstitials).
54 // - Main frame does not own RenderFrameHost.
55 TEST_F(FrameTreeTest, RootNode) {
56 FrameTree frame_tree(new NavigatorImpl(NULL, NULL), NULL, NULL, NULL, NULL);
57
58 // Initial state has empty node.
59 FrameTreeNode* root = frame_tree.root();
60 ASSERT_TRUE(root);
61 EXPECT_FALSE(frame_tree.GetMainFrame());
62
63 // Swap in main frame.
64 RenderFrameHostImpl* dummy = reinterpret_cast<RenderFrameHostImpl*>(0x1);
65 frame_tree.SwapMainFrame(dummy);
66 EXPECT_EQ(root, frame_tree.root());
67 EXPECT_EQ(dummy, frame_tree.GetMainFrame());
68
69 // Move back to NULL.
70 frame_tree.SwapMainFrame(NULL);
71 EXPECT_EQ(root, frame_tree.root());
72 EXPECT_FALSE(frame_tree.GetMainFrame());
73
74 // Move back to an invalid pointer, let the FrameTree go out of scope. Test
75 // should not crash because the main frame isn't owned.
76 frame_tree.SwapMainFrame(dummy);
77 }
78
79 // Test that swapping the main frame resets the renderer-assigned frame id. 50 // Test that swapping the main frame resets the renderer-assigned frame id.
80 // - On creation, frame id is unassigned. 51 // - On creation, frame id is unassigned.
81 // - After a swap, frame id is unassigned. 52 // - After a swap, frame id is unassigned.
82 TEST_F(FrameTreeTest, FirstNavigationAfterSwap) { 53 TEST_F(FrameTreeTest, FirstNavigationAfterSwap) {
83 FrameTree frame_tree(new NavigatorImpl(NULL, NULL), NULL, NULL, NULL, NULL); 54 FrameTree frame_tree(new NavigatorImpl(NULL, NULL), NULL, NULL, NULL, NULL);
84 55
85 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap()); 56 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap());
86 EXPECT_EQ(FrameTreeNode::kInvalidFrameId, 57 EXPECT_EQ(FrameTreeNode::kInvalidFrameId,
87 frame_tree.root()->frame_id()); 58 frame_tree.root()->frame_id());
88 frame_tree.OnFirstNavigationAfterSwap(1); 59 frame_tree.OnFirstNavigationAfterSwap(1);
89 EXPECT_FALSE(frame_tree.IsFirstNavigationAfterSwap()); 60 EXPECT_FALSE(frame_tree.IsFirstNavigationAfterSwap());
90 EXPECT_EQ(1, frame_tree.root()->frame_id()); 61 EXPECT_EQ(1, frame_tree.root()->frame_id());
91 62
92 frame_tree.SwapMainFrame(NULL); 63 frame_tree.ResetForMainFrameSwap();
93 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap()); 64 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap());
94 EXPECT_EQ(FrameTreeNode::kInvalidFrameId, 65 EXPECT_EQ(FrameTreeNode::kInvalidFrameId,
95 frame_tree.root()->frame_id()); 66 frame_tree.root()->frame_id());
96 } 67 }
97 68
98 // Exercise tree manipulation routines. 69 // Exercise tree manipulation routines.
99 // - Add a series of nodes and verify tree structure. 70 // - Add a series of nodes and verify tree structure.
100 // - Remove a series of nodes and verify tree structure. 71 // - Remove a series of nodes and verify tree structure.
101 TEST_F(FrameTreeTest, Shape) { 72 TEST_F(FrameTreeTest, Shape) {
102 FrameTree frame_tree(new NavigatorImpl(NULL, NULL), NULL, NULL, NULL, NULL); 73 FrameTree frame_tree(new NavigatorImpl(NULL, NULL), NULL, NULL, NULL, NULL);
103 74
104 std::string no_children_node("no children node"); 75 std::string no_children_node("no children node");
105 std::string deep_subtree("node with deep subtree"); 76 std::string deep_subtree("node with deep subtree");
106 77
107 // Ensure the top-level node of the FrameTree is initialized by simulating a
108 // main frame swap here.
109 scoped_ptr<RenderFrameHostImpl> render_frame_host =
110 RenderFrameHostFactory::Create(static_cast<RenderViewHostImpl*>(rvh()),
111 NULL,
112 &frame_tree,
113 frame_tree.root(),
114 process()->GetNextRoutingID(),
115 false);
116 frame_tree.SwapMainFrame(render_frame_host.get());
117 frame_tree.OnFirstNavigationAfterSwap(5); 78 frame_tree.OnFirstNavigationAfterSwap(5);
118 79
119 ASSERT_EQ("5: []", GetTreeState(&frame_tree)); 80 ASSERT_EQ("5: []", GetTreeState(&frame_tree));
120 81
121 // Simulate attaching a series of frames to build the frame tree. 82 // Simulate attaching a series of frames to build the frame tree.
122 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 14, std::string()); 83 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 14, std::string());
123 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 15, std::string()); 84 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 15, std::string());
124 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 16, std::string()); 85 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 16, std::string());
125 86
126 frame_tree.AddFrame(process()->GetNextRoutingID(), 14, 244, std::string()); 87 frame_tree.AddFrame(process()->GetNextRoutingID(), 14, 244, std::string());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 frame_tree.RemoveFrame(NULL, 5, 15); 132 frame_tree.RemoveFrame(NULL, 5, 15);
172 ASSERT_EQ("5: [14: [244: [], 245: []], " 133 ASSERT_EQ("5: [14: [244: [], 245: []], "
173 "16: [264: [], 266: [], " 134 "16: [264: [], 266: [], "
174 "267 'node with deep subtree': " 135 "267 'node with deep subtree': "
175 "[365: [455: [555: []]]], 268: []]]", 136 "[365: [455: [555: []]]], 268: []]]",
176 GetTreeState(&frame_tree)); 137 GetTreeState(&frame_tree));
177 } 138 }
178 139
179 } // namespace 140 } // namespace
180 } // namespace content 141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698