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

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

Issue 105523006: Revert 241151 "Make RenderFrameHostManager swap RenderFrameHosts..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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"
11 #include "content/browser/frame_host/render_frame_host_impl.h" 11 #include "content/browser/frame_host/render_frame_host_impl.h"
12 #include "content/browser/renderer_host/render_view_host_impl.h" 12 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/public/test/mock_render_process_host.h" 13 #include "content/public/test/mock_render_process_host.h"
15 #include "content/public/test/test_browser_context.h" 14 #include "content/public/test/test_browser_context.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "content/public/test/test_renderer_host.h" 16 #include "content/public/test/test_renderer_host.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 namespace content { 19 namespace content {
21 namespace { 20 namespace {
22 21
23 class FrameTreeTest : public RenderViewHostTestHarness { 22 class FrameTreeTest : public RenderViewHostTestHarness {
(...skipping 17 matching lines...) Expand all
41 const char* separator = ""; 40 const char* separator = "";
42 for (size_t i = 0; i < node->child_count(); i++) { 41 for (size_t i = 0; i < node->child_count(); i++) {
43 result->append(separator); 42 result->append(separator);
44 AppendTreeNodeState(node->child_at(i), result); 43 AppendTreeNodeState(node->child_at(i), result);
45 separator = ", "; 44 separator = ", ";
46 } 45 }
47 result->append("]"); 46 result->append("]");
48 } 47 }
49 }; 48 };
50 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
51 // Test that swapping the main frame resets the renderer-assigned frame id. 79 // Test that swapping the main frame resets the renderer-assigned frame id.
52 // - On creation, frame id is unassigned. 80 // - On creation, frame id is unassigned.
53 // - After a swap, frame id is unassigned. 81 // - After a swap, frame id is unassigned.
54 TEST_F(FrameTreeTest, FirstNavigationAfterSwap) { 82 TEST_F(FrameTreeTest, FirstNavigationAfterSwap) {
55 FrameTree frame_tree(new NavigatorImpl(NULL, NULL), NULL, NULL, NULL, NULL); 83 FrameTree frame_tree(new NavigatorImpl(NULL, NULL), NULL, NULL, NULL, NULL);
56 84
57 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap()); 85 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap());
58 EXPECT_EQ(FrameTreeNode::kInvalidFrameId, 86 EXPECT_EQ(FrameTreeNode::kInvalidFrameId,
59 frame_tree.root()->frame_id()); 87 frame_tree.root()->frame_id());
60 frame_tree.OnFirstNavigationAfterSwap(1); 88 frame_tree.OnFirstNavigationAfterSwap(1);
61 EXPECT_FALSE(frame_tree.IsFirstNavigationAfterSwap()); 89 EXPECT_FALSE(frame_tree.IsFirstNavigationAfterSwap());
62 EXPECT_EQ(1, frame_tree.root()->frame_id()); 90 EXPECT_EQ(1, frame_tree.root()->frame_id());
63 91
64 frame_tree.ResetForMainFrameSwap(); 92 frame_tree.SwapMainFrame(NULL);
65 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap()); 93 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap());
66 EXPECT_EQ(FrameTreeNode::kInvalidFrameId, 94 EXPECT_EQ(FrameTreeNode::kInvalidFrameId,
67 frame_tree.root()->frame_id()); 95 frame_tree.root()->frame_id());
68 } 96 }
69 97
70 // Exercise tree manipulation routines. 98 // Exercise tree manipulation routines.
71 // - Add a series of nodes and verify tree structure. 99 // - Add a series of nodes and verify tree structure.
72 // - Remove a series of nodes and verify tree structure. 100 // - Remove a series of nodes and verify tree structure.
73 TEST_F(FrameTreeTest, Shape) { 101 TEST_F(FrameTreeTest, Shape) {
74 // Use the FrameTree of the WebContents so that it has all the delegates it 102 FrameTree frame_tree(new NavigatorImpl(NULL, NULL), NULL, NULL, NULL, NULL);
75 // needs. We may want to consider a test version of this.
76 FrameTree* frame_tree =
77 static_cast<WebContentsImpl*>(web_contents())->GetFrameTree();
78 103
79 std::string no_children_node("no children node"); 104 std::string no_children_node("no children node");
80 std::string deep_subtree("node with deep subtree"); 105 std::string deep_subtree("node with deep subtree");
81 106
82 frame_tree->OnFirstNavigationAfterSwap(5); 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);
83 118
84 ASSERT_EQ("5: []", GetTreeState(frame_tree)); 119 ASSERT_EQ("5: []", GetTreeState(&frame_tree));
85 120
86 // Simulate attaching a series of frames to build the frame tree. 121 // Simulate attaching a series of frames to build the frame tree.
87 frame_tree->AddFrame(process()->GetNextRoutingID(), 5, 14, std::string()); 122 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 14, std::string());
88 frame_tree->AddFrame(process()->GetNextRoutingID(), 5, 15, std::string()); 123 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 15, std::string());
89 frame_tree->AddFrame(process()->GetNextRoutingID(), 5, 16, std::string()); 124 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 16, std::string());
90 125
91 frame_tree->AddFrame(process()->GetNextRoutingID(), 14, 244, std::string()); 126 frame_tree.AddFrame(process()->GetNextRoutingID(), 14, 244, std::string());
92 frame_tree->AddFrame(process()->GetNextRoutingID(), 15, 255, 127 frame_tree.AddFrame(process()->GetNextRoutingID(), 15, 255, no_children_node);
93 no_children_node); 128 frame_tree.AddFrame(process()->GetNextRoutingID(), 14, 245, std::string());
94 frame_tree->AddFrame(process()->GetNextRoutingID(), 14, 245, std::string());
95 129
96 ASSERT_EQ("5: [14: [244: [], 245: []], " 130 ASSERT_EQ("5: [14: [244: [], 245: []], "
97 "15: [255 'no children node': []], " 131 "15: [255 'no children node': []], "
98 "16: []]", 132 "16: []]",
99 GetTreeState(frame_tree)); 133 GetTreeState(&frame_tree));
100 134
101 frame_tree->AddFrame(process()->GetNextRoutingID(), 16, 264, std::string()); 135 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 264, std::string());
102 frame_tree->AddFrame(process()->GetNextRoutingID(), 16, 265, std::string()); 136 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 265, std::string());
103 frame_tree->AddFrame(process()->GetNextRoutingID(), 16, 266, std::string()); 137 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 266, std::string());
104 frame_tree->AddFrame(process()->GetNextRoutingID(), 16, 267, deep_subtree); 138 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 267, deep_subtree);
105 frame_tree->AddFrame(process()->GetNextRoutingID(), 16, 268, std::string()); 139 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 268, std::string());
106 140
107 frame_tree->AddFrame(process()->GetNextRoutingID(), 267, 365, std::string()); 141 frame_tree.AddFrame(process()->GetNextRoutingID(), 267, 365, std::string());
108 frame_tree->AddFrame(process()->GetNextRoutingID(), 365, 455, std::string()); 142 frame_tree.AddFrame(process()->GetNextRoutingID(), 365, 455, std::string());
109 frame_tree->AddFrame(process()->GetNextRoutingID(), 455, 555, std::string()); 143 frame_tree.AddFrame(process()->GetNextRoutingID(), 455, 555, std::string());
110 frame_tree->AddFrame(process()->GetNextRoutingID(), 555, 655, std::string()); 144 frame_tree.AddFrame(process()->GetNextRoutingID(), 555, 655, std::string());
111 145
112 // Now that's it's fully built, verify the tree structure is as expected. 146 // Now that's it's fully built, verify the tree structure is as expected.
113 ASSERT_EQ("5: [14: [244: [], 245: []], " 147 ASSERT_EQ("5: [14: [244: [], 245: []], "
114 "15: [255 'no children node': []], " 148 "15: [255 'no children node': []], "
115 "16: [264: [], 265: [], 266: [], " 149 "16: [264: [], 265: [], 266: [], "
116 "267 'node with deep subtree': " 150 "267 'node with deep subtree': "
117 "[365: [455: [555: [655: []]]]], 268: []]]", 151 "[365: [455: [555: [655: []]]]], 268: []]]",
118 GetTreeState(frame_tree)); 152 GetTreeState(&frame_tree));
119 153
120 // Test removing of nodes. Clear the frame removal listener so we can pass a 154 // Test removing of nodes.
121 // NULL RFH here. 155 frame_tree.RemoveFrame(NULL, 555, 655);
122 frame_tree->ClearFrameRemoveListenerForTesting();
123 frame_tree->RemoveFrame(NULL, 555, 655);
124 ASSERT_EQ("5: [14: [244: [], 245: []], " 156 ASSERT_EQ("5: [14: [244: [], 245: []], "
125 "15: [255 'no children node': []], " 157 "15: [255 'no children node': []], "
126 "16: [264: [], 265: [], 266: [], " 158 "16: [264: [], 265: [], 266: [], "
127 "267 'node with deep subtree': " 159 "267 'node with deep subtree': "
128 "[365: [455: [555: []]]], 268: []]]", 160 "[365: [455: [555: []]]], 268: []]]",
129 GetTreeState(frame_tree)); 161 GetTreeState(&frame_tree));
130 162
131 frame_tree->RemoveFrame(NULL, 16, 265); 163 frame_tree.RemoveFrame(NULL, 16, 265);
132 ASSERT_EQ("5: [14: [244: [], 245: []], " 164 ASSERT_EQ("5: [14: [244: [], 245: []], "
133 "15: [255 'no children node': []], " 165 "15: [255 'no children node': []], "
134 "16: [264: [], 266: [], " 166 "16: [264: [], 266: [], "
135 "267 'node with deep subtree': " 167 "267 'node with deep subtree': "
136 "[365: [455: [555: []]]], 268: []]]", 168 "[365: [455: [555: []]]], 268: []]]",
137 GetTreeState(frame_tree)); 169 GetTreeState(&frame_tree));
138 170
139 frame_tree->RemoveFrame(NULL, 5, 15); 171 frame_tree.RemoveFrame(NULL, 5, 15);
140 ASSERT_EQ("5: [14: [244: [], 245: []], " 172 ASSERT_EQ("5: [14: [244: [], 245: []], "
141 "16: [264: [], 266: [], " 173 "16: [264: [], 266: [], "
142 "267 'node with deep subtree': " 174 "267 'node with deep subtree': "
143 "[365: [455: [555: []]]], 268: []]]", 175 "[365: [455: [555: []]]], 268: []]]",
144 GetTreeState(frame_tree)); 176 GetTreeState(&frame_tree));
145 } 177 }
146 178
147 } // namespace 179 } // namespace
148 } // namespace content 180 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/browser/frame_host/frame_tree_node.cc ('k') | trunk/src/content/browser/frame_host/interstitial_page_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698