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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 196133032: Add test for filtering of IPC messages when RenderFrameHost is swapped out. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file_path.h"
5 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
6 #include "content/browser/frame_host/cross_site_transferring_request.h" 7 #include "content/browser/frame_host/cross_site_transferring_request.h"
7 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
8 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
9 #include "content/browser/frame_host/navigator.h" 10 #include "content/browser/frame_host/navigator.h"
10 #include "content/browser/frame_host/render_frame_host_manager.h" 11 #include "content/browser/frame_host/render_frame_host_manager.h"
11 #include "content/browser/site_instance_impl.h" 12 #include "content/browser/site_instance_impl.h"
12 #include "content/browser/webui/web_ui_controller_factory_registry.h" 13 #include "content/browser/webui/web_ui_controller_factory_registry.h"
13 #include "content/common/frame_messages.h" 14 #include "content/common/frame_messages.h"
14 #include "content/common/view_messages.h" 15 #include "content/common/view_messages.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 dest_rvh2->OnSwappedOut(false); 242 dest_rvh2->OnSwappedOut(false);
242 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()-> 243 static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()->
243 pending_render_view_host())->SendNavigate(102, kChromeUrl); 244 pending_render_view_host())->SendNavigate(102, kChromeUrl);
244 245
245 EXPECT_NE(active_rvh()->GetSiteInstance(), 246 EXPECT_NE(active_rvh()->GetSiteInstance(),
246 contents2->GetRenderViewHost()->GetSiteInstance()); 247 contents2->GetRenderViewHost()->GetSiteInstance());
247 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), 248 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(),
248 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); 249 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess());
249 } 250 }
250 251
252 // This observer is used to check whether IPC messages are being filtered for
253 // swapped out RenderFrameHost objects. It observes the plugin crash events,
254 // which the test which follows it simulates being sent. The test is succsesful
Charlie Reis 2014/03/19 20:40:57 nit: which the FilterMessagesWhileSwappedOut test
nasko 2014/03/21 20:32:56 Done.
255 // if the event is not observed. See http://crbug.com/351815
256 class PluginCrashObserver : public WebContentsObserver {
257 public:
258 PluginCrashObserver(WebContents* web_contents)
259 : WebContentsObserver(web_contents),
260 event_triggered_(false) {}
261
262 virtual void PluginCrashed(const base::FilePath& plugin_path,
263 base::ProcessId plugin_pid) OVERRIDE {
264 event_triggered_ = true;
265 }
266
267 bool event_triggered() {
268 return event_triggered_;
269 }
270
271 private:
272 bool event_triggered_;
273
274 DISALLOW_COPY_AND_ASSIGN(PluginCrashObserver);
275 };
276
251 // Ensure that the browser ignores most IPC messages that arrive from a 277 // Ensure that the browser ignores most IPC messages that arrive from a
252 // RenderViewHost that has been swapped out. We do not want to take 278 // RenderViewHost that has been swapped out. We do not want to take
253 // action on requests from a non-active renderer. The main exception is 279 // action on requests from a non-active renderer. The main exception is
254 // for synchronous messages, which cannot be ignored without leaving the 280 // for synchronous messages, which cannot be ignored without leaving the
255 // renderer in a stuck state. See http://crbug.com/93427. 281 // renderer in a stuck state. See http://crbug.com/93427.
256 TEST_F(RenderFrameHostManagerTest, FilterMessagesWhileSwappedOut) { 282 TEST_F(RenderFrameHostManagerTest, FilterMessagesWhileSwappedOut) {
257 const GURL kChromeURL("chrome://foo"); 283 const GURL kChromeURL("chrome://foo");
258 const GURL kDestUrl("http://www.google.com/"); 284 const GURL kDestUrl("http://www.google.com/");
259 285
260 // Navigate our first tab to a chrome url and then to the destination. 286 // Navigate our first tab to a chrome url and then to the destination.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 direction))); 323 direction)));
298 EXPECT_EQ(dest_title, contents()->GetTitle()); 324 EXPECT_EQ(dest_title, contents()->GetTitle());
299 325
300 // The old renderer, being slow, now updates the title. It should be filtered 326 // The old renderer, being slow, now updates the title. It should be filtered
301 // out and not take effect. 327 // out and not take effect.
302 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, ntp_rvh->rvh_state()); 328 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, ntp_rvh->rvh_state());
303 EXPECT_TRUE(ntp_rvh->OnMessageReceived( 329 EXPECT_TRUE(ntp_rvh->OnMessageReceived(
304 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 0, ntp_title, direction))); 330 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 0, ntp_title, direction)));
305 EXPECT_EQ(dest_title, contents()->GetTitle()); 331 EXPECT_EQ(dest_title, contents()->GetTitle());
306 332
333 // The same logic should apply to RenderFrameHosts as well and routing through
334 // swapped out RFH shouldn't be allowed. Use a PluginCrashObserver to check
335 // if the IPC message is allowed through or not.
336 PluginCrashObserver crash_observer(contents());
337 // TODO(nasko): The following line shouldn't be needed when we are properly
338 // swapping out RFH objects or move to proxy objects.
339 ntp_rvh->main_render_frame_host()->set_swapped_out(true);
Charlie Reis 2014/03/19 20:40:57 Is this line actually needed? You're checking for
nasko 2014/03/21 20:32:56 Quite a bit has changed, so this is no longer appl
340 EXPECT_TRUE(ntp_rvh->main_render_frame_host()->is_swapped_out());
341 EXPECT_TRUE(ntp_rvh->main_render_frame_host()->OnMessageReceived(
342 FrameHostMsg_PluginCrashed(
343 main_rfh()->GetRoutingID(), base::FilePath(), 0)));
344 EXPECT_FALSE(crash_observer.event_triggered());
345
307 // We cannot filter out synchronous IPC messages, because the renderer would 346 // We cannot filter out synchronous IPC messages, because the renderer would
308 // be left waiting for a reply. We pick RunBeforeUnloadConfirm as an example 347 // be left waiting for a reply. We pick RunBeforeUnloadConfirm as an example
309 // that can run easily within a unit test, and that needs to receive a reply 348 // that can run easily within a unit test, and that needs to receive a reply
310 // without showing an actual dialog. 349 // without showing an actual dialog.
311 MockRenderProcessHost* ntp_process_host = 350 MockRenderProcessHost* ntp_process_host =
312 static_cast<MockRenderProcessHost*>(ntp_rvh->GetProcess()); 351 static_cast<MockRenderProcessHost*>(ntp_rvh->GetProcess());
313 ntp_process_host->sink().ClearMessages(); 352 ntp_process_host->sink().ClearMessages();
314 const base::string16 msg = base::ASCIIToUTF16("Message"); 353 const base::string16 msg = base::ASCIIToUTF16("Message");
315 bool result = false; 354 bool result = false;
316 base::string16 unused; 355 base::string16 unused;
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 1612
1574 // Simulate the swap out ack. 1613 // Simulate the swap out ack.
1575 rvh1->OnSwappedOut(false); 1614 rvh1->OnSwappedOut(false);
1576 1615
1577 // rvh1 should be swapped out. 1616 // rvh1 should be swapped out.
1578 EXPECT_FALSE(destruction_observer.rvh_deleted()); 1617 EXPECT_FALSE(destruction_observer.rvh_deleted());
1579 EXPECT_TRUE(rvh1->IsSwappedOut()); 1618 EXPECT_TRUE(rvh1->IsSwappedOut());
1580 } 1619 }
1581 1620
1582 } // namespace content 1621 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698