blob: 0f28e549560455183dd3a5bc2dfc659aaccd0a38 [file] [log] [blame]
Albert J. Wongcb004632018-07-10 22:58:251// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]9b159a52013-10-03 17:24:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
danakjc492bf82020-09-09 20:02:445#include "content/browser/renderer_host/frame_tree.h"
[email protected]9b159a52013-10-03 17:24:556
avib7348942015-12-25 20:57:107#include <stddef.h>
8
9#include "base/macros.h"
[email protected]9b159a52013-10-03 17:24:5510#include "base/run_loop.h"
[email protected]7cc7ebd2013-10-08 00:59:0011#include "base/strings/string_number_conversions.h"
danakjc492bf82020-09-09 20:02:4412#include "content/browser/renderer_host/navigator.h"
13#include "content/browser/renderer_host/render_frame_host_factory.h"
14#include "content/browser/renderer_host/render_frame_host_impl.h"
[email protected]9b159a52013-10-03 17:24:5515#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]94d0cc12013-12-18 00:07:4116#include "content/browser/web_contents/web_contents_impl.h"
naskob985af12015-02-06 04:15:3317#include "content/common/frame_messages.h"
[email protected]14266072014-04-19 00:35:2018#include "content/public/browser/web_contents_observer.h"
Gabriel Charettec7108742019-08-23 03:31:4019#include "content/public/test/browser_task_environment.h"
[email protected]9b159a52013-10-03 17:24:5520#include "content/public/test/mock_render_process_host.h"
21#include "content/public/test/test_browser_context.h"
[email protected]6b50e362014-08-15 05:15:5922#include "content/test/test_render_frame_host.h"
[email protected]14266072014-04-19 00:35:2023#include "content/test/test_render_view_host.h"
24#include "content/test/test_web_contents.h"
Gyuyoung Kim6c9ce9022019-11-26 05:40:0825#include "mojo/public/cpp/bindings/pending_receiver.h"
[email protected]9b159a52013-10-03 17:24:5526#include "testing/gtest/include/gtest/gtest.h"
Blink Reformata30d4232018-04-07 15:31:0627#include "third_party/blink/public/common/frame/frame_policy.h"
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:5428#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
[email protected]9b159a52013-10-03 17:24:5529
30namespace content {
dgroganfb22f9a2014-10-20 21:32:3231
[email protected]9b159a52013-10-03 17:24:5532namespace {
33
[email protected]14266072014-04-19 00:35:2034// Appends a description of the structure of the frame tree to |result|.
35void AppendTreeNodeState(FrameTreeNode* node, std::string* result) {
36 result->append(
Raul Tambre6c0c3f5b2019-02-04 17:44:1737 base::NumberToString(node->current_frame_host()->GetRoutingID()));
schenney6408fed22015-04-17 17:44:5738 if (!node->current_frame_host()->IsRenderFrameLive())
39 result->append("*"); // Asterisk next to dead frames.
40
[email protected]14266072014-04-19 00:35:2041 if (!node->frame_name().empty()) {
42 result->append(" '");
43 result->append(node->frame_name());
44 result->append("'");
45 }
46 result->append(": [");
47 const char* separator = "";
48 for (size_t i = 0; i < node->child_count(); i++) {
49 result->append(separator);
50 AppendTreeNodeState(node->child_at(i), result);
51 separator = ", ";
52 }
53 result->append("]");
54}
55
Gyuyoung Kim6c9ce9022019-11-26 05:40:0856mojo::PendingReceiver<service_manager::mojom::InterfaceProvider>
57CreateStubInterfaceProviderReceiver() {
58 return TestRenderFrameHost::CreateStubInterfaceProviderReceiver();
Balazs Engedyba034e72017-10-27 22:26:2859}
60
Oksana Zhuravlovafee097c2019-07-26 17:01:3061mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker>
62CreateStubBrowserInterfaceBrokerReceiver() {
63 return TestRenderFrameHost::CreateStubBrowserInterfaceBrokerReceiver();
64}
65
[email protected]14266072014-04-19 00:35:2066// Logs calls to WebContentsObserver along with the state of the frame tree,
67// for later use in EXPECT_EQ().
68class TreeWalkingWebContentsLogger : public WebContentsObserver {
69 public:
70 explicit TreeWalkingWebContentsLogger(WebContents* web_contents)
71 : WebContentsObserver(web_contents) {}
72
dchengc2282aa2014-10-21 12:07:5873 ~TreeWalkingWebContentsLogger() override {
[email protected]14266072014-04-19 00:35:2074 EXPECT_EQ("", log_) << "Activity logged that was not expected";
75 }
76
77 // Gets and resets the log, which is a string of what happened.
78 std::string GetLog() {
79 std::string result = log_;
80 log_.clear();
81 return result;
82 }
83
84 // content::WebContentsObserver implementation.
dchengc2282aa2014-10-21 12:07:5885 void RenderFrameCreated(RenderFrameHost* render_frame_host) override {
[email protected]14266072014-04-19 00:35:2086 LogWhatHappened("RenderFrameCreated", render_frame_host);
87 }
88
dchengc2282aa2014-10-21 12:07:5889 void RenderFrameHostChanged(RenderFrameHost* old_host,
90 RenderFrameHost* new_host) override {
[email protected]02d7b6e2014-06-24 21:01:5091 if (old_host)
naskof5940b9f2015-03-02 23:04:0592 LogWhatHappened("RenderFrameHostChanged(old)", old_host);
93 LogWhatHappened("RenderFrameHostChanged(new)", new_host);
[email protected]02d7b6e2014-06-24 21:01:5094 }
95
dchengc2282aa2014-10-21 12:07:5896 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override {
[email protected]14266072014-04-19 00:35:2097 LogWhatHappened("RenderFrameDeleted", render_frame_host);
98 }
99
dchengc2282aa2014-10-21 12:07:58100 void RenderProcessGone(base::TerminationStatus status) override {
[email protected]14266072014-04-19 00:35:20101 LogWhatHappened("RenderProcessGone");
102 }
103
104 private:
105 void LogWhatHappened(const std::string& event_name) {
106 if (!log_.empty()) {
107 log_.append("\n");
108 }
109 log_.append(event_name + " -> ");
110 AppendTreeNodeState(
111 static_cast<WebContentsImpl*>(web_contents())->GetFrameTree()->root(),
112 &log_);
113 }
114
115 void LogWhatHappened(const std::string& event_name, RenderFrameHost* rfh) {
116 LogWhatHappened(
117 base::StringPrintf("%s(%d)", event_name.c_str(), rfh->GetRoutingID()));
118 }
119
120 std::string log_;
121
122 DISALLOW_COPY_AND_ASSIGN(TreeWalkingWebContentsLogger);
123};
124
dgroganfb22f9a2014-10-20 21:32:32125} // namespace
126
[email protected]14266072014-04-19 00:35:20127class FrameTreeTest : public RenderViewHostImplTestHarness {
[email protected]7cc7ebd2013-10-08 00:59:00128 protected:
129 // Prints a FrameTree, for easy assertions of the tree hierarchy.
130 std::string GetTreeState(FrameTree* frame_tree) {
131 std::string result;
[email protected]fa944cb82013-11-15 17:51:21132 AppendTreeNodeState(frame_tree->root(), &result);
[email protected]7cc7ebd2013-10-08 00:59:00133 return result;
134 }
nick4ed970292016-01-20 21:46:45135
136 std::string GetTraversalOrder(FrameTree* frame_tree,
Alex Moshchuk27caae82017-09-11 23:11:18137 FrameTreeNode* subtree_to_skip) {
nick4ed970292016-01-20 21:46:45138 std::string result;
Alex Moshchuk27caae82017-09-11 23:11:18139 for (FrameTreeNode* node :
140 frame_tree->NodesExceptSubtree(subtree_to_skip)) {
dcheng57e39e22016-01-21 00:25:38141 if (!result.empty())
142 result += " ";
Raul Tambre6c0c3f5b2019-02-04 17:44:17143 result +=
144 base::NumberToString(node->current_frame_host()->GetRoutingID());
dcheng57e39e22016-01-21 00:25:38145 }
nick4ed970292016-01-20 21:46:45146 return result;
147 }
[email protected]9b159a52013-10-03 17:24:55148};
149
[email protected]9b159a52013-10-03 17:24:55150// Exercise tree manipulation routines.
151// - Add a series of nodes and verify tree structure.
152// - Remove a series of nodes and verify tree structure.
nasko9f2261b2015-07-02 11:40:26153TEST_F(FrameTreeTest, Shape) {
nick8814e652015-12-18 01:44:12154 main_test_rfh()->InitializeRenderFrameIfNeeded();
155
[email protected]94d0cc12013-12-18 00:07:41156 // Use the FrameTree of the WebContents so that it has all the delegates it
157 // needs. We may want to consider a test version of this.
[email protected]14266072014-04-19 00:35:20158 FrameTree* frame_tree = contents()->GetFrameTree();
[email protected]58faf942014-02-20 21:03:58159 FrameTreeNode* root = frame_tree->root();
[email protected]190b8c52013-11-09 01:35:44160
[email protected]9b159a52013-10-03 17:24:55161 std::string no_children_node("no children node");
162 std::string deep_subtree("node with deep subtree");
dgroganfb22f9a2014-10-20 21:32:32163 int process_id = root->current_frame_host()->GetProcess()->GetID();
[email protected]9b159a52013-10-03 17:24:55164
nasko9f2261b2015-07-02 11:40:26165 // Do not navigate each frame separately, since that will clutter the test
166 // itself. Instead, leave them in "not live" state, which is indicated by the
167 // * after the frame id, since this test cares about the shape, not the
nick8814e652015-12-18 01:44:12168 // frame liveness.
Fergal Dalyfd9136d2020-03-11 14:53:36169 EXPECT_EQ("1: []", GetTreeState(frame_tree));
[email protected]7cc7ebd2013-10-08 00:59:00170
Antonio Gomes58d38062020-04-30 01:50:14171 constexpr auto kOwnerType = blink::mojom::FrameOwnerElementType::kIframe;
[email protected]9b159a52013-10-03 17:24:55172 // Simulate attaching a series of frames to build the frame tree.
Alexander Timin381e7e182020-04-28 19:04:03173 frame_tree->AddFrame(root->current_frame_host(), process_id, 14,
174 CreateStubInterfaceProviderReceiver(),
175 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41176 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03177 "uniqueName0", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04178 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03179 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
180 frame_tree->AddFrame(root->current_frame_host(), process_id, 15,
181 CreateStubInterfaceProviderReceiver(),
182 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41183 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03184 "uniqueName1", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04185 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03186 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
187 frame_tree->AddFrame(root->current_frame_host(), process_id, 16,
188 CreateStubInterfaceProviderReceiver(),
189 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41190 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03191 "uniqueName2", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04192 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03193 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
194 frame_tree->AddFrame(root->child_at(0)->current_frame_host(), process_id, 244,
195 CreateStubInterfaceProviderReceiver(),
196 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41197 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03198 "uniqueName3", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04199 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03200 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
201 frame_tree->AddFrame(root->child_at(1)->current_frame_host(), process_id, 255,
202 CreateStubInterfaceProviderReceiver(),
203 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41204 blink::mojom::TreeScopeType::kDocument, no_children_node,
Alexander Timin381e7e182020-04-28 19:04:03205 "uniqueName4", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04206 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03207 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
208 frame_tree->AddFrame(root->child_at(0)->current_frame_host(), process_id, 245,
209 CreateStubInterfaceProviderReceiver(),
210 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41211 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03212 "uniqueName5", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04213 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03214 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
[email protected]9b159a52013-10-03 17:24:55215
dcheng3ce04b62015-10-26 23:30:55216 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36217 "1: [14: [244: [], 245: []], "
nick8814e652015-12-18 01:44:12218 "15: [255 'no children node': []], "
219 "16: []]",
dcheng3ce04b62015-10-26 23:30:55220 GetTreeState(frame_tree));
[email protected]9b159a52013-10-03 17:24:55221
[email protected]58faf942014-02-20 21:03:58222 FrameTreeNode* child_16 = root->child_at(2);
Alexander Timin381e7e182020-04-28 19:04:03223 frame_tree->AddFrame(child_16->current_frame_host(), process_id, 264,
224 CreateStubInterfaceProviderReceiver(),
225 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41226 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03227 "uniqueName6", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04228 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03229 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
230 frame_tree->AddFrame(child_16->current_frame_host(), process_id, 265,
231 CreateStubInterfaceProviderReceiver(),
232 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41233 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03234 "uniqueName7", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04235 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03236 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
237 frame_tree->AddFrame(child_16->current_frame_host(), process_id, 266,
238 CreateStubInterfaceProviderReceiver(),
239 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41240 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03241 "uniqueName8", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04242 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03243 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
244 frame_tree->AddFrame(child_16->current_frame_host(), process_id, 267,
245 CreateStubInterfaceProviderReceiver(),
246 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41247 blink::mojom::TreeScopeType::kDocument, deep_subtree,
Alexander Timin381e7e182020-04-28 19:04:03248 "uniqueName9", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04249 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03250 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
251 frame_tree->AddFrame(child_16->current_frame_host(), process_id, 268,
252 CreateStubInterfaceProviderReceiver(),
253 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41254 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03255 "uniqueName10", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04256 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03257 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
[email protected]9b159a52013-10-03 17:24:55258
[email protected]58faf942014-02-20 21:03:58259 FrameTreeNode* child_267 = child_16->child_at(3);
Alexander Timin381e7e182020-04-28 19:04:03260 frame_tree->AddFrame(child_267->current_frame_host(), process_id, 365,
Gyuyoung Kim6c9ce9022019-11-26 05:40:08261 CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30262 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41263 blink::mojom::TreeScopeType::kDocument, std::string(),
Alexander Timin381e7e182020-04-28 19:04:03264 "uniqueName11", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04265 base::UnguessableToken::Create(), blink::FramePolicy(),
Alexander Timin381e7e182020-04-28 19:04:03266 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
267 frame_tree->AddFrame(child_267->child_at(0)->current_frame_host(), process_id,
268 455, CreateStubInterfaceProviderReceiver(),
269 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41270 blink::mojom::TreeScopeType::kDocument, std::string(),
Oksana Zhuravlova8b88e572019-01-07 21:54:00271 "uniqueName12", false, base::UnguessableToken::Create(),
Dave Tapuska84449382020-05-01 00:39:04272 base::UnguessableToken::Create(), blink::FramePolicy(),
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54273 blink::mojom::FrameOwnerProperties(), false, kOwnerType);
Alexander Timin381e7e182020-04-28 19:04:03274 frame_tree->AddFrame(
275 child_267->child_at(0)->child_at(0)->current_frame_host(), process_id,
276 555, CreateStubInterfaceProviderReceiver(),
277 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41278 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName13",
Dave Tapuska84449382020-05-01 00:39:04279 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
280 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), false,
281 kOwnerType);
Alexander Timin381e7e182020-04-28 19:04:03282 frame_tree->AddFrame(
283 child_267->child_at(0)->child_at(0)->child_at(0)->current_frame_host(),
284 process_id, 655, CreateStubInterfaceProviderReceiver(),
285 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41286 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName14",
Dave Tapuska84449382020-05-01 00:39:04287 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
288 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), false,
289 kOwnerType);
[email protected]9b159a52013-10-03 17:24:55290
[email protected]7cc7ebd2013-10-08 00:59:00291 // Now that's it's fully built, verify the tree structure is as expected.
dcheng3ce04b62015-10-26 23:30:55292 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36293 "1: [14: [244: [], 245: []], "
nick8814e652015-12-18 01:44:12294 "15: [255 'no children node': []], "
295 "16: [264: [], 265: [], 266: [], "
296 "267 'node with deep subtree': "
297 "[365: [455: [555: [655: []]]]], 268: []]]",
dcheng3ce04b62015-10-26 23:30:55298 GetTreeState(frame_tree));
[email protected]9b159a52013-10-03 17:24:55299
nick4ed970292016-01-20 21:46:45300 // Verify that traversal order is breadth first, even if we skip a subtree.
301 FrameTreeNode* child_14 = root->child_at(0);
302 FrameTreeNode* child_15 = root->child_at(1);
303 FrameTreeNode* child_244 = child_14->child_at(0);
304 FrameTreeNode* child_245 = child_14->child_at(1);
[email protected]58faf942014-02-20 21:03:58305 FrameTreeNode* child_555 = child_267->child_at(0)->child_at(0)->child_at(0);
nick4ed970292016-01-20 21:46:45306 FrameTreeNode* child_655 = child_555->child_at(0);
Fergal Dalyfd9136d2020-03-11 14:53:36307 EXPECT_EQ("1 14 15 16 244 245 255 264 265 266 267 268 365 455 555 655",
nick4ed970292016-01-20 21:46:45308 GetTraversalOrder(frame_tree, nullptr));
Fergal Dalyfd9136d2020-03-11 14:53:36309 EXPECT_EQ("1", GetTraversalOrder(frame_tree, root));
310 EXPECT_EQ("1 14 15 16 255 264 265 266 267 268 365 455 555 655",
nick4ed970292016-01-20 21:46:45311 GetTraversalOrder(frame_tree, child_14));
Fergal Dalyfd9136d2020-03-11 14:53:36312 EXPECT_EQ("1 14 15 16 244 245 255 264 265 266 267 268 365 455 555 655",
nick4ed970292016-01-20 21:46:45313 GetTraversalOrder(frame_tree, child_244));
Fergal Dalyfd9136d2020-03-11 14:53:36314 EXPECT_EQ("1 14 15 16 244 245 255 264 265 266 267 268 365 455 555 655",
nick4ed970292016-01-20 21:46:45315 GetTraversalOrder(frame_tree, child_245));
Fergal Dalyfd9136d2020-03-11 14:53:36316 EXPECT_EQ("1 14 15 16 244 245 264 265 266 267 268 365 455 555 655",
nick4ed970292016-01-20 21:46:45317 GetTraversalOrder(frame_tree, child_15));
Fergal Dalyfd9136d2020-03-11 14:53:36318 EXPECT_EQ("1 14 15 16 244 245 255 264 265 266 267 268",
nick4ed970292016-01-20 21:46:45319 GetTraversalOrder(frame_tree, child_267));
Fergal Dalyfd9136d2020-03-11 14:53:36320 EXPECT_EQ("1 14 15 16 244 245 255 264 265 266 267 268 365 455 555",
Alex Moshchuk27caae82017-09-11 23:11:18321 GetTraversalOrder(frame_tree, child_555));
Fergal Dalyfd9136d2020-03-11 14:53:36322 EXPECT_EQ("1 14 15 16 244 245 255 264 265 266 267 268 365 455 555 655",
nick4ed970292016-01-20 21:46:45323 GetTraversalOrder(frame_tree, child_655));
324
[email protected]58faf942014-02-20 21:03:58325 frame_tree->RemoveFrame(child_555);
dcheng3ce04b62015-10-26 23:30:55326 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36327 "1: [14: [244: [], 245: []], "
nick8814e652015-12-18 01:44:12328 "15: [255 'no children node': []], "
329 "16: [264: [], 265: [], 266: [], "
330 "267 'node with deep subtree': "
331 "[365: [455: []]], 268: []]]",
dcheng3ce04b62015-10-26 23:30:55332 GetTreeState(frame_tree));
[email protected]9b159a52013-10-03 17:24:55333
[email protected]58faf942014-02-20 21:03:58334 frame_tree->RemoveFrame(child_16->child_at(1));
dcheng3ce04b62015-10-26 23:30:55335 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36336 "1: [14: [244: [], 245: []], "
nick8814e652015-12-18 01:44:12337 "15: [255 'no children node': []], "
338 "16: [264: [], 266: [], "
339 "267 'node with deep subtree': "
340 "[365: [455: []]], 268: []]]",
dcheng3ce04b62015-10-26 23:30:55341 GetTreeState(frame_tree));
[email protected]9b159a52013-10-03 17:24:55342
[email protected]58faf942014-02-20 21:03:58343 frame_tree->RemoveFrame(root->child_at(1));
dcheng3ce04b62015-10-26 23:30:55344 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36345 "1: [14: [244: [], 245: []], "
nick8814e652015-12-18 01:44:12346 "16: [264: [], 266: [], "
347 "267 'node with deep subtree': "
348 "[365: [455: []]], 268: []]]",
dcheng3ce04b62015-10-26 23:30:55349 GetTreeState(frame_tree));
[email protected]9b159a52013-10-03 17:24:55350}
351
creis6a93a812015-04-24 23:13:17352// Ensure frames can be found by frame_tree_node_id, routing ID, or name.
Charlie Reisb1405622018-04-02 22:52:39353TEST_F(FrameTreeTest, FindFrames) {
lfg269b702f2015-06-08 19:28:19354 main_test_rfh()->InitializeRenderFrameIfNeeded();
355
creis6a93a812015-04-24 23:13:17356 // Add a few child frames to the main frame.
357 FrameTree* frame_tree = contents()->GetFrameTree();
358 FrameTreeNode* root = frame_tree->root();
lfg269b702f2015-06-08 19:28:19359
Antonio Gomes58d38062020-04-30 01:50:14360 constexpr auto kOwnerType = blink::mojom::FrameOwnerElementType::kIframe;
lukasza464d8692016-02-22 19:26:32361 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08362 22, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30363 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41364 blink::mojom::TreeScopeType::kDocument, "child0", "uniqueName0", false,
Dave Tapuska84449382020-05-01 00:39:04365 base::UnguessableToken::Create(), base::UnguessableToken::Create(),
366 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
lukasza464d8692016-02-22 19:26:32367 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08368 23, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30369 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41370 blink::mojom::TreeScopeType::kDocument, "child1", "uniqueName1", false,
Dave Tapuska84449382020-05-01 00:39:04371 base::UnguessableToken::Create(), base::UnguessableToken::Create(),
372 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
lukasza464d8692016-02-22 19:26:32373 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08374 24, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30375 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41376 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName2",
Dave Tapuska84449382020-05-01 00:39:04377 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
378 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
creis6a93a812015-04-24 23:13:17379 FrameTreeNode* child0 = root->child_at(0);
380 FrameTreeNode* child1 = root->child_at(1);
381 FrameTreeNode* child2 = root->child_at(2);
382
383 // Add one grandchild frame.
dcheng860817a2015-05-22 03:16:56384 child1->current_frame_host()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08385 33, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30386 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41387 blink::mojom::TreeScopeType::kDocument, "grandchild", "uniqueName3",
Dave Tapuska84449382020-05-01 00:39:04388 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
389 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
creis6a93a812015-04-24 23:13:17390 FrameTreeNode* grandchild = child1->child_at(0);
391
392 // Ensure they can be found by FTN id.
393 EXPECT_EQ(root, frame_tree->FindByID(root->frame_tree_node_id()));
394 EXPECT_EQ(child0, frame_tree->FindByID(child0->frame_tree_node_id()));
395 EXPECT_EQ(child1, frame_tree->FindByID(child1->frame_tree_node_id()));
396 EXPECT_EQ(child2, frame_tree->FindByID(child2->frame_tree_node_id()));
397 EXPECT_EQ(grandchild, frame_tree->FindByID(grandchild->frame_tree_node_id()));
398 EXPECT_EQ(nullptr, frame_tree->FindByID(-1));
399
400 // Ensure they can be found by routing id.
401 int process_id = main_test_rfh()->GetProcess()->GetID();
402 EXPECT_EQ(root, frame_tree->FindByRoutingID(process_id,
403 main_test_rfh()->GetRoutingID()));
404 EXPECT_EQ(child0, frame_tree->FindByRoutingID(process_id, 22));
405 EXPECT_EQ(child1, frame_tree->FindByRoutingID(process_id, 23));
406 EXPECT_EQ(child2, frame_tree->FindByRoutingID(process_id, 24));
407 EXPECT_EQ(grandchild, frame_tree->FindByRoutingID(process_id, 33));
408 EXPECT_EQ(nullptr, frame_tree->FindByRoutingID(process_id, 37));
409
410 // Ensure they can be found by name, if they have one.
411 EXPECT_EQ(root, frame_tree->FindByName(std::string()));
412 EXPECT_EQ(child0, frame_tree->FindByName("child0"));
413 EXPECT_EQ(child1, frame_tree->FindByName("child1"));
414 EXPECT_EQ(grandchild, frame_tree->FindByName("grandchild"));
415 EXPECT_EQ(nullptr, frame_tree->FindByName("no such frame"));
416}
417
paulmeyer322777fb2016-05-16 23:15:39418// Check that PreviousSibling() and NextSibling() are retrieved correctly.
419TEST_F(FrameTreeTest, GetSibling) {
lfg269b702f2015-06-08 19:28:19420 main_test_rfh()->InitializeRenderFrameIfNeeded();
421
Antonio Gomes58d38062020-04-30 01:50:14422 constexpr auto kOwnerType = blink::mojom::FrameOwnerElementType::kIframe;
alexmos9f8705a2015-05-06 19:58:59423 // Add a few child frames to the main frame.
424 FrameTree* frame_tree = contents()->GetFrameTree();
425 FrameTreeNode* root = frame_tree->root();
lukasza464d8692016-02-22 19:26:32426 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08427 22, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30428 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41429 blink::mojom::TreeScopeType::kDocument, "child0", "uniqueName0", false,
Dave Tapuska84449382020-05-01 00:39:04430 base::UnguessableToken::Create(), base::UnguessableToken::Create(),
431 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
lukasza464d8692016-02-22 19:26:32432 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08433 23, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30434 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41435 blink::mojom::TreeScopeType::kDocument, "child1", "uniqueName1", false,
Dave Tapuska84449382020-05-01 00:39:04436 base::UnguessableToken::Create(), base::UnguessableToken::Create(),
437 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
lukasza464d8692016-02-22 19:26:32438 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08439 24, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30440 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41441 blink::mojom::TreeScopeType::kDocument, "child2", "uniqueName2", false,
Dave Tapuska84449382020-05-01 00:39:04442 base::UnguessableToken::Create(), base::UnguessableToken::Create(),
443 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
alexmos9f8705a2015-05-06 19:58:59444 FrameTreeNode* child0 = root->child_at(0);
445 FrameTreeNode* child1 = root->child_at(1);
446 FrameTreeNode* child2 = root->child_at(2);
447
448 // Add one grandchild frame.
dcheng860817a2015-05-22 03:16:56449 child1->current_frame_host()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08450 33, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30451 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41452 blink::mojom::TreeScopeType::kDocument, "grandchild", "uniqueName3",
Dave Tapuska84449382020-05-01 00:39:04453 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
454 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
alexmos9f8705a2015-05-06 19:58:59455 FrameTreeNode* grandchild = child1->child_at(0);
456
paulmeyer322777fb2016-05-16 23:15:39457 // Test PreviousSibling().
alexmos9f8705a2015-05-06 19:58:59458 EXPECT_EQ(nullptr, root->PreviousSibling());
459 EXPECT_EQ(nullptr, child0->PreviousSibling());
460 EXPECT_EQ(child0, child1->PreviousSibling());
461 EXPECT_EQ(child1, child2->PreviousSibling());
462 EXPECT_EQ(nullptr, grandchild->PreviousSibling());
paulmeyer322777fb2016-05-16 23:15:39463
464 // Test NextSibling().
465 EXPECT_EQ(nullptr, root->NextSibling());
466 EXPECT_EQ(child1, child0->NextSibling());
467 EXPECT_EQ(child2, child1->NextSibling());
468 EXPECT_EQ(nullptr, child2->NextSibling());
469 EXPECT_EQ(nullptr, grandchild->NextSibling());
alexmos9f8705a2015-05-06 19:58:59470}
471
[email protected]14266072014-04-19 00:35:20472// Do some simple manipulations of the frame tree, making sure that
473// WebContentsObservers see a consistent view of the tree as we go.
474TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) {
475 TreeWalkingWebContentsLogger activity(contents());
schenney6408fed22015-04-17 17:44:57476 contents()->NavigateAndCommit(GURL("http://www.google.com"));
Fergal Dalyfd9136d2020-03-11 14:53:36477 EXPECT_EQ("RenderFrameCreated(1) -> 1: []", activity.GetLog());
schenney6408fed22015-04-17 17:44:57478
[email protected]14266072014-04-19 00:35:20479 FrameTree* frame_tree = contents()->GetFrameTree();
480 FrameTreeNode* root = frame_tree->root();
481
Antonio Gomes58d38062020-04-30 01:50:14482 constexpr auto kOwnerType = blink::mojom::FrameOwnerElementType::kIframe;
[email protected]14266072014-04-19 00:35:20483 // Simulate attaching a series of frames to build the frame tree.
lukasza464d8692016-02-22 19:26:32484 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08485 14, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30486 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41487 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName0",
Dave Tapuska84449382020-05-01 00:39:04488 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
489 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
naskof5940b9f2015-03-02 23:04:05490 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36491 "RenderFrameHostChanged(new)(14) -> 1: []\n"
492 "RenderFrameCreated(14) -> 1: [14: []]",
naskof5940b9f2015-03-02 23:04:05493 activity.GetLog());
lukasza464d8692016-02-22 19:26:32494 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08495 18, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30496 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41497 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName1",
Dave Tapuska84449382020-05-01 00:39:04498 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
499 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
naskof5940b9f2015-03-02 23:04:05500 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36501 "RenderFrameHostChanged(new)(18) -> 1: [14: []]\n"
502 "RenderFrameCreated(18) -> 1: [14: [], 18: []]",
naskof5940b9f2015-03-02 23:04:05503 activity.GetLog());
[email protected]14266072014-04-19 00:35:20504 frame_tree->RemoveFrame(root->child_at(0));
Fergal Dalyfd9136d2020-03-11 14:53:36505 EXPECT_EQ("RenderFrameDeleted(14) -> 1: [18: []]", activity.GetLog());
[email protected]14266072014-04-19 00:35:20506 frame_tree->RemoveFrame(root->child_at(0));
Fergal Dalyfd9136d2020-03-11 14:53:36507 EXPECT_EQ("RenderFrameDeleted(18) -> 1: []", activity.GetLog());
[email protected]14266072014-04-19 00:35:20508}
509
510// Make sure that WebContentsObservers see a consistent view of the tree after
511// recovery from a render process crash.
512TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) {
513 TreeWalkingWebContentsLogger activity(contents());
schenney6408fed22015-04-17 17:44:57514 contents()->NavigateAndCommit(GURL("http://www.google.com"));
Fergal Dalyfd9136d2020-03-11 14:53:36515 EXPECT_EQ("RenderFrameCreated(1) -> 1: []", activity.GetLog());
[email protected]14266072014-04-19 00:35:20516
Antonio Gomes58d38062020-04-30 01:50:14517 constexpr auto kOwnerType = blink::mojom::FrameOwnerElementType::kIframe;
lukasza464d8692016-02-22 19:26:32518 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08519 22, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30520 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41521 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName0",
Dave Tapuska84449382020-05-01 00:39:04522 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
523 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
naskof5940b9f2015-03-02 23:04:05524 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36525 "RenderFrameHostChanged(new)(22) -> 1: []\n"
526 "RenderFrameCreated(22) -> 1: [22: []]",
naskof5940b9f2015-03-02 23:04:05527 activity.GetLog());
lukasza464d8692016-02-22 19:26:32528 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08529 23, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30530 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41531 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName1",
Dave Tapuska84449382020-05-01 00:39:04532 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
533 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
naskof5940b9f2015-03-02 23:04:05534 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36535 "RenderFrameHostChanged(new)(23) -> 1: [22: []]\n"
536 "RenderFrameCreated(23) -> 1: [22: [], 23: []]",
naskof5940b9f2015-03-02 23:04:05537 activity.GetLog());
[email protected]14266072014-04-19 00:35:20538
539 // Crash the renderer
nick16b07652015-04-18 02:35:31540 main_test_rfh()->GetProcess()->SimulateCrash();
[email protected]14266072014-04-19 00:35:20541 EXPECT_EQ(
Fergal Dalyfd9136d2020-03-11 14:53:36542 "RenderProcessGone -> 1*: [22*: [], 23*: []]\n"
543 "RenderFrameDeleted(23) -> 1*: []\n"
544 "RenderFrameDeleted(22) -> 1*: []\n"
545 "RenderFrameDeleted(1) -> 1*: []",
[email protected]14266072014-04-19 00:35:20546 activity.GetLog());
547}
548
dgroganfb22f9a2014-10-20 21:32:32549// Ensure that frames are not added to the tree, if the process passed in
550// is different than the process of the parent node.
551TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) {
schenney6408fed22015-04-17 17:44:57552 contents()->NavigateAndCommit(GURL("http://www.google.com"));
dgroganfb22f9a2014-10-20 21:32:32553 FrameTree* frame_tree = contents()->GetFrameTree();
554 FrameTreeNode* root = frame_tree->root();
555 int process_id = root->current_frame_host()->GetProcess()->GetID();
556
Fergal Dalyfd9136d2020-03-11 14:53:36557 ASSERT_EQ("1: []", GetTreeState(frame_tree));
dgroganfb22f9a2014-10-20 21:32:32558
559 // Simulate attaching a frame from mismatched process id.
dcheng5f60abb2015-05-28 01:39:36560 ASSERT_FALSE(frame_tree->AddFrame(
Alexander Timin381e7e182020-04-28 19:04:03561 root->current_frame_host(), process_id + 1, 1,
562 CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30563 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41564 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName0",
Dave Tapuska84449382020-05-01 00:39:04565 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
566 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), false,
Antonio Gomes58d38062020-04-30 01:50:14567 blink::mojom::FrameOwnerElementType::kIframe));
Fergal Dalyfd9136d2020-03-11 14:53:36568 ASSERT_EQ("1: []", GetTreeState(frame_tree));
dgroganfb22f9a2014-10-20 21:32:32569}
570
naskoaeca57b2015-02-13 00:50:46571// Ensure that frames removed while a process has crashed are not preserved in
572// the global map of id->frame.
573TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) {
lfg269b702f2015-06-08 19:28:19574 main_test_rfh()->InitializeRenderFrameIfNeeded();
575
naskoaeca57b2015-02-13 00:50:46576 // Add a couple child frames to the main frame.
577 FrameTreeNode* root = contents()->GetFrameTree()->root();
578
Antonio Gomes58d38062020-04-30 01:50:14579 constexpr auto kOwnerType = blink::mojom::FrameOwnerElementType::kIframe;
lukasza464d8692016-02-22 19:26:32580 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08581 22, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30582 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41583 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName0",
Dave Tapuska84449382020-05-01 00:39:04584 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
585 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
lukasza464d8692016-02-22 19:26:32586 main_test_rfh()->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08587 23, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30588 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41589 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName1",
Dave Tapuska84449382020-05-01 00:39:04590 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
591 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
naskoaeca57b2015-02-13 00:50:46592
dmazzonie950ea232015-03-13 21:39:45593 // Add one grandchild frame.
594 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host();
Ehsan Karamad192a8da2018-10-21 03:48:08595 child1_rfh->OnCreateChildFrame(
Gyuyoung Kim6c9ce9022019-11-26 05:40:08596 33, CreateStubInterfaceProviderReceiver(),
Oksana Zhuravlovafee097c2019-07-26 17:01:30597 CreateStubBrowserInterfaceBrokerReceiver(),
Antonio Gomes9d5c1ef2020-04-30 20:56:41598 blink::mojom::TreeScopeType::kDocument, std::string(), "uniqueName2",
Dave Tapuska84449382020-05-01 00:39:04599 false, base::UnguessableToken::Create(), base::UnguessableToken::Create(),
600 blink::FramePolicy(), blink::mojom::FrameOwnerProperties(), kOwnerType);
dmazzonie950ea232015-03-13 21:39:45601
naskoaeca57b2015-02-13 00:50:46602 // Ensure they can be found by id.
vishal.b782eb5d2015-04-29 12:22:57603 int id1 = root->child_at(0)->frame_tree_node_id();
604 int id2 = root->child_at(1)->frame_tree_node_id();
605 int id3 = root->child_at(0)->child_at(0)->frame_tree_node_id();
dmazzonie950ea232015-03-13 21:39:45606 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1));
607 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2));
608 EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3));
naskoaeca57b2015-02-13 00:50:46609
610 // Crash the renderer.
nick16b07652015-04-18 02:35:31611 main_test_rfh()->GetProcess()->SimulateCrash();
naskoaeca57b2015-02-13 00:50:46612
613 // Ensure they cannot be found by id after the process has crashed.
dmazzonie950ea232015-03-13 21:39:45614 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1));
615 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2));
616 EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3));
naskoaeca57b2015-02-13 00:50:46617}
618
[email protected]9b159a52013-10-03 17:24:55619} // namespace content