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

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

Issue 2932453002: PlzNavigate: Release StreamHandle. (Closed)
Patch Set: Add real urls in tests ( rebase...) Created 3 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/frame_host/render_frame_host_impl.h" 5 #include "content/browser/frame_host/render_frame_host_impl.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "content/browser/web_contents/web_contents_impl.h" 8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/common/frame_messages.h" 9 #include "content/common/frame_messages.h"
10 #include "content/public/browser/javascript_dialog_manager.h" 10 #include "content/public/browser/javascript_dialog_manager.h"
11 #include "content/public/browser/render_frame_host.h" 11 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/browser_side_navigation_policy.h"
13 #include "content/public/common/content_client.h" 14 #include "content/public/common/content_client.h"
14 #include "content/public/test/browser_test_utils.h" 15 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/content_browser_test.h" 16 #include "content/public/test/content_browser_test.h"
16 #include "content/public/test/content_browser_test_utils.h" 17 #include "content/public/test/content_browser_test_utils.h"
17 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
18 #include "content/shell/browser/shell.h" 19 #include "content/shell/browser/shell.h"
19 #include "content/test/test_content_browser_client.h" 20 #include "content/test/test_content_browser_client.h"
21 #include "net/dns/mock_host_resolver.h"
22 #include "net/test/embedded_test_server/embedded_test_server.h"
20 23
21 namespace content { 24 namespace content {
22 25
23 namespace { 26 namespace {
24 27
25 // Implementation of ContentBrowserClient that overrides 28 // Implementation of ContentBrowserClient that overrides
26 // OverridePageVisibilityState() and allows consumers to set a value. 29 // OverridePageVisibilityState() and allows consumers to set a value.
27 class PrerenderTestContentBrowserClient : public TestContentBrowserClient { 30 class PrerenderTestContentBrowserClient : public TestContentBrowserClient {
28 public: 31 public:
29 PrerenderTestContentBrowserClient() 32 PrerenderTestContentBrowserClient()
(...skipping 20 matching lines...) Expand all
50 53
51 DISALLOW_COPY_AND_ASSIGN(PrerenderTestContentBrowserClient); 54 DISALLOW_COPY_AND_ASSIGN(PrerenderTestContentBrowserClient);
52 }; 55 };
53 56
54 } // anonymous namespace 57 } // anonymous namespace
55 58
56 // TODO(mlamouri): part of these tests were removed because they were dependent 59 // TODO(mlamouri): part of these tests were removed because they were dependent
57 // on an environment were focus is guaranteed. This is only for 60 // on an environment were focus is guaranteed. This is only for
58 // interactive_ui_tests so these bits need to move there. 61 // interactive_ui_tests so these bits need to move there.
59 // See https://crbug.com/491535 62 // See https://crbug.com/491535
60 using RenderFrameHostImplBrowserTest = ContentBrowserTest; 63 class RenderFrameHostImplBrowserTest : public ContentBrowserTest {
64 protected:
65 void SetUpOnMainThread() override {
66 host_resolver()->AddRule("*", "127.0.0.1");
67 SetupCrossSiteRedirector(embedded_test_server());
68 ASSERT_TRUE(embedded_test_server()->Start());
69 }
70 };
61 71
62 // Test that when creating a new window, the main frame is correctly focused. 72 // Test that when creating a new window, the main frame is correctly focused.
63 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, 73 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
64 IsFocused_AtLoad) { 74 IsFocused_AtLoad) {
65 EXPECT_TRUE( 75 EXPECT_TRUE(
66 NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html"))); 76 NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
67 77
68 // The main frame should be focused. 78 // The main frame should be focused.
69 WebContents* web_contents = shell()->web_contents(); 79 WebContents* web_contents = shell()->web_contents();
70 EXPECT_EQ(web_contents->GetMainFrame(), web_contents->GetFocusedFrame()); 80 EXPECT_EQ(web_contents->GetMainFrame(), web_contents->GetFocusedFrame());
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 RenderFrameDeletedObserver deleted_observer( 356 RenderFrameDeletedObserver deleted_observer(
347 new_shell->web_contents()->GetMainFrame()); 357 new_shell->web_contents()->GetMainFrame());
348 deleted_observer.WaitUntilDeleted(); 358 deleted_observer.WaitUntilDeleted();
349 359
350 bool is_closed = false; 360 bool is_closed = false;
351 EXPECT_TRUE(ExecuteScriptAndExtractBool( 361 EXPECT_TRUE(ExecuteScriptAndExtractBool(
352 shell(), "domAutomationController.send(popup.closed)", &is_closed)); 362 shell(), "domAutomationController.send(popup.closed)", &is_closed));
353 EXPECT_TRUE(is_closed); 363 EXPECT_TRUE(is_closed);
354 } 364 }
355 365
366 // After a navigation, the StreamHandle must be released.
367 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, StreamHandleReleased) {
368 EXPECT_TRUE(NavigateToURL(shell(), GetTestUrl("", "title1.html")));
369 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
370 RenderFrameHostImpl* main_frame =
371 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
372 EXPECT_EQ(nullptr, main_frame->stream_handle_for_testing());
373 }
374
375 namespace {
376 class DropStreamHandleConsumedFilter : public BrowserMessageFilter {
377 public:
378 DropStreamHandleConsumedFilter() : BrowserMessageFilter(FrameMsgStart) {}
379
380 protected:
381 ~DropStreamHandleConsumedFilter() override {}
382
383 private:
384 // BrowserMessageFilter:
385 bool OnMessageReceived(const IPC::Message& message) override {
386 return message.type() == FrameHostMsg_StreamHandleConsumed::ID;
387 }
388
389 DISALLOW_COPY_AND_ASSIGN(DropStreamHandleConsumedFilter);
390 };
391 } // namespace
392
393 // After a renderer crash, the StreamHandle must be released.
394 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest,
395 StreamHandleReleasedOnRendererCrash) {
396 // |stream_handle_| is only used with PlzNavigate.
397 if (!IsBrowserSideNavigationEnabled())
398 return;
399
400 GURL url_1(embedded_test_server()->GetURL("a.com", "/title1.html"));
401 GURL url_2(embedded_test_server()->GetURL("a.com", "/title2.html"));
402
403 EXPECT_TRUE(NavigateToURL(shell(), url_1));
404
405 // Set up a filter to make sure that the browser is not notified that its
406 // |stream_handle_| has been consumed.
407 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
408 RenderFrameHostImpl* main_frame =
409 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame());
410 scoped_refptr<DropStreamHandleConsumedFilter> filter =
411 new DropStreamHandleConsumedFilter();
412 main_frame->GetProcess()->AddFilter(filter.get());
413
414 EXPECT_TRUE(NavigateToURL(shell(), url_2));
415
416 // Check that the |stream_handle_| hasn't been released yet.
417 EXPECT_NE(nullptr, main_frame->stream_handle_for_testing());
418
419 // Make the renderer crash.
420 RenderProcessHost* renderer_process = main_frame->GetProcess();
421 RenderProcessHostWatcher crash_observer(
422 renderer_process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
423 renderer_process->Shutdown(0, false);
424 crash_observer.Wait();
425
426 // The |stream_handle_| must have been released now.
427 EXPECT_EQ(nullptr, main_frame->stream_handle_for_testing());
428 }
429
356 } // namespace content 430 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | content/child/web_url_loader_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698