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

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

Issue 82033002: Always create FrameTreeNodes and RenderFrameHosts for every frame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix two bugs with slow/crashed renderers; add tests Created 7 years, 1 month 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/frame_host/frame_tree.h"
6 #include "content/browser/frame_host/frame_tree_node.h"
7 #include "content/browser/renderer_host/render_view_host_impl.h"
8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/public/browser/notification_service.h"
10 #include "content/public/browser/notification_types.h"
11 #include "content/public/common/url_constants.h"
12 #include "content/public/test/test_navigation_observer.h"
13 #include "content/public/test/test_utils.h"
14 #include "content/shell/browser/shell.h"
15 #include "content/test/content_browser_test.h"
16 #include "content/test/content_browser_test_utils.h"
17 #include "net/dns/mock_host_resolver.h"
18
19 namespace content {
20
21 class FrameTreeBrowserTest : public ContentBrowserTest {
22 public:
23 FrameTreeBrowserTest() {}
24
25 private:
26 DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest);
27 };
28
29 // Ensures FrameTree correctly reflects page structure during navigations.
30 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape) {
31 host_resolver()->AddRule("*", "127.0.0.1");
32 ASSERT_TRUE(test_server()->Start());
33
34 GURL base_url = test_server()->GetURL("files/site_isolation/");
35 GURL::Replacements replace_host;
36 std::string host_str("A.com"); // Must stay in scope with replace_host.
37 replace_host.SetHostStr(host_str);
38 base_url = base_url.ReplaceComponents(replace_host);
39
40 // Load doc without iframes. Verify FrameTree just has root.
41 // Frame tree:
42 // Site-A Root
43 NavigateToURL(shell(), base_url.Resolve("blank.html"));
44 FrameTreeNode* root =
45 static_cast<WebContentsImpl*>(shell()->web_contents())->
46 GetFrameTree()->root();
47 EXPECT_EQ(0U, root->child_count());
48
49 // Add 2 same-site frames. Verify 3 nodes in tree with proper names.
50 // Frame tree:
51 // Site-A Root -- Site-A frame1
52 // \-- Site-A frame2
53 WindowedNotificationObserver observer1(
54 content::NOTIFICATION_LOAD_STOP,
55 content::Source<NavigationController>(
56 &shell()->web_contents()->GetController()));
57 NavigateToURL(shell(), base_url.Resolve("frames-X-X.html"));
58 observer1.Wait();
59 ASSERT_EQ(2U, root->child_count());
60 EXPECT_EQ(0U, root->child_at(0)->child_count());
61 EXPECT_EQ(0U, root->child_at(1)->child_count());
62 }
63
64 // TODO(ajwong): Talk with nasko and merge this functionality with
65 // FrameTreeShape.
66 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape2) {
67 ASSERT_TRUE(test_server()->Start());
68 NavigateToURL(shell(),
69 test_server()->GetURL("files/frame_tree/top.html"));
70
71 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
72 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
73 wc->GetRenderViewHost());
74 FrameTreeNode* root = wc->GetFrameTree()->root();
75
76 // Check that the root node is properly created with the frame id of the
77 // initial navigation.
78 ASSERT_EQ(3UL, root->child_count());
79 EXPECT_EQ(std::string(), root->frame_name());
80 EXPECT_EQ(rvh->main_frame_id(), root->frame_id());
81
82 ASSERT_EQ(2UL, root->child_at(0)->child_count());
83 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str());
84
85 // Verify the deepest node exists and has the right name.
86 ASSERT_EQ(2UL, root->child_at(2)->child_count());
87 EXPECT_EQ(1UL, root->child_at(2)->child_at(1)->child_count());
88 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_at(0)->child_count());
89 EXPECT_STREQ("3-1-id",
90 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str());
91
92 // Navigate to about:blank, which should leave only the root node of the frame
93 // tree in the browser process.
94 NavigateToURL(shell(), test_server()->GetURL("files/title1.html"));
95
96 root = wc->GetFrameTree()->root();
97 EXPECT_EQ(0UL, root->child_count());
98 EXPECT_EQ(std::string(), root->frame_name());
99 EXPECT_EQ(rvh->main_frame_id(), root->frame_id());
100 }
101
102 // Test that we can navigate away if the previous renderer doesn't clean up its
103 // child frames.
104 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeAfterCrash) {
105 ASSERT_TRUE(test_server()->Start());
106 NavigateToURL(shell(),
107 test_server()->GetURL("files/frame_tree/top.html"));
108
109 // Crash the renderer so that it doesn't send any FrameDetached messages.
110 WindowedNotificationObserver crash_observer(
111 NOTIFICATION_RENDERER_PROCESS_CLOSED,
112 NotificationService::AllSources());
113 NavigateToURL(shell(), GURL(kChromeUICrashURL));
114 crash_observer.Wait();
115
116 // The frame tree should be cleared, and the frame ID should be reset.
117 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
118 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
119 wc->GetRenderViewHost());
120 FrameTreeNode* root = wc->GetFrameTree()->root();
121 EXPECT_EQ(0UL, root->child_count());
122 EXPECT_EQ(FrameTreeNode::kInvalidFrameId, root->frame_id());
123 EXPECT_EQ(rvh->main_frame_id(), root->frame_id());
124
125 // Navigate to a new URL.
126 NavigateToURL(shell(), test_server()->GetURL("files/title1.html"));
127
128 // The frame ID should now be set.
129 EXPECT_EQ(0UL, root->child_count());
130 EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id());
131 EXPECT_EQ(rvh->main_frame_id(), root->frame_id());
132 }
133
134 // Test that we can navigate away if the previous renderer doesn't clean up its
135 // child frames.
136 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, NavigateWithLeftoverFrames) {
137 host_resolver()->AddRule("*", "127.0.0.1");
138 ASSERT_TRUE(test_server()->Start());
139
140 GURL base_url = test_server()->GetURL("files/site_isolation/");
141 GURL::Replacements replace_host;
142 std::string host_str("A.com"); // Must stay in scope with replace_host.
143 replace_host.SetHostStr(host_str);
144 base_url = base_url.ReplaceComponents(replace_host);
145
146 NavigateToURL(shell(),
147 test_server()->GetURL("files/frame_tree/top.html"));
148
149 // Hang the renderer so that it doesn't send any FrameDetached messages.
150 // (This navigation will never complete, so don't wait for it.)
151 shell()->LoadURL(GURL(kChromeUIHangURL));
152
153 // Check that the frame tree still has children.
154 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
155 FrameTreeNode* root = wc->GetFrameTree()->root();
156 ASSERT_EQ(3UL, root->child_count());
157
158 // Navigate to a new URL. We use LoadURL because NavigateToURL will try to
159 // wait for the previous navigation to stop.
160 TestNavigationObserver tab_observer(wc, 1);
161 shell()->LoadURL(base_url.Resolve("blank.html"));
162 tab_observer.Wait();
163
164 // The frame tree should now be cleared, and the frame ID should be valid.
165 EXPECT_EQ(0UL, root->child_count());
166 EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id());
167 }
168
169 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/frame_tree_node.cc » ('j') | content/browser/renderer_host/render_view_host_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698