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

Unified 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: unittests. Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/frame_tree_unittest.cc
diff --git a/content/browser/renderer_host/frame_tree_unittest.cc b/content/browser/renderer_host/frame_tree_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..264e256c41fcbd04f4c3b087d30e7cb3f31f99b5
--- /dev/null
+++ b/content/browser/renderer_host/frame_tree_unittest.cc
@@ -0,0 +1,147 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/frame_tree.h"
+
+#include "base/run_loop.h"
+#include "content/browser/renderer_host/render_frame_host_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"
+#include "content/public/test/test_renderer_host.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+namespace {
+
+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).
+// - Main frame does not own RenderFrameHost.
+TEST_F(FrameTreeTest, RootNode) {
+ FrameTree frame_tree;
+
+ // Initial state has empty node.
+ FrameTreeNode* root = frame_tree.GetRootForTesting();
+ 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.GetRootForTesting());
+ EXPECT_EQ(dummy, frame_tree.GetMainFrame());
+
+ // Move back to NULL.
Charlie Reis 2013/09/27 19:19:21 It's not immediately clear why we need to support
awong 2013/09/27 20:50:09 It's in the top level comment.
+ frame_tree.SwapMainFrame(NULL);
+ EXPECT_EQ(root, frame_tree.GetRootForTesting());
+ 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 swapping of main frame resets the render-assgined frame id.
Charlie Reis 2013/09/27 19:19:21 nit: Test that swapping the main frame (hard to re
awong 2013/09/27 20:50:09 Done.
+// - On creation, frame id is unassigned.
+// - After a swap, frame id is unassigned.
+TEST_F(FrameTreeTest, FirstNavigationAfterSwap) {
+ FrameTree frame_tree;
+
+ ASSERT_TRUE(frame_tree.IsFirstNavigationAfterSwap());
Charlie Reis 2013/09/27 19:19:21 These should use EXPECT, right? (ASSERT is for th
awong 2013/09/27 20:50:09 Good catch. done.
+ frame_tree.OnFirstNavigationAfterSwap(1);
+ ASSERT_FALSE(frame_tree.IsFirstNavigationAfterSwap());
+
+ frame_tree.SwapMainFrame(NULL);
+ ASSERT_TRUE(frame_tree.IsFirstNavigationAfterSwap());
Charlie Reis 2013/09/27 19:19:21 We haven't actually tested anything about the fram
awong 2013/09/27 20:50:09 Done.
+}
+
+// Exercise tree manipulation routines.
+// - Add a series of nodes and verify tree structure.
Charlie Reis 2013/09/27 19:19:21 nit: One less indent space, like the comments abov
awong 2013/09/27 20:50:09 Done.
+// - Remove a series of nodes and verify tree structure.
+TEST_F(FrameTreeTest, Shape) {
+ FrameTree frame_tree;
+ 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 initalized by simulating a
Charlie Reis 2013/09/27 19:19:21 initialized
awong 2013/09/27 20:50:09 Done.
+ // main frame swap here.
+ RenderFrameHostImpl render_frame_host(process(), &frame_tree,
+ process()->GetNextRoutingID(), false);
+ frame_tree.SwapMainFrame(&render_frame_host);
+ frame_tree.OnFirstNavigationAfterSwap(5);
+
+ // Let's send a series of messages for frame attached and build the
Charlie Reis 2013/09/27 19:19:21 for frame attached -> to simulate attaching a fram
awong 2013/09/27 20:50:09 rewrote the whole comment.
+ // 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(), 14, 245, std::string());
+
+ frame_tree.AddFrame(process()->GetNextRoutingID(), 15, 255, no_children_node);
+
+ 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());
+
+ // Now, verify the tree structure is as expected.
+ FrameTreeNode* root = frame_tree.GetRootForTesting();
+ EXPECT_EQ(5, root->frame_id());
+ EXPECT_EQ(3UL, root->child_count());
+
+ EXPECT_EQ(2UL, root->child_at(0)->child_count());
+ EXPECT_EQ(0UL, root->child_at(0)->child_at(0)->child_count());
+ EXPECT_EQ(0UL, root->child_at(0)->child_at(1)->child_count());
+
+ EXPECT_EQ(1UL, root->child_at(1)->child_count());
+ EXPECT_EQ(0UL, root->child_at(1)->child_at(0)->child_count());
+ EXPECT_STREQ(no_children_node.c_str(),
+ root->child_at(1)->child_at(0)->frame_name().c_str());
+
+ EXPECT_EQ(5UL, root->child_at(2)->child_count());
+ EXPECT_EQ(0UL, root->child_at(2)->child_at(0)->child_count());
+ EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_count());
+ EXPECT_EQ(0UL, root->child_at(2)->child_at(2)->child_count());
+ EXPECT_EQ(1UL, root->child_at(2)->child_at(3)->child_count());
+ EXPECT_STREQ(deep_subtree.c_str(),
+ root->child_at(2)->child_at(3)->frame_name().c_str());
+ EXPECT_EQ(0UL, root->child_at(2)->child_at(4)->child_count());
+
+ FrameTreeNode* deep_tree = root->child_at(2)->child_at(3)->child_at(0);
+ EXPECT_EQ(365, deep_tree->frame_id());
+ EXPECT_EQ(1UL, deep_tree->child_count());
+ EXPECT_EQ(455, deep_tree->child_at(0)->frame_id());
+ EXPECT_EQ(1UL, deep_tree->child_at(0)->child_count());
+ EXPECT_EQ(555, deep_tree->child_at(0)->child_at(0)->frame_id());
+ EXPECT_EQ(1UL, deep_tree->child_at(0)->child_at(0)->child_count());
+ EXPECT_EQ(655, deep_tree->child_at(0)->child_at(0)->child_at(0)->frame_id());
+ EXPECT_EQ(0UL,
+ deep_tree->child_at(0)->child_at(0)->child_at(0)->child_count());
+
+ // Test removing of nodes.
+ frame_tree.RemoveFrame(555, 655);
+ EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count());
+
+ frame_tree.RemoveFrame(16, 265);
+ EXPECT_EQ(4UL, root->child_at(2)->child_count());
+
+ frame_tree.RemoveFrame(5, 15);
+ EXPECT_EQ(2UL, root->child_count());
+}
+
+} // namespace
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698