OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" | 32 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" |
33 #include "content/browser/renderer_host/render_view_host_impl.h" | 33 #include "content/browser/renderer_host/render_view_host_impl.h" |
34 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 34 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
35 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 35 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
36 #include "content/browser/web_contents/web_contents_impl.h" | 36 #include "content/browser/web_contents/web_contents_impl.h" |
37 #include "content/common/child_process_messages.h" | 37 #include "content/common/child_process_messages.h" |
38 #include "content/common/frame_messages.h" | 38 #include "content/common/frame_messages.h" |
39 #include "content/common/input/synthetic_tap_gesture_params.h" | 39 #include "content/common/input/synthetic_tap_gesture_params.h" |
40 #include "content/common/input_messages.h" | 40 #include "content/common/input_messages.h" |
41 #include "content/common/view_messages.h" | 41 #include "content/common/view_messages.h" |
42 #include "content/public/browser/cert_store.h" | |
43 #include "content/public/browser/interstitial_page_delegate.h" | 42 #include "content/public/browser/interstitial_page_delegate.h" |
44 #include "content/public/browser/notification_observer.h" | 43 #include "content/public/browser/notification_observer.h" |
45 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
46 #include "content/public/browser/notification_types.h" | 45 #include "content/public/browser/notification_types.h" |
47 #include "content/public/browser/resource_dispatcher_host.h" | 46 #include "content/public/browser/resource_dispatcher_host.h" |
48 #include "content/public/common/browser_side_navigation_policy.h" | 47 #include "content/public/common/browser_side_navigation_policy.h" |
49 #include "content/public/common/content_switches.h" | 48 #include "content/public/common/content_switches.h" |
50 #include "content/public/common/url_constants.h" | 49 #include "content/public/common/url_constants.h" |
51 #include "content/public/test/browser_test_utils.h" | 50 #include "content/public/test/browser_test_utils.h" |
52 #include "content/public/test/content_browser_test_utils.h" | 51 #include "content/public/test/content_browser_test_utils.h" |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 bool expected_visibility_state_; | 519 bool expected_visibility_state_; |
521 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 520 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
522 NotificationRegistrar registrar_; | 521 NotificationRegistrar registrar_; |
523 bool was_observed_; | 522 bool was_observed_; |
524 bool did_fail_; | 523 bool did_fail_; |
525 Source<RenderWidgetHost> source_; | 524 Source<RenderWidgetHost> source_; |
526 | 525 |
527 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostVisibilityObserver); | 526 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostVisibilityObserver); |
528 }; | 527 }; |
529 | 528 |
530 // A mock CertStore that always assigns the render process host id as | |
531 // the certificate id. Certificates are never removed. | |
532 class MockCertStore : public CertStore { | |
533 public: | |
534 MockCertStore() {} | |
535 ~MockCertStore() override {} | |
536 | |
537 int StoreCert(net::X509Certificate* cert, | |
538 int render_process_host_id) override { | |
539 certs_[render_process_host_id] = cert; | |
540 return render_process_host_id; | |
541 } | |
542 | |
543 bool RetrieveCert(int cert_id, | |
544 scoped_refptr<net::X509Certificate>* cert) override { | |
545 if (certs_.find(cert_id) == certs_.end()) | |
546 return false; | |
547 *cert = certs_[cert_id]; | |
548 return true; | |
549 } | |
550 | |
551 private: | |
552 std::map<int, scoped_refptr<net::X509Certificate>> certs_; | |
553 | |
554 DISALLOW_COPY_AND_ASSIGN(MockCertStore); | |
555 }; | |
556 | |
557 class TestInterstitialDelegate : public InterstitialPageDelegate { | 529 class TestInterstitialDelegate : public InterstitialPageDelegate { |
558 private: | 530 private: |
559 // InterstitialPageDelegate: | 531 // InterstitialPageDelegate: |
560 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; } | 532 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; } |
561 }; | 533 }; |
562 | 534 |
563 } // namespace | 535 } // namespace |
564 | 536 |
565 // | 537 // |
566 // SitePerProcessBrowserTest | 538 // SitePerProcessBrowserTest |
(...skipping 6212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6779 int child_value = 2; | 6751 int child_value = 2; |
6780 EXPECT_TRUE(ExecuteScriptAndExtractInt(root, script.c_str(), &root_value)); | 6752 EXPECT_TRUE(ExecuteScriptAndExtractInt(root, script.c_str(), &root_value)); |
6781 | 6753 |
6782 EXPECT_TRUE( | 6754 EXPECT_TRUE( |
6783 ExecuteScriptAndExtractInt(child, script.c_str(), &child_value)); | 6755 ExecuteScriptAndExtractInt(child, script.c_str(), &child_value)); |
6784 | 6756 |
6785 EXPECT_EQ(root_value, child_value); | 6757 EXPECT_EQ(root_value, child_value); |
6786 } | 6758 } |
6787 } | 6759 } |
6788 | 6760 |
6789 // Tests that the certificate store is updated during a cross-site | |
6790 // redirect navigation. (See https://crbug.com/561754.) Ignores | |
6791 // certificate errors so that it can use the cross-site redirector to | |
6792 // redirect from HTTPS to HTTPS. | |
6793 IN_PROC_BROWSER_TEST_F(SitePerProcessIgnoreCertErrorsBrowserTest, | |
6794 CrossSiteRedirectCertificateStore) { | |
6795 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | |
6796 https_server.ServeFilesFromSourceDirectory("content/test/data"); | |
6797 ASSERT_TRUE(https_server.Start()); | |
6798 SetupCrossSiteRedirector(&https_server); | |
6799 | |
6800 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | |
6801 ASSERT_TRUE(rdh); | |
6802 MockCertStore mock_cert_store; | |
6803 rdh->cert_store_for_testing_ = &mock_cert_store; | |
6804 | |
6805 // First, navigate to an |https_server| URL to ensure that the site | |
6806 // instance is assigned a site. This will force a renderer transfer to | |
6807 // happen on the following navigation that redirects to a different | |
6808 // site. | |
6809 GURL url(https_server.GetURL("/title1.html")); | |
6810 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
6811 int original_process_id = | |
6812 shell()->web_contents()->GetRenderProcessHost()->GetID(); | |
6813 | |
6814 url = https_server.GetURL("/cross-site/a.test/title1.html"); | |
6815 // NavigateToURL() returns false because the committed URL doesn't | |
6816 // match |url| (because it redirected). | |
6817 EXPECT_FALSE(NavigateToURL(shell(), url)); | |
6818 EXPECT_TRUE(IsLastCommittedEntryOfPageType(shell()->web_contents(), | |
6819 PAGE_TYPE_NORMAL)); | |
6820 int new_process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); | |
6821 | |
6822 // Test that the mock certificate store saw the certificate associated with | |
6823 // the new renderer process. | |
6824 EXPECT_NE(original_process_id, new_process_id); | |
6825 scoped_refptr<net::X509Certificate> original_cert; | |
6826 scoped_refptr<net::X509Certificate> transfer_cert; | |
6827 ASSERT_TRUE( | |
6828 mock_cert_store.RetrieveCert(original_process_id, &original_cert)); | |
6829 ASSERT_TRUE(mock_cert_store.RetrieveCert(new_process_id, &transfer_cert)); | |
6830 EXPECT_TRUE(https_server.GetCertificate()->Equals(original_cert.get())); | |
6831 EXPECT_TRUE(https_server.GetCertificate()->Equals(transfer_cert.get())); | |
6832 // Test that the final cert id stored in the navigation entry is the | |
6833 // cert id corresponding to the second renderer process. | |
6834 EXPECT_EQ(new_process_id, shell() | |
6835 ->web_contents() | |
6836 ->GetController() | |
6837 .GetVisibleEntry() | |
6838 ->GetSSL() | |
6839 .cert_id); | |
6840 } | |
6841 | |
6842 // Tests that the swapped out state on RenderViewHost is properly reset when | 6761 // Tests that the swapped out state on RenderViewHost is properly reset when |
6843 // the main frame is navigated to the same SiteInstance as one of its child | 6762 // the main frame is navigated to the same SiteInstance as one of its child |
6844 // frames. | 6763 // frames. |
6845 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 6764 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
6846 NavigateMainFrameToChildSite) { | 6765 NavigateMainFrameToChildSite) { |
6847 GURL main_url(embedded_test_server()->GetURL( | 6766 GURL main_url(embedded_test_server()->GetURL( |
6848 "a.com", "/cross_site_iframe_factory.html?a(b)")); | 6767 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
6849 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 6768 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
6850 | 6769 |
6851 WebContentsImpl* contents = web_contents(); | 6770 WebContentsImpl* contents = web_contents(); |
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7995 child_rfh->OnDispatchLoad(); | 7914 child_rfh->OnDispatchLoad(); |
7996 | 7915 |
7997 // In the bug, OnDispatchLoad killed the b.com renderer. Ensure that this is | 7916 // In the bug, OnDispatchLoad killed the b.com renderer. Ensure that this is |
7998 // not the case. Note that the process kill doesn't happen immediately, so | 7917 // not the case. Note that the process kill doesn't happen immediately, so |
7999 // IsRenderFrameLive() can't be checked here (yet). Instead, check that | 7918 // IsRenderFrameLive() can't be checked here (yet). Instead, check that |
8000 // JavaScript can still execute in b.com using the popup. | 7919 // JavaScript can still execute in b.com using the popup. |
8001 EXPECT_TRUE(ExecuteScript(popup_shell->web_contents(), "true")); | 7920 EXPECT_TRUE(ExecuteScript(popup_shell->web_contents(), "true")); |
8002 } | 7921 } |
8003 | 7922 |
8004 } // namespace content | 7923 } // namespace content |
OLD | NEW |