Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / content / browser / frame_host / frame_tree_unittest.cc
index 8936bfa..bed8617 100644 (file)
@@ -22,6 +22,7 @@
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace content {
+
 namespace {
 
 // Appends a description of the structure of the frame tree to |result|.
@@ -102,6 +103,8 @@ class TreeWalkingWebContentsLogger : public WebContentsObserver {
   DISALLOW_COPY_AND_ASSIGN(TreeWalkingWebContentsLogger);
 };
 
+}  // namespace
+
 class FrameTreeTest : public RenderViewHostImplTestHarness {
  protected:
   // Prints a FrameTree, for easy assertions of the tree hierarchy.
@@ -123,17 +126,18 @@ TEST_F(FrameTreeTest, Shape) {
 
   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': []], "
@@ -141,18 +145,19 @@ TEST_F(FrameTreeTest, Shape) {
             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: []], "
@@ -227,5 +232,18 @@ TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) {
       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