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

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

Issue 23841002: Create a new RenderFrameHost per child frame when --site-per-process is enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: notify observers regardless of flag Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/frame_tree.h"
6
7 #include "base/run_loop.h"
8 #include "content/browser/renderer_host/render_frame_host_impl.h"
9 #include "content/public/test/mock_render_process_host.h"
10 #include "content/public/test/test_browser_context.h"
11 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "content/public/test/test_renderer_host.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace content {
16 namespace {
17
18 class FrameTreeTest : public RenderViewHostTestHarness {
19 };
20
21 // The root node never changes during navigation even though its
22 // RenderFrameHost does.
23 // - Swapping main frame doesn't change root node.
24 // - Swapping back to NULL doesn't crash (easier tear-down for interstitials).
25 // - Main frame does not own RenderFrameHost.
26 TEST_F(FrameTreeTest, RootNode) {
27 FrameTree frame_tree;
28
29 // Initial state has empty node.
30 FrameTreeNode* root = frame_tree.GetRootForTesting();
31 ASSERT_TRUE(root);
32 EXPECT_FALSE(frame_tree.GetMainFrame());
33
34 // Swap in main frame.
35 RenderFrameHostImpl* dummy = reinterpret_cast<RenderFrameHostImpl*>(0x1);
36 frame_tree.SwapMainFrame(dummy);
37 EXPECT_EQ(root, frame_tree.GetRootForTesting());
38 EXPECT_EQ(dummy, frame_tree.GetMainFrame());
39
40 // Move back to NULL.
41 frame_tree.SwapMainFrame(NULL);
42 EXPECT_EQ(root, frame_tree.GetRootForTesting());
43 EXPECT_FALSE(frame_tree.GetMainFrame());
44
45 // Move back to an invalid pointer, let the FrameTree go out of scope. Test
46 // should not crash because the main frame isn't owned.
47 frame_tree.SwapMainFrame(dummy);
48 }
49
50 // Test that swapping the main frame resets the renderer-assigned frame id.
51 // - On creation, frame id is unassigned.
52 // - After a swap, frame id is unassigned.
53 TEST_F(FrameTreeTest, FirstNavigationAfterSwap) {
54 FrameTree frame_tree;
55
56 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap());
57 EXPECT_EQ(FrameTreeNode::kInvalidFrameId,
58 frame_tree.GetRootForTesting()->frame_id());
59 frame_tree.OnFirstNavigationAfterSwap(1);
60 EXPECT_FALSE(frame_tree.IsFirstNavigationAfterSwap());
61 EXPECT_EQ(1, frame_tree.GetRootForTesting()->frame_id());
62
63 frame_tree.SwapMainFrame(NULL);
64 EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap());
65 EXPECT_EQ(FrameTreeNode::kInvalidFrameId,
66 frame_tree.GetRootForTesting()->frame_id());
67 }
68
69 // Exercise tree manipulation routines.
70 // - Add a series of nodes and verify tree structure.
71 // - Remove a series of nodes and verify tree structure.
72 TEST_F(FrameTreeTest, Shape) {
73 FrameTree frame_tree;
74 std::string no_children_node("no children node");
75 std::string deep_subtree("node with deep subtree");
76
77 // Ensure the top-level node of the FrameTree is initialized by simulating a
78 // main frame swap here.
79 RenderFrameHostImpl render_frame_host(process(), &frame_tree,
80 process()->GetNextRoutingID(), false);
81 frame_tree.SwapMainFrame(&render_frame_host);
82 frame_tree.OnFirstNavigationAfterSwap(5);
83
84 // Simulate attaching a series of frames to build the frame tree.
85 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 14, std::string());
86 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 15, std::string());
87 frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 16, std::string());
88
89 frame_tree.AddFrame(process()->GetNextRoutingID(), 14, 244, std::string());
90 frame_tree.AddFrame(process()->GetNextRoutingID(), 14, 245, std::string());
91
92 frame_tree.AddFrame(process()->GetNextRoutingID(), 15, 255, no_children_node);
93
94 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 264, std::string());
95 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 265, std::string());
96 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 266, std::string());
97 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 267, deep_subtree);
98 frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 268, std::string());
99
100 frame_tree.AddFrame(process()->GetNextRoutingID(), 267, 365, std::string());
101 frame_tree.AddFrame(process()->GetNextRoutingID(), 365, 455, std::string());
102 frame_tree.AddFrame(process()->GetNextRoutingID(), 455, 555, std::string());
103 frame_tree.AddFrame(process()->GetNextRoutingID(), 555, 655, std::string());
104
105 // Now, verify the tree structure is as expected.
106 FrameTreeNode* root = frame_tree.GetRootForTesting();
107 EXPECT_EQ(5, root->frame_id());
108 EXPECT_EQ(3UL, root->child_count());
109
110 EXPECT_EQ(2UL, root->child_at(0)->child_count());
111 EXPECT_EQ(0UL, root->child_at(0)->child_at(0)->child_count());
112 EXPECT_EQ(0UL, root->child_at(0)->child_at(1)->child_count());
113
114 EXPECT_EQ(1UL, root->child_at(1)->child_count());
115 EXPECT_EQ(0UL, root->child_at(1)->child_at(0)->child_count());
116 EXPECT_STREQ(no_children_node.c_str(),
117 root->child_at(1)->child_at(0)->frame_name().c_str());
118
119 EXPECT_EQ(5UL, root->child_at(2)->child_count());
120 EXPECT_EQ(0UL, root->child_at(2)->child_at(0)->child_count());
121 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_count());
122 EXPECT_EQ(0UL, root->child_at(2)->child_at(2)->child_count());
123 EXPECT_EQ(1UL, root->child_at(2)->child_at(3)->child_count());
124 EXPECT_STREQ(deep_subtree.c_str(),
125 root->child_at(2)->child_at(3)->frame_name().c_str());
126 EXPECT_EQ(0UL, root->child_at(2)->child_at(4)->child_count());
127
128 FrameTreeNode* deep_tree = root->child_at(2)->child_at(3)->child_at(0);
129 EXPECT_EQ(365, deep_tree->frame_id());
130 EXPECT_EQ(1UL, deep_tree->child_count());
131 EXPECT_EQ(455, deep_tree->child_at(0)->frame_id());
132 EXPECT_EQ(1UL, deep_tree->child_at(0)->child_count());
133 EXPECT_EQ(555, deep_tree->child_at(0)->child_at(0)->frame_id());
134 EXPECT_EQ(1UL, deep_tree->child_at(0)->child_at(0)->child_count());
135 EXPECT_EQ(655, deep_tree->child_at(0)->child_at(0)->child_at(0)->frame_id());
136 EXPECT_EQ(0UL,
137 deep_tree->child_at(0)->child_at(0)->child_at(0)->child_count());
138
139 // Test removing of nodes.
140 frame_tree.RemoveFrame(555, 655);
141 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count());
142
143 frame_tree.RemoveFrame(16, 265);
144 EXPECT_EQ(4UL, root->child_at(2)->child_count());
145
146 frame_tree.RemoveFrame(5, 15);
147 EXPECT_EQ(2UL, root->child_count());
148 }
149
150 } // namespace
151 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/frame_tree_node.cc ('k') | content/browser/renderer_host/render_frame_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698