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 6f1bb3303805386ad0aa7a5c112fa2960ca39b7d..ede3513ab68f71aa419dc56331ff371213a99109 100644 |
--- a/content/browser/frame_host/frame_tree_unittest.cc |
+++ b/content/browser/frame_host/frame_tree_unittest.cc |
@@ -10,6 +10,7 @@ |
#include "content/browser/frame_host/render_frame_host_factory.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" |
@@ -47,35 +48,6 @@ class FrameTreeTest : public RenderViewHostTestHarness { |
} |
}; |
-// The root node never changes during navigation even though its |
-// RenderFrameHost does. |
-// - 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) { |
- FrameTree frame_tree(new NavigatorImpl(NULL, NULL), NULL, NULL, NULL, NULL); |
- |
- // Initial state has empty node. |
- FrameTreeNode* root = frame_tree.root(); |
- ASSERT_TRUE(root); |
- EXPECT_FALSE(frame_tree.GetMainFrame()); |
- |
- // Swap in main frame. |
- RenderFrameHostImpl* dummy = reinterpret_cast<RenderFrameHostImpl*>(0x1); |
- frame_tree.SwapMainFrame(dummy); |
- EXPECT_EQ(root, frame_tree.root()); |
- EXPECT_EQ(dummy, frame_tree.GetMainFrame()); |
- |
- // Move back to NULL. |
- frame_tree.SwapMainFrame(NULL); |
- EXPECT_EQ(root, frame_tree.root()); |
- EXPECT_FALSE(frame_tree.GetMainFrame()); |
- |
- // 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. |
@@ -89,7 +61,7 @@ TEST_F(FrameTreeTest, FirstNavigationAfterSwap) { |
EXPECT_FALSE(frame_tree.IsFirstNavigationAfterSwap()); |
EXPECT_EQ(1, frame_tree.root()->frame_id()); |
- frame_tree.SwapMainFrame(NULL); |
+ frame_tree.ResetForMainFrameSwap(); |
EXPECT_TRUE(frame_tree.IsFirstNavigationAfterSwap()); |
EXPECT_EQ(FrameTreeNode::kInvalidFrameId, |
frame_tree.root()->frame_id()); |
@@ -99,49 +71,43 @@ TEST_F(FrameTreeTest, FirstNavigationAfterSwap) { |
// - 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 NavigatorImpl(NULL, 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(); |
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. |
- scoped_ptr<RenderFrameHostImpl> render_frame_host = |
- RenderFrameHostFactory::Create(static_cast<RenderViewHostImpl*>(rvh()), |
- NULL, |
- &frame_tree, |
- frame_tree.root(), |
- process()->GetNextRoutingID(), |
- false); |
- frame_tree.SwapMainFrame(render_frame_host.get()); |
- frame_tree.OnFirstNavigationAfterSwap(5); |
+ frame_tree->OnFirstNavigationAfterSwap(5); |
- ASSERT_EQ("5: []", GetTreeState(&frame_tree)); |
+ ASSERT_EQ("5: []", 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(), 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()); |
+ 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)); |
+ 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(), 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(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()); |
// Now that's it's fully built, verify the tree structure is as expected. |
ASSERT_EQ("5: [14: [244: [], 245: []], " |
@@ -149,31 +115,33 @@ TEST_F(FrameTreeTest, Shape) { |
"16: [264: [], 265: [], 266: [], " |
"267 'node with deep subtree': " |
"[365: [455: [555: [655: []]]]], 268: []]]", |
- GetTreeState(&frame_tree)); |
+ GetTreeState(frame_tree)); |
- // Test removing of nodes. |
- frame_tree.RemoveFrame(NULL, 555, 655); |
+ // Test removing of nodes. Clear the frame removal listener so we can pass a |
+ // NULL RFH here. |
+ frame_tree->ClearFrameRemoveListenerForTesting(); |
+ frame_tree->RemoveFrame(NULL, 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)); |
+ GetTreeState(frame_tree)); |
- frame_tree.RemoveFrame(NULL, 16, 265); |
+ frame_tree->RemoveFrame(NULL, 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)); |
+ GetTreeState(frame_tree)); |
- frame_tree.RemoveFrame(NULL, 5, 15); |
+ frame_tree->RemoveFrame(NULL, 5, 15); |
ASSERT_EQ("5: [14: [244: [], 245: []], " |
"16: [264: [], 266: [], " |
"267 'node with deep subtree': " |
"[365: [455: [555: []]]], 268: []]]", |
- GetTreeState(&frame_tree)); |
+ GetTreeState(frame_tree)); |
} |
} // namespace |