OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/renderer_host/render_view_host_impl.h" | 7 #include "content/browser/renderer_host/render_view_host_impl.h" |
8 #include "content/browser/renderer_host/test_render_view_host.h" | 8 #include "content/browser/renderer_host/test_render_view_host.h" |
9 #include "content/browser/site_instance_impl.h" | 9 #include "content/browser/site_instance_impl.h" |
10 #include "content/browser/web_contents/frame_tree_node.h" | |
11 #include "content/browser/web_contents/interstitial_page_impl.h" | 10 #include "content/browser/web_contents/interstitial_page_impl.h" |
12 #include "content/browser/web_contents/navigation_entry_impl.h" | 11 #include "content/browser/web_contents/navigation_entry_impl.h" |
13 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 12 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
14 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
15 #include "content/public/browser/global_request_id.h" | 14 #include "content/public/browser/global_request_id.h" |
16 #include "content/public/browser/interstitial_page_delegate.h" | 15 #include "content/public/browser/interstitial_page_delegate.h" |
17 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
18 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
19 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
20 #include "content/public/browser/render_widget_host_view.h" | 19 #include "content/public/browser/render_widget_host_view.h" |
(...skipping 2116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2137 // crash. | 2136 // crash. |
2138 TEST_F(WebContentsImplTest, PendingContents) { | 2137 TEST_F(WebContentsImplTest, PendingContents) { |
2139 scoped_ptr<TestWebContents> other_contents( | 2138 scoped_ptr<TestWebContents> other_contents( |
2140 static_cast<TestWebContents*>(CreateTestWebContents())); | 2139 static_cast<TestWebContents*>(CreateTestWebContents())); |
2141 contents()->AddPendingContents(other_contents.get()); | 2140 contents()->AddPendingContents(other_contents.get()); |
2142 int route_id = other_contents->GetRenderViewHost()->GetRoutingID(); | 2141 int route_id = other_contents->GetRenderViewHost()->GetRoutingID(); |
2143 other_contents.reset(); | 2142 other_contents.reset(); |
2144 EXPECT_EQ(NULL, contents()->GetCreatedWindow(route_id)); | 2143 EXPECT_EQ(NULL, contents()->GetCreatedWindow(route_id)); |
2145 } | 2144 } |
2146 | 2145 |
2147 // This test asserts the shape of the frame tree is correct, based on incoming | |
2148 // frame attached/detached messages. | |
2149 TEST_F(WebContentsImplTest, FrameTreeShape) { | |
2150 std::string no_children_node("no children node"); | |
2151 std::string deep_subtree("node with deep subtree"); | |
2152 | |
2153 // The initial navigation will create a frame_tree_root_ node with the top | |
2154 // level frame id. Simulate that by just creating it here. | |
2155 contents()->frame_tree_root_.reset( | |
2156 new FrameTreeNode(5, std::string("top-level"))); | |
2157 | |
2158 // Let's send a series of messages for frame attached and build the | |
2159 // frame tree. | |
2160 contents()->OnFrameAttached(5, 14, std::string()); | |
2161 contents()->OnFrameAttached(5, 15, std::string()); | |
2162 contents()->OnFrameAttached(5, 16, std::string()); | |
2163 | |
2164 contents()->OnFrameAttached(14, 244, std::string()); | |
2165 contents()->OnFrameAttached(14, 245, std::string()); | |
2166 | |
2167 contents()->OnFrameAttached(15, 255, no_children_node); | |
2168 | |
2169 contents()->OnFrameAttached(16, 264, std::string()); | |
2170 contents()->OnFrameAttached(16, 265, std::string()); | |
2171 contents()->OnFrameAttached(16, 266, std::string()); | |
2172 contents()->OnFrameAttached(16, 267, deep_subtree); | |
2173 contents()->OnFrameAttached(16, 268, std::string()); | |
2174 | |
2175 contents()->OnFrameAttached(267, 365, std::string()); | |
2176 contents()->OnFrameAttached(365, 455, std::string()); | |
2177 contents()->OnFrameAttached(455, 555, std::string()); | |
2178 contents()->OnFrameAttached(555, 655, std::string()); | |
2179 | |
2180 // Now, verify the tree structure is as expected. | |
2181 FrameTreeNode* root = contents()->frame_tree_root_.get(); | |
2182 EXPECT_EQ(5, root->frame_id()); | |
2183 EXPECT_EQ(3UL, root->child_count()); | |
2184 | |
2185 EXPECT_EQ(2UL, root->child_at(0)->child_count()); | |
2186 EXPECT_EQ(0UL, root->child_at(0)->child_at(0)->child_count()); | |
2187 EXPECT_EQ(0UL, root->child_at(0)->child_at(1)->child_count()); | |
2188 | |
2189 EXPECT_EQ(1UL, root->child_at(1)->child_count()); | |
2190 EXPECT_EQ(0UL, root->child_at(1)->child_at(0)->child_count()); | |
2191 EXPECT_STREQ(no_children_node.c_str(), | |
2192 root->child_at(1)->child_at(0)->frame_name().c_str()); | |
2193 | |
2194 EXPECT_EQ(5UL, root->child_at(2)->child_count()); | |
2195 EXPECT_EQ(0UL, root->child_at(2)->child_at(0)->child_count()); | |
2196 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_count()); | |
2197 EXPECT_EQ(0UL, root->child_at(2)->child_at(2)->child_count()); | |
2198 EXPECT_EQ(1UL, root->child_at(2)->child_at(3)->child_count()); | |
2199 EXPECT_STREQ(deep_subtree.c_str(), | |
2200 root->child_at(2)->child_at(3)->frame_name().c_str()); | |
2201 EXPECT_EQ(0UL, root->child_at(2)->child_at(4)->child_count()); | |
2202 | |
2203 FrameTreeNode* deep_tree = root->child_at(2)->child_at(3)->child_at(0); | |
2204 EXPECT_EQ(365, deep_tree->frame_id()); | |
2205 EXPECT_EQ(1UL, deep_tree->child_count()); | |
2206 EXPECT_EQ(455, deep_tree->child_at(0)->frame_id()); | |
2207 EXPECT_EQ(1UL, deep_tree->child_at(0)->child_count()); | |
2208 EXPECT_EQ(555, deep_tree->child_at(0)->child_at(0)->frame_id()); | |
2209 EXPECT_EQ(1UL, deep_tree->child_at(0)->child_at(0)->child_count()); | |
2210 EXPECT_EQ(655, deep_tree->child_at(0)->child_at(0)->child_at(0)->frame_id()); | |
2211 EXPECT_EQ(0UL, | |
2212 deep_tree->child_at(0)->child_at(0)->child_at(0)->child_count()); | |
2213 | |
2214 // Test removing of nodes. | |
2215 contents()->OnFrameDetached(555, 655); | |
2216 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count()); | |
2217 | |
2218 contents()->OnFrameDetached(16, 265); | |
2219 EXPECT_EQ(4UL, root->child_at(2)->child_count()); | |
2220 | |
2221 contents()->OnFrameDetached(5, 15); | |
2222 EXPECT_EQ(2UL, root->child_count()); | |
2223 } | |
2224 | |
2225 } // namespace content | 2146 } // namespace content |
OLD | NEW |