[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 5 | #include "content/browser/frame_host/frame_tree.h" |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 6 | |
| 7 | #include "base/run_loop.h" |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 8 | #include "base/strings/string_number_conversions.h" |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 9 | #include "content/browser/frame_host/navigator_impl.h" |
[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 10 | #include "content/browser/frame_host/render_frame_host_factory.h" |
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 11 | #include "content/browser/frame_host/render_frame_host_impl.h" |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 12 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 13 | #include "content/browser/web_contents/web_contents_impl.h" |
nasko | b985af1 | 2015-02-06 04:15:33 | [diff] [blame] | 14 | #include "content/common/frame_messages.h" |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 15 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 16 | #include "content/public/test/mock_render_process_host.h" |
| 17 | #include "content/public/test/test_browser_context.h" |
| 18 | #include "content/public/test/test_browser_thread_bundle.h" |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 19 | #include "content/test/test_render_frame_host.h" |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 20 | #include "content/test/test_render_view_host.h" |
| 21 | #include "content/test/test_web_contents.h" |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 22 | #include "testing/gtest/include/gtest/gtest.h" |
| 23 | |
| 24 | namespace content { |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 25 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 26 | namespace { |
| 27 | |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 28 | // Appends a description of the structure of the frame tree to |result|. |
| 29 | void AppendTreeNodeState(FrameTreeNode* node, std::string* result) { |
| 30 | result->append( |
| 31 | base::Int64ToString(node->current_frame_host()->GetRoutingID())); |
schenney | 6408fed2 | 2015-04-17 17:44:57 | [diff] [blame] | 32 | if (!node->current_frame_host()->IsRenderFrameLive()) |
| 33 | result->append("*"); // Asterisk next to dead frames. |
| 34 | |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 35 | if (!node->frame_name().empty()) { |
| 36 | result->append(" '"); |
| 37 | result->append(node->frame_name()); |
| 38 | result->append("'"); |
| 39 | } |
| 40 | result->append(": ["); |
| 41 | const char* separator = ""; |
| 42 | for (size_t i = 0; i < node->child_count(); i++) { |
| 43 | result->append(separator); |
| 44 | AppendTreeNodeState(node->child_at(i), result); |
| 45 | separator = ", "; |
| 46 | } |
| 47 | result->append("]"); |
| 48 | } |
| 49 | |
| 50 | // Logs calls to WebContentsObserver along with the state of the frame tree, |
| 51 | // for later use in EXPECT_EQ(). |
| 52 | class TreeWalkingWebContentsLogger : public WebContentsObserver { |
| 53 | public: |
| 54 | explicit TreeWalkingWebContentsLogger(WebContents* web_contents) |
| 55 | : WebContentsObserver(web_contents) {} |
| 56 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 57 | ~TreeWalkingWebContentsLogger() override { |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 58 | EXPECT_EQ("", log_) << "Activity logged that was not expected"; |
| 59 | } |
| 60 | |
| 61 | // Gets and resets the log, which is a string of what happened. |
| 62 | std::string GetLog() { |
| 63 | std::string result = log_; |
| 64 | log_.clear(); |
| 65 | return result; |
| 66 | } |
| 67 | |
| 68 | // content::WebContentsObserver implementation. |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 69 | void RenderFrameCreated(RenderFrameHost* render_frame_host) override { |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 70 | LogWhatHappened("RenderFrameCreated", render_frame_host); |
| 71 | } |
| 72 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 73 | void RenderFrameHostChanged(RenderFrameHost* old_host, |
| 74 | RenderFrameHost* new_host) override { |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 75 | if (old_host) |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 76 | LogWhatHappened("RenderFrameHostChanged(old)", old_host); |
| 77 | LogWhatHappened("RenderFrameHostChanged(new)", new_host); |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 78 | } |
| 79 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 80 | void RenderFrameDeleted(RenderFrameHost* render_frame_host) override { |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 81 | LogWhatHappened("RenderFrameDeleted", render_frame_host); |
| 82 | } |
| 83 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 84 | void RenderProcessGone(base::TerminationStatus status) override { |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 85 | LogWhatHappened("RenderProcessGone"); |
| 86 | } |
| 87 | |
| 88 | private: |
| 89 | void LogWhatHappened(const std::string& event_name) { |
| 90 | if (!log_.empty()) { |
| 91 | log_.append("\n"); |
| 92 | } |
| 93 | log_.append(event_name + " -> "); |
| 94 | AppendTreeNodeState( |
| 95 | static_cast<WebContentsImpl*>(web_contents())->GetFrameTree()->root(), |
| 96 | &log_); |
| 97 | } |
| 98 | |
| 99 | void LogWhatHappened(const std::string& event_name, RenderFrameHost* rfh) { |
| 100 | LogWhatHappened( |
| 101 | base::StringPrintf("%s(%d)", event_name.c_str(), rfh->GetRoutingID())); |
| 102 | } |
| 103 | |
| 104 | std::string log_; |
| 105 | |
| 106 | DISALLOW_COPY_AND_ASSIGN(TreeWalkingWebContentsLogger); |
| 107 | }; |
| 108 | |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 109 | } // namespace |
| 110 | |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 111 | class FrameTreeTest : public RenderViewHostImplTestHarness { |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 112 | protected: |
| 113 | // Prints a FrameTree, for easy assertions of the tree hierarchy. |
| 114 | std::string GetTreeState(FrameTree* frame_tree) { |
| 115 | std::string result; |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 116 | AppendTreeNodeState(frame_tree->root(), &result); |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 117 | return result; |
| 118 | } |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 119 | }; |
| 120 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 121 | // Exercise tree manipulation routines. |
| 122 | // - Add a series of nodes and verify tree structure. |
| 123 | // - Remove a series of nodes and verify tree structure. |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 124 | // |
| 125 | // TODO(nick): http://crbug.com/444722 Disabled temporarily because of a bad |
| 126 | // interaction with the WebContentsObserverConsistencyChecker -- calling |
| 127 | // AddFrame directly causes the RFH to not be announced. We either need to |
| 128 | // rewrite this test, or be consistent in the layer at which we announce render |
| 129 | // frame creation. |
| 130 | TEST_F(FrameTreeTest, DISABLED_Shape) { |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 131 | // Use the FrameTree of the WebContents so that it has all the delegates it |
| 132 | // needs. We may want to consider a test version of this. |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 133 | FrameTree* frame_tree = contents()->GetFrameTree(); |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 134 | FrameTreeNode* root = frame_tree->root(); |
[email protected] | 190b8c5 | 2013-11-09 01:35:44 | [diff] [blame] | 135 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 136 | std::string no_children_node("no children node"); |
| 137 | std::string deep_subtree("node with deep subtree"); |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 138 | int process_id = root->current_frame_host()->GetProcess()->GetID(); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 139 | |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 140 | ASSERT_EQ("1: []", GetTreeState(frame_tree)); |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 141 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 142 | // Simulate attaching a series of frames to build the frame tree. |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 143 | frame_tree->AddFrame(root, process_id, 14, std::string()); |
| 144 | frame_tree->AddFrame(root, process_id, 15, std::string()); |
| 145 | frame_tree->AddFrame(root, process_id, 16, std::string()); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 146 | |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 147 | frame_tree->AddFrame(root->child_at(0), process_id, 244, std::string()); |
| 148 | frame_tree->AddFrame(root->child_at(1), process_id, 255, no_children_node); |
| 149 | frame_tree->AddFrame(root->child_at(0), process_id, 245, std::string()); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 150 | |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 151 | ASSERT_EQ("1: [14: [244: [], 245: []], " |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 152 | "15: [255 'no children node': []], " |
| 153 | "16: []]", |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 154 | GetTreeState(frame_tree)); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 155 | |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 156 | FrameTreeNode* child_16 = root->child_at(2); |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 157 | frame_tree->AddFrame(child_16, process_id, 264, std::string()); |
| 158 | frame_tree->AddFrame(child_16, process_id, 265, std::string()); |
| 159 | frame_tree->AddFrame(child_16, process_id, 266, std::string()); |
| 160 | frame_tree->AddFrame(child_16, process_id, 267, deep_subtree); |
| 161 | frame_tree->AddFrame(child_16, process_id, 268, std::string()); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 162 | |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 163 | FrameTreeNode* child_267 = child_16->child_at(3); |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 164 | frame_tree->AddFrame(child_267, process_id, 365, std::string()); |
| 165 | frame_tree->AddFrame(child_267->child_at(0), process_id, 455, std::string()); |
| 166 | frame_tree->AddFrame(child_267->child_at(0)->child_at(0), process_id, 555, |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 167 | std::string()); |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 168 | frame_tree->AddFrame(child_267->child_at(0)->child_at(0)->child_at(0), |
| 169 | process_id, 655, std::string()); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 170 | |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 171 | // Now that's it's fully built, verify the tree structure is as expected. |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 172 | ASSERT_EQ("1: [14: [244: [], 245: []], " |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 173 | "15: [255 'no children node': []], " |
| 174 | "16: [264: [], 265: [], 266: [], " |
| 175 | "267 'node with deep subtree': " |
| 176 | "[365: [455: [555: [655: []]]]], 268: []]]", |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 177 | GetTreeState(frame_tree)); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 178 | |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 179 | FrameTreeNode* child_555 = child_267->child_at(0)->child_at(0)->child_at(0); |
| 180 | frame_tree->RemoveFrame(child_555); |
| 181 | ASSERT_EQ("1: [14: [244: [], 245: []], " |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 182 | "15: [255 'no children node': []], " |
| 183 | "16: [264: [], 265: [], 266: [], " |
| 184 | "267 'node with deep subtree': " |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 185 | "[365: [455: []]], 268: []]]", |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 186 | GetTreeState(frame_tree)); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 187 | |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 188 | frame_tree->RemoveFrame(child_16->child_at(1)); |
| 189 | ASSERT_EQ("1: [14: [244: [], 245: []], " |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 190 | "15: [255 'no children node': []], " |
| 191 | "16: [264: [], 266: [], " |
| 192 | "267 'node with deep subtree': " |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 193 | "[365: [455: []]], 268: []]]", |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 194 | GetTreeState(frame_tree)); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 195 | |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 196 | frame_tree->RemoveFrame(root->child_at(1)); |
| 197 | ASSERT_EQ("1: [14: [244: [], 245: []], " |
[email protected] | 7cc7ebd | 2013-10-08 00:59:00 | [diff] [blame] | 198 | "16: [264: [], 266: [], " |
| 199 | "267 'node with deep subtree': " |
[email protected] | 58faf94 | 2014-02-20 21:03:58 | [diff] [blame] | 200 | "[365: [455: []]], 268: []]]", |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 201 | GetTreeState(frame_tree)); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 202 | } |
| 203 | |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 204 | // Do some simple manipulations of the frame tree, making sure that |
| 205 | // WebContentsObservers see a consistent view of the tree as we go. |
| 206 | TEST_F(FrameTreeTest, ObserverWalksTreeDuringFrameCreation) { |
| 207 | TreeWalkingWebContentsLogger activity(contents()); |
schenney | 6408fed2 | 2015-04-17 17:44:57 | [diff] [blame] | 208 | contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 209 | EXPECT_EQ("", activity.GetLog()); |
| 210 | |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 211 | FrameTree* frame_tree = contents()->GetFrameTree(); |
| 212 | FrameTreeNode* root = frame_tree->root(); |
| 213 | |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 214 | // Simulate attaching a series of frames to build the frame tree. |
alexmos | e48b1df93 | 2015-01-16 01:34:17 | [diff] [blame] | 215 | main_test_rfh()->OnCreateChildFrame(14, std::string(), SandboxFlags::NONE); |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 216 | EXPECT_EQ( |
| 217 | "RenderFrameHostChanged(new)(14) -> 1: []\n" |
| 218 | "RenderFrameCreated(14) -> 1: [14: []]", |
| 219 | activity.GetLog()); |
alexmos | e48b1df93 | 2015-01-16 01:34:17 | [diff] [blame] | 220 | main_test_rfh()->OnCreateChildFrame(18, std::string(), SandboxFlags::NONE); |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 221 | EXPECT_EQ( |
| 222 | "RenderFrameHostChanged(new)(18) -> 1: [14: []]\n" |
| 223 | "RenderFrameCreated(18) -> 1: [14: [], 18: []]", |
| 224 | activity.GetLog()); |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 225 | frame_tree->RemoveFrame(root->child_at(0)); |
| 226 | EXPECT_EQ("RenderFrameDeleted(14) -> 1: [18: []]", activity.GetLog()); |
| 227 | frame_tree->RemoveFrame(root->child_at(0)); |
| 228 | EXPECT_EQ("RenderFrameDeleted(18) -> 1: []", activity.GetLog()); |
| 229 | } |
| 230 | |
| 231 | // Make sure that WebContentsObservers see a consistent view of the tree after |
| 232 | // recovery from a render process crash. |
| 233 | TEST_F(FrameTreeTest, ObserverWalksTreeAfterCrash) { |
| 234 | TreeWalkingWebContentsLogger activity(contents()); |
schenney | 6408fed2 | 2015-04-17 17:44:57 | [diff] [blame] | 235 | contents()->NavigateAndCommit(GURL("http://www.google.com")); |
| 236 | EXPECT_EQ("", activity.GetLog()); |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 237 | |
alexmos | e48b1df93 | 2015-01-16 01:34:17 | [diff] [blame] | 238 | main_test_rfh()->OnCreateChildFrame(22, std::string(), SandboxFlags::NONE); |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 239 | EXPECT_EQ( |
| 240 | "RenderFrameHostChanged(new)(22) -> 1: []\n" |
| 241 | "RenderFrameCreated(22) -> 1: [22: []]", |
| 242 | activity.GetLog()); |
alexmos | e48b1df93 | 2015-01-16 01:34:17 | [diff] [blame] | 243 | main_test_rfh()->OnCreateChildFrame(23, std::string(), SandboxFlags::NONE); |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 244 | EXPECT_EQ( |
| 245 | "RenderFrameHostChanged(new)(23) -> 1: [22: []]\n" |
| 246 | "RenderFrameCreated(23) -> 1: [22: [], 23: []]", |
| 247 | activity.GetLog()); |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 248 | |
| 249 | // Crash the renderer |
nick | 16b0765 | 2015-04-18 02:35:31 | [diff] [blame^] | 250 | main_test_rfh()->GetProcess()->SimulateCrash(); |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 251 | EXPECT_EQ( |
nick | 16b0765 | 2015-04-18 02:35:31 | [diff] [blame^] | 252 | "RenderFrameDeleted(23) -> 1: [22: [], 23*: []]\n" |
| 253 | "RenderFrameDeleted(22) -> 1: [22*: [], 23*: []]\n" |
| 254 | "RenderFrameDeleted(1) -> 1: []\n" // TODO(nick): Should be "1*:" |
| 255 | "RenderProcessGone -> 1*: []", |
[email protected] | 1426607 | 2014-04-19 00:35:20 | [diff] [blame] | 256 | activity.GetLog()); |
| 257 | } |
| 258 | |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 259 | // Ensure that frames are not added to the tree, if the process passed in |
| 260 | // is different than the process of the parent node. |
| 261 | TEST_F(FrameTreeTest, FailAddFrameWithWrongProcessId) { |
schenney | 6408fed2 | 2015-04-17 17:44:57 | [diff] [blame] | 262 | contents()->NavigateAndCommit(GURL("http://www.google.com")); |
dgrogan | fb22f9a | 2014-10-20 21:32:32 | [diff] [blame] | 263 | FrameTree* frame_tree = contents()->GetFrameTree(); |
| 264 | FrameTreeNode* root = frame_tree->root(); |
| 265 | int process_id = root->current_frame_host()->GetProcess()->GetID(); |
| 266 | |
| 267 | ASSERT_EQ("1: []", GetTreeState(frame_tree)); |
| 268 | |
| 269 | // Simulate attaching a frame from mismatched process id. |
| 270 | ASSERT_FALSE(frame_tree->AddFrame(root, process_id + 1, 1, std::string())); |
| 271 | ASSERT_EQ("1: []", GetTreeState(frame_tree)); |
| 272 | } |
| 273 | |
nasko | aeca57b | 2015-02-13 00:50:46 | [diff] [blame] | 274 | // Ensure that frames removed while a process has crashed are not preserved in |
| 275 | // the global map of id->frame. |
| 276 | TEST_F(FrameTreeTest, ProcessCrashClearsGlobalMap) { |
| 277 | // Add a couple child frames to the main frame. |
| 278 | FrameTreeNode* root = contents()->GetFrameTree()->root(); |
| 279 | |
| 280 | main_test_rfh()->OnCreateChildFrame(22, std::string(), SandboxFlags::NONE); |
| 281 | main_test_rfh()->OnCreateChildFrame(23, std::string(), SandboxFlags::NONE); |
| 282 | |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 283 | // Add one grandchild frame. |
| 284 | RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host(); |
| 285 | child1_rfh->OnCreateChildFrame(33, std::string(), SandboxFlags::NONE); |
| 286 | |
nasko | aeca57b | 2015-02-13 00:50:46 | [diff] [blame] | 287 | // Ensure they can be found by id. |
| 288 | int64 id1 = root->child_at(0)->frame_tree_node_id(); |
| 289 | int64 id2 = root->child_at(1)->frame_tree_node_id(); |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 290 | int64 id3 = root->child_at(0)->child_at(0)->frame_tree_node_id(); |
| 291 | EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id1)); |
| 292 | EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id2)); |
| 293 | EXPECT_TRUE(FrameTreeNode::GloballyFindByID(id3)); |
nasko | aeca57b | 2015-02-13 00:50:46 | [diff] [blame] | 294 | |
| 295 | // Crash the renderer. |
nick | 16b0765 | 2015-04-18 02:35:31 | [diff] [blame^] | 296 | main_test_rfh()->GetProcess()->SimulateCrash(); |
nasko | aeca57b | 2015-02-13 00:50:46 | [diff] [blame] | 297 | |
| 298 | // Ensure they cannot be found by id after the process has crashed. |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 299 | EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id1)); |
| 300 | EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id2)); |
| 301 | EXPECT_FALSE(FrameTreeNode::GloballyFindByID(id3)); |
nasko | aeca57b | 2015-02-13 00:50:46 | [diff] [blame] | 302 | } |
| 303 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 304 | } // namespace content |