#include "testing/gtest/include/gtest/gtest.h"
namespace content {
+
namespace {
// Appends a description of the structure of the frame tree to |result|.
DISALLOW_COPY_AND_ASSIGN(TreeWalkingWebContentsLogger);
};
+} // namespace
+
class FrameTreeTest : public RenderViewHostImplTestHarness {
protected:
// Prints a FrameTree, for easy assertions of the tree hierarchy.
std::string no_children_node("no children node");
std::string deep_subtree("node with deep subtree");
+ int process_id = root->current_frame_host()->GetProcess()->GetID();
ASSERT_EQ("1: []", GetTreeState(frame_tree));
// Simulate attaching a series of frames to build the frame tree.
- frame_tree->AddFrame(root, 14, std::string());
- frame_tree->AddFrame(root, 15, std::string());
- frame_tree->AddFrame(root, 16, std::string());
+ frame_tree->AddFrame(root, process_id, 14, std::string());
+ frame_tree->AddFrame(root, process_id, 15, std::string());
+ frame_tree->AddFrame(root, process_id, 16, std::string());
- frame_tree->AddFrame(root->child_at(0), 244, std::string());
- frame_tree->AddFrame(root->child_at(1), 255, no_children_node);
- frame_tree->AddFrame(root->child_at(0), 245, std::string());
+ frame_tree->AddFrame(root->child_at(0), process_id, 244, std::string());
+ frame_tree->AddFrame(root->child_at(1), process_id, 255, no_children_node);
+ frame_tree->AddFrame(root->child_at(0), process_id, 245, std::string());
ASSERT_EQ("1: [14: [244: [], 245: []], "
"15: [255 'no children node': []], "
GetTreeState(frame_tree));
FrameTreeNode* child_16 = root->child_at(2);
- frame_tree->AddFrame(child_16, 264, std::string());
- frame_tree->AddFrame(child_16, 265, std::string());
- frame_tree->AddFrame(child_16, 266, std::string());
- frame_tree->AddFrame(child_16, 267, deep_subtree);
- frame_tree->AddFrame(child_16, 268, std::string());
+ frame_tree->AddFrame(child_16, process_id, 264, std::string());
+ frame_tree->AddFrame(child_16, process_id, 265, std::string());
+ frame_tree->AddFrame(child_16, process_id, 266, std::string());
+ frame_tree->AddFrame(child_16, process_id, 267, deep_subtree);
+ frame_tree->AddFrame(child_16, process_id, 268, std::string());
FrameTreeNode* child_267 = child_16->child_at(3);
- frame_tree->AddFrame(child_267, 365, std::string());
- frame_tree->AddFrame(child_267->child_at(0), 455, std::string());
- frame_tree->AddFrame(child_267->child_at(0)->child_at(0), 555, std::string());
- frame_tree->AddFrame(child_267->child_at(0)->child_at(0)->child_at(0), 655,
+ frame_tree->AddFrame(child_267, process_id, 365, std::string());
+ frame_tree->AddFrame(child_267->child_at(0), process_id, 455, std::string());
+ frame_tree->AddFrame(child_267->child_at(0)->child_at(0), process_id, 555,
std::string());
+ frame_tree->AddFrame(child_267->child_at(0)->child_at(0)->child_at(0),
+ process_id, 655, std::string());
// Now that's it's fully built, verify the tree structure is as expected.
ASSERT_EQ("1: [14: [244: [], 245: []], "
activity.GetLog());
}
-} // namespace
+// Ensure that frames are not added to the tree, if the process passed in
+// is different than the process of the parent node.
+TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) {
+ FrameTree* frame_tree = contents()->GetFrameTree();
+ FrameTreeNode* root = frame_tree->root();
+ int process_id = root->current_frame_host()->GetProcess()->GetID();
+
+ ASSERT_EQ("1: []", GetTreeState(frame_tree));
+
+ // Simulate attaching a frame from mismatched process id.
+ ASSERT_FALSE(frame_tree->AddFrame(root, process_id + 1, 1, std::string()));
+ ASSERT_EQ("1: []", GetTreeState(frame_tree));
+}
+
} // namespace content