Index: content/browser/frame_host/frame_tree_unittest.cc |
diff --git a/content/browser/frame_host/frame_tree_unittest.cc b/content/browser/frame_host/frame_tree_unittest.cc |
index 6edc1e077ad029ca008504d3e6e257cfecbc9d86..b9014422c98a0f0ed3de128c59a007051208ae09 100644 |
--- a/content/browser/frame_host/frame_tree_unittest.cc |
+++ b/content/browser/frame_host/frame_tree_unittest.cc |
@@ -9,6 +9,7 @@ |
#include "content/browser/frame_host/navigator.h" |
#include "content/browser/frame_host/render_frame_host_impl.h" |
#include "content/browser/renderer_host/render_view_host_impl.h" |
+#include "content/browser/web_contents/web_contents_impl.h" |
#include "content/public/test/mock_render_process_host.h" |
#include "content/public/test/test_browser_context.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
@@ -29,7 +30,9 @@ class FrameTreeTest : public RenderViewHostTestHarness { |
private: |
void AppendTreeNodeState(FrameTreeNode* node, std::string* result) { |
- result->append(base::Int64ToString(node->frame_id())); |
+ int frame_id = node->render_frame_host()->render_view_host()-> |
+ GetFrameIDForTesting(node->frame_tree_node_id()); |
+ result->append(base::Int64ToString(frame_id)); |
if (!node->frame_name().empty()) { |
result->append(" '"); |
result->append(node->frame_name()); |
@@ -51,7 +54,8 @@ class FrameTreeTest : public RenderViewHostTestHarness { |
// - Swapping main frame doesn't change root node. |
// - Swapping back to NULL doesn't crash (easier tear-down for interstitials). |
// - Main frame does not own RenderFrameHost. |
-TEST_F(FrameTreeTest, RootNode) { |
+// TODO(creis): Do we still want these tests? Depends on SwapMainFrame. |
+/*TEST_F(FrameTreeTest, RootNode) { |
FrameTree frame_tree(new Navigator(NULL, NULL), NULL, NULL, NULL); |
// Initial state has empty node. |
@@ -73,12 +77,12 @@ TEST_F(FrameTreeTest, RootNode) { |
// Move back to an invalid pointer, let the FrameTree go out of scope. Test |
// should not crash because the main frame isn't owned. |
frame_tree.SwapMainFrame(dummy); |
-} |
+}*/ |
// Test that swapping the main frame resets the renderer-assigned frame id. |
// - On creation, frame id is unassigned. |
// - After a swap, frame id is unassigned. |
-TEST_F(FrameTreeTest, FirstNavigationAfterSwap) { |
+/*TEST_F(FrameTreeTest, FirstNavigationAfterSwap) { |
FrameTree frame_tree(new Navigator(NULL, NULL), NULL, NULL, NULL); |
EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap()); |
@@ -92,83 +96,104 @@ TEST_F(FrameTreeTest, FirstNavigationAfterSwap) { |
EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap()); |
EXPECT_EQ(FrameTreeNode::kInvalidFrameId, |
frame_tree.root()->frame_id()); |
-} |
+}*/ |
// Exercise tree manipulation routines. |
// - Add a series of nodes and verify tree structure. |
// - Remove a series of nodes and verify tree structure. |
TEST_F(FrameTreeTest, Shape) { |
- FrameTree frame_tree(new Navigator(NULL, NULL), NULL, NULL, NULL); |
+ // Use the FrameTree of the WebContents so that it has all the delegates it |
+ // needs. We may want to consider a test version of this. |
+ FrameTree* frame_tree = |
+ static_cast<WebContentsImpl*>(web_contents())->GetFrameTree(); |
+ |
+ // Navigate to a URL to register the frame ID. |
+ NavigateAndCommit(GURL("about:blank")); |
std::string no_children_node("no children node"); |
std::string deep_subtree("node with deep subtree"); |
// Ensure the top-level node of the FrameTree is initialized by simulating a |
// main frame swap here. |
- RenderFrameHostImpl render_frame_host(static_cast<RenderViewHostImpl*>(rvh()), |
- &frame_tree, |
- process()->GetNextRoutingID(), false); |
- frame_tree.SwapMainFrame(&render_frame_host); |
- frame_tree.OnFirstNavigationAfterSwap(5); |
+ RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh()); |
- ASSERT_EQ("5: []", GetTreeState(&frame_tree)); |
+ // kFrameId in TestRenderViewHost is 13. |
+ ASSERT_EQ("13: []", GetTreeState(frame_tree)); |
// Simulate attaching a series of frames to build the frame tree. |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 14, std::string()); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 15, std::string()); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 5, 16, std::string()); |
- |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 14, 244, std::string()); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 15, 255, no_children_node); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 14, 245, std::string()); |
- |
- ASSERT_EQ("5: [14: [244: [], 245: []], " |
- "15: [255 'no children node': []], " |
- "16: []]", |
- GetTreeState(&frame_tree)); |
- |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 264, std::string()); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 265, std::string()); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 266, std::string()); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 267, deep_subtree); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 16, 268, std::string()); |
- |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 267, 365, std::string()); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 365, 455, std::string()); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 455, 555, std::string()); |
- frame_tree.AddFrame(process()->GetNextRoutingID(), 555, 655, std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 13, 14, |
+ std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 13, 15, |
+ std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 13, 16, |
+ std::string()); |
+ |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 14, 244, |
+ std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 15, 255, |
+ no_children_node); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 14, 245, |
+ std::string()); |
+ |
+ ASSERT_EQ("13: [14: [244: [], 245: []], " |
+ "15: [255 'no children node': []], " |
+ "16: []]", |
+ GetTreeState(frame_tree)); |
+ |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 16, 264, |
+ std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 16, 265, |
+ std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 16, 266, |
+ std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 16, 267, |
+ deep_subtree); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 16, 268, |
+ std::string()); |
+ |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 267, 365, |
+ std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 365, 455, |
+ std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 455, 555, |
+ std::string()); |
+ frame_tree->AddFrame(rvhi, process()->GetNextRoutingID(), 555, 655, |
+ std::string()); |
// Now that's it's fully built, verify the tree structure is as expected. |
- ASSERT_EQ("5: [14: [244: [], 245: []], " |
- "15: [255 'no children node': []], " |
- "16: [264: [], 265: [], 266: [], " |
- "267 'node with deep subtree': " |
- "[365: [455: [555: [655: []]]]], 268: []]]", |
- GetTreeState(&frame_tree)); |
+ ASSERT_EQ("13: [14: [244: [], 245: []], " |
+ "15: [255 'no children node': []], " |
+ "16: [264: [], 265: [], 266: [], " |
+ "267 'node with deep subtree': " |
+ "[365: [455: [555: [655: []]]]], 268: []]]", |
+ GetTreeState(frame_tree)); |
// Test removing of nodes. |
- frame_tree.RemoveFrame(555, 655); |
- ASSERT_EQ("5: [14: [244: [], 245: []], " |
- "15: [255 'no children node': []], " |
- "16: [264: [], 265: [], 266: [], " |
- "267 'node with deep subtree': " |
- "[365: [455: [555: []]]], 268: []]]", |
- GetTreeState(&frame_tree)); |
- |
- frame_tree.RemoveFrame(16, 265); |
- ASSERT_EQ("5: [14: [244: [], 245: []], " |
- "15: [255 'no children node': []], " |
- "16: [264: [], 266: [], " |
- "267 'node with deep subtree': " |
- "[365: [455: [555: []]]], 268: []]]", |
- GetTreeState(&frame_tree)); |
- |
- frame_tree.RemoveFrame(5, 15); |
- ASSERT_EQ("5: [14: [244: [], 245: []], " |
- "16: [264: [], 266: [], " |
- "267 'node with deep subtree': " |
- "[365: [455: [555: []]]], 268: []]]", |
- GetTreeState(&frame_tree)); |
+ frame_tree->RemoveFrame(rvhi->GetFrameTreeNodeID(555), |
+ rvhi->GetFrameTreeNodeID(655)); |
+ ASSERT_EQ("13: [14: [244: [], 245: []], " |
+ "15: [255 'no children node': []], " |
+ "16: [264: [], 265: [], 266: [], " |
+ "267 'node with deep subtree': " |
+ "[365: [455: [555: []]]], 268: []]]", |
+ GetTreeState(frame_tree)); |
+ |
+ frame_tree->RemoveFrame(rvhi->GetFrameTreeNodeID(16), |
+ rvhi->GetFrameTreeNodeID(265)); |
+ ASSERT_EQ("13: [14: [244: [], 245: []], " |
+ "15: [255 'no children node': []], " |
+ "16: [264: [], 266: [], " |
+ "267 'node with deep subtree': " |
+ "[365: [455: [555: []]]], 268: []]]", |
+ GetTreeState(frame_tree)); |
+ |
+ frame_tree->RemoveFrame(rvhi->GetFrameTreeNodeID(13), |
+ rvhi->GetFrameTreeNodeID(15)); |
+ ASSERT_EQ("13: [14: [244: [], 245: []], " |
+ "16: [264: [], 266: [], " |
+ "267 'node with deep subtree': " |
+ "[365: [455: [555: []]]], 268: []]]", |
+ GetTreeState(frame_tree)); |
} |
} // namespace |